From cf5b05bf73740adcd5d364e0959deaf11c57ee55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Mon, 1 May 2017 17:43:29 +0200 Subject: [PATCH] Add unit test for Registration orderCertificate --- .../shredzone/acme4j/RegistrationTest.java | 55 +++++++++++++++++++ .../resources/json/requestOrderResponse.json | 6 +- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java index 0fc56ebe..569a6984 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java @@ -15,6 +15,7 @@ package org.shredzone.acme4j; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import static org.shredzone.acme4j.util.AcmeUtils.parseTimestamp; import static org.shredzone.acme4j.util.TestUtils.*; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; @@ -24,6 +25,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.security.KeyPair; +import java.time.Instant; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -195,6 +197,59 @@ public class RegistrationTest { provider.close(); } + /** + * Test that a new {@link Authorization} can be created. + */ + @Test + public void testOrderCertificate() throws Exception { + byte[] csr = TestUtils.getResourceAsByteArray("/csr.der"); + Instant notBefore = parseTimestamp("2016-01-01T00:00:00Z"); + Instant notAfter = parseTimestamp("2016-01-08T00:00:00Z"); + + TestableConnectionProvider provider = new TestableConnectionProvider() { + @Override + public void sendSignedRequest(URL url, JSONBuilder claims, Session session) { + assertThat(url, is(resourceUrl)); + assertThat(claims.toString(), sameJSONAs(getJSON("requestOrderRequest").toString())); + assertThat(session, is(notNullValue())); + } + + @Override + public int accept(int... httpStatus) throws AcmeException { + assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_CREATED)); + return HttpURLConnection.HTTP_CREATED; + } + + @Override + public JSON readJsonResponse() { + return getJSON("requestOrderResponse"); + } + + @Override + public URL getLocation() { + return locationUrl; + } + }; + + Session session = provider.createSession(); + + provider.putTestResource(Resource.NEW_ORDER, resourceUrl); + + Registration registration = new Registration(session, locationUrl); + Order order = registration.orderCertificate(csr, notBefore, notAfter); + + assertThat(order.getCsr(), is(csr)); + assertThat(order.getNotBefore(), is(parseTimestamp("2016-01-01T00:10:00Z"))); + assertThat(order.getNotAfter(), is(parseTimestamp("2016-01-08T00:10:00Z"))); + assertThat(order.getExpires(), is(parseTimestamp("2016-01-10T00:00:00Z"))); + assertThat(order.getStatus(), is(Status.PENDING)); + assertThat(order.getLocation(), is(locationUrl)); + assertThat(order.getAuthorizations(), is(notNullValue())); + assertThat(order.getAuthorizations().size(), is(2)); + + provider.close(); + } + /** * Test that a new {@link Authorization} can be created. */ diff --git a/acme4j-client/src/test/resources/json/requestOrderResponse.json b/acme4j-client/src/test/resources/json/requestOrderResponse.json index 8445e004..c4dbd03a 100644 --- a/acme4j-client/src/test/resources/json/requestOrderResponse.json +++ b/acme4j-client/src/test/resources/json/requestOrderResponse.json @@ -1,9 +1,9 @@ { "status": "pending", - "expires": "2016-01-01T00:00:00Z", + "expires": "2016-01-10T00:00:00Z", "csr": "MIIChDCCAWwCAQAwFjEUMBIGA1UEAwwLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCPemmumcNGR0hsPo-2N6nkJ0FcEMdb0_MlucHR0dNeHEvn8vmcQHlYRjkDVX0aypnfKQI3tvhTBKLdlNvbVIW1TQ_Wbqh9TQlC8G3Hog8nRQ2vAzO4sH6nhvdrAFUmq6hkATpU3iQuDvtYu03ExaYHKsItLocl1OndaQizBn5udBv1baOW3Kd790k6lEWGrD-TXo6uwuMha2k_YBGNKd4S4UuPmbPV9SUVW8JSylBSgDhvY3BHv-dfdIMhVwRMZDFaa0mHDIYUiwcEaU5x4P6Q5bGP2wxcUPCLwFsbAK5K6B2T2P3A2fNjGBAlHwEkg6VMvi7jax8MD-oRnku2M2JLAgMBAAGgKTAnBgkqhkiG9w0BCQ4xGjAYMBYGA1UdEQQPMA2CC2V4YW1wbGUuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQACnMZdjE1jVqnkHkEeGrMXujWuwuiKLZVa4YZ9fL0UIGOqqf4b9-3JmtEiLB9ycQO5N9rW4V-6_DBMeoeRBLu-wranHnxU4ds6GzNzBxKfI86_8t5pdQK4Cglv7yfseseZRdQtvcR2ejkW0F3SL1DF5Sk3T46aRYiUXxeoNC4Uh3zoIHOv8YGUa-DuZQ6OnHMhPrdsfU09L7KVAMTq1bodjGWmgoIJm4x5JSm19GbhYAm9Q9XWnN56YHqgS3FtS9n3wDxz7Dvo24whto1tUU5hnjrp31rTvyxG3kydoEZf2Ciq_82bQDb40kwnoO6RytPYJVMRIBsP2mCfaFtIt9Eb", - "notBefore": "2016-01-01T00:00:00Z", - "notAfter": "2016-01-08T00:00:00Z", + "notBefore": "2016-01-01T00:10:00Z", + "notAfter": "2016-01-08T00:10:00Z", "authorizations": [ "https://example.com/acme/authz/1234", "https://example.com/acme/authz/2345"