Also accept 'urn:ietf:params:acme:error' error responses

pull/17/merge
Richard Körber 2016-03-21 23:12:24 +01:00
parent b8bfc5fa0f
commit 19787f4c00
5 changed files with 18 additions and 9 deletions

View File

@ -25,7 +25,8 @@ public class AcmeRateLimitExceededException extends AcmeServerException {
* Creates a new {@link AcmeRateLimitExceededException}.
*
* @param type
* System readable error type (here {@code "urn:acme:error:rateLimited"})
* System readable error type (here
* {@code "urn:ietf:params:acme:error:rateLimited"})
* @param detail
* Human readable error message
*/

View File

@ -22,7 +22,8 @@ package org.shredzone.acme4j.exception;
public class AcmeServerException extends AcmeException {
private static final long serialVersionUID = 5971622508467042792L;
private static final String ACME_ERROR_PREFIX = "urn:acme:error:";
private static final String ACME_ERROR_PREFIX = "urn:ietf:params:acme:error:";
private static final String ACME_ERROR_PREFIX_DEPRECATED = "urn:acme:error:";
private final String type;
@ -30,7 +31,8 @@ public class AcmeServerException extends AcmeException {
* Creates a new {@link AcmeServerException}.
*
* @param type
* System readable error type (e.g. {@code "urn:acme:error:malformed"})
* System readable error type (e.g.
* {@code "urn:ietf:params:acme:error:malformed"})
* @param detail
* Human readable error message
*/
@ -51,13 +53,16 @@ public class AcmeServerException extends AcmeException {
/**
* Returns the ACME error type. This is the last part of the type URN, e.g.
* {@code "malformed"} on {@code "urn:acme:error:malformed"}.
* {@code "malformed"} on {@code "urn:ietf:params:acme:error:malformed"}.
*
* @return ACME error type, or {@code null} if this is not an {@code "urn:acme:error"}
* @return ACME error type, or {@code null} if this is not an
* {@code "urn:ietf:params:acme:error"}
*/
public String getAcmeErrorType() {
if (type.startsWith(ACME_ERROR_PREFIX)) {
return type.substring(ACME_ERROR_PREFIX.length());
} else if (type.startsWith(ACME_ERROR_PREFIX_DEPRECATED)) {
return type.substring(ACME_ERROR_PREFIX_DEPRECATED.length());
} else {
return null;
}

View File

@ -26,7 +26,8 @@ public class AcmeUnauthorizedException extends AcmeServerException {
* Creates a new {@link AcmeUnauthorizedException}.
*
* @param type
* System readable error type (here {@code "urn:acme:error:unauthorized"})
* System readable error type (here
* {@code "urn:ietf:params:acme:error:unauthorized"})
* @param detail
* Human readable error message
*/

View File

@ -42,8 +42,8 @@ import org.shredzone.acme4j.connector.HttpConnector;
import org.shredzone.acme4j.connector.Resource;
import org.shredzone.acme4j.connector.Session;
import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.exception.AcmeRateLimitExceededException;
import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.exception.AcmeRateLimitExceededException;
import org.shredzone.acme4j.exception.AcmeServerException;
import org.shredzone.acme4j.exception.AcmeUnauthorizedException;
import org.shredzone.acme4j.util.ClaimBuilder;
@ -322,9 +322,11 @@ public class DefaultConnection implements Connection {
switch (type) {
case "urn:acme:error:unauthorized":
case "urn:ietf:params:acme:error:unauthorized":
throw new AcmeUnauthorizedException(type, detail);
case "urn:acme:error:rateLimited":
case "urn:ietf:params:acme:error:rateLimited":
throw new AcmeRateLimitExceededException(type, detail);
default:

View File

@ -194,7 +194,7 @@ public class DefaultConnectionTest {
*/
@Test
public void testThrowException() throws Exception {
String jsonData = "{\"type\":\"urn:acme:error:unauthorized\",\"detail\":\"Invalid response: 404\"}";
String jsonData = "{\"type\":\"urn:ietf:params:acme:error:unauthorized\",\"detail\":\"Invalid response: 404\"}";
when(mockUrlConnection.getHeaderField("Content-Type")).thenReturn("application/problem+json");
when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN);
@ -205,7 +205,7 @@ public class DefaultConnectionTest {
conn.throwAcmeException();
fail("Expected to fail");
} catch (AcmeServerException ex) {
assertThat(ex.getType(), is("urn:acme:error:unauthorized"));
assertThat(ex.getType(), is("urn:ietf:params:acme:error:unauthorized"));
assertThat(ex.getMessage(), is("Invalid response: 404"));
assertThat(ex.getAcmeErrorType(), is("unauthorized"));
} catch (AcmeException ex) {