Пример #1
0
 public async Task ShouldFailWhenUpdateRegistrationWithoutAccount()
 {
     using (var client = new AcmeClient(WellKnownServers.LetsEncryptStaging))
     {
         await Assert.ThrowsAsync <InvalidOperationException>(
             () => client.UpdateRegistration(new AcmeAccount()));
     }
 }
Пример #2
0
        public async Task CanUpdateRegistration()
        {
            var accountKey = await Helper.LoadkeyV1();

            var regLocation = new Uri("http://example.com/reg/1");
            var mock        = MockHttp(async req =>
            {
                if (req.Method == HttpMethod.Post && req.RequestUri == regLocation)
                {
                    var payload = await ParsePayload <RegistrationEntity>(req);
                    Assert.Equal(ResourceTypes.Registration, payload.Resource);
                    Assert.Equal(1, payload.Contact?.Count);
                    Assert.Equal($"another-{email}", payload.Contact[0]);
                    Assert.NotNull(payload.Agreement);

                    var respJson = new
                    {
                        contact   = payload.Contact,
                        agreement = payload.Agreement,
                        resource  = ResourceTypes.Registration
                    };

                    var resp = CreateResponse(respJson, HttpStatusCode.Created, regLocation);
                    resp.Headers.Add("Link", $"<{tos}>; rel=\"terms-of-service\"");
                    return(resp);
                }

                return(null);
            });

            using (var http = new HttpClient(mock.Object))
                using (var handler = new AcmeHttpHandler(server, http))
                {
                    using (var client = new AcmeClient(handler))
                    {
                        client.Use(accountKey.Export());

                        var account = new AcmeAccount
                        {
                            Location = regLocation,
                            Data     = new RegistrationEntity
                            {
                                Resource  = ResourceTypes.Registration,
                                Contact   = new[] { $"another-{email}" },
                                Agreement = tos
                            }
                        };

                        var result = await client.UpdateRegistration(account);

                        Assert.Equal(ResourceTypes.Registration, result.Data.Resource);
                        Assert.Equal(tos, account.Data.Agreement);
                        Assert.Equal(regLocation, account.Location);
                    }

                    mock.As <IDisposable>().Verify(x => x.Dispose(), Times.Never());
                }
        }
Пример #3
0
        public static async Task <Uri> GetAcmeUriV1()
        {
            if (stagingServerV1 != null)
            {
                return(stagingServerV1);
            }

            var key = await Helper.LoadkeyV1();

            foreach (var uri in StagingServersV1)
            {
                var httpSucceed = false;
                try
                {
                    await http.Value.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);

                    httpSucceed = true;
                }
                catch
                {
                }

                if (httpSucceed)
                {
                    using (var client = new AcmeClient(new AcmeHttpHandler(uri, http.Value)))
                    {
                        client.Use(key.Export());

                        try
                        {
                            var account = await client.NewRegistraton();

                            account.Data.Agreement = account.GetTermsOfServiceUri();
                            await client.UpdateRegistration(account);
                        }
                        catch
                        {
                            // account already exists
                        }

                        return(stagingServerV1 = uri);
                    }
                }
            }

            throw new Exception("Staging server unavailable.");
        }
Пример #4
0
        public async Task RunAccountFlow(KeyAlgorithm algorithm)
        {
            var dirUri = await IntegrationHelper.GetAcmeUriV1();

            var key = new AccountKey(algorithm);

            using (var client = new AcmeClient(IntegrationHelper.GetAcmeHttpHandler(dirUri)))
            {
                client.Use(key.Export());
                var reg = await client.NewRegistraton();

                reg.Data.Agreement = reg.GetTermsOfServiceUri();

                await client.UpdateRegistration(reg);

                var newKey = new AccountKey().Export();
                await client.ChangeKey(reg, newKey);

                await client.DeleteRegistration(reg);
            }
        }