Skip to content

Commit 875c528

Browse files
authored
Improve security config validation (#1154)
Initialize username and password with null to avoid them being `undefined`. With `undefined` value it still works due to `CodecUtil.encodeNullable` logic but it may be confusing. Also, if `token` is not provided in token credentials throw instead of ignoring.
1 parent baa3f35 commit 875c528

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/config/ConfigBuilder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ export class ConfigBuilder {
137137
}
138138

139139
private handleUsernamePasswordCredentials(jsonObject: any): void {
140-
let username: string;
141-
let password: string;
140+
let username: string | null = null;
141+
let password: string | null = null;
142142
for (const key in jsonObject) {
143143
const value = jsonObject[key];
144144
if (key === 'username') {
@@ -168,7 +168,7 @@ export class ConfigBuilder {
168168
}
169169

170170
if (token == null) {
171-
return;
171+
throw new RangeError('\'token\' option must be provided in token credentials.');
172172
}
173173

174174
this.effectiveConfig.security.token = new TokenCredentialsImpl(token, encoding);

test/unit/config/ConfigBuilderTest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,14 @@ describe('ConfigBuilderValidationTest', function () {
570570
}
571571
}
572572
},
573+
// token field is mandatory
574+
{
575+
'security': {
576+
'token': {
577+
'encoding': TokenEncoding.ASCII
578+
}
579+
}
580+
},
573581
{
574582
'security': {
575583
'token': {

0 commit comments

Comments
 (0)