Skip to content

Commit 93df27c

Browse files
committed
Reduce casing complexity, loop over options registery, endsWith('sock')
1 parent e46941a commit 93df27c

File tree

3 files changed

+90
-78
lines changed

3 files changed

+90
-78
lines changed

src/cmap/auth/mongo_credentials.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,24 @@ export class MongoCredentials {
138138
}
139139

140140
if (this.mechanism === AuthMechanism.MONGODB_X509 && this.password != null) {
141+
if (this.password === '') {
142+
Reflect.set(this, 'password', undefined);
143+
return;
144+
}
141145
throw new TypeError(`Password not allowed for mechanism MONGODB-X509`);
142146
}
143147
}
148+
149+
static merge(
150+
creds: MongoCredentials,
151+
options: Partial<MongoCredentialsOptions>
152+
): MongoCredentials {
153+
return new MongoCredentials({
154+
username: options.username ?? creds.username,
155+
password: options.password ?? creds.password,
156+
mechanism: options.mechanism ?? creds.mechanism,
157+
mechanismProperties: options.mechanismProperties ?? creds.mechanismProperties,
158+
source: options.source ?? creds.source ?? options.db
159+
});
160+
}
144161
}

0 commit comments

Comments
 (0)