Beispiel #1
0
        public void TwoThreadsInterleavingFailuresStillRetriesOnce()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string thread1Auth;
            string thread2Auth;
            string error;

            // Populate an initial PAT on two threads
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);

            // Simulate a 401 error on one threads
            dut.RevokeAndCheckCanRetry(thread1Auth).ShouldEqual(true);

            // That thread then retries
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);

            // The second thread fails with the old PAT
            dut.RevokeAndCheckCanRetry(thread2Auth).ShouldEqual(true);

            // The second thread should be able to get a PAT
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);
        }
        public void TwoThreadsInterleavingFailuresStillRetriesOnce()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = this.GetGitProcess();

            GitAuthentication dut = new GitAuthentication(gitProcess, "mock://repoUrl");

            dut.TryInitializeAndRequireAuth(tracer, out _);

            string thread1Auth;
            string thread2Auth;
            string error;

            // Populate an initial PAT on two threads
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);

            // Simulate a 401 error on one threads
            dut.Revoke(thread1Auth);

            // That thread then retries
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);

            // The second thread fails with the old PAT
            dut.Revoke(thread2Auth);

            // The second thread should be able to get a PAT
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true, error);
        }
        private MockGitProcess GetGitProcess()
        {
            MockGitProcess gitProcess = new MockGitProcess();

            gitProcess.SetExpectedCommandResult("config gvfs.FunctionalTests.UserName", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.GenericFailureCode));
            gitProcess.SetExpectedCommandResult("config gvfs.FunctionalTests.Password", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.GenericFailureCode));

            if (this.sslSettingsPresent)
            {
                gitProcess.SetExpectedCommandResult("config --get-urlmatch http mock://repoUrl", () => new GitProcess.Result($"http.sslCert {CertificatePath}\nhttp.sslCertPasswordProtected true\n\n", string.Empty, GitProcess.Result.SuccessCode));
            }
            else
            {
                gitProcess.SetExpectedCommandResult("config --get-urlmatch http mock://repoUrl", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
            }

            int revocations = 0;

            gitProcess.SetExpectedCommandResult(
                "-c credential.useHttpPath=true credential fill",
                () => new GitProcess.Result("username=username\r\npassword=password" + revocations + "\r\n", string.Empty, GitProcess.Result.SuccessCode));

            gitProcess.SetExpectedCommandResult(
                "credential reject",
                () =>
            {
                revocations++;
                return(new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
            });
            return(gitProcess);
        }
Beispiel #4
0
        public void TwoThreadsFailAtOnceStillRetriesOnce()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = this.GetGitProcess();

            GitAuthentication dut = new GitAuthentication(gitProcess, "mock://repoUrl");

            dut.TryInitializeAndRequireAuth(tracer, out _);

            string authString;
            string error;

            // Populate an initial PAT on two threads
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true);
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true);

            // Simulate a 401 error on two threads
            dut.RejectCredentials(tracer, authString);
            dut.RejectCredentials(tracer, authString);
            gitProcess.CredentialRejections["mock://repoUrl"].Count.ShouldEqual(1);
            gitProcess.CredentialRejections["mock://repoUrl"][0].BasicAuthString.ShouldEqual(authString);

            // Both threads should still be able to get a PAT for retry purposes
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "The second thread caused back off when it shouldn't");
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true);
        }
        public void TwoThreadsInterleavingFailuresShouldntStompASuccess()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = this.GetGitProcess();

            GitAuthentication dut = new GitAuthentication(gitProcess, "mock://repoUrl");

            dut.TryInitializeAndRequireAuth(tracer, out _);

            string thread1Auth;
            string thread2Auth;
            string error;

            // Populate an initial PAT on two threads
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);

            // Simulate a 401 error on one threads
            dut.Revoke(thread1Auth);

            // That thread then retries and succeeds
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);
            dut.ConfirmCredentialsWorked(thread1Auth);

            // If the second thread fails with the old PAT, it shouldn't stomp the new PAT
            dut.Revoke(thread2Auth);

            // The second thread should be able to get a PAT
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);
            thread2Auth.ShouldEqual(thread1Auth, "The second thread stomp the first threads good auth string");
        }
Beispiel #6
0
        public void TwoThreadsInterleavingFailuresStillRetriesOnce()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = this.GetGitProcess();

            GitAuthentication dut = new GitAuthentication(gitProcess, "mock://repoUrl");

            dut.TryInitializeAndRequireAuth(tracer, out _);

            string thread1Auth;
            string thread1AuthRetry;
            string thread2Auth;
            string thread2AuthRetry;
            string error;

            // Populate an initial PAT on two threads
            dut.TryGetCredentials(tracer, out thread1Auth, out error).ShouldEqual(true);
            dut.TryGetCredentials(tracer, out thread2Auth, out error).ShouldEqual(true);

            // Simulate a 401 error on one threads
            dut.RejectCredentials(tracer, thread1Auth);
            gitProcess.CredentialRejections["mock://repoUrl"].Count.ShouldEqual(1);
            gitProcess.CredentialRejections["mock://repoUrl"][0].BasicAuthString.ShouldEqual(thread1Auth);

            // That thread then retries
            dut.TryGetCredentials(tracer, out thread1AuthRetry, out error).ShouldEqual(true);

            // The second thread fails with the old PAT
            dut.RejectCredentials(tracer, thread2Auth);
            gitProcess.CredentialRejections["mock://repoUrl"].Count.ShouldEqual(1, "Should not have rejected a second time");
            gitProcess.CredentialRejections["mock://repoUrl"][0].BasicAuthString.ShouldEqual(thread1Auth, "Should only have rejected thread1's initial credential");

            // The second thread should be able to get a PAT
            dut.TryGetCredentials(tracer, out thread2AuthRetry, out error).ShouldEqual(true, error);
        }
Beispiel #7
0
        public void AuthShouldBackoffAfterFirstRetryFailure()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = this.GetGitProcess();

            GitAuthentication dut = new GitAuthentication(gitProcess, "mock://repoUrl");

            dut.TryInitializeAndRequireAuth(tracer, out _);

            string authString;
            string error;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get initial credential");

            dut.RejectCredentials(tracer, authString);
            dut.IsBackingOff.ShouldEqual(false, "Should not backoff after credentials initially rejected");
            gitProcess.CredentialRejections["mock://repoUrl"].Count.ShouldEqual(1);

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to retry getting credential on iteration");
            dut.IsBackingOff.ShouldEqual(false, "Should not backoff after successfully getting credentials");

            dut.RejectCredentials(tracer, authString);
            dut.IsBackingOff.ShouldEqual(true, "Should continue to backoff after rejecting credentials");
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "TryGetCredential should not succeed during backoff");
            gitProcess.CredentialRejections["mock://repoUrl"].Count.ShouldEqual(2);
        }
Beispiel #8
0
        public void ContinuesToBackoffIfTryGetCredentialsFails()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = this.GetGitProcess();

            GitAuthentication dut = new GitAuthentication(gitProcess, "mock://repoUrl");

            dut.TryInitializeAndRequireAuth(tracer, out _);

            string authString;
            string error;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get initial credential");
            dut.RejectCredentials(tracer, authString);
            gitProcess.CredentialRejections["mock://repoUrl"].Count.ShouldEqual(1);

            gitProcess.ShouldFail = true;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "Succeeded despite GitProcess returning failure");
            dut.IsBackingOff.ShouldEqual(true, "Should continue to backoff if failed to get credentials");

            dut.RejectCredentials(tracer, authString);
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "TryGetCredential should not succeed during backoff");
            dut.IsBackingOff.ShouldEqual(true, "Should continue to backoff if failed to get credentials");
            gitProcess.CredentialRejections["mock://repoUrl"].Count.ShouldEqual(1);
        }
 public TestScalarEnlistment()
     : base("mock:\\path", "mock:\\path", "mock://repoUrl", "mock:\\git", authentication: null)
 {
     this.gitProcess = new MockGitProcess();
     this.gitProcess.SetExpectedCommandResult(
         "config --local scalar.enlistment-id",
         () => new GitProcess.Result(EnlistmentId, string.Empty, GitProcess.Result.SuccessCode));
 }
Beispiel #10
0
 public void TearDown()
 {
     this.fileSystem          = null;
     this.gitProcess          = null;
     this.context             = null;
     this.gitParentPath       = null;
     this.gvfsMetadataPath    = null;
     this.enlistmentDirectory = null;
 }
Beispiel #11
0
 public void Setup()
 {
     this.tracer                  = new MockTracer();
     this.gitProcess              = new MockGitProcess();
     this.mockDirectory           = new MockDirectory("mock://root", null, null);
     this.fileSystem              = new MockFileSystem(this.mockDirectory);
     this.certificateVerifierMock = new Mock <CertificateVerifier>();
     this.certificateStoreMock    = new Mock <SystemCertificateStore>();
 }
Beispiel #12
0
        public void DetectsFailuresInDiffTree()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = new MockGitProcess();

            gitProcess.SetExpectedCommandResult("diff-tree -r -t sha1 sha2", () => new GitProcess.Result(string.Empty, string.Empty, 1));

            DiffHelper diffBackwards = new DiffHelper(tracer, new Mock.Common.MockGVFSEnlistment(), gitProcess, new List <string>(), new List <string>());

            diffBackwards.PerformDiff("sha1", "sha2");
            diffBackwards.HasFailures.ShouldEqual(true);
        }
Beispiel #13
0
        public void DetectsFailuresInLsTree()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = new MockGitProcess();

            gitProcess.SetExpectedCommandResult("ls-tree -r -t sha1", () => new GitProcess.Result(string.Empty, string.Empty, 1));

            DiffHelper diffBackwards = new DiffHelper(tracer, new Mock.Common.MockGSDEnlistment(), gitProcess, new List <string>(), new List <string>(), includeSymLinks: this.IncludeSymLinks);

            diffBackwards.PerformDiff(null, "sha1");
            diffBackwards.HasFailures.ShouldEqual(true);
        }
Beispiel #14
0
        public void DetectsFailuresInLsTree()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = new MockGitProcess(new ConfigurableFileSystem());

            gitProcess.SetExpectedCommandResult("ls-tree -r -t sha1", () => new GitProcess.Result(string.Empty, string.Empty, 1));

            DiffHelper diffBackwards = new DiffHelper(tracer, new MockEnlistment(), gitProcess, new List <string>(), new List <string>());

            diffBackwards.PerformDiff(null, "sha1");
            diffBackwards.HasFailures.ShouldEqual(true);
        }
Beispiel #15
0
        private MockGVFSEnlistment CreateEnlistment(string newConfigValue = null, string oldConfigValue = null)
        {
            MockGitProcess gitProcess = new MockGitProcess();

            gitProcess.SetExpectedCommandResult(
                "config --local gvfs.cache-server",
                () => new GitProcess.Result(newConfigValue ?? string.Empty, string.Empty, newConfigValue != null ? GitProcess.Result.SuccessCode : GitProcess.Result.GenericFailureCode));
            gitProcess.SetExpectedCommandResult(
                "config gvfs.mock:..repourl.cache-server-url",
                () => new GitProcess.Result(oldConfigValue ?? string.Empty, string.Empty, oldConfigValue != null ? GitProcess.Result.SuccessCode : GitProcess.Result.GenericFailureCode));

            return(new MockGVFSEnlistment(gitProcess));
        }
        private void TestSetup()
        {
            this.gitProcess = new MockGitProcess();

            // Create enlistment using git process
            GVFSEnlistment enlistment = new MockGVFSEnlistment(this.gitProcess);

            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, null, null));

            // Create and return Context
            this.tracer = new MockTracer();
            this.context = new GVFSContext(this.tracer, fileSystem, repository: null, enlistment: enlistment);
        }
Beispiel #17
0
        public void TryLoadConfigFailsWhenGitFailsToReadConfig()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = new MockGitProcess();

            gitProcess.SetExpectedCommandResult("config gvfs.max-retries", () => new GitProcess.Result(string.Empty, ReadConfigFailureMessage, GitProcess.Result.GenericFailureCode));
            gitProcess.SetExpectedCommandResult("config gvfs.timeout-seconds", () => new GitProcess.Result(string.Empty, ReadConfigFailureMessage, GitProcess.Result.GenericFailureCode));

            RetryConfig config;
            string      error;

            RetryConfig.TryLoadFromGitConfig(tracer, gitProcess, out config, out error).ShouldEqual(false);
            error.ShouldContain(ReadConfigFailureMessage);
        }
Beispiel #18
0
        public void TryLoadConfigEnforcesMinimumValuesOnTimeout()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = new MockGitProcess();

            gitProcess.SetExpectedCommandResult("config gvfs.max-retries", () => new GitProcess.Result("3", string.Empty, GitProcess.Result.SuccessCode));
            gitProcess.SetExpectedCommandResult("config gvfs.timeout-seconds", () => new GitProcess.Result("-1", string.Empty, GitProcess.Result.SuccessCode));

            RetryConfig config;
            string      error;

            RetryConfig.TryLoadFromGitConfig(tracer, gitProcess, out config, out error).ShouldEqual(false);
            error.ShouldContain("Invalid value -1 for setting gvfs.timeout-seconds, value must be greater than or equal to 0");
        }
Beispiel #19
0
        public void TryLoadConfigUsesDefaultValuesWhenEntriesAreBlank()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = new MockGitProcess();

            gitProcess.SetExpectedCommandResult("config gvfs.max-retries", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
            gitProcess.SetExpectedCommandResult("config gvfs.timeout-seconds", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));

            RetryConfig config;
            string      error;

            RetryConfig.TryLoadFromGitConfig(tracer, gitProcess, out config, out error).ShouldEqual(true);
            error.ShouldEqual(string.Empty);
            config.MaxRetries.ShouldEqual(RetryConfig.DefaultMaxRetries);
            config.MaxAttempts.ShouldEqual(config.MaxRetries + 1);
            config.Timeout.ShouldEqual(TimeSpan.FromSeconds(RetryConfig.DefaultTimeoutSeconds));
        }
Beispiel #20
0
        public void ParsesConfiguredCacheName()
        {
            MockGitProcess git = new MockGitProcess();

            git.SetExpectedCommandResult("config gvfs.cache-server", () => new GitProcess.Result(UserSuppliedCacheName, string.Empty, GitProcess.Result.SuccessCode));

            string          error;
            CacheServerInfo output;

            CacheServerInfo.TryDetermineCacheServer(
                userUrlish: null,
                gitProcess: git,
                enlistment: this.enlistment,
                knownCaches: KnownCaches,
                output: out output,
                error: out error).ShouldBeTrue(error);
            output.Url.ShouldEqual(UserSuppliedUrl);
        }
Beispiel #21
0
        public void ResolvesUrlIntoFriendlyName()
        {
            MockGitProcess git = new MockGitProcess();

            string          error;
            CacheServerInfo output;

            CacheServerInfo.TryDetermineCacheServer(
                userUrlish: UserSuppliedUrl,
                gitProcess: git,
                enlistment: this.enlistment,
                knownCaches: KnownCaches,
                output: out output,
                error: out error).ShouldBeTrue(error);

            output.Name.ShouldEqual(UserSuppliedCacheName);
            output.Url.ShouldEqual(UserSuppliedUrl);
        }
Beispiel #22
0
        public void FallsBackToDeprecatedConfigSetting()
        {
            MockGitProcess git = new MockGitProcess();

            git.SetExpectedCommandResult(@"config gvfs.mock:\repourl.cache-server-url", () => new GitProcess.Result(UserSuppliedUrl, string.Empty, GitProcess.Result.SuccessCode));
            git.SetExpectedCommandResult(@"config --local  gvfs.cache-server " + UserSuppliedUrl, () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode));
            string          error;
            CacheServerInfo output;

            CacheServerInfo.TryDetermineCacheServer(
                userUrlish: null,
                gitProcess: git,
                enlistment: this.enlistment,
                knownCaches: null,
                output: out output,
                error: out error).ShouldBeTrue(error);

            output.Url.ShouldEqual(UserSuppliedUrl);
        }
Beispiel #23
0
        public void BackoffIsNotInEffectAfterSuccess()
        {
            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = this.GetGitProcess();

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            for (int i = 0; i < 5; ++i)
            {
                dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get credential on iteration " + i + ": " + error);
                dut.Revoke(authString);
                dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to retry getting credential on iteration " + i + ": " + error);
                dut.ConfirmCredentialsWorked(authString);
                dut.IsBackingOff.ShouldEqual(false, "Should reset backoff after successfully refreshing credentials");
            }
        }
Beispiel #24
0
        public void FallsBackToDefaultCache()
        {
            MockGitProcess git = new MockGitProcess();

            git.SetExpectedCommandResult(@"config gvfs.mock:\repourl.cache-server-url", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.GenericFailureCode));

            string          error;
            CacheServerInfo output;

            CacheServerInfo.TryDetermineCacheServer(
                userUrlish: null,
                gitProcess: git,
                enlistment: this.enlistment,
                knownCaches: KnownCaches,
                output: out output,
                error: out error).ShouldBeTrue(error);

            output.Name.ShouldEqual(DefaultCacheName);
        }
        public void TryLoadConfigUsesConfiguredValues()
        {
            int maxRetries     = RetryConfig.DefaultMaxRetries + 1;
            int timeoutSeconds = RetryConfig.DefaultTimeoutSeconds + 1;

            MockTracer     tracer     = new MockTracer();
            MockGitProcess gitProcess = new MockGitProcess();

            gitProcess.SetExpectedCommandResult("config scalar.max-retries", () => new GitProcess.Result(maxRetries.ToString(), string.Empty, GitProcess.Result.SuccessCode));
            gitProcess.SetExpectedCommandResult("config scalar.timeout-seconds", () => new GitProcess.Result(timeoutSeconds.ToString(), string.Empty, GitProcess.Result.SuccessCode));

            RetryConfig config;
            string      error;

            RetryConfig.TryLoadFromGitConfig(tracer, gitProcess, out config, out error).ShouldEqual(true);
            error.ShouldEqual(string.Empty);
            config.MaxRetries.ShouldEqual(maxRetries);
            config.MaxAttempts.ShouldEqual(config.MaxRetries + 1);
            config.Timeout.ShouldEqual(TimeSpan.FromSeconds(timeoutSeconds));
        }
Beispiel #26
0
        public void ShouldOnlyRetryAuthOnce()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get initial credential");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true, "Should retry once");

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to retry getting credential on iteration");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(false, "Should not retry more than once");
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "TryGetCredential should not succeed during backoff");
        }
        private MockGitProcess GetGitProcess()
        {
            MockGitProcess gitProcess = new MockGitProcess();
            gitProcess.SetExpectedCommandResult("config gvfs.FunctionalTests.UserName", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.GenericFailureCode));
            gitProcess.SetExpectedCommandResult("config gvfs.FunctionalTests.Password", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.GenericFailureCode));

            int revocations = 0;
            gitProcess.SetExpectedCommandResult(
                "credential fill",
                () => new GitProcess.Result("username=username\r\npassword=password" + revocations + "\r\n", string.Empty, GitProcess.Result.SuccessCode));

            gitProcess.SetExpectedCommandResult(
                "credential reject",
                () =>
                {
                    revocations++;
                    return new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode);
                });
            return gitProcess;
        }
Beispiel #28
0
        public void GitProcessFailuresAreRetried()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            gitProcess.ShouldFail = true;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "Succeeded despite GitProcess returning failure");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true, "Should retry once");

            gitProcess.ShouldFail = false;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get credential on retry");
        }
Beispiel #29
0
        public void SetUp()
        {
            MockTracer tracer = new MockTracer();

            string enlistmentRoot  = Path.Combine("mock:", "GVFS", "UnitTests", "Repo");
            string statusCachePath = Path.Combine("mock:", "GVFS", "UnitTests", "Repo", GVFSPlatform.Instance.Constants.DotGVFSRoot, "gitStatusCache");

            this.gitProcess = new MockGitProcess();
            this.gitProcess.SetExpectedCommandResult($"--no-optional-locks status \"--serialize={statusCachePath}", () => new GitProcess.Result(string.Empty, string.Empty, 0), true);
            MockGVFSEnlistment enlistment = new MockGVFSEnlistment(enlistmentRoot, "fake://repoUrl", "fake://gitBinPath", this.gitProcess);

            enlistment.InitializeCachePathsFromKey("fake:\\gvfsSharedCache", "fakeCacheKey");

            this.gitParentPath    = enlistment.WorkingDirectoryBackingRoot;
            this.gvfsMetadataPath = enlistment.DotGVFSRoot;

            this.enlistmentDirectory = new MockDirectory(
                enlistmentRoot,
                new MockDirectory[]
            {
                new MockDirectory(this.gitParentPath, folders: null, files: null),
            },
                null);

            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "config"), ".git config Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "HEAD"), ".git HEAD Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "logs", "HEAD"), "HEAD Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "info", "always_exclude"), "always_exclude Contents", createDirectories: true);
            this.enlistmentDirectory.CreateDirectory(Path.Combine(this.gitParentPath, ".git", "objects", "pack"));

            this.fileSystem = new MockFileSystem(this.enlistmentDirectory);
            this.fileSystem.AllowMoveFile = true;
            this.fileSystem.DeleteNonExistentFileThrowsException = false;

            this.context = new GVFSContext(
                tracer,
                this.fileSystem,
                new MockGitRepo(tracer, enlistment, this.fileSystem),
                enlistment);
        }
Beispiel #30
0
        public void DoesNotRetryIfTryGetCredentialsFails()
        {
            MockTracer     tracer     = new MockTracer();
            MockEnlistment enlistment = new MockEnlistment();
            MockGitProcess gitProcess = new MockGitProcess(enlistment);

            GitAuthentication dut = new GitAuthentication(gitProcess);

            string authString;
            string error;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(true, "Failed to get initial credential");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(true, "Should retry once");

            gitProcess.ShouldFail = true;

            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "Succeeded despite GitProcess returning failure");

            dut.RevokeAndCheckCanRetry(authString).ShouldEqual(false, "Should not retry if GitProcess fails after retry");
            dut.TryGetCredentials(tracer, out authString, out error).ShouldEqual(false, "TryGetCredential should not succeed during backoff");
        }