Account extends AcmeJsonResource { public Authorization preAuthorizeDomain(String domain) throws AcmeException { Objects.requireNonNull(domain, "domain"); if (domain.isEmpty()) { throw new IllegalArgumentException("domain must not be empty"); } return preAuthorize(Identifier.dns(domain)); } protected  Account(Login login); @Nullable Boolean getTermsOfServiceAgreed(); List<URI> getContacts(); Status getStatus(); boolean hasExternalAccountBinding(); @Nullable String getKeyIdentifier(); Iterator<Order> getOrders(); OrderBuilder newOrder(); Authorization preAuthorizeDomain(String domain); Authorization preAuthorize(Identifier identifier); void changeKey(KeyPair newKeyPair); void deactivate(); EditableAccount modify();  }
@Test public void testPreAuthorizeDomain() throws Exception { TestableConnectionProvider provider = new TestableConnectionProvider() { @Override public int sendSignedRequest(URL url, JSONBuilder claims, Login login) { assertThat(url, is(resourceUrl)); assertThat(claims.toString(), sameJSONAs(getJSON("newAuthorizationRequest").toString())); assertThat(login, is(notNullValue())); return HttpURLConnection.HTTP_CREATED; } @Override public JSON readJsonResponse() { return getJSON("newAuthorizationResponse"); } @Override public URL getLocation() { return locationUrl; } }; Login login = provider.createLogin(); provider.putTestResource(Resource.NEW_AUTHZ, resourceUrl); provider.putTestChallenge(Http01Challenge.TYPE, Http01Challenge::new); provider.putTestChallenge(Dns01Challenge.TYPE, Dns01Challenge::new); String domainName = "example.org"; Account account = new Account(login); Authorization auth = account.preAuthorizeDomain(domainName); assertThat(auth.getIdentifier().getDomain(), is(domainName)); assertThat(auth.getStatus(), is(Status.PENDING)); assertThat(auth.getExpires(), is(nullValue())); assertThat(auth.getLocation(), is(locationUrl)); assertThat(auth.getChallenges(), containsInAnyOrder( provider.getChallenge(Http01Challenge.TYPE), provider.getChallenge(Dns01Challenge.TYPE))); provider.close(); }
@Test public void testNoPreAuthorizeDomain() throws Exception { URI problemType = URI.create("urn:ietf:params:acme:error:rejectedIdentifier"); String problemDetail = "example.org is blacklisted"; TestableConnectionProvider provider = new TestableConnectionProvider() { @Override public int sendSignedRequest(URL url, JSONBuilder claims, Login login) throws AcmeException { assertThat(url, is(resourceUrl)); assertThat(claims.toString(), sameJSONAs(getJSON("newAuthorizationRequest").toString())); assertThat(login, is(notNullValue())); Problem problem = TestUtils.createProblem(problemType, problemDetail, resourceUrl); throw new AcmeServerException(problem); } }; Login login = provider.createLogin(); provider.putTestResource(Resource.NEW_AUTHZ, resourceUrl); Account account = new Account(login); try { account.preAuthorizeDomain("example.org"); fail("preauthorization was accepted"); } catch (AcmeServerException ex) { assertThat(ex.getType(), is(problemType)); assertThat(ex.getMessage(), is(problemDetail)); } provider.close(); }
@Test public void testAuthorizeBadDomain() throws Exception { TestableConnectionProvider provider = new TestableConnectionProvider(); provider.putTestResource(Resource.NEW_NONCE, resourceUrl); Login login = provider.createLogin(); Account account = login.getAccount(); try { account.preAuthorizeDomain(null); fail("null domain was accepted"); } catch (NullPointerException ex) { } try { account.preAuthorizeDomain(""); fail("empty domain string was accepted"); } catch (IllegalArgumentException ex) { } try { account.preAuthorizeDomain("example.com"); fail("preauthorization was accepted"); } catch (AcmeException ex) { assertThat(ex.getMessage(), is("Server does not offer newAuthz")); } provider.close(); }