@@ -983,5 +983,98 @@ public async Task TestRunnerJobRequestMessageFromRunService_AuthMigrationFallbac
983
983
Assert . False ( hc . AllowAuthMigration ) ;
984
984
}
985
985
}
986
+
987
+ [ Fact ]
988
+ [ Trait ( "Level" , "L0" ) ]
989
+ [ Trait ( "Category" , "Runner" ) ]
990
+ public async Task TestRunnerEnableAuthMigrationByDefault ( )
991
+ {
992
+ using ( var hc = new TestHostContext ( this ) )
993
+ {
994
+ //Arrange
995
+ var runner = new Runner . Listener . Runner ( ) ;
996
+ hc . SetSingleton < IConfigurationManager > ( _configurationManager . Object ) ;
997
+ hc . SetSingleton < IJobNotification > ( _jobNotification . Object ) ;
998
+ hc . SetSingleton < IMessageListener > ( _messageListener . Object ) ;
999
+ hc . SetSingleton < IPromptManager > ( _promptManager . Object ) ;
1000
+ hc . SetSingleton < IConfigurationStore > ( _configStore . Object ) ;
1001
+ hc . SetSingleton < ICredentialManager > ( _credentialManager . Object ) ;
1002
+ hc . SetSingleton < IRunnerServer > ( _runnerServer . Object ) ;
1003
+ hc . EnqueueInstance < IErrorThrottler > ( _acquireJobThrottler . Object ) ;
1004
+
1005
+ runner . Initialize ( hc ) ;
1006
+ var settings = new RunnerSettings
1007
+ {
1008
+ PoolId = 43242 ,
1009
+ AgentId = 5678 ,
1010
+ Ephemeral = true ,
1011
+ ServerUrl = "https://github.com" ,
1012
+ } ;
1013
+
1014
+ var message1 = new TaskAgentMessage ( )
1015
+ {
1016
+ Body = JsonUtility . ToString ( new RunnerJobRequestRef ( ) { BillingOwnerId = "github" , RunnerRequestId = "999" , RunServiceUrl = "https://run-service.com" } ) ,
1017
+ MessageId = 4234 ,
1018
+ MessageType = JobRequestMessageTypes . RunnerJobRequest
1019
+ } ;
1020
+
1021
+ var messages = new Queue < TaskAgentMessage > ( ) ;
1022
+ messages . Enqueue ( message1 ) ;
1023
+ messages . Enqueue ( message1 ) ;
1024
+ _updater . Setup ( x => x . SelfUpdate ( It . IsAny < AgentRefreshMessage > ( ) , It . IsAny < IJobDispatcher > ( ) , It . IsAny < bool > ( ) , It . IsAny < CancellationToken > ( ) ) )
1025
+ . Returns ( Task . FromResult ( true ) ) ;
1026
+ _configurationManager . Setup ( x => x . LoadSettings ( ) )
1027
+ . Returns ( settings ) ;
1028
+ _configurationManager . Setup ( x => x . IsConfigured ( ) )
1029
+ . Returns ( true ) ;
1030
+ _messageListener . Setup ( x => x . CreateSessionAsync ( It . IsAny < CancellationToken > ( ) ) )
1031
+ . Returns ( Task . FromResult < CreateSessionResult > ( CreateSessionResult . Failure ) ) ;
1032
+ _jobNotification . Setup ( x => x . StartClient ( It . IsAny < String > ( ) ) )
1033
+ . Callback ( ( ) =>
1034
+ {
1035
+
1036
+ } ) ;
1037
+
1038
+ var throwError = true ;
1039
+ _runServer . Setup ( x => x . GetJobMessageAsync ( "999" , "github" , It . IsAny < CancellationToken > ( ) ) )
1040
+ . Returns ( ( ) =>
1041
+ {
1042
+ if ( throwError )
1043
+ {
1044
+ Assert . True ( hc . AllowAuthMigration ) ;
1045
+ throwError = false ;
1046
+ throw new NotSupportedException ( "some error" ) ;
1047
+ }
1048
+
1049
+ return Task . FromResult ( CreateJobRequestMessage ( "test" ) ) ;
1050
+ } ) ;
1051
+
1052
+ _credentialManager . Setup ( x => x . LoadCredentials ( true ) ) . Returns ( new VssCredentials ( ) ) ;
1053
+
1054
+ _configStore . Setup ( x => x . IsServiceConfigured ( ) ) . Returns ( false ) ;
1055
+
1056
+ var credData = new CredentialData ( )
1057
+ {
1058
+ Scheme = Constants . Configuration . OAuth ,
1059
+ } ;
1060
+ credData . Data [ "ClientId" ] = "testClientId" ;
1061
+ credData . Data [ "AuthUrl" ] = "https://github.com" ;
1062
+ credData . Data [ "EnableAuthMigrationByDefault" ] = "true" ;
1063
+ _configStore . Setup ( x => x . GetCredentials ( ) ) . Returns ( credData ) ;
1064
+
1065
+ Assert . False ( hc . AllowAuthMigration ) ;
1066
+
1067
+ //Act
1068
+ var command = new CommandSettings ( hc , new string [ ] { "run" } ) ;
1069
+ var returnCode = await runner . ExecuteCommand ( command ) ;
1070
+
1071
+ //Assert
1072
+ Assert . Equal ( Constants . Runner . ReturnCode . TerminatedError , returnCode ) ;
1073
+
1074
+ _messageListener . Verify ( x => x . CreateSessionAsync ( It . IsAny < CancellationToken > ( ) ) , Times . Once ( ) ) ;
1075
+
1076
+ Assert . True ( hc . AllowAuthMigration ) ;
1077
+ }
1078
+ }
986
1079
}
987
1080
}
0 commit comments