mirror of https://github.com/shred/acme4j
Parse dates, use Date instead of String
parent
74750a9f88
commit
fa31a1cf94
|
@ -18,6 +18,7 @@ import java.net.URI;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.shredzone.acme4j.challenge.Challenge;
|
||||
|
@ -33,7 +34,7 @@ public class Authorization implements Serializable {
|
|||
private URI location;
|
||||
private String domain;
|
||||
private Status status;
|
||||
private String expires;
|
||||
private Date expires;
|
||||
private List<Challenge> challenges;
|
||||
private List<List<Challenge>> combinations;
|
||||
|
||||
|
@ -96,14 +97,14 @@ public class Authorization implements Serializable {
|
|||
/**
|
||||
* Gets the expiry date of the authorization, if set by the server.
|
||||
*/
|
||||
public String getExpires() {
|
||||
public Date getExpires() {
|
||||
return expires;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expiry date of the authorization.
|
||||
*/
|
||||
public void setExpires(String expires) {
|
||||
public void setExpires(Date expires) {
|
||||
this.expires = expires;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.shredzone.acme4j.challenge;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.shredzone.acme4j.Status;
|
||||
|
@ -45,7 +46,7 @@ public interface Challenge extends Serializable {
|
|||
/**
|
||||
* Returns the validation date, if returned by the server.
|
||||
*/
|
||||
String getValidated();
|
||||
Date getValidated();
|
||||
|
||||
/**
|
||||
* Sets the challenge state by reading the given JSON map.
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.net.URISyntaxException;
|
|||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -31,6 +32,7 @@ import org.jose4j.jwk.JsonWebKey.OutputControlLevel;
|
|||
import org.jose4j.lang.JoseException;
|
||||
import org.shredzone.acme4j.Status;
|
||||
import org.shredzone.acme4j.util.ClaimBuilder;
|
||||
import org.shredzone.acme4j.util.TimestampParser;
|
||||
|
||||
/**
|
||||
* A generic implementation of {@link Challenge}. It can be used as a base class for
|
||||
|
@ -78,8 +80,13 @@ public class GenericChallenge implements Challenge {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getValidated() {
|
||||
return get(KEY_VALIDATED);
|
||||
public Date getValidated() {
|
||||
String valStr = get(KEY_VALIDATED);
|
||||
if (valStr != null) {
|
||||
return TimestampParser.parse(valStr);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.shredzone.acme4j.connector.Session;
|
|||
import org.shredzone.acme4j.exception.AcmeConflictException;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
import org.shredzone.acme4j.util.ClaimBuilder;
|
||||
import org.shredzone.acme4j.util.TimestampParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -412,7 +413,11 @@ public abstract class AbstractAcmeClient implements AcmeClient {
|
|||
@SuppressWarnings("unchecked")
|
||||
private void unmarshalAuthorization(Map<String, Object> json, Authorization auth) {
|
||||
auth.setStatus(Status.parse((String) json.get("status"), Status.PENDING));
|
||||
auth.setExpires((String) json.get("expires"));
|
||||
|
||||
String expires = (String) json.get("expires");
|
||||
if (expires != null) {
|
||||
auth.setExpires(TimestampParser.parse(expires));
|
||||
}
|
||||
|
||||
Map<String, Object> identifier = (Map<String, Object>) json.get("identifier");
|
||||
if (identifier != null) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -71,6 +72,8 @@ public class AuthorizationTest {
|
|||
*/
|
||||
@Test
|
||||
public void testGetterAndSetter() {
|
||||
Date expiry = new Date();
|
||||
|
||||
Authorization auth = new Authorization();
|
||||
|
||||
assertThat(auth.getDomain(), is(nullValue()));
|
||||
|
@ -81,13 +84,13 @@ public class AuthorizationTest {
|
|||
|
||||
auth.setDomain("example.com");
|
||||
auth.setStatus(Status.INVALID);
|
||||
auth.setExpires("2015-12-12T17:19:36.336785823Z");
|
||||
auth.setExpires(expiry);
|
||||
auth.setChallenges(authorization.getChallenges());
|
||||
auth.setCombinations(authorization.getCombinations());
|
||||
|
||||
assertThat(auth.getDomain(), is("example.com"));
|
||||
assertThat(auth.getStatus(), is(Status.INVALID));
|
||||
assertThat(auth.getExpires(), is("2015-12-12T17:19:36.336785823Z"));
|
||||
assertThat(auth.getExpires(), is(expiry));
|
||||
assertThat(auth.getChallenges(), is(sameInstance(authorization.getChallenges())));
|
||||
assertThat(auth.getCombinations(), is(sameInstance(authorization.getCombinations())));
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.junit.Test;
|
|||
import org.shredzone.acme4j.Status;
|
||||
import org.shredzone.acme4j.util.ClaimBuilder;
|
||||
import org.shredzone.acme4j.util.TestUtils;
|
||||
import org.shredzone.acme4j.util.TimestampParser;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GenericChallenge}.
|
||||
|
@ -63,7 +64,7 @@ public class GenericChallengeTest {
|
|||
assertThat(challenge.getType(), is("generic-01"));
|
||||
assertThat(challenge.getStatus(), is(Status.VALID));
|
||||
assertThat(challenge.getLocation(), is(new URI("http://example.com/challenge/123")));
|
||||
assertThat(challenge.getValidated(), is("2015-12-12T17:19:36.336785823Z"));
|
||||
assertThat(challenge.getValidated(), is(TimestampParser.parse("2015-12-12T17:19:36.336785823Z")));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.shredzone.acme4j.connector.Session;
|
|||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
import org.shredzone.acme4j.util.ClaimBuilder;
|
||||
import org.shredzone.acme4j.util.TestUtils;
|
||||
import org.shredzone.acme4j.util.TimestampParser;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractAcmeClient}.
|
||||
|
@ -275,7 +276,7 @@ public class AbstractAcmeClientTest {
|
|||
|
||||
assertThat(auth.getDomain(), is("example.org"));
|
||||
assertThat(auth.getStatus(), is(Status.VALID));
|
||||
assertThat(auth.getExpires(), is("2015-03-01"));
|
||||
assertThat(auth.getExpires(), is(TimestampParser.parse("2016-01-02T17:12:40Z")));
|
||||
assertThat(auth.getLocation(), is(locationUri));
|
||||
|
||||
assertThat(auth.getChallenges(), containsInAnyOrder(
|
||||
|
|
|
@ -58,7 +58,7 @@ newAuthorizationResponse = \
|
|||
updateAuthorizationResponse = \
|
||||
{\
|
||||
"status": "valid",\
|
||||
"expires": "2015-03-01",\
|
||||
"expires": "2016-01-02T17:12:40Z",\
|
||||
"identifier": {\
|
||||
"type": "dns",\
|
||||
"value": "example.org"\
|
||||
|
|
Loading…
Reference in New Issue