Ejemplo n.º 1
0
        public void Test_OcspWorker_Scan_NoUris()
        {
            // Arrange
            var certificate   = CreationHelpers.CreateCertificate();
            var bcCertificate = CreationHelpers.CreateBCCertificate();
            var issuer        = CreationHelpers.CreateIntermediate();
            var bcIssuer      = CreationHelpers.CreateBCIntermediate();

            var workerInformation = MockWorkerInformation(hostname: "google.com", certificate: certificate, issuer: issuer);
            var ocsp = MockOcsp(certificate: bcCertificate, issuer: bcIssuer, ocspUris: new Uri[0]);

            var previousWorker = new Mock <IAsyncWorker>();

            previousWorker.Setup(x => x.Scan(workerInformation)).ReturnsAsync(new List <ScanResult>());

            var workerMock = new Mock <OcspWorker>(previousWorker.Object)
            {
                CallBase = true
            };

            workerMock.Setup(x => x.CreateOcsp(bcCertificate, bcIssuer)).Returns(ocsp);

            // Act
            var worker   = workerMock.Object;
            var response = worker.Scan(workerInformation);

            response.Wait();

            // Assert
            var result = response.Result.Single() as OcspResponse;

            Mock.VerifyAll();
            Assert.AreEqual(Enums.OcspRevocationStatus.Unknown, result.Status);
            Assert.IsNull(result.RevocationReason);
        }
Ejemplo n.º 2
0
        public void Test_OcspWorker_Scan_OneInvalidThenValidOcspResponse()
        {
            // Arrange
            var            certificate    = CreationHelpers.CreateCertificate();
            var            bcCertificate  = CreationHelpers.CreateBCCertificate();
            var            issuer         = CreationHelpers.CreateIntermediate();
            var            bcIssuer       = CreationHelpers.CreateBCIntermediate();
            var            uri            = new Uri("https://google.com");
            var            bingUri        = new Uri("https://bing.com");
            HttpWebRequest bingWebRequest = (HttpWebRequest)WebRequest.Create(bingUri);
            HttpWebRequest webRequest     = (HttpWebRequest)WebRequest.Create(uri);
            var            ocspResponse   = new OcspResponse()
            {
                Status = 0
            };

            var workerInformation = MockWorkerInformation(hostname: "google.com", certificate: certificate, issuer: issuer);
            var ocsp = MockOcsp(certificate: bcCertificate, issuer: bcIssuer, ocspUris: new[] { uri, bingUri });

            var previousWorker = new Mock <IAsyncWorker>();

            previousWorker.Setup(x => x.Scan(workerInformation)).ReturnsAsync(new List <ScanResult>());

            var workerMock = new Mock <OcspWorker>(previousWorker.Object)
            {
                CallBase = true
            };

            workerMock.Setup(x => x.CreateOcsp(bcCertificate, bcIssuer)).Returns(ocsp);
            workerMock.Setup(x => x.CreateOcspRequest(ocsp, uri)).Returns(webRequest);
            workerMock.Setup(x => x.CreateOcspRequest(ocsp, bingUri)).Returns(bingWebRequest);
            workerMock.Setup(x => x.SendOcspRequest(webRequest)).ThrowsAsync(new Exception());
            workerMock.Setup(x => x.SendOcspRequest(bingWebRequest)).ReturnsAsync(ocspResponse);

            // Act
            var worker   = workerMock.Object;
            var response = worker.Scan(workerInformation);

            response.Wait();

            // Assert
            var result = response.Result.Single() as OcspResponse;

            Mock.VerifyAll();
            Assert.AreEqual(Enums.OcspRevocationStatus.Good, result.Status);
            Assert.IsNull(result.RevocationReason);
        }
Ejemplo n.º 3
0
        public void Test_OcspWorker_CreateOcspRequest_Basic()
        {
            //Arrange
            var certificate   = CreationHelpers.CreateCertificate();
            var bcCertificate = CreationHelpers.CreateBCCertificate();
            var issuer        = CreationHelpers.CreateIntermediate();
            var bcIssuer      = CreationHelpers.CreateBCIntermediate();

            var ocspUri           = new Uri("http://ocsp.pki.goog/gts1o1");
            var workerInformation = MockWorkerInformation(hostname: "google.com", certificate: certificate, issuer: issuer);
            var ocsp           = MockOcsp(certificate: bcCertificate, issuer: bcIssuer, ocspUris: new Uri[] { ocspUri });
            var previousWorker = MockPreviousWorker(workerInformation);
            var worker         = new OcspWorker(previousWorker.Object);

            //Act
            var result = worker.CreateOcspRequest(ocsp, ocspUri);

            //Assert
            Assert.AreEqual(ocspUri, result.Address);
            Assert.AreEqual("POST", result.Method);
            Assert.AreEqual("application/ocsp-request", result.ContentType);
            Assert.AreEqual("application/ocsp-response", result.Accept);
        }