public async Task ValidateRegisterAsyncThrowsExceptionFromRestClient()
        {
            var testSystem = new TestSystem().WithDirectoryResponse();

            var(acmeClient, restClient) = testSystem.Build();

            var testContacts  = new[] { "mailto:[email protected]", "+1 012-3456-789" };
            var returnAccount = new Account {
            };

            restClient.Setup(rc => rc.PostAsync <Account>(TestHelpers.acmeDirectory.NewAccount, It.IsAny <Account>(), It.IsAny <CancellationToken>()))
            .Throws(new ACMEException(1234, "detail"));

            try
            {
                await acmeClient.RegisterAsync(testContacts);
            }
            catch (ACMEException exception)
            {
                Assert.AreEqual(1234, exception.Status);
                Assert.AreEqual("detail", exception.Message);

                return;
            }

            Assert.Fail("Failed to stop in catch.");
        }
        public async Task ValidateAcmeClientThrowsArgumentNullExceptionWhenCertificateIsNull()
        {
            var testSystem = new TestSystem().WithDirectoryResponse();

            var(acmeClient, restClient) = testSystem.Build();

            await acmeClient.RevokeCertificateAsync(null, RevocationReason.PriviledgeWithdrawn);
        }
Example #3
0
        public async Task ValidateAcmeClientThrowsArgumentNullExceptionWhenCertificateIsNull()
        {
            TestSystem testSystem = new TestSystem().WithDirectoryResponse();

            (ACMEClient acmeClient, Moq.Mock <HttpClient> _) = testSystem.Build();

            await acmeClient.RevokeCertificateAsync(null, RevocationReason.PriviledgeWithdrawn);
        }
Example #4
0
        public async Task ValidateRegisterAsyncThrowsExceptionFromRestClient()
        {
            TestSystem testSystem = new TestSystem()
                                    .WithDirectoryResponse()
                                    .WithErrorResponse(TestHelpers.AcmeDirectory.NewAccount, "detail", string.Empty, 1234, HttpStatusCode.BadRequest);

            (ACMEClient acmeClient, _) = testSystem.Build();

            var           testContacts = new[] { "mailto:[email protected]", "+1 012-3456-789" };
            ACMEException exception    = await Assert.ThrowsExceptionAsync <ACMEException>(() => acmeClient.RegisterAsync(testContacts));

            Assert.AreEqual(1234, exception.Status);
            Assert.AreEqual("detail", exception.Message);
        }
        public async Task ValidateRegisterAsyncThrowsInvalidServerResponseForBadResponse()
        {
            var testSystem = new TestSystem().WithDirectoryResponse();

            var(acmeClient, restClient) = testSystem.Build();

            var testContacts  = new[] { "mailto:[email protected]", "+1 012-3456-789" };
            var returnAccount = new Account {
            };

            restClient.Setup(rc => rc.PostAsync <Account>(TestHelpers.acmeDirectory.NewAccount, It.IsAny <Account>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(((Account)null, string.Empty)));

            await acmeClient.RegisterAsync(testContacts);
        }
        public async Task ValidateSuccesfullValidationFlow()
        {
            var testSystem = new TestSystem().WithDirectoryResponse();

            var(acmeClient, restClient) = testSystem.Build();

            restClient.Setup(rc => rc.PostAsync <string>(TestHelpers.acmeDirectory.RevokeCertificate, It.IsAny <CertificateRevocationRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult((string.Empty, string.Empty)));

            var testCertificate = new CertificateMock(Guid.NewGuid().ToString());

            await acmeClient.GetDirectoryAsync();

            await acmeClient.RevokeCertificateAsync(testCertificate, RevocationReason.PriviledgeWithdrawn);

            restClient.Verify(rc => rc.PostAsync <string>(TestHelpers.acmeDirectory.RevokeCertificate,
                                                          It.Is <CertificateRevocationRequest>(req => req.Certificate == testCertificate.GetPublicKeyString() && req.Reason == RevocationReason.PriviledgeWithdrawn),
                                                          It.IsAny <CancellationToken>()), Times.Once, "Rest Client wasn't called with expected parameters.");
        }
Example #7
0
        public async Task ValidateSuccesfullValidationFlow()
        {
            TestSystem testSystem = new TestSystem()
                                    .WithDirectoryResponse()
                                    .WithResponse(TestHelpers.AcmeDirectory.RevokeCertificate, string.Empty);

            (ACMEClient acmeClient, _) = testSystem.Build();

            var testCertificate = new CertificateMock(Guid.NewGuid().ToString());

            await acmeClient.GetDirectoryAsync();

            await acmeClient.RevokeCertificateAsync(testCertificate, RevocationReason.PriviledgeWithdrawn);

            /*
             * restClient.Verify(rc => rc.PostAsyn<string>(TestHelpers.acmeDirectory.RevokeCertificate,
             * It.Is<CertificateRevocationRequest>(req => req.Reason == RevocationReason.PriviledgeWithdrawn),
             * It.IsAny<CancellationToken>()), Times.Once, "Rest Client wasn't called with expected parameters."); */
        }
Example #8
0
        public async Task ValidateRegisterAsyncPositiveFlow()
        {
            var testContacts  = new[] { "mailto:[email protected]", "+1 012-3456-789" };
            var returnAccount = new Account {
            };

            TestSystem testSystem = new TestSystem()
                                    .WithDirectoryResponse()
                                    .WithResponse(TestHelpers.AcmeDirectory.NewAccount, returnAccount, locationHeader: new Uri(TestHelpers.BaseUri, "/account/1234"));

            (ACMEClient acmeClient, _) = testSystem.Build();

            await acmeClient.RegisterAsync(testContacts);

            /*
             * restClient.Verify(rc => rc.PostAsync<Account>(TestHelpers.acmeDirectory.NewAccount,
             *  It.Is<Account>(req => req.Contacts == testContacts && req.TermsOfServiceAgreed),
             *  It.IsAny<CancellationToken>()), Times.Once, "Rest Client wasn't called with expected parameters.");
             *
             * restClient.Verify(rc => rc.GetAsync<ACMEDirectory>(new Uri(TestHelpers.baseUri, "directory"), It.IsAny<CancellationToken>()),
             *  Times.Once, "Rest Client wasn't called with expected parameters.");*/
        }
        public async Task ValidateRegisterAsyncPositiveFlow()
        {
            var testSystem = new TestSystem().WithDirectoryResponse();

            var(acmeClient, restClient) = testSystem.Build();

            var testContacts  = new[] { "mailto:[email protected]", "+1 012-3456-789" };
            var returnAccount = new Account {
            };

            restClient.Setup(rc => rc.PostAsync <Account>(TestHelpers.acmeDirectory.NewAccount, It.IsAny <Account>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult((returnAccount, string.Empty)));

            await acmeClient.RegisterAsync(testContacts);

            restClient.Verify(rc => rc.PostAsync <Account>(TestHelpers.acmeDirectory.NewAccount,
                                                           It.Is <Account>(req => req.Contacts == testContacts && req.TermsOfServiceAgreed),
                                                           It.IsAny <CancellationToken>()), Times.Once, "Rest Client wasn't called with expected parameters.");

            restClient.Verify(rc => rc.GetAsync <ACMEDirectory>(new Uri(TestHelpers.baseUri, "directory"), It.IsAny <CancellationToken>()),
                              Times.Once, "Rest Client wasn't called with expected parameters.");
        }