Beispiel #1
0
 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)
                                                  );
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }