File tree Expand file tree Collapse file tree 5 files changed +33
-7
lines changed Expand file tree Collapse file tree 5 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ export interface AuthMechanismProperties extends Document {
58
58
SERVICE_NAME ?: string ;
59
59
SERVICE_REALM ?: string ;
60
60
CANONICALIZE_HOST_NAME ?: GSSAPICanonicalizationValue ;
61
+ /** @internal */
61
62
AWS_SESSION_TOKEN ?: string ;
62
63
/** A user provided OIDC machine callback function. */
63
64
OIDC_CALLBACK ?: OIDCCallbackFunction ;
Original file line number Diff line number Diff line change @@ -56,12 +56,10 @@ export class MongoDBAWS extends AuthProvider {
56
56
) ;
57
57
}
58
58
59
- if ( ! authContext . credentials . username ) {
60
- authContext . credentials = await makeTempCredentials (
61
- authContext . credentials ,
62
- this . credentialFetcher
63
- ) ;
64
- }
59
+ authContext . credentials = await makeTempCredentials (
60
+ authContext . credentials ,
61
+ this . credentialFetcher
62
+ ) ;
65
63
66
64
const { credentials } = authContext ;
67
65
Original file line number Diff line number Diff line change @@ -423,6 +423,18 @@ export function parseOptions(
423
423
) ;
424
424
}
425
425
426
+ if ( isAws ) {
427
+ const { username, password } = mongoOptions . credentials ;
428
+ if ( username || password ) {
429
+ throw new MongoParseError (
430
+ 'username and password cannot be provided when using MONGODB-AWS'
431
+ ) ;
432
+ }
433
+ if ( mongoOptions . credentials . mechanismProperties . AWS_SESSION_TOKEN ) {
434
+ throw new MongoParseError ( 'AWS_SESSION_TOKEN cannot be provided when using MONGODB-AWS' ) ;
435
+ }
436
+ }
437
+
426
438
mongoOptions . credentials . validate ( ) ;
427
439
428
440
// Check if the only auth related option provided was authSource, if so we can remove credentials
Original file line number Diff line number Diff line change 440
440
}
441
441
}
442
442
},
443
+ {
444
+ "description" : " should throw an exception if username provided (MONGODB-AWS) implies default mechanism)" ,
445
+ "uri" : " mongodb://user:localhost.com/" ,
446
+ "valid" : false
447
+ },
448
+ {
449
+ "description" : " should throw an exception if username and password provided (MONGODB-AWS) implies default mechanism)" ,
450
+ "uri" : " mongodb://user@pass:localhost.com/" ,
451
+ "valid" : false
452
+ },
453
+ {
454
+ "description" : " should throw an exception if AWS_SESSION_TOKEN provided (MONGODB-AWS) implies default mechanism)" ,
455
+ "uri" : " mongodb://localhost/?authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:token" ,
456
+ "valid" : false
457
+ },
443
458
{
444
459
"description" : " should recognise the mechanism with test environment (MONGODB-OIDC)" ,
445
460
"uri" : " mongodb://localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:test" ,
Original file line number Diff line number Diff line change @@ -480,4 +480,4 @@ tests:
480
480
(MONGODB-OIDC)
481
481
uri : mongodb://user:pass@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:k8s
482
482
valid : false
483
- credential : null
483
+ credential : null
You can’t perform that action at this time.
0 commit comments