Skip to content

Commit 10302b9

Browse files
authored
Merge branch 'main' into pje/proto-check_run_id
2 parents cb4e6e7 + 1c319b4 commit 10302b9

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

src/Runner.Common/HostContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void EnableAuthMigration(string trace)
268268
}
269269
}
270270

271-
_trace.Info($"Enable auth migration at {_deferredAuthMigrationTime.ToString("O")}.");
271+
_trace.Info($"Enable auth migration at {DateTime.UtcNow.ToString("O")}.");
272272
AuthMigrationChanged?.Invoke(this, new AuthMigrationEventArgs(trace));
273273
}
274274

src/Runner.Listener/Runner.cs

+9
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ public async Task<int> ExecuteCommand(CommandSettings command)
309309
_term.WriteLine("https://docs.github.com/en/actions/hosting-your-own-runners/autoscaling-with-self-hosted-runners#using-ephemeral-runners-for-autoscaling", ConsoleColor.Yellow);
310310
}
311311

312+
var cred = store.GetCredentials();
313+
if (cred != null &&
314+
cred.Scheme == Constants.Configuration.OAuth &&
315+
cred.Data.ContainsKey("EnableAuthMigrationByDefault"))
316+
{
317+
Trace.Info("Enable auth migration by default.");
318+
HostContext.EnableAuthMigration("EnableAuthMigrationByDefault");
319+
}
320+
312321
// Run the runner interactively or as service
313322
return await RunAsync(settings, command.RunOnce || settings.Ephemeral);
314323
}

src/Test/L0/Listener/RunnerL0.cs

+93
Original file line numberDiff line numberDiff line change
@@ -983,5 +983,98 @@ public async Task TestRunnerJobRequestMessageFromRunService_AuthMigrationFallbac
983983
Assert.False(hc.AllowAuthMigration);
984984
}
985985
}
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+
}
9861079
}
9871080
}

0 commit comments

Comments
 (0)