From d778f13dee88476bfdd42f0abef74708c9261349 Mon Sep 17 00:00:00 2001 From: Mike Coutermarsh Date: Sun, 15 Dec 2019 18:38:42 -0800 Subject: [PATCH] Remove runner flow: Change from PAT to "deletion token" in prompt (#225) * Updating prompt deletion token Currently if you leave the token off the command, we're showing "Enter your personal access token:" Which won't work. This updates prompt to "deletion token" * Call correct function in test * Fix command text in test --- src/Runner.Listener/CommandSettings.cs | 9 +++++++ .../Configuration/ConfigurationManager.cs | 2 +- src/Test/L0/Listener/CommandSettingsL0.cs | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Runner.Listener/CommandSettings.cs b/src/Runner.Listener/CommandSettings.cs index c9d5e4c17..1d0c999a4 100644 --- a/src/Runner.Listener/CommandSettings.cs +++ b/src/Runner.Listener/CommandSettings.cs @@ -224,6 +224,15 @@ namespace GitHub.Runner.Listener validator: Validators.NonEmptyValidator); } + public string GetRunnerDeletionToken() + { + return GetArgOrPrompt( + name: Constants.Runner.CommandLine.Args.Token, + description: "Enter runner deletion token:", + defaultValue: string.Empty, + validator: Validators.NonEmptyValidator); + } + public string GetUrl(bool suppressPromptIfEmpty = false) { // Note, GetArg does not consume the arg (like GetArgOrPrompt does). diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index df394ac2e..b24912c05 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -443,7 +443,7 @@ namespace GitHub.Runner.Listener.Configuration } else { - var githubToken = command.GetToken(); + var githubToken = command.GetRunnerDeletionToken(); GitHubAuthResult authResult = await GetTenantCredential(settings.GitHubUrl, githubToken); creds = authResult.ToVssCredentials(); Trace.Info("cred retrieved via GitHub auth"); diff --git a/src/Test/L0/Listener/CommandSettingsL0.cs b/src/Test/L0/Listener/CommandSettingsL0.cs index cdfcadfb7..a6ba943ff 100644 --- a/src/Test/L0/Listener/CommandSettingsL0.cs +++ b/src/Test/L0/Listener/CommandSettingsL0.cs @@ -513,6 +513,33 @@ namespace GitHub.Runner.Common.Tests } } + [Fact] + [Trait("Level", "L0")] + [Trait("Category", nameof(CommandSettings))] + public void PromptsForRunnerDeletionToken() + { + using (TestHostContext hc = CreateTestContext()) + { + // Arrange. + var command = new CommandSettings(hc, args: new string[0]); + _promptManager + .Setup(x => x.ReadValue( + Constants.Runner.CommandLine.Args.Token, // argName + "Enter runner deletion token:", // description + true, // secret + string.Empty, // defaultValue + Validators.NonEmptyValidator, // validator + false)) // unattended + .Returns("some token"); + + // Act. + string actual = command.GetRunnerDeletionToken(); + + // Assert. + Assert.Equal("some token", actual); + } + } + [Fact] [Trait("Level", "L0")] [Trait("Category", nameof(CommandSettings))]