@@ -236,6 +236,7 @@ public void TestEvaluateOptionsProvidedAliasWithEnvVarConfig()
236236
237237 // Specify config via env var
238238 this . envMock . Setup ( e => e . Get ( "AZUREAUTH_CONFIG" ) ) . Returns ( configFile ) ;
239+ this . envMock . Setup ( env => env . Get ( It . Is < string > ( key => key != "AZUREAUTH_CONFIG" ) ) ) . Returns < string > ( key => null ) ;
239240
240241 // Specify a client override on the command line.
241242 subject . Client = clientOverride ;
@@ -444,6 +445,72 @@ public void TestEvaluateOptionsWithoutAliasValidCommandLineOptions()
444445 subject . TokenFetcherOptions . Should ( ) . BeEquivalentTo ( expected ) ;
445446 }
446447
448+ [ Test ]
449+ public void TestEvaluateOptionsWithAuthModeFromCommandLineOptions ( )
450+ {
451+ CommandAad subject = this . serviceProvider . GetService < CommandAad > ( ) ;
452+ subject . Resource = "f0e8d801-3a50-48fd-b2da-6476d6e832a2" ;
453+ subject . Client = "e19f71ed-3b14-448d-9346-9eff9753646b" ;
454+ subject . Tenant = "9f6227ee-3d14-473e-8bed-1281171ef8c9" ;
455+ subject . AuthModes = new List < AuthMode > ( ) { AuthMode . DeviceCode } ;
456+
457+ this . envMock . Setup ( env => env . Get ( EnvVars . AuthMode ) ) . Returns ( "Web,DeviceCode" ) ;
458+ subject . EvaluateOptions ( ) . Should ( ) . BeTrue ( ) ;
459+ subject . AuthModes . Should ( ) . Contain ( new [ ] { AuthMode . DeviceCode } ) ;
460+ }
461+
462+ [ Test ]
463+ public void TestEvaluateOptionsWithAuthModeFromEnvVar ( )
464+ {
465+ CommandAad subject = this . serviceProvider . GetService < CommandAad > ( ) ;
466+ subject . Resource = "f0e8d801-3a50-48fd-b2da-6476d6e832a2" ;
467+ subject . Client = "e19f71ed-3b14-448d-9346-9eff9753646b" ;
468+ subject . Tenant = "9f6227ee-3d14-473e-8bed-1281171ef8c9" ;
469+
470+ this . envMock . Setup ( env => env . Get ( "AZUREAUTH_MODE" ) ) . Returns ( "Web,DeviceCode" ) ;
471+ subject . EvaluateOptions ( ) . Should ( ) . BeTrue ( ) ;
472+ subject . AuthModes . Should ( ) . Contain ( new [ ] { AuthMode . Web , AuthMode . DeviceCode } ) ;
473+ }
474+
475+ [ Test ]
476+ public void TestEvaluateOptionsWithNoAuthModeInEnvVarOrOptions ( )
477+ {
478+ CommandAad subject = this . serviceProvider . GetService < CommandAad > ( ) ;
479+ subject . Resource = "f0e8d801-3a50-48fd-b2da-6476d6e832a2" ;
480+ subject . Client = "e19f71ed-3b14-448d-9346-9eff9753646b" ;
481+ subject . Tenant = "9f6227ee-3d14-473e-8bed-1281171ef8c9" ;
482+
483+ this . envMock . Setup ( env => env . Get ( It . IsAny < string > ( ) ) ) . Returns ( ( string ) null ) ;
484+ subject . EvaluateOptions ( ) . Should ( ) . BeTrue ( ) ;
485+ subject . AuthModes . Should ( ) . Contain ( new [ ] { AuthMode . Default } ) ;
486+ }
487+
488+ [ Test ]
489+ public void TestEvaluateOptionsWithAuthModeFromInvalidEnvVars ( )
490+ {
491+ CommandAad subject = this . serviceProvider . GetService < CommandAad > ( ) ;
492+ subject . Resource = "f0e8d801-3a50-48fd-b2da-6476d6e832a2" ;
493+ subject . Client = "e19f71ed-3b14-448d-9346-9eff9753646b" ;
494+ subject . Tenant = "9f6227ee-3d14-473e-8bed-1281171ef8c9" ;
495+
496+ this . envMock . Setup ( env => env . Get ( EnvVars . AuthMode ) ) . Returns ( "Invalid" ) ;
497+ subject . EvaluateOptions ( ) . Should ( ) . BeFalse ( ) ;
498+ this . logTarget . Logs . Should ( ) . ContainMatch ( $ "Invalid value specified for environment variable { EnvVars . AuthMode } *") ;
499+ }
500+
501+ [ Test ]
502+ public void TestEvaluateOptionsWithAuthModeFromEmptyEnvVars ( )
503+ {
504+ CommandAad subject = this . serviceProvider . GetService < CommandAad > ( ) ;
505+ subject . Resource = "f0e8d801-3a50-48fd-b2da-6476d6e832a2" ;
506+ subject . Client = "e19f71ed-3b14-448d-9346-9eff9753646b" ;
507+ subject . Tenant = "9f6227ee-3d14-473e-8bed-1281171ef8c9" ;
508+
509+ this . envMock . Setup ( env => env . Get ( EnvVars . AuthMode ) ) . Returns ( "" ) ;
510+ subject . EvaluateOptions ( ) . Should ( ) . BeTrue ( ) ;
511+ subject . AuthModes . Should ( ) . Contain ( new [ ] { AuthMode . Default } ) ;
512+ }
513+
447514 /// <summary>
448515 /// The root path.
449516 /// </summary>
0 commit comments