diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java index 9fd660b9..0ec12c8f 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java @@ -37,6 +37,7 @@ import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeLazyLoadingException; import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.exception.AcmeRetryAfterException; +import org.shredzone.acme4j.provider.pebble.Pebble; import org.shredzone.acme4j.util.JSON; import org.shredzone.acme4j.util.JSONBuilder; import org.slf4j.Logger; @@ -50,16 +51,14 @@ public class Registration extends AcmeResource { private static final Logger LOG = LoggerFactory.getLogger(Registration.class); private static final String KEY_TOS_AGREED = "terms-of-service-agreed"; - private static final String KEY_AUTHORIZATIONS = "authorizations"; - private static final String KEY_CERTIFICATES = "certificates"; + private static final String KEY_ORDERS = "orders"; private static final String KEY_CONTACT = "contact"; private static final String KEY_STATUS = "status"; private final List contacts = new ArrayList<>(); private Status status; private Boolean termsOfServiceAgreed; - private URL authorizations; - private URL certificates; + private URL orders; private boolean loaded = false; protected Registration(Session session, URL location) { @@ -109,37 +108,20 @@ public class Registration extends AcmeResource { } /** - * Returns an {@link Iterator} of all {@link Authorization} belonging to this + * Returns an {@link Iterator} of all {@link Order} belonging to this * {@link Registration}. *

* Using the iterator will initiate one or more requests to the ACME server. * - * @return {@link Iterator} instance that returns {@link Authorization} objects. + * @return {@link Iterator} instance that returns {@link Order} objects. * {@link Iterator#hasNext()} and {@link Iterator#next()} may throw * {@link AcmeProtocolException} if a batch of authorization URIs could not be * fetched from the server. */ - public Iterator getAuthorizations() throws AcmeException { - LOG.debug("getAuthorizations"); + public Iterator getOrders() throws AcmeException { + LOG.debug("getOrders"); load(); - return new ResourceIterator<>(getSession(), KEY_AUTHORIZATIONS, authorizations, Authorization::bind); - } - - /** - * Returns an {@link Iterator} of all {@link Certificate} belonging to this - * {@link Registration}. - *

- * Using the iterator will initiate one or more requests to the ACME server. - * - * @return {@link Iterator} instance that returns {@link Certificate} objects. - * {@link Iterator#hasNext()} and {@link Iterator#next()} may throw - * {@link AcmeProtocolException} if a batch of certificate URIs could not be - * fetched from the server. - */ - public Iterator getCertificates() throws AcmeException { - LOG.debug("getCertificates"); - load(); - return new ResourceIterator<>(getSession(), KEY_CERTIFICATES, certificates, Certificate::bind); + return new ResourceIterator<>(getSession(), KEY_ORDERS, orders, Order::bind); } /** @@ -329,8 +311,10 @@ public class Registration extends AcmeResource { .forEach(contacts::add); } - this.authorizations = json.get(KEY_AUTHORIZATIONS).asURL(); - this.certificates = json.get(KEY_CERTIFICATES).asURL(); + // TODO PEBBLE: returns an empty string as URL + if (!Pebble.workaround()) { + this.orders = json.get(KEY_ORDERS).asURL(); + } if (json.contains(KEY_STATUS)) { this.status = Status.parse(json.get(KEY_STATUS).asString()); diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java index 7621de57..0fc56ebe 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java @@ -74,17 +74,9 @@ public class RegistrationTest { @Override public void sendRequest(URL url, Session session) { - if (url("https://example.com/acme/reg/1/authz").equals(url)) { + if (url("https://example.com/acme/acct/1/orders").equals(url)) { jsonResponse = new JSONBuilder() - .array("authorizations", "https://example.com/acme/auth/1") - .toJSON(); - response = HttpURLConnection.HTTP_OK; - return; - } - - if (url("https://example.com/acme/reg/1/cert").equals(url)) { - jsonResponse = new JSONBuilder() - .array("certificates", "https://example.com/acme/cert/1") + .array("orders", "https://example.com/acme/order/1") .toJSON(); response = HttpURLConnection.HTTP_OK; return; @@ -134,15 +126,10 @@ public class RegistrationTest { assertThat(registration.getContacts().get(0), is(URI.create("mailto:foo2@example.com"))); assertThat(registration.getStatus(), is(Status.VALID)); - Iterator authIt = registration.getAuthorizations(); - assertThat(authIt, not(nullValue())); - assertThat(authIt.next().getLocation(), is(url("https://example.com/acme/auth/1"))); - assertThat(authIt.hasNext(), is(false)); - - Iterator certIt = registration.getCertificates(); - assertThat(certIt, not(nullValue())); - assertThat(certIt.next().getLocation(), is(url("https://example.com/acme/cert/1"))); - assertThat(certIt.hasNext(), is(false)); + Iterator orderIt = registration.getOrders(); + assertThat(orderIt, not(nullValue())); + assertThat(orderIt.next().getLocation(), is(url("https://example.com/acme/order/1"))); + assertThat(orderIt.hasNext(), is(false)); provider.close(); } diff --git a/acme4j-client/src/test/resources/json/updateRegistrationResponse.json b/acme4j-client/src/test/resources/json/updateRegistrationResponse.json index 3103eebb..06830820 100644 --- a/acme4j-client/src/test/resources/json/updateRegistrationResponse.json +++ b/acme4j-client/src/test/resources/json/updateRegistrationResponse.json @@ -1,9 +1,8 @@ { + "status": "valid", "contact": [ "mailto:foo2@example.com" ], - "status": "valid", "terms-of-service-agreed": true, - "authorizations": "https://example.com/acme/reg/1/authz", - "certificates": "https://example.com/acme/reg/1/cert" + "orders": "https://example.com/acme/acct/1/orders" }