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.lang.JoseException;
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.AcmeException;
import org.shredzone.acme4j.exception.AcmeNetworkException;
@ -431,10 +431,10 @@ public class DefaultConnection implements Connection {
return new AcmeUnauthorizedException(type, detail);
}
if ("agreementRequired".equals(error)) {
if ("userActionRequired".equals(error)) {
URI instance = resolveRelative(json.get("instance").asString());
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)) {

View File

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

View File

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