Exemplo n.º 1
0
        public void GetCertificateShouldReturnNullWhenCertificateCommonNameSettingIsEmpty()
        {
            GitSsl           sut    = new GitSsl(string.Empty, new Dictionary <string, GitConfigSetting>());
            X509Certificate2 result = sut.GetCertificate(this.tracer, this.gitProcess);

            result.ShouldBeNull();
        }
Exemplo n.º 2
0
        public void GetCertificateShouldReturnCertificateFromStoreAccordingToRulesWhenFileDoesNotExist()
        {
            X509Certificate2 certificate = this.MakeCertificateValid(GenerateTestCertificate());

            this.SetupGitCertificatePassword();
            GitSsl gitSsl = new GitSsl(
                string.Empty,
                GetGitConfig(),
                () => this.certificateStoreMock.Object,
                this.certificateVerifierMock.Object,
                this.fileSystem);

            this.SetupCertificateStore(
                true,
                this.MakeCertificateValid(GenerateTestCertificate(CertificateName + "suphix")),
                this.MakeCertificateValid(GenerateTestCertificate("prefix" + CertificateName)),
                this.MakeCertificateValid(GenerateTestCertificate("not this certificate")),
                this.MakeCertificateValid(GenerateTestCertificate(), false),
                this.MakeCertificateValid(GenerateTestCertificate(validFrom: DateTimeOffset.Now.AddDays(-4))),
                this.MakeCertificateValid(GenerateTestCertificate(validTo: DateTimeOffset.Now.AddDays(4))),
                certificate);

            X509Certificate2 result = gitSsl.GetCertificate(this.tracer, this.gitProcess);

            result.ShouldNotBeNull();
            result.ShouldEqual(certificate);
        }
Exemplo n.º 3
0
        public void GetCertificateShouldReturnCertificateFromFileWhenFileExistsAndIsPasswordProtectedAndIsValid()
        {
            X509Certificate2 certificate = GenerateTestCertificate();

            this.SetupCertificateFile(certificate, CertificatePassword);
            this.SetupGitCertificatePassword();
            this.MakeCertificateValid(certificate);
            GitSsl gitSsl = new GitSsl(string.Empty, GetGitConfig(), () => this.certificateStoreMock.Object, this.certificateVerifierMock.Object, this.fileSystem);

            X509Certificate2 result = gitSsl.GetCertificate(this.tracer, this.gitProcess);

            result.ShouldNotBeNull();
            result.ShouldEqual(certificate);
        }
Exemplo n.º 4
0
        public void GetCertificateShouldReturnNullWhenFileExistsAndIsNotPasswordProtectedAndIsInvalid()
        {
            X509Certificate2 certificate = GenerateTestCertificate();

            this.SetupCertificateFile(certificate);
            this.MakeCertificateValid(certificate, false);
            GitSsl gitSsl = new GitSsl(
                GetGitConfig(
                    new GitConfigSetting(GitConfigSetting.HttpSslCertPasswordProtected, "false")),
                () => this.certificateStoreMock.Object,
                this.certificateVerifierMock.Object,
                this.fileSystem);

            X509Certificate2 result = gitSsl.GetCertificate(this.tracer, this.gitProcess);

            result.ShouldBeNull();
        }
Exemplo n.º 5
0
        public void GetCertificateShouldReturnNullWhenNoMatchingCertificatesExist()
        {
            this.SetupGitCertificatePassword();
            GitSsl gitSsl = new GitSsl(
                GetGitConfig(),
                () => this.certificateStoreMock.Object,
                this.certificateVerifierMock.Object,
                this.fileSystem);

            this.SetupCertificateStore(
                true,
                this.MakeCertificateValid(GenerateTestCertificate(CertificateName + "suphix")),
                this.MakeCertificateValid(GenerateTestCertificate("prefix" + CertificateName)),
                this.MakeCertificateValid(GenerateTestCertificate("not this certificate")));

            X509Certificate2 result = gitSsl.GetCertificate(this.tracer, this.gitProcess);

            result.ShouldBeNull();
        }