コード例 #1
0
 public async Task GitHubAuthentication_GetAuthenticationAsync_AuthenticationModesNone_ThrowsException()
 {
     var context = new TestCommandContext();
     var auth    = new GitHubAuthentication(context);
     await Assert.ThrowsAsync <ArgumentException>("modes",
                                                  () => auth.GetAuthenticationAsync(null, null, AuthenticationModes.None)
                                                  );
 }
コード例 #2
0
        public async Task GitHubAuthentication_GetAuthenticationAsync_AuthenticationModesAll_RequiresInteraction()
        {
            var context = new TestCommandContext();

            context.Settings.IsInteractionAllowed = false;
            var auth      = new GitHubAuthentication(context);
            var exception = await Assert.ThrowsAsync <InvalidOperationException>(
                () => auth.GetAuthenticationAsync(new Uri("https://github.com"), null, AuthenticationModes.All)
                );

            Assert.Equal("Cannot prompt because user interactivity has been disabled.", exception.Message);
        }
コード例 #3
0
        public async Task GitHubAuthentication_GetAuthenticationAsync_TerminalPromptsDisabled_Throws()
        {
            var context = new TestCommandContext();

            context.Settings.IsTerminalPromptsEnabled = false;
            var auth      = new GitHubAuthentication(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);
        }
コード例 #4
0
        public async Task GitHubAuthentication_GetAuthenticationAsync_Terminal()
        {
            var context = new TestCommandContext();

            context.FileSystem.Files["/usr/local/bin/GitHub.UI"] = new byte[0];
            context.FileSystem.Files[@"C:\Program Files\Git Credential Manager Core\GitHub.UI.exe"] = new byte[0];
            var auth = new GitHubAuthentication(context);

            context.Terminal.Prompts["option (enter for default)"] = "";
            var result = await auth.GetAuthenticationAsync(null, null, AuthenticationModes.All);

            Assert.Equal(AuthenticationModes.Device, result.AuthenticationMode);
        }
コード例 #5
0
        public async Task GitHubAuthentication_GetAuthenticationAsync_SingleChoice_TerminalAndInteractionNotRequired(GitHub.AuthenticationModes modes)
        {
            var context = new TestCommandContext();

            context.Settings.IsTerminalPromptsEnabled            = false;
            context.Settings.IsInteractionAllowed                = false;
            context.SessionManager.IsDesktopSession              = true; // necessary for browser
            context.FileSystem.Files["/usr/local/bin/GitHub.UI"] = new byte[0];
            context.FileSystem.Files[@"C:\Program Files\Git Credential Manager Core\GitHub.UI.exe"] = new byte[0];
            var auth   = new GitHubAuthentication(context);
            var result = await auth.GetAuthenticationAsync(null, null, modes);

            Assert.Equal(modes, result.AuthenticationMode);
        }
コード例 #6
0
        private static void Delete()
        {
            Trace.WriteLine("Program::Erase");

            string[] args = Environment.GetCommandLineArgs();

            if (args.Length < 3)
            {
                goto error_parse;
            }

            string url = args[2];
            Uri    uri = null;

            if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
                {
                    goto error_parse;
                }
            }
            else
            {
                url = String.Format("{0}://{1}", Uri.UriSchemeHttps, url);
                if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
                {
                    goto error_parse;
                }
            }

            var stdin = Console.OpenStandardInput();
            OperationArguments operationArguments = new OperationArguments(stdin);

            operationArguments.QueryUri = uri;

            LoadOperationArguments(operationArguments);

            BaseAuthentication authentication = CreateAuthentication(operationArguments);

            switch (operationArguments.Authority)
            {
            default:
            case AuthorityType.Basic:
                Trace.WriteLine("   deleting basic credentials");
                authentication.DeleteCredentials(operationArguments.TargetUri);
                break;

            case AuthorityType.AzureDirectory:
            case AuthorityType.MicrosoftAccount:
                Trace.WriteLine("   deleting VSTS credentials");
                BaseVstsAuthentication vstsAuth = authentication as BaseVstsAuthentication;
                vstsAuth.DeleteCredentials(operationArguments.TargetUri);
                // call delete twice to purge any stored ADA tokens
                vstsAuth.DeleteCredentials(operationArguments.TargetUri);
                break;

            case AuthorityType.GitHub:
                Trace.WriteLine("   deleting GitHub credentials");
                GitHubAuthentication ghAuth = authentication as GitHubAuthentication;
                ghAuth.DeleteCredentials(operationArguments.TargetUri);
                break;
            }

            return;

error_parse:
            Console.Error.WriteLine("Fatal: unable to parse target URI.");
        }