public async Task GitLabAuthentication_GetAuthenticationAsync_AuthenticationModesNone_ThrowsException() { var context = new TestCommandContext(); var auth = new GitLabAuthentication(context); await Assert.ThrowsAsync <ArgumentException>("modes", () => auth.GetAuthenticationAsync(null, null, AuthenticationModes.None) ); }
public async Task GitLabAuthentication_GetAuthenticationAsync_Terminal() { var context = new TestCommandContext(); var auth = new GitLabAuthentication(context); context.SessionManager.IsDesktopSession = true; context.Terminal.Prompts["option (enter for default)"] = ""; var result = await auth.GetAuthenticationAsync(null, null, AuthenticationModes.All); Assert.Equal(AuthenticationModes.Browser, result.AuthenticationMode); }
public async Task GitLabAuthentication_GetAuthenticationAsync_AuthenticationModesAll_RequiresInteraction() { var context = new TestCommandContext(); context.Settings.IsInteractionAllowed = false; var auth = new GitLabAuthentication(context); var exception = await Assert.ThrowsAsync <InvalidOperationException>( () => auth.GetAuthenticationAsync(new Uri("https://GitLab.com"), null, AuthenticationModes.All) ); Assert.Equal("Cannot prompt because user interactivity has been disabled.", exception.Message); }
public async Task GitLabAuthentication_GetAuthenticationAsync_TerminalPromptsDisabled_Throws() { var context = new TestCommandContext(); context.Settings.IsTerminalPromptsEnabled = false; var auth = new GitLabAuthentication(context); var exception = await Assert.ThrowsAsync <InvalidOperationException>( () => auth.GetAuthenticationAsync(null, null, AuthenticationModes.All) ); Assert.Equal("Cannot prompt because terminal prompts have been disabled.", exception.Message); }
public async Task GitLabAuthentication_GetAuthenticationAsync_SingleChoice_TerminalAndInteractionNotRequired(GitLab.AuthenticationModes modes) { var context = new TestCommandContext(); context.Settings.IsTerminalPromptsEnabled = false; context.Settings.IsInteractionAllowed = false; context.SessionManager.IsDesktopSession = true; // necessary for browser var auth = new GitLabAuthentication(context); var result = await auth.GetAuthenticationAsync(null, null, modes); Assert.Equal(modes, result.AuthenticationMode); }
public async Task GitLabAuthentication_GetAuthenticationAsync_ChooseBasic() { var context = new TestCommandContext(); var auth = new GitLabAuthentication(context); context.Terminal.Prompts["option (enter for default)"] = "2"; context.Terminal.Prompts["Username"] = "******"; context.Terminal.SecretPrompts["Password"] = "******"; var result = await auth.GetAuthenticationAsync(null, null, AuthenticationModes.All); Assert.Equal(AuthenticationModes.Basic, result.AuthenticationMode); Assert.Equal("username", result.Credential.Account); Assert.Equal("password", result.Credential.Password); }