mirror of https://github.com/shred/acme4j
Change challenge errors to error
parent
8597e84d53
commit
472f1497db
|
@ -13,12 +13,8 @@
|
||||||
*/
|
*/
|
||||||
package org.shredzone.acme4j.challenge;
|
package org.shredzone.acme4j.challenge;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.shredzone.acme4j.AcmeJsonResource;
|
import org.shredzone.acme4j.AcmeJsonResource;
|
||||||
|
@ -29,7 +25,6 @@ import org.shredzone.acme4j.connector.Connection;
|
||||||
import org.shredzone.acme4j.exception.AcmeException;
|
import org.shredzone.acme4j.exception.AcmeException;
|
||||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||||
import org.shredzone.acme4j.toolbox.JSON;
|
import org.shredzone.acme4j.toolbox.JSON;
|
||||||
import org.shredzone.acme4j.toolbox.JSON.Array;
|
|
||||||
import org.shredzone.acme4j.toolbox.JSONBuilder;
|
import org.shredzone.acme4j.toolbox.JSONBuilder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -51,7 +46,7 @@ public class Challenge extends AcmeJsonResource {
|
||||||
protected static final String KEY_URL = "url";
|
protected static final String KEY_URL = "url";
|
||||||
protected static final String KEY_STATUS = "status";
|
protected static final String KEY_STATUS = "status";
|
||||||
protected static final String KEY_VALIDATED = "validated";
|
protected static final String KEY_VALIDATED = "validated";
|
||||||
protected static final String KEY_ERRORS = "errors";
|
protected static final String KEY_ERROR = "error";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new generic {@link Challenge} object.
|
* Creates a new generic {@link Challenge} object.
|
||||||
|
@ -114,29 +109,12 @@ public class Challenge extends AcmeJsonResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of reasons why the challenge has failed in the past, if returned by
|
* Returns a reason why the challenge has failed in the past, if returned by the
|
||||||
* the server. New errors are always appended to the end of the list.
|
* server. If there are multiple errors, they can be found in
|
||||||
|
* {@link Problem#getSubProblems()}.
|
||||||
*/
|
*/
|
||||||
public List<Problem> getErrors() {
|
public Problem getError() {
|
||||||
URL location = getLocation();
|
return getJSON().get(KEY_ERROR).asProblem(getLocation());
|
||||||
return Collections.unmodifiableList(getJSON().get(KEY_ERRORS)
|
|
||||||
.asArray()
|
|
||||||
.stream()
|
|
||||||
.map(it -> it.asProblem(location))
|
|
||||||
.collect(toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the last reason why the challenge has failed, if returned by the server.
|
|
||||||
* {@code null} if there are no errors.
|
|
||||||
*/
|
|
||||||
public Problem getLastError() {
|
|
||||||
Array errors = getJSON().get(KEY_ERRORS).asArray();
|
|
||||||
if (!errors.isEmpty()) {
|
|
||||||
return errors.get(errors.size() - 1).asProblem(getLocation());
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jose4j.lang.JoseException;
|
import org.jose4j.lang.JoseException;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -102,21 +101,11 @@ public class ChallengeTest {
|
||||||
assertThat(challenge.getJSON().get("notPresent").asString(), is(nullValue()));
|
assertThat(challenge.getJSON().get("notPresent").asString(), is(nullValue()));
|
||||||
assertThat(challenge.getJSON().get("notPresentUrl").asURL(), is(nullValue()));
|
assertThat(challenge.getJSON().get("notPresentUrl").asURL(), is(nullValue()));
|
||||||
|
|
||||||
List<Problem> errors = challenge.getErrors();
|
Problem error = challenge.getError();
|
||||||
assertThat(errors, is(notNullValue()));
|
assertThat(error, is(notNullValue()));
|
||||||
assertThat(errors, hasSize(2));
|
assertThat(error.getType(), is(URI.create("urn:ietf:params:acme:error:incorrectResponse")));
|
||||||
assertThat(errors.get(0).getType(), is(URI.create("urn:ietf:params:acme:error:connection")));
|
assertThat(error.getDetail(), is("bad token"));
|
||||||
assertThat(errors.get(0).getDetail(), is("connection refused"));
|
assertThat(error.getInstance(), is(URI.create("http://example.com/documents/faq.html")));
|
||||||
assertThat(errors.get(0).getInstance(), is(URI.create("http://example.com/documents/error.html")));
|
|
||||||
assertThat(errors.get(1).getType(), is(URI.create("urn:ietf:params:acme:error:incorrectResponse")));
|
|
||||||
assertThat(errors.get(1).getDetail(), is("bad token"));
|
|
||||||
assertThat(errors.get(1).getInstance(), is(URI.create("http://example.com/documents/faq.html")));
|
|
||||||
|
|
||||||
Problem lastError = challenge.getLastError();
|
|
||||||
assertThat(lastError, is(notNullValue()));
|
|
||||||
assertThat(lastError.getType(), is(URI.create("urn:ietf:params:acme:error:incorrectResponse")));
|
|
||||||
assertThat(lastError.getDetail(), is("bad token"));
|
|
||||||
assertThat(lastError.getInstance(), is(URI.create("http://example.com/documents/faq.html")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,16 +3,9 @@
|
||||||
"status": "invalid",
|
"status": "invalid",
|
||||||
"url": "http://example.com/challenge/123",
|
"url": "http://example.com/challenge/123",
|
||||||
"validated": "2015-12-12T17:19:36.336785823Z",
|
"validated": "2015-12-12T17:19:36.336785823Z",
|
||||||
"errors": [
|
"error": {
|
||||||
{
|
|
||||||
"type": "urn:ietf:params:acme:error:connection",
|
|
||||||
"detail": "connection refused",
|
|
||||||
"instance": "/documents/error.html"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "urn:ietf:params:acme:error:incorrectResponse",
|
"type": "urn:ietf:params:acme:error:incorrectResponse",
|
||||||
"detail": "bad token",
|
"detail": "bad token",
|
||||||
"instance": "/documents/faq.html"
|
"instance": "/documents/faq.html"
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue