Rename to AcmeUserActionRequiredException

pull/55/head
Richard Körber 2017-04-30 17:03:59 +02:00
parent 25b13a74e4
commit e748df364d
3 changed files with 33 additions and 34 deletions

View File

@ -44,7 +44,7 @@ import org.jose4j.jwk.PublicJsonWebKey;
import org.jose4j.jws.JsonWebSignature; import org.jose4j.jws.JsonWebSignature;
import org.jose4j.lang.JoseException; import org.jose4j.lang.JoseException;
import org.shredzone.acme4j.Session; import org.shredzone.acme4j.Session;
import org.shredzone.acme4j.exception.AcmeAgreementRequiredException; import org.shredzone.acme4j.exception.AcmeUserActionRequiredException;
import org.shredzone.acme4j.exception.AcmeConflictException; import org.shredzone.acme4j.exception.AcmeConflictException;
import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.exception.AcmeNetworkException; import org.shredzone.acme4j.exception.AcmeNetworkException;
@ -431,10 +431,10 @@ public class DefaultConnection implements Connection {
return new AcmeUnauthorizedException(type, detail); return new AcmeUnauthorizedException(type, detail);
} }
if ("agreementRequired".equals(error)) { if ("userActionRequired".equals(error)) {
URI instance = resolveRelative(json.get("instance").asString()); URI instance = resolveRelative(json.get("instance").asString());
URI tos = getLinks("terms-of-service").stream().findFirst().orElse(null); URI tos = getLinks("terms-of-service").stream().findFirst().orElse(null);
return new AcmeAgreementRequiredException(type, detail, tos, toURL(instance)); return new AcmeUserActionRequiredException(type, detail, tos, toURL(instance));
} }
if ("rateLimited".equals(error)) { if ("rateLimited".equals(error)) {

View File

@ -17,46 +17,45 @@ import java.net.URI;
import java.net.URL; import java.net.URL;
/** /**
* An exception that is thrown when the client needs to accept the terms of service in * An exception that is thrown when the user is required to take action as indicated.
* order to continue.
*/ */
public class AcmeAgreementRequiredException extends AcmeServerException { public class AcmeUserActionRequiredException extends AcmeServerException {
private static final long serialVersionUID = 7719055447283858352L; private static final long serialVersionUID = 7719055447283858352L;
private final URI agreementUri; private final URI tosUri;
private final URL instance; private final URL instance;
/** /**
* Creates a new {@link AcmeAgreementRequiredException}. * Creates a new {@link AcmeUserActionRequiredException}.
* *
* @param type * @param type
* System readable error type (here * System readable error type (here
* {@code "urn:ietf:params:acme:error:agreementRequired"}) * {@code "urn:ietf:params:acme:error:userActionRequired"})
* @param detail * @param detail
* Human readable error message * Human readable error message
* @param agreementUri * @param tosUri
* {@link URI} of the agreement document to accept * {@link URI} of the terms-of-service document to accept
* @param instance * @param instance
* {@link URL} to be visited by a human, showing instructions for how to * {@link URL} to be visited by a human, showing instructions for how to
* agree to the terms and conditions. * agree to the terms and conditions.
*/ */
public AcmeAgreementRequiredException(String type, String detail, URI agreementUri, URL instance) { public AcmeUserActionRequiredException(String type, String detail, URI tosUri, URL instance) {
super(type, detail); super(type, detail);
this.agreementUri = agreementUri; this.tosUri = tosUri;
this.instance = instance; this.instance = instance;
} }
/** /**
* Returns the {@link URI} of the agreement document to accept, or {@code null} if * Returns the {@link URI} of the terms-of-service document to accept, or {@code null}
* the server did not provide a link to such a document. * if the server did not provide a link to such a document.
*/ */
public URI getAgreementUri() { public URI getTermsOfServiceUri() {
return agreementUri; return tosUri;
} }
/** /**
* Returns the {@link URL} of a document showing a human how to agree to the terms and * Returns the {@link URL} of a document indicating the action required by the user,
* conditions, or {@code null} if the server did not provide such a link. * or {@code null} if the server did not provide such a link.
*/ */
public URL getInstance() { public URL getInstance() {
return instance; return instance;

View File

@ -23,26 +23,26 @@ import java.net.URL;
import org.junit.Test; import org.junit.Test;
/** /**
* Unit tests for {@link AcmeAgreementRequiredException}. * Unit tests for {@link AcmeUserActionRequiredException}.
*/ */
public class AcmeAgreementRequiredExceptionTest { public class AcmeUserActionRequiredExceptionTest {
/** /**
* Test that parameters are correctly returned. * Test that parameters are correctly returned.
*/ */
@Test @Test
public void testAcmeAgreementRequiredException() throws MalformedURLException { public void testAcmeUserActionRequiredException() throws MalformedURLException {
String type = "urn:ietf:params:acme:error:agreementRequired"; String type = "urn:ietf:params:acme:error:userActionRequired";
String detail = "Agreement is required"; String detail = "Accept new TOS";
URI agreementUri = URI.create("http://example.com/agreement.pdf"); URI tosUri = URI.create("http://example.com/agreement.pdf");
URL instanceUrl = new URL("http://example.com/howToAgree.html"); URL instanceUrl = new URL("http://example.com/howToAgree.html");
AcmeAgreementRequiredException ex AcmeUserActionRequiredException ex
= new AcmeAgreementRequiredException(type, detail, agreementUri, instanceUrl); = new AcmeUserActionRequiredException(type, detail, tosUri, instanceUrl);
assertThat(ex.getType(), is(type)); assertThat(ex.getType(), is(type));
assertThat(ex.getMessage(), is(detail)); assertThat(ex.getMessage(), is(detail));
assertThat(ex.getAgreementUri(), is(agreementUri)); assertThat(ex.getTermsOfServiceUri(), is(tosUri));
assertThat(ex.getInstance(), is(instanceUrl)); assertThat(ex.getInstance(), is(instanceUrl));
} }
@ -50,16 +50,16 @@ public class AcmeAgreementRequiredExceptionTest {
* Test that optional parameters are null-safe. * Test that optional parameters are null-safe.
*/ */
@Test @Test
public void testNullAcmeAgreementRequiredException() { public void testNullAcmeUserActionRequiredException() {
String type = "urn:ietf:params:acme:error:agreementRequired"; String type = "urn:ietf:params:acme:error:userActionRequired";
String detail = "Agreement is required"; String detail = "Call our service";
AcmeAgreementRequiredException ex AcmeUserActionRequiredException ex
= new AcmeAgreementRequiredException(type, detail, null, null); = new AcmeUserActionRequiredException(type, detail, null, null);
assertThat(ex.getType(), is(type)); assertThat(ex.getType(), is(type));
assertThat(ex.getMessage(), is(detail)); assertThat(ex.getMessage(), is(detail));
assertThat(ex.getAgreementUri(), nullValue()); assertThat(ex.getTermsOfServiceUri(), nullValue());
assertThat(ex.getInstance(), nullValue()); assertThat(ex.getInstance(), nullValue());
} }