diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/it/AbstractPebbleIT.java b/acme4j-client/src/test/java/org/shredzone/acme4j/it/AbstractPebbleIT.java new file mode 100644 index 00000000..203f62a2 --- /dev/null +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/it/AbstractPebbleIT.java @@ -0,0 +1,81 @@ +/* + * acme4j - Java ACME client + * + * Copyright (C) 2017 Richard "Shred" Körber + * http://acme4j.shredzone.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +package org.shredzone.acme4j.it; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertThat; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; + +/** + * Superclass for all Pebble related integration tests. + *
+ * These tests require a running
+ * Pebble ACME test server at
+ * localhost port 14000.
+ */
+public abstract class AbstractPebbleIT {
+
+ private final String pebbleHost = System.getProperty("pebbleHost", "localhost");
+ private final int pebblePort = Integer.parseInt(System.getProperty("pebblePort", "14000"));
+
+ /**
+ * @return The {@link URI} of the pebble server to test against.
+ */
+ protected URI pebbleURI() {
+ return URI.create("acme://pebble/" + pebbleHost + ":" + pebblePort);
+ }
+
+ /**
+ * Creates a fresh key pair.
+ *
+ * @return Created {@link KeyPair}, guaranteed to be unknown to the Pebble server
+ */
+ protected KeyPair createKeyPair() {
+ try {
+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
+ keyGen.initialize(2048);
+ return keyGen.generateKeyPair();
+ } catch (NoSuchAlgorithmException ex) {
+ throw new InternalError(ex);
+ }
+ }
+
+ /**
+ * Asserts that the given {@link URI} is not {@code null} and refers to the Pebble
+ * server.
+ *
+ * @param uri
+ * {@link URI} to assert
+ */
+ protected void assertIsPebbleUri(URI uri) {
+ assertThat(uri, not(nullValue()));
+
+ try {
+ URL url = uri.toURL();
+ assertThat(url.getProtocol(), is("http"));
+ assertThat(url.getHost(), is(pebbleHost));
+ assertThat(url.getPort(), is(pebblePort));
+ assertThat(url.getPath(), not(isEmptyOrNullString()));
+ } catch (MalformedURLException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+ }
+
+}
diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/it/SessionIT.java b/acme4j-client/src/test/java/org/shredzone/acme4j/it/SessionIT.java
new file mode 100644
index 00000000..bf47f007
--- /dev/null
+++ b/acme4j-client/src/test/java/org/shredzone/acme4j/it/SessionIT.java
@@ -0,0 +1,72 @@
+/*
+ * acme4j - Java ACME client
+ *
+ * Copyright (C) 2017 Richard "Shred" Körber
+ * http://acme4j.shredzone.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+package org.shredzone.acme4j.it;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.assertThat;
+import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
+
+import java.security.KeyPair;
+
+import org.junit.Test;
+import org.shredzone.acme4j.Metadata;
+import org.shredzone.acme4j.Session;
+import org.shredzone.acme4j.connector.Resource;
+import org.shredzone.acme4j.exception.AcmeException;
+
+/**
+ * Session related integration tests.
+ */
+public class SessionIT extends AbstractPebbleIT {
+
+ private final KeyPair keyPair = createKeyPair();
+
+ @Test
+ public void testNonce() throws AcmeException {
+ Session session = new Session(pebbleURI(), keyPair);
+
+ // No nonce yet on a fresh session
+ assertThat(session.getNonce(), is(nullValue()));
+
+ // Request directory, also providing a nonce
+ session.getMetadata();
+
+ // A nonce must be set now
+ assertThat(session.getNonce(), not(nullValue()));
+ assertThat(session.provider(), not(nullValue()));
+ }
+
+ @Test
+ public void testResources() throws AcmeException {
+ Session session = new Session(pebbleURI(), keyPair);
+
+ assertIsPebbleUri(session.resourceUri(Resource.NEW_NONCE));
+ assertIsPebbleUri(session.resourceUri(Resource.NEW_REG));
+ }
+
+ @Test
+ public void testMetadata() throws AcmeException {
+ Session session = new Session(pebbleURI(), keyPair);
+
+ Metadata meta = session.getMetadata();
+ assertThat(meta, not(nullValue()));
+
+ // Pebble does not currently deliver any metadata
+ assertThat(meta.getTermsOfService(), is(nullValue()));
+ assertThat(meta.getWebsite(), is(nullValue()));
+ assertThat(meta.getCaaIdentities(), is(empty()));
+ assertThat(meta.getJSON().toString(), sameJSONAs("{}"));
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index c3ea136d..59e099bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,6 +55,7 @@