Ejemplo n.º 1
0
        public CommandContext()
        {
            Streams = new StandardStreams();
            Trace   = new Trace();
            Git     = new LibGit2(Trace);

            if (PlatformUtils.IsWindows())
            {
                FileSystem      = new WindowsFileSystem();
                Environment     = new WindowsEnvironment(FileSystem);
                Terminal        = new WindowsTerminal(Trace);
                CredentialStore = WindowsCredentialManager.Open();
            }
            else if (PlatformUtils.IsPosix())
            {
                if (PlatformUtils.IsMacOS())
                {
                    FileSystem      = new MacOSFileSystem();
                    CredentialStore = MacOSKeychain.Open();
                }
                else if (PlatformUtils.IsLinux())
                {
                    throw new NotImplementedException();
                }

                Environment = new PosixEnvironment(FileSystem);
                Terminal    = new PosixTerminal(Trace);
            }

            string repoPath = Git.GetRepositoryPath(FileSystem.GetCurrentDirectory());

            Settings          = new Settings(Environment, Git, repoPath);
            HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams);
        }
Ejemplo n.º 2
0
        public void WindowsCredentialManager_AddOrUpdate_UsernameWithAtCharacter()
        {
            WindowsCredentialManager credManager = WindowsCredentialManager.Open(TestNamespace);

            // Create a service that is guaranteed to be unique
            string       uniqueGuid = Guid.NewGuid().ToString("N");
            string       service    = $"https://example.com/{uniqueGuid}";
            const string userName   = "******";
            const string password   = "******";

            string expectedTargetName = $"{TestNamespace}:https://example.com/{uniqueGuid}";

            try
            {
                // Write
                credManager.AddOrUpdate(service, userName, password);

                // Read
                ICredential cred = credManager.Get(service, userName);

                // Validate
                var winCred = cred as WindowsCredential;
                Assert.NotNull(winCred);
                Assert.Equal(userName, winCred.UserName);
                Assert.Equal(password, winCred.Password);
                Assert.Equal(service, winCred.Service);
                Assert.Equal(expectedTargetName, winCred.TargetName);
            }
            finally
            {
                // Ensure we clean up after ourselves even in case of 'get' failures
                credManager.Remove(service, userName);
            }
        }
Ejemplo n.º 3
0
        public CommandContext()
        {
            Streams    = new StandardStreams();
            Trace      = new Trace();
            FileSystem = new FileSystem();

            var git    = new LibGit2();
            var envars = new EnvironmentVariables(Environment.GetEnvironmentVariables());

            Settings = new Settings(envars, git)
            {
                RepositoryPath = git.GetRepositoryPath(FileSystem.GetCurrentDirectory())
            };

            HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams);

            if (PlatformUtils.IsWindows())
            {
                Terminal        = new WindowsTerminal(Trace);
                CredentialStore = WindowsCredentialManager.Open();
            }
            else if (PlatformUtils.IsPosix())
            {
                Terminal = new PosixTerminal(Trace);

                if (PlatformUtils.IsMacOS())
                {
                    CredentialStore = MacOSKeychain.Open();
                }
                else if (PlatformUtils.IsLinux())
                {
                    throw new NotImplementedException();
                }
            }
        }
        public void WindowsCredentialManager_ReadWriteDelete()
        {
            WindowsCredentialManager credManager = WindowsCredentialManager.Open();

            // Create a key that is guarenteed to be unique
            string       key        = $"secretkey-{Guid.NewGuid():N}";
            const string userName   = "******";
            const string password   = "******";
            var          credential = new GitCredential(userName, password);

            try
            {
                // Write
                credManager.AddOrUpdate(key, credential);

                // Read
                ICredential outCredential = credManager.Get(key);

                Assert.NotNull(outCredential);
                Assert.Equal(credential.UserName, outCredential.UserName);
                Assert.Equal(credential.Password, outCredential.Password);
            }
            finally
            {
                // Ensure we clean up after ourselves even in case of 'get' failures
                credManager.Remove(key);
            }
        }
Ejemplo n.º 5
0
        public void WindowsCredentialManager_Remove_KeyNotFound_ReturnsFalse()
        {
            WindowsCredentialManager credManager = WindowsCredentialManager.Open(TestNamespace);

            // Unique service; guaranteed not to exist!
            string service = Guid.NewGuid().ToString("N");

            bool result = credManager.Remove(service, account: null);

            Assert.False(result);
        }
Ejemplo n.º 6
0
        public void WindowsCredentialManager_Get_KeyNotFound_ReturnsNull()
        {
            WindowsCredentialManager credManager = WindowsCredentialManager.Open(TestNamespace);

            // Unique service; guaranteed not to exist!
            string service = Guid.NewGuid().ToString("N");

            ICredential credential = credManager.Get(service, account: null);

            Assert.Null(credential);
        }
        public void WindowsCredentialManager_Remove_KeyNotFound_ReturnsFalse()
        {
            WindowsCredentialManager credManager = WindowsCredentialManager.Open();

            // Unique key; guaranteed not to exist!
            string key = Guid.NewGuid().ToString("N");

            bool result = credManager.Remove(key);

            Assert.False(result);
        }
        public void WindowsCredentialManager_Get_KeyNotFound_ReturnsNull()
        {
            WindowsCredentialManager credManager = WindowsCredentialManager.Open();

            // Unique key; guaranteed not to exist!
            string key = Guid.NewGuid().ToString("N");

            ICredential credential = credManager.Get(key);

            Assert.Null(credential);
        }
Ejemplo n.º 9
0
        public void WindowsCredentialManager_AddOrUpdate_TargetNameAlreadyExistsAndUserWithAtCharacter_CreatesWithEscapedUserInTargetName()
        {
            WindowsCredentialManager credManager = WindowsCredentialManager.Open(TestNamespace);

            // Create a service that is guaranteed to be unique
            string       uniqueGuid       = Guid.NewGuid().ToString("N");
            string       service          = $"https://example.com/{uniqueGuid}";
            const string userName1        = "*****@*****.**";
            const string userName2        = "*****@*****.**";
            const string escapedUserName2 = "jane.doe_auth.com";
            const string password1        = "letmein123";
            const string password2        = "password123";

            string expectedTargetName1 = $"{TestNamespace}:https://example.com/{uniqueGuid}";
            string expectedTargetName2 = $"{TestNamespace}:https://{escapedUserName2}@example.com/{uniqueGuid}";

            try
            {
                // Add first credential
                credManager.AddOrUpdate(service, userName1, password1);

                // Add second credential
                credManager.AddOrUpdate(service, userName2, password2);

                // Validate first credential properties
                ICredential cred1    = credManager.Get(service, userName1);
                var         winCred1 = cred1 as WindowsCredential;
                Assert.NotNull(winCred1);
                Assert.Equal(userName1, winCred1.UserName);
                Assert.Equal(password1, winCred1.Password);
                Assert.Equal(service, winCred1.Service);
                Assert.Equal(expectedTargetName1, winCred1.TargetName);

                // Validate second credential properties
                ICredential cred2    = credManager.Get(service, userName2);
                var         winCred2 = cred2 as WindowsCredential;
                Assert.NotNull(winCred2);
                Assert.Equal(userName2, winCred2.UserName);
                Assert.Equal(password2, winCred2.Password);
                Assert.Equal(service, winCred2.Service);
                Assert.Equal(expectedTargetName2, winCred2.TargetName);
            }
            finally
            {
                // Ensure we clean up after ourselves in case of failures
                credManager.Remove(service, userName1);
                credManager.Remove(service, userName2);
            }
        }
Ejemplo n.º 10
0
        public CommandContext()
        {
            Streams = new StandardStreams();
            Trace   = new Trace();

            if (PlatformUtils.IsWindows())
            {
                FileSystem     = new WindowsFileSystem();
                SessionManager = new WindowsSessionManager();
                SystemPrompts  = new WindowsSystemPrompts();
                Environment    = new WindowsEnvironment(FileSystem);
                Terminal       = new WindowsTerminal(Trace);
                Git            = new GitProcess(
                    Trace,
                    Environment.LocateExecutable("git.exe"),
                    FileSystem.GetCurrentDirectory()
                    );
                Settings        = new Settings(Environment, Git);
                CredentialStore = WindowsCredentialManager.Open(Settings.CredentialNamespace);
            }
            else if (PlatformUtils.IsMacOS())
            {
                FileSystem     = new MacOSFileSystem();
                SessionManager = new MacOSSessionManager();
                SystemPrompts  = new MacOSSystemPrompts();
                Environment    = new PosixEnvironment(FileSystem);
                Terminal       = new PosixTerminal(Trace);
                Git            = new GitProcess(
                    Trace,
                    Environment.LocateExecutable("git"),
                    FileSystem.GetCurrentDirectory()
                    );
                Settings        = new Settings(Environment, Git);
                CredentialStore = MacOSKeychain.Open(Settings.CredentialNamespace);
            }
            else if (PlatformUtils.IsLinux())
            {
                FileSystem = new LinuxFileSystem();
                // TODO: support more than just 'Posix' or X11
                SessionManager = new PosixSessionManager();
                SystemPrompts  = new LinuxSystemPrompts();
                Environment    = new PosixEnvironment(FileSystem);
                Terminal       = new PosixTerminal(Trace);
                Git            = new GitProcess(
                    Trace,
                    Environment.LocateExecutable("git"),
                    FileSystem.GetCurrentDirectory()
                    );
                Settings        = new Settings(Environment, Git);
                CredentialStore = new LinuxCredentialStore(Settings, Git, Settings.CredentialNamespace);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }

            HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams);

            // Set the parent window handle/ID
            SystemPrompts.ParentWindowId = Settings.ParentWindowId;
        }