mirror of https://github.com/shred/acme4j
Upgrade all tests to JUnit 5
parent
edf2018433
commit
f3c7e8a46c
|
@ -189,7 +189,7 @@ public class DefaultConnection implements Connection {
|
|||
}
|
||||
|
||||
JSON result = JSON.parse(in);
|
||||
LOG.debug("Result JSON: {}", result.toString());
|
||||
LOG.debug("Result JSON: {}", result);
|
||||
return result;
|
||||
} catch (IOException ex) {
|
||||
throw new AcmeNetworkException(ex);
|
||||
|
|
|
@ -67,7 +67,7 @@ public class AcmeUserActionRequiredException extends AcmeServerException {
|
|||
try {
|
||||
return instance.toURL();
|
||||
} catch (MalformedURLException ex) {
|
||||
throw new AcmeProtocolException("Bad instance URL: " + instance.toString(), ex);
|
||||
throw new AcmeProtocolException("Bad instance URL: " + instance, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.security.KeyPair;
|
|||
import javax.crypto.SecretKey;
|
||||
|
||||
import org.jose4j.jwx.CompactSerializer;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.shredzone.acme4j.connector.Resource;
|
||||
import org.shredzone.acme4j.provider.TestableConnectionProvider;
|
||||
|
|
|
@ -17,7 +17,8 @@ import static java.util.Collections.emptyList;
|
|||
import static java.util.Collections.singletonList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
|
||||
|
@ -34,7 +35,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
import org.jose4j.jws.JsonWebSignature;
|
||||
import org.jose4j.jwx.CompactSerializer;
|
||||
import org.jose4j.lang.JoseException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Account.EditableAccount;
|
||||
import org.shredzone.acme4j.challenge.Dns01Challenge;
|
||||
import org.shredzone.acme4j.challenge.Http01Challenge;
|
||||
|
@ -255,13 +256,11 @@ public class AccountTest {
|
|||
|
||||
Account account = new Account(login);
|
||||
|
||||
try {
|
||||
account.preAuthorizeDomain("example.org");
|
||||
fail("preauthorization was accepted");
|
||||
} catch (AcmeServerException ex) {
|
||||
assertThat(ex.getType(), is(problemType));
|
||||
assertThat(ex.getMessage(), is(problemDetail));
|
||||
}
|
||||
AcmeServerException ex = assertThrows(AcmeServerException.class, () ->
|
||||
account.preAuthorizeDomain("example.org")
|
||||
);
|
||||
assertThat(ex.getType(), is(problemType));
|
||||
assertThat(ex.getMessage(), is(problemDetail));
|
||||
|
||||
provider.close();
|
||||
}
|
||||
|
@ -278,27 +277,9 @@ public class AccountTest {
|
|||
Login login = provider.createLogin();
|
||||
Account account = login.getAccount();
|
||||
|
||||
try {
|
||||
account.preAuthorizeDomain(null);
|
||||
fail("null domain was accepted");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
account.preAuthorizeDomain("");
|
||||
fail("empty domain string was accepted");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
account.preAuthorizeDomain("example.com");
|
||||
fail("preauthorization was accepted");
|
||||
} catch (AcmeException ex) {
|
||||
// expected
|
||||
assertThat(ex.getMessage(), is("Server does not offer newAuthz"));
|
||||
}
|
||||
assertThrows(NullPointerException.class, () -> account.preAuthorizeDomain(null));
|
||||
assertThrows(IllegalArgumentException.class, () -> account.preAuthorizeDomain(""));
|
||||
assertThrows(AcmeException.class, () -> account.preAuthorizeDomain("example.com"));
|
||||
|
||||
provider.close();
|
||||
}
|
||||
|
@ -342,7 +323,7 @@ public class AccountTest {
|
|||
expectedPayload.append("}}");
|
||||
assertThat(decodedPayload, sameJSONAs(expectedPayload.toString()));
|
||||
} catch (JoseException ex) {
|
||||
fail("decoding inner payload failed");
|
||||
fail(ex);
|
||||
}
|
||||
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
|
@ -370,15 +351,17 @@ public class AccountTest {
|
|||
/**
|
||||
* Test that the same account key is not accepted for change.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testChangeSameKey() throws Exception {
|
||||
TestableConnectionProvider provider = new TestableConnectionProvider();
|
||||
Login login = provider.createLogin();
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
TestableConnectionProvider provider = new TestableConnectionProvider();
|
||||
Login login = provider.createLogin();
|
||||
|
||||
Account account = new Account(login);
|
||||
account.changeKey(login.getKeyPair());
|
||||
Account account = new Account(login);
|
||||
account.changeKey(login.getKeyPair());
|
||||
|
||||
provider.close();
|
||||
provider.close();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,7 @@ import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
|||
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
import org.shredzone.acme4j.toolbox.JSON;
|
||||
import org.shredzone.acme4j.toolbox.TestUtils;
|
||||
|
|
|
@ -15,8 +15,7 @@ package org.shredzone.acme4j;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -25,7 +24,7 @@ import java.io.ObjectOutputStream;
|
|||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.toolbox.TestUtils;
|
||||
|
||||
/**
|
||||
|
@ -97,16 +96,18 @@ public class AcmeResourceTest {
|
|||
/**
|
||||
* Test if a rebind attempt fails.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testRebind() throws Exception {
|
||||
Login login = TestUtils.login();
|
||||
URL location = new URL("http://example.com/acme/resource");
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
Login login = TestUtils.login();
|
||||
URL location = new URL("http://example.com/acme/resource");
|
||||
|
||||
AcmeResource resource = new DummyResource(login, location);
|
||||
assertThat(resource.getLogin(), is(login));
|
||||
AcmeResource resource = new DummyResource(login, location);
|
||||
assertThat(resource.getLogin(), is(login));
|
||||
|
||||
Login login2 = TestUtils.login();
|
||||
resource.rebind(login2); // fails to rebind to another login
|
||||
Login login2 = TestUtils.login();
|
||||
resource.rebind(login2); // fails to rebind to another login
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,8 +15,7 @@ package org.shredzone.acme4j;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
|
@ -28,7 +27,7 @@ import java.time.Duration;
|
|||
import java.time.Instant;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.challenge.Challenge;
|
||||
import org.shredzone.acme4j.challenge.Dns01Challenge;
|
||||
import org.shredzone.acme4j.challenge.Http01Challenge;
|
||||
|
@ -105,10 +104,12 @@ public class AuthorizationTest {
|
|||
* Test that {@link Authorization#findChallenge(String)} fails on duplicate
|
||||
* challenges.
|
||||
*/
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testFailDuplicateChallenges() throws IOException {
|
||||
Authorization authorization = createChallengeAuthorization();
|
||||
authorization.findChallenge(DUPLICATE_TYPE);
|
||||
assertThrows(AcmeProtocolException.class, () -> {
|
||||
Authorization authorization = createChallengeAuthorization();
|
||||
authorization.findChallenge(DUPLICATE_TYPE);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.connector.Resource;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
import org.shredzone.acme4j.provider.TestableConnectionProvider;
|
||||
|
|
|
@ -15,14 +15,13 @@ package org.shredzone.acme4j;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
import org.shredzone.acme4j.toolbox.JSONBuilder;
|
||||
|
||||
|
@ -74,9 +73,11 @@ public class IdentifierTest {
|
|||
assertThat(id2.getDomain(), is("xn--xml-qla7ae5k.com"));
|
||||
}
|
||||
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testNoDns() {
|
||||
new Identifier("foo", "example.com").getDomain();
|
||||
assertThrows(AcmeProtocolException.class, () ->
|
||||
new Identifier("foo", "example.com").getDomain()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -97,9 +98,11 @@ public class IdentifierTest {
|
|||
assertThat(id3.getIP().getHostAddress(), is("192.168.2.99"));
|
||||
}
|
||||
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testNoIp() {
|
||||
new Identifier("foo", "example.com").getIP();
|
||||
assertThrows(AcmeProtocolException.class, () ->
|
||||
new Identifier("foo", "example.com").getIP()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -15,8 +15,7 @@ package org.shredzone.acme4j;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
|
@ -26,7 +25,7 @@ import java.net.HttpURLConnection;
|
|||
import java.net.URL;
|
||||
import java.security.KeyPair;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.shredzone.acme4j.challenge.Challenge;
|
||||
import org.shredzone.acme4j.challenge.Dns01Challenge;
|
||||
|
|
|
@ -15,8 +15,7 @@ package org.shredzone.acme4j;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
|
@ -29,9 +28,10 @@ import java.time.Duration;
|
|||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.connector.Resource;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
import org.shredzone.acme4j.provider.TestableConnectionProvider;
|
||||
import org.shredzone.acme4j.toolbox.JSON;
|
||||
import org.shredzone.acme4j.toolbox.JSONBuilder;
|
||||
|
@ -179,20 +179,22 @@ public class OrderBuilderTest {
|
|||
/**
|
||||
* Test that an auto-renewal {@link Order} cannot be created if unsupported by the CA.
|
||||
*/
|
||||
@Test(expected = AcmeException.class)
|
||||
@Test
|
||||
public void testAutoRenewOrderCertificateFails() throws Exception {
|
||||
TestableConnectionProvider provider = new TestableConnectionProvider();
|
||||
provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
|
||||
assertThrows(AcmeException.class, () -> {
|
||||
TestableConnectionProvider provider = new TestableConnectionProvider();
|
||||
provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
|
||||
|
||||
Login login = provider.createLogin();
|
||||
Login login = provider.createLogin();
|
||||
|
||||
Account account = new Account(login);
|
||||
account.newOrder()
|
||||
.domain("example.org")
|
||||
.autoRenewal()
|
||||
.create();
|
||||
Account account = new Account(login);
|
||||
account.newOrder()
|
||||
.domain("example.org")
|
||||
.autoRenewal()
|
||||
.create();
|
||||
|
||||
provider.close();
|
||||
provider.close();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,35 +209,35 @@ public class OrderBuilderTest {
|
|||
|
||||
Account account = new Account(login);
|
||||
|
||||
assertThrows("accepted notBefore", IllegalArgumentException.class, () -> {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
OrderBuilder ob = account.newOrder().autoRenewal();
|
||||
ob.notBefore(someInstant);
|
||||
});
|
||||
}, "accepted notBefore");
|
||||
|
||||
assertThrows("accepted notAfter", IllegalArgumentException.class, () -> {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
OrderBuilder ob = account.newOrder().autoRenewal();
|
||||
ob.notAfter(someInstant);
|
||||
});
|
||||
}, "accepted notAfter");
|
||||
|
||||
assertThrows("accepted autoRenewal", IllegalArgumentException.class, () -> {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
OrderBuilder ob = account.newOrder().notBefore(someInstant);
|
||||
ob.autoRenewal();
|
||||
});
|
||||
}, "accepted autoRenewal");
|
||||
|
||||
assertThrows("accepted autoRenewalStart", IllegalArgumentException.class, () -> {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
OrderBuilder ob = account.newOrder().notBefore(someInstant);
|
||||
ob.autoRenewalStart(someInstant);
|
||||
});
|
||||
}, "accepted autoRenewalStart");
|
||||
|
||||
assertThrows("accepted autoRenewalEnd", IllegalArgumentException.class, () -> {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
OrderBuilder ob = account.newOrder().notBefore(someInstant);
|
||||
ob.autoRenewalEnd(someInstant);
|
||||
});
|
||||
}, "accepted autoRenewalEnd");
|
||||
|
||||
assertThrows("accepted autoRenewalLifetime", IllegalArgumentException.class, () -> {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
OrderBuilder ob = account.newOrder().notBefore(someInstant);
|
||||
ob.autoRenewalLifetime(Duration.ofDays(7));
|
||||
});
|
||||
}, "accepted autoRenewalLifetime");
|
||||
|
||||
provider.close();
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.time.Duration;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.provider.TestableConnectionProvider;
|
||||
import org.shredzone.acme4j.toolbox.JSON;
|
||||
import org.shredzone.acme4j.toolbox.JSONBuilder;
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.net.URI;
|
|||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.toolbox.JSON;
|
||||
import org.shredzone.acme4j.toolbox.JSONBuilder;
|
||||
import org.shredzone.acme4j.toolbox.TestUtils;
|
||||
|
|
|
@ -15,8 +15,7 @@ package org.shredzone.acme4j;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.*;
|
||||
|
||||
|
@ -27,7 +26,7 @@ import java.security.KeyPair;
|
|||
import java.time.Duration;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.shredzone.acme4j.connector.Resource;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
|
@ -61,10 +60,12 @@ public class SessionTest {
|
|||
assertThat(session3, not(nullValue()));
|
||||
assertThat(session3.getServerUri(), is(serverUri));
|
||||
|
||||
assertThrows("Bad URI in constructor", IllegalArgumentException.class,
|
||||
() -> new Session("#*aBaDuRi*#"));
|
||||
assertThrows("Unsupported URI", IllegalArgumentException.class,
|
||||
() -> new Session(URI.create("acme://invalid"), new GenericAcmeProvider()));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new Session("#*aBaDuRi*#"),
|
||||
"Bad URI in constructor");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new Session(URI.create("acme://invalid"), new GenericAcmeProvider()),
|
||||
"Unsupported URI");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,8 +16,7 @@ package org.shredzone.acme4j;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Status} enumeration.
|
||||
|
|
|
@ -16,8 +16,7 @@ package org.shredzone.acme4j.challenge;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
|
@ -29,7 +28,7 @@ import java.net.URL;
|
|||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.Problem;
|
||||
import org.shredzone.acme4j.Status;
|
||||
|
@ -85,9 +84,11 @@ public class ChallengeTest {
|
|||
/**
|
||||
* Test that an exception is thrown on challenge type mismatch.
|
||||
*/
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testNotAcceptable() {
|
||||
new Http01Challenge(TestUtils.login(), getJSON("dnsChallenge"));
|
||||
assertThrows(AcmeProtocolException.class, () ->
|
||||
new Http01Challenge(TestUtils.login(), getJSON("dnsChallenge"))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,9 +198,11 @@ public class ChallengeTest {
|
|||
/**
|
||||
* Test that unmarshalling something different like a challenge fails.
|
||||
*/
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testBadUnmarshall() {
|
||||
new Challenge(TestUtils.login(), getJSON("updateAccountResponse"));
|
||||
assertThrows(AcmeProtocolException.class, () ->
|
||||
new Challenge(TestUtils.login(), getJSON("updateAccountResponse"))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is;
|
|||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.Status;
|
||||
import org.shredzone.acme4j.toolbox.JSONBuilder;
|
||||
|
|
|
@ -15,10 +15,11 @@ package org.shredzone.acme4j.challenge;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.Status;
|
||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
|
@ -57,10 +58,12 @@ public class HttpChallengeTest {
|
|||
/**
|
||||
* Test that an exception is thrown if there is no token.
|
||||
*/
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testNoTokenSet() {
|
||||
Http01Challenge challenge = new Http01Challenge(login, getJSON("httpNoTokenChallenge"));
|
||||
challenge.getToken();
|
||||
assertThrows(AcmeProtocolException.class, () -> {
|
||||
Http01Challenge challenge = new Http01Challenge(login, getJSON("httpNoTokenChallenge"));
|
||||
challenge.getToken();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is;
|
|||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.Status;
|
||||
import org.shredzone.acme4j.toolbox.AcmeUtils;
|
||||
|
|
|
@ -13,12 +13,11 @@
|
|||
*/
|
||||
package org.shredzone.acme4j.challenge;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
import org.shredzone.acme4j.provider.TestableConnectionProvider;
|
||||
|
|
|
@ -18,8 +18,8 @@ import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
|
|||
import static java.util.Collections.singletonList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
|
@ -51,8 +51,8 @@ import java.util.Optional;
|
|||
|
||||
import org.jose4j.jws.JsonWebSignature;
|
||||
import org.jose4j.jwx.CompactSerializer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.Session;
|
||||
|
@ -85,7 +85,7 @@ public class DefaultConnectionTest {
|
|||
private Login login;
|
||||
private KeyPair keyPair;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws AcmeException, IOException {
|
||||
mockUrlConnection = mock(HttpURLConnection.class);
|
||||
|
||||
|
@ -390,8 +390,6 @@ public class DefaultConnectionTest {
|
|||
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
|
||||
conn.conn = mockUrlConnection;
|
||||
conn.handleRetryAfter("no header");
|
||||
} catch (AcmeRetryAfterException ex) {
|
||||
fail("an AcmeRetryAfterException was thrown");
|
||||
}
|
||||
|
||||
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
|
||||
|
@ -407,8 +405,6 @@ public class DefaultConnectionTest {
|
|||
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
|
||||
conn.conn = mockUrlConnection;
|
||||
conn.handleRetryAfter("http ok");
|
||||
} catch (AcmeRetryAfterException ex) {
|
||||
fail("an AcmeRetryAfterException was thrown");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -725,22 +721,15 @@ public class DefaultConnectionTest {
|
|||
@Override
|
||||
public void resetNonce(Session session) {
|
||||
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
|
||||
if (session.getNonce() == null) {
|
||||
session.setNonce(nonce1);
|
||||
} else {
|
||||
fail("unknown nonce");
|
||||
}
|
||||
assertThat(session.getNonce(), nullValue());
|
||||
session.setNonce(nonce1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNonce() {
|
||||
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
|
||||
if (session.getNonce() == nonce1) {
|
||||
return nonce2;
|
||||
} else {
|
||||
fail("unknown nonce");
|
||||
return null;
|
||||
}
|
||||
assertThat(session.getNonce(), is(nonce1));
|
||||
return nonce2;
|
||||
}
|
||||
}) {
|
||||
JSONBuilder cb = new JSONBuilder();
|
||||
|
@ -800,22 +789,15 @@ public class DefaultConnectionTest {
|
|||
@Override
|
||||
public void resetNonce(Session session) {
|
||||
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
|
||||
if (session.getNonce() == null) {
|
||||
session.setNonce(nonce1);
|
||||
} else {
|
||||
fail("unknown nonce");
|
||||
}
|
||||
assertThat(session.getNonce(), nullValue());
|
||||
session.setNonce(nonce1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNonce() {
|
||||
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
|
||||
if (session.getNonce() == nonce1) {
|
||||
return nonce2;
|
||||
} else {
|
||||
fail("unknown nonce");
|
||||
return null;
|
||||
}
|
||||
assertThat(session.getNonce(), is(nonce1));
|
||||
return nonce2;
|
||||
}
|
||||
}) {
|
||||
conn.sendSignedPostAsGetRequest(requestUrl, login);
|
||||
|
@ -873,22 +855,15 @@ public class DefaultConnectionTest {
|
|||
@Override
|
||||
public void resetNonce(Session session) {
|
||||
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
|
||||
if (session.getNonce() == null) {
|
||||
session.setNonce(nonce1);
|
||||
} else {
|
||||
fail("unknown nonce");
|
||||
}
|
||||
assertThat(session.getNonce(), nullValue());
|
||||
session.setNonce(nonce1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNonce() {
|
||||
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
|
||||
if (session.getNonce() == nonce1) {
|
||||
return nonce2;
|
||||
} else {
|
||||
fail("unknown nonce");
|
||||
return null;
|
||||
}
|
||||
assertThat(session.getNonce(), is(nonce1));
|
||||
return nonce2;
|
||||
}
|
||||
}) {
|
||||
conn.sendCertificateRequest(requestUrl, login);
|
||||
|
@ -924,22 +899,15 @@ public class DefaultConnectionTest {
|
|||
@Override
|
||||
public void resetNonce(Session session) {
|
||||
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
|
||||
if (session.getNonce() == null) {
|
||||
session.setNonce(nonce1);
|
||||
} else {
|
||||
fail("unknown nonce");
|
||||
}
|
||||
assertThat(session.getNonce(), nullValue());
|
||||
session.setNonce(nonce1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNonce() {
|
||||
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
|
||||
if (session.getNonce() == nonce1) {
|
||||
return nonce2;
|
||||
} else {
|
||||
fail("unknown nonce");
|
||||
return null;
|
||||
}
|
||||
assertThat(session.getNonce(), is(nonce1));
|
||||
return nonce2;
|
||||
}
|
||||
}) {
|
||||
JSONBuilder cb = new JSONBuilder();
|
||||
|
@ -989,17 +957,19 @@ public class DefaultConnectionTest {
|
|||
/**
|
||||
* Test signed POST requests if there is no nonce.
|
||||
*/
|
||||
@Test(expected = AcmeException.class)
|
||||
@Test
|
||||
public void testSendSignedRequestNoNonce() throws Exception {
|
||||
when(mockHttpConnection.openConnection(eq(new URL("https://example.com/acme/new-nonce")), any()))
|
||||
.thenReturn(mockUrlConnection);
|
||||
when(mockUrlConnection.getResponseCode())
|
||||
.thenReturn(HttpURLConnection.HTTP_NOT_FOUND);
|
||||
|
||||
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
|
||||
JSONBuilder cb = new JSONBuilder();
|
||||
conn.sendSignedRequest(requestUrl, cb, DefaultConnectionTest.this.session, DefaultConnectionTest.this.keyPair);
|
||||
}
|
||||
assertThrows(AcmeException.class, () -> {
|
||||
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
|
||||
JSONBuilder cb = new JSONBuilder();
|
||||
conn.sendSignedRequest(requestUrl, cb, DefaultConnectionTest.this.session, DefaultConnectionTest.this.keyPair);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1061,7 +1031,7 @@ public class DefaultConnectionTest {
|
|||
/**
|
||||
* Test that a bad certificate throws an exception.
|
||||
*/
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testReadBadCertificate() throws Exception {
|
||||
// Build a broken certificate chain PEM file
|
||||
byte[] brokenPem;
|
||||
|
@ -1079,10 +1049,12 @@ public class DefaultConnectionTest {
|
|||
when(mockUrlConnection.getHeaderField("Content-Type")).thenReturn("application/pem-certificate-chain");
|
||||
when(mockUrlConnection.getInputStream()).thenReturn(new ByteArrayInputStream(brokenPem));
|
||||
|
||||
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
|
||||
conn.conn = mockUrlConnection;
|
||||
conn.readCertificates();
|
||||
}
|
||||
assertThrows(AcmeProtocolException.class, () -> {
|
||||
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
|
||||
conn.conn = mockUrlConnection;
|
||||
conn.readCertificates();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,8 +23,8 @@ import java.net.HttpURLConnection;
|
|||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link HttpConnector}.
|
||||
|
@ -59,7 +59,7 @@ public class HttpConnectorTest {
|
|||
* builds.
|
||||
*/
|
||||
@Test
|
||||
@Category(HttpURLConnection.class)
|
||||
@Tag("requires-network")
|
||||
public void testOpenConnection() throws IOException {
|
||||
NetworkSettings settings = new NetworkSettings();
|
||||
HttpConnector connector = new HttpConnector();
|
||||
|
|
|
@ -15,14 +15,13 @@ package org.shredzone.acme4j.connector;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link NetworkSettings}.
|
||||
|
@ -52,14 +51,18 @@ public class NetworkSettingsTest {
|
|||
public void testInvalidTimeouts() {
|
||||
NetworkSettings settings = new NetworkSettings();
|
||||
|
||||
assertThrows("timeout accepted null", IllegalArgumentException.class,
|
||||
() -> settings.setTimeout(null));
|
||||
assertThrows("timeout accepted zero duration", IllegalArgumentException.class,
|
||||
() -> settings.setTimeout(Duration.ZERO));
|
||||
assertThrows("timeout accepted negative duration", IllegalArgumentException.class,
|
||||
() -> settings.setTimeout(Duration.ofSeconds(20).negated()));
|
||||
assertThrows("timeout accepted out of range value", IllegalArgumentException.class,
|
||||
() -> settings.setTimeout(Duration.ofMillis(Integer.MAX_VALUE + 1L)));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> settings.setTimeout(null),
|
||||
"timeout accepted null");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> settings.setTimeout(Duration.ZERO),
|
||||
"timeout accepted zero duration");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> settings.setTimeout(Duration.ofSeconds(20).negated()),
|
||||
"timeout accepted negative duration");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> settings.setTimeout(Duration.ofMillis(Integer.MAX_VALUE + 1L)),
|
||||
"timeout accepted out of range value");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.shredzone.acme4j.connector;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -27,8 +28,8 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Authorization;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.provider.TestableConnectionProvider;
|
||||
|
@ -47,7 +48,7 @@ public class ResourceIteratorTest {
|
|||
private final List<URL> resourceURLs = new ArrayList<>(PAGES * RESOURCES_PER_PAGE);
|
||||
private final List<URL> pageURLs = new ArrayList<>(PAGES);
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
resourceURLs.clear();
|
||||
for (int ix = 0; ix < RESOURCES_PER_PAGE * PAGES; ix++) {
|
||||
|
@ -63,13 +64,15 @@ public class ResourceIteratorTest {
|
|||
/**
|
||||
* Test if the {@link ResourceIterator} handles a {@code null} start URL.
|
||||
*/
|
||||
@Test(expected = NoSuchElementException.class)
|
||||
@Test
|
||||
public void nullTest() throws IOException {
|
||||
Iterator<Authorization> it = createIterator(null);
|
||||
assertThrows(NoSuchElementException.class, () -> {
|
||||
Iterator<Authorization> it = createIterator(null);
|
||||
|
||||
assertThat(it, not(nullValue()));
|
||||
assertThat(it.hasNext(), is(false));
|
||||
it.next(); // throws NoSuchElementException
|
||||
assertThat(it, not(nullValue()));
|
||||
assertThat(it.hasNext(), is(false));
|
||||
it.next(); // throws NoSuchElementException
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,11 +117,13 @@ public class ResourceIteratorTest {
|
|||
/**
|
||||
* Test that {@link Iterator#remove()} fails.
|
||||
*/
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@Test
|
||||
public void removeTest() throws IOException {
|
||||
Iterator<Authorization> it = createIterator(pageURLs.get(0));
|
||||
it.next();
|
||||
it.remove(); // throws UnsupportedOperationException
|
||||
assertThrows(UnsupportedOperationException.class, () -> {
|
||||
Iterator<Authorization> it = createIterator(pageURLs.get(0));
|
||||
it.next();
|
||||
it.remove(); // throws UnsupportedOperationException
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@ package org.shredzone.acme4j.connector;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test for {@link Resource}.
|
||||
|
|
|
@ -15,12 +15,13 @@ package org.shredzone.acme4j.connector;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.Session;
|
||||
import org.shredzone.acme4j.challenge.Challenge;
|
||||
|
@ -38,9 +39,11 @@ public class SessionProviderTest {
|
|||
* There are no testing providers accepting {@code acme://example.org}. Test that
|
||||
* connecting to this URI will result in an {@link IllegalArgumentException}.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testNone() throws Exception {
|
||||
new Session(new URI("acme://example.org")).provider();
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new Session(new URI("acme://example.org")).provider()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,9 +66,11 @@ public class SessionProviderTest {
|
|||
* There are two testing providers accepting {@code acme://example.net}. Test that
|
||||
* connecting to this URI will result in an {@link IllegalArgumentException}.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testDuplicate() throws Exception {
|
||||
new Session(new URI("acme://example.net")).provider();
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new Session(new URI("acme://example.net")).provider()
|
||||
);
|
||||
}
|
||||
|
||||
public static class Provider1 implements AcmeProvider {
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link TrimmingInputStream}.
|
||||
|
|
|
@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.nullValue;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AcmeException}.
|
||||
|
@ -48,7 +48,7 @@ public class AcmeExceptionTest {
|
|||
|
||||
AcmeException ex = new AcmeException(message, cause);
|
||||
assertThat(ex.getMessage(), is(message));
|
||||
assertThat(ex.getCause(), is((Throwable) cause));
|
||||
assertThat(ex.getCause(), is(cause));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import static org.mockito.Mockito.mock;
|
|||
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.AcmeResource;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.toolbox.TestUtils;
|
||||
|
|
|
@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AcmeNetworkException}.
|
||||
|
|
|
@ -16,7 +16,7 @@ package org.shredzone.acme4j.exception;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AcmeProtocolException}.
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.time.Instant;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Problem;
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,11 +15,12 @@ package org.shredzone.acme4j.exception;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AcmeRetryAfterException}.
|
||||
|
@ -43,9 +44,11 @@ public class AcmeRetryAfterExceptionTest {
|
|||
/**
|
||||
* Test that date is required.
|
||||
*/
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testRequiredAcmeRetryAfterException() throws AcmeException {
|
||||
throw new AcmeRetryAfterException("null-test", null);
|
||||
@Test
|
||||
public void testRequiredAcmeRetryAfterException() {
|
||||
assertThrows(NullPointerException.class, () -> {
|
||||
throw new AcmeRetryAfterException("null-test", null);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.net.MalformedURLException;
|
|||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Problem;
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,8 +15,7 @@ package org.shredzone.acme4j.provider;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||
|
@ -31,7 +30,7 @@ import java.time.temporal.ChronoUnit;
|
|||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Login;
|
||||
import org.shredzone.acme4j.Session;
|
||||
import org.shredzone.acme4j.challenge.Challenge;
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.connector.Connection;
|
||||
import org.shredzone.acme4j.connector.DefaultConnection;
|
||||
|
||||
|
|
|
@ -15,14 +15,13 @@ package org.shredzone.acme4j.provider.letsencrypt;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LetsEncryptAcmeProvider}.
|
||||
|
|
|
@ -15,14 +15,13 @@ package org.shredzone.acme4j.provider.pebble;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PebbleAcmeProvider}.
|
||||
|
|
|
@ -16,8 +16,7 @@ package org.shredzone.acme4j.toolbox;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.AcmeUtils.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -40,17 +39,16 @@ import java.util.List;
|
|||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
import org.shredzone.acme4j.toolbox.AcmeUtils.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AcmeUtils}.
|
||||
*/
|
||||
public class AcmeUtilsTest {
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
@ -173,14 +171,18 @@ public class AcmeUtilsTest {
|
|||
*/
|
||||
@Test
|
||||
public void testInvalid() {
|
||||
assertThrows("accepted empty string", IllegalArgumentException.class,
|
||||
() -> parseTimestamp(""));
|
||||
assertThrows("accepted nonsense string", IllegalArgumentException.class,
|
||||
() -> parseTimestamp("abc"));
|
||||
assertThrows("accepted date only string", IllegalArgumentException.class,
|
||||
() -> parseTimestamp("2015-12-27"));
|
||||
assertThrows("accepted string without time", IllegalArgumentException.class,
|
||||
() -> parseTimestamp("2015-12-27T"));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> parseTimestamp(""),
|
||||
"accepted empty string");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> parseTimestamp("abc"),
|
||||
"accepted nonsense string");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> parseTimestamp("2015-12-27"),
|
||||
"accepted date only string");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> parseTimestamp("2015-12-27T"),
|
||||
"accepted string without time");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,12 +254,15 @@ public class AcmeUtilsTest {
|
|||
public void testValidateContact() {
|
||||
AcmeUtils.validateContact(URI.create("mailto:foo@example.com"));
|
||||
|
||||
assertThrows("multiple recipients are accepted", IllegalArgumentException.class,
|
||||
() -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com,bar@example.com")));
|
||||
assertThrows("hfields are accepted", IllegalArgumentException.class,
|
||||
() -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com?to=bar@example.com")));
|
||||
assertThrows("only hfields are accepted", IllegalArgumentException.class,
|
||||
() -> AcmeUtils.validateContact(URI.create("mailto:?to=foo@example.com")));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com,bar@example.com")),
|
||||
"multiple recipients are accepted");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com?to=bar@example.com")),
|
||||
"hfields are accepted");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> AcmeUtils.validateContact(URI.create("mailto:?to=foo@example.com")),
|
||||
"only hfields are accepted");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.Map;
|
|||
|
||||
import org.jose4j.json.JsonUtil;
|
||||
import org.jose4j.lang.JoseException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test for {@link JSONBuilder}.
|
||||
|
|
|
@ -16,8 +16,7 @@ package org.shredzone.acme4j.toolbox;
|
|||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
|
||||
|
||||
|
@ -40,7 +39,7 @@ import java.util.Map;
|
|||
import java.util.NoSuchElementException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Problem;
|
||||
import org.shredzone.acme4j.Status;
|
||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
|
@ -92,9 +91,11 @@ public class JSONTest {
|
|||
/**
|
||||
* Test that bad JSON fails.
|
||||
*/
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testParsersBadJSON() {
|
||||
JSON.parse("This is no JSON.");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> JSON.parse("This is no JSON.")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -246,30 +247,42 @@ public class JSONTest {
|
|||
assertThat(json.get("none").optional().isPresent(), is(false));
|
||||
assertThat(json.get("none").map(Value::asString).isPresent(), is(false));
|
||||
|
||||
assertThrows("asString", AcmeProtocolException.class,
|
||||
() -> json.get("none").asString());
|
||||
assertThrows("asURI", AcmeProtocolException.class,
|
||||
() -> json.get("none").asURI());
|
||||
assertThrows("asURL", AcmeProtocolException.class,
|
||||
() -> json.get("none").asURL());
|
||||
assertThrows("asInstant", AcmeProtocolException.class,
|
||||
() -> json.get("none").asInstant());
|
||||
assertThrows("asDuration", AcmeProtocolException.class,
|
||||
() -> json.get("none").asDuration());
|
||||
assertThrows("asObject", AcmeProtocolException.class,
|
||||
() -> json.get("none").asObject());
|
||||
assertThrows("asEncodedObject", AcmeProtocolException.class,
|
||||
() -> json.get("none").asEncodedObject());
|
||||
assertThrows("asStatus", AcmeProtocolException.class,
|
||||
() -> json.get("none").asStatus());
|
||||
assertThrows("asBinary", AcmeProtocolException.class,
|
||||
() -> json.get("none").asBinary());
|
||||
assertThrows("asProblem", AcmeProtocolException.class,
|
||||
() -> json.get("none").asProblem(BASE_URL));
|
||||
assertThrows("asInt", AcmeProtocolException.class,
|
||||
() -> json.get("none").asInt());
|
||||
assertThrows("asBoolean", AcmeProtocolException.class,
|
||||
() -> json.get("none").asBoolean());
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asString(),
|
||||
"asString");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asURI(),
|
||||
"asURI");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asURL(),
|
||||
"asURL");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asInstant(),
|
||||
"asInstant");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asDuration(),
|
||||
"asDuration");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asObject(),
|
||||
"asObject");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asEncodedObject(),
|
||||
"asEncodedObject");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asStatus(),
|
||||
"asStatus");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asBinary(),
|
||||
"asBinary");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asProblem(BASE_URL),
|
||||
"asProblem");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asInt(),
|
||||
"asInt");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("none").asBoolean(),
|
||||
"asBoolean");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -279,24 +292,33 @@ public class JSONTest {
|
|||
public void testWrongGetter() {
|
||||
JSON json = TestUtils.getJSON("datatypes");
|
||||
|
||||
assertThrows("asObject", AcmeProtocolException.class,
|
||||
() -> json.get("text").asObject());
|
||||
assertThrows("asEncodedObject", AcmeProtocolException.class,
|
||||
() -> json.get("text").asEncodedObject());
|
||||
assertThrows("asArray", AcmeProtocolException.class,
|
||||
() -> json.get("text").asArray());
|
||||
assertThrows("asInt", AcmeProtocolException.class,
|
||||
() -> json.get("text").asInt());
|
||||
assertThrows("asURI", AcmeProtocolException.class,
|
||||
() -> json.get("text").asURI());
|
||||
assertThrows("asURL", AcmeProtocolException.class,
|
||||
() -> json.get("text").asURL());
|
||||
assertThrows("asInstant", AcmeProtocolException.class,
|
||||
() -> json.get("text").asInstant());
|
||||
assertThrows("asDuration", AcmeProtocolException.class,
|
||||
() -> json.get("text").asDuration());
|
||||
assertThrows("asProblem", AcmeProtocolException.class,
|
||||
() -> json.get("text").asProblem(BASE_URL));
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asObject(),
|
||||
"asObject");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asEncodedObject(),
|
||||
"asEncodedObject");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asArray(),
|
||||
"asArray");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asInt(),
|
||||
"asInt");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asURI(),
|
||||
"asURI");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asURL(),
|
||||
"asURL");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asInstant(),
|
||||
"asInstant");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asDuration(),
|
||||
"asDuration");
|
||||
assertThrows(AcmeProtocolException.class,
|
||||
() -> json.get("text").asProblem(BASE_URL),
|
||||
"asProblem");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@ package org.shredzone.acme4j.toolbox;
|
|||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
|
||||
|
||||
|
@ -33,7 +33,7 @@ import org.jose4j.jwk.PublicJsonWebKey;
|
|||
import org.jose4j.jws.JsonWebSignature;
|
||||
import org.jose4j.jwx.CompactSerializer;
|
||||
import org.jose4j.lang.JoseException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JoseUtils}.
|
||||
|
@ -307,7 +307,7 @@ public class JoseUtilsTest {
|
|||
expectedPayload.append("}");
|
||||
assertThat(decodedPayload, sameJSONAs(expectedPayload.toString()));
|
||||
} catch (JoseException ex) {
|
||||
fail(ex.getMessage());
|
||||
fail(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,12 @@ import static java.util.concurrent.TimeUnit.SECONDS;
|
|||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.KeyPair;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Account;
|
||||
import org.shredzone.acme4j.AccountBuilder;
|
||||
import org.shredzone.acme4j.Authorization;
|
||||
|
@ -80,9 +79,7 @@ public class OrderHttpIT {
|
|||
.conditionEvaluationListener(cond -> updateAuth(auth))
|
||||
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
|
||||
|
||||
if (auth.getStatus() != Status.VALID) {
|
||||
fail("Authorization failed");
|
||||
}
|
||||
assertThat(auth.getStatus(), is(Status.VALID));
|
||||
|
||||
client.httpRemoveToken(challenge.getToken());
|
||||
}
|
||||
|
|
|
@ -16,14 +16,13 @@ package org.shredzone.acme4j.it.pebble;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.security.KeyPair;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Account;
|
||||
import org.shredzone.acme4j.AccountBuilder;
|
||||
import org.shredzone.acme4j.Login;
|
||||
|
@ -192,11 +191,11 @@ public class AccountIT extends PebbleITBase {
|
|||
KeyPair newKeyPair = createKeyPair();
|
||||
acct.changeKey(newKeyPair);
|
||||
|
||||
assertThrows("Old account key is still accessible", AcmeServerException.class, () -> {
|
||||
assertThrows(AcmeServerException.class, () -> {
|
||||
Session sessionOldKey = new Session(pebbleURI());
|
||||
Account oldAccount = sessionOldKey.login(location, keyPair).getAccount();
|
||||
oldAccount.update();
|
||||
});
|
||||
}, "Old account key is still accessible");
|
||||
|
||||
Session sessionNewKey = new Session(pebbleURI());
|
||||
Account newAccount = sessionNewKey.login(location, newKeyPair).getAccount();
|
||||
|
@ -223,12 +222,12 @@ public class AccountIT extends PebbleITBase {
|
|||
assertThat(acct.getStatus(), is(Status.DEACTIVATED));
|
||||
|
||||
// Make sure account cannot be accessed any more...
|
||||
AcmeUnauthorizedException ex = assertThrows("Account can still be accessed",
|
||||
AcmeUnauthorizedException.class, () -> {
|
||||
AcmeUnauthorizedException ex = assertThrows(AcmeUnauthorizedException.class,
|
||||
() -> {
|
||||
Session session2 = new Session(pebbleURI());
|
||||
Account acct2 = session2.login(location, keyPair).getAccount();
|
||||
acct2.update();
|
||||
});
|
||||
}, "Account can still be accessed");
|
||||
assertThat(ex.getMessage(), is("Account has been deactivated"));
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
|
|||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.KeyPair;
|
||||
|
@ -27,7 +26,7 @@ import java.time.Duration;
|
|||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Account;
|
||||
import org.shredzone.acme4j.AccountBuilder;
|
||||
import org.shredzone.acme4j.Authorization;
|
||||
|
@ -43,7 +42,6 @@ import org.shredzone.acme4j.challenge.Http01Challenge;
|
|||
import org.shredzone.acme4j.challenge.TlsAlpn01Challenge;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
import org.shredzone.acme4j.exception.AcmeServerException;
|
||||
import org.shredzone.acme4j.exception.AcmeUnauthorizedException;
|
||||
import org.shredzone.acme4j.it.BammBammClient;
|
||||
import org.shredzone.acme4j.util.CSRBuilder;
|
||||
|
||||
|
@ -186,9 +184,7 @@ public class OrderIT extends PebbleITBase {
|
|||
.conditionEvaluationListener(cond -> updateAuth(auth))
|
||||
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
|
||||
|
||||
if (auth.getStatus() != Status.VALID) {
|
||||
fail("Authorization failed");
|
||||
}
|
||||
assertThat(auth.getStatus(), is(Status.VALID));
|
||||
}
|
||||
|
||||
CSRBuilder csr = new CSRBuilder();
|
||||
|
@ -204,9 +200,7 @@ public class OrderIT extends PebbleITBase {
|
|||
.conditionEvaluationListener(cond -> updateOrder(order))
|
||||
.until(order::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING, Status.READY)));
|
||||
|
||||
if (order.getStatus() != Status.VALID) {
|
||||
fail("Order failed");
|
||||
}
|
||||
assertThat(order.getStatus(), is(Status.VALID));
|
||||
|
||||
Certificate certificate = order.getCertificate();
|
||||
X509Certificate cert = certificate.getCertificate();
|
||||
|
@ -224,16 +218,17 @@ public class OrderIT extends PebbleITBase {
|
|||
revoker.revoke(session, certificate, keyPair, domainKeyPair);
|
||||
|
||||
// Make sure certificate is revoked
|
||||
AcmeException ex = assertThrows("Could download revoked cert", AcmeException.class, () -> {
|
||||
AcmeException ex = assertThrows(AcmeException.class, () -> {
|
||||
Login login2 = session.login(account.getLocation(), keyPair);
|
||||
Certificate cert2 = login2.bindCertificate(certificate.getLocation());
|
||||
cert2.download();
|
||||
});
|
||||
}, "Could download revoked cert");
|
||||
assertThat(ex.getMessage(), is("HTTP 404: Not Found"));
|
||||
|
||||
// Try to revoke again
|
||||
AcmeServerException ex2 = assertThrows("Could revoke again", AcmeServerException.class,
|
||||
() -> certificate.revoke());
|
||||
AcmeServerException ex2 = assertThrows(AcmeServerException.class,
|
||||
() -> certificate.revoke(),
|
||||
"Could revoke again");
|
||||
assertThat(ex2.getProblem().getType(), is(URI.create("urn:ietf:params:acme:error:alreadyRevoked")));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import static java.util.stream.Collectors.toList;
|
|||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
@ -28,7 +27,7 @@ import java.time.temporal.ChronoUnit;
|
|||
import java.util.List;
|
||||
|
||||
import org.bouncycastle.asn1.x509.GeneralName;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Account;
|
||||
import org.shredzone.acme4j.AccountBuilder;
|
||||
import org.shredzone.acme4j.Authorization;
|
||||
|
@ -102,9 +101,7 @@ public class OrderWildcardIT extends PebbleITBase {
|
|||
.conditionEvaluationListener(cond -> updateAuth(auth))
|
||||
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
|
||||
|
||||
if (auth.getStatus() != Status.VALID) {
|
||||
fail("Authorization failed");
|
||||
}
|
||||
assertThat(auth.getStatus(), is(Status.VALID));
|
||||
}
|
||||
|
||||
CSRBuilder csr = new CSRBuilder();
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.security.KeyPair;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.shredzone.acme4j.Authorization;
|
||||
import org.shredzone.acme4j.Order;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
|
@ -51,7 +51,7 @@ public abstract class PebbleITBase {
|
|||
|
||||
private final List<CleanupCallback> cleanup = new ArrayList<>();
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void performCleanup() throws Exception {
|
||||
for (CleanupCallback callback : cleanup) {
|
||||
callback.cleanup();
|
||||
|
|
|
@ -19,7 +19,7 @@ import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
|
|||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Metadata;
|
||||
import org.shredzone.acme4j.Session;
|
||||
import org.shredzone.acme4j.connector.Resource;
|
||||
|
|
|
@ -40,7 +40,7 @@ public interface ResponseBodyGenerator {
|
|||
/**
|
||||
* The content-type of the response body: {@value #RESPONSE_BODY_TYPE}
|
||||
*/
|
||||
public static final String RESPONSE_BODY_TYPE = "text/plain";
|
||||
String RESPONSE_BODY_TYPE = "text/plain";
|
||||
|
||||
/**
|
||||
* Sets the content of the {@link Message}.
|
||||
|
|
|
@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
import jakarta.mail.internet.AddressException;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests of {@link EmailIdentifier}.
|
||||
|
|
|
@ -15,11 +15,12 @@ package org.shredzone.acme4j.smime.challenge;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Status;
|
||||
import org.shredzone.acme4j.challenge.Challenge;
|
||||
import org.shredzone.acme4j.provider.AbstractAcmeProvider;
|
||||
|
@ -63,10 +64,12 @@ public class EmailReply00ChallengeTest extends SMIMETests {
|
|||
/**
|
||||
* Test that {@link EmailReply00Challenge#getAuthorization()} is not implemented.
|
||||
*/
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@Test
|
||||
public void testInvalidGetAuthorization() {
|
||||
EmailReply00Challenge challenge = new EmailReply00Challenge(mockLogin(), getJSON("emailReplyChallenge"));
|
||||
challenge.getAuthorization();
|
||||
assertThrows(UnsupportedOperationException.class, () -> {
|
||||
EmailReply00Challenge challenge = new EmailReply00Challenge(mockLogin(), getJSON("emailReplyChallenge"));
|
||||
challenge.getAuthorization();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@ package org.shredzone.acme4j.smime.csr;
|
|||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -47,9 +47,8 @@ import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
|||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.util.KeyPairUtils;
|
||||
|
||||
/**
|
||||
|
@ -60,7 +59,7 @@ public class SMIMECSRBuilderTest {
|
|||
private static KeyPair testKey;
|
||||
private static KeyPair testEcKey;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
|
@ -241,10 +240,12 @@ public class SMIMECSRBuilderTest {
|
|||
/**
|
||||
* Make sure an exception is thrown when nothing is set.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testNoEmail() throws IOException {
|
||||
SMIMECSRBuilder builder = new SMIMECSRBuilder();
|
||||
builder.sign(testKey);
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
SMIMECSRBuilder builder = new SMIMECSRBuilder();
|
||||
builder.sign(testKey);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,13 +255,13 @@ public class SMIMECSRBuilderTest {
|
|||
public void testNoSign() throws IOException {
|
||||
SMIMECSRBuilder builder = new SMIMECSRBuilder();
|
||||
|
||||
assertThrows("getCSR", IllegalStateException.class, builder::getCSR);
|
||||
assertThrows("getEncoded", IllegalStateException.class, builder::getEncoded);
|
||||
assertThrows("write", IllegalStateException.class,() -> {
|
||||
assertThrows(IllegalStateException.class, builder::getCSR, "getCSR");
|
||||
assertThrows(IllegalStateException.class, builder::getEncoded, "getEncoded");
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
try (StringWriter w = new StringWriter()) {
|
||||
builder.write(w);
|
||||
}
|
||||
});
|
||||
},"write");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.shredzone.acme4j.smime.email;
|
|||
import static jakarta.mail.Message.RecipientType.TO;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
@ -23,7 +24,7 @@ import java.util.Optional;
|
|||
import jakarta.mail.Message;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Identifier;
|
||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
import org.shredzone.acme4j.smime.EmailIdentifier;
|
||||
|
@ -35,10 +36,10 @@ import org.shredzone.acme4j.smime.challenge.EmailReply00Challenge;
|
|||
*/
|
||||
public class EmailProcessorTest extends SMIMETests {
|
||||
|
||||
private InternetAddress expectedFrom = email("acme-generator@example.org");
|
||||
private InternetAddress expectedTo = email("alexey@example.com");
|
||||
private InternetAddress expectedReplyTo = email("acme-validator@example.org");
|
||||
private Message message = mockMessage("challenge");
|
||||
private final InternetAddress expectedFrom = email("acme-generator@example.org");
|
||||
private final InternetAddress expectedTo = email("alexey@example.com");
|
||||
private final InternetAddress expectedReplyTo = email("acme-validator@example.org");
|
||||
private final Message message = mockMessage("challenge");
|
||||
|
||||
@Test
|
||||
public void testEmailParser() throws MessagingException {
|
||||
|
@ -55,46 +56,60 @@ public class EmailProcessorTest extends SMIMETests {
|
|||
assertThat(processor.getReplyTo(), contains(email("acme-validator@example.org")));
|
||||
}
|
||||
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void textExpectedFromFails() {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.expectedFrom(expectedTo);
|
||||
assertThrows(AcmeProtocolException.class, () -> {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.expectedFrom(expectedTo);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void textExpectedToFails() {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.expectedTo(expectedFrom);
|
||||
assertThrows(AcmeProtocolException.class, () -> {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.expectedTo(expectedFrom);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void textExpectedIdentifierFails1() {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.expectedIdentifier(EmailIdentifier.email(expectedFrom));
|
||||
assertThrows(AcmeProtocolException.class, () -> {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.expectedIdentifier(EmailIdentifier.email(expectedFrom));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void textExpectedIdentifierFails2() {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.expectedIdentifier(Identifier.ip("192.168.0.1"));
|
||||
assertThrows(AcmeProtocolException.class, () -> {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.expectedIdentifier(Identifier.ip("192.168.0.1"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void textNoChallengeFails1() {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.getToken();
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.getToken();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void textNoChallengeFails2() {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.getAuthorization();
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.getAuthorization();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void textNoChallengeFails3() {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.respond();
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.respond();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -108,11 +123,13 @@ public class EmailProcessorTest extends SMIMETests {
|
|||
assertThat(processor.respond(), is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test(expected = AcmeProtocolException.class)
|
||||
@Test
|
||||
public void testChallengeMismatch() {
|
||||
EmailReply00Challenge challenge = mockChallenge("emailReplyChallengeMismatch");
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.withChallenge(challenge);
|
||||
assertThrows(AcmeProtocolException.class, () -> {
|
||||
EmailReply00Challenge challenge = mockChallenge("emailReplyChallengeMismatch");
|
||||
EmailProcessor processor = new EmailProcessor(message);
|
||||
processor.withChallenge(challenge);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -15,8 +15,7 @@ package org.shredzone.acme4j.util;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -24,6 +23,7 @@ import java.io.StringReader;
|
|||
import java.io.StringWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyPair;
|
||||
import java.security.Security;
|
||||
import java.util.Arrays;
|
||||
|
@ -45,8 +45,8 @@ import org.bouncycastle.openssl.PEMParser;
|
|||
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Identifier;
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ public class CSRBuilderTest {
|
|||
private static KeyPair testKey;
|
||||
private static KeyPair testEcKey;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
|
@ -230,25 +230,29 @@ public class CSRBuilderTest {
|
|||
builder.write(baos);
|
||||
pemBytes = baos.toByteArray();
|
||||
}
|
||||
assertThat(new String(pemBytes, "utf-8"), is(equalTo(pem)));
|
||||
assertThat(new String(pemBytes, StandardCharsets.UTF_8), is(equalTo(pem)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure an exception is thrown when no domain is set.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testNoDomain() throws IOException {
|
||||
CSRBuilder builder = new CSRBuilder();
|
||||
builder.sign(testKey);
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
CSRBuilder builder = new CSRBuilder();
|
||||
builder.sign(testKey);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure an exception is thrown when an unknown identifier type is used.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testUnknownType() {
|
||||
CSRBuilder builder = new CSRBuilder();
|
||||
builder.addIdentifier(new Identifier("UnKnOwN", "123"));
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CSRBuilder builder = new CSRBuilder();
|
||||
builder.addIdentifier(new Identifier("UnKnOwN", "123"));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,13 +262,13 @@ public class CSRBuilderTest {
|
|||
public void testNoSign() throws IOException {
|
||||
CSRBuilder builder = new CSRBuilder();
|
||||
|
||||
assertThrows("getCSR()", IllegalStateException.class, builder::getCSR);
|
||||
assertThrows("getEncoded()", IllegalStateException.class, builder::getEncoded);
|
||||
assertThrows("write()", IllegalStateException.class, () -> {
|
||||
assertThrows(IllegalStateException.class, builder::getCSR, "getCSR()");
|
||||
assertThrows(IllegalStateException.class, builder::getEncoded, "getEncoded()");
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
try (StringWriter w = new StringWriter()) {
|
||||
builder.write(w);
|
||||
};
|
||||
});
|
||||
}
|
||||
}, "write()");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.bouncycastle.asn1.BERTags;
|
|||
import org.bouncycastle.asn1.DEROctetString;
|
||||
import org.bouncycastle.asn1.x509.GeneralName;
|
||||
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.shredzone.acme4j.Identifier;
|
||||
import org.shredzone.acme4j.challenge.TlsAlpn01Challenge;
|
||||
import org.shredzone.acme4j.toolbox.AcmeUtils;
|
||||
|
|
|
@ -27,8 +27,8 @@ import java.security.interfaces.ECPublicKey;
|
|||
import java.security.interfaces.RSAPublicKey;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link KeyPairUtils}.
|
||||
|
@ -37,7 +37,7 @@ public class KeyPairUtilsTest {
|
|||
private static final int KEY_SIZE = 2048;
|
||||
private static final String EC_CURVE = "secp256r1";
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -119,7 +119,7 @@
|
|||
<configuration combine.children="append">
|
||||
<parallel>classes</parallel>
|
||||
<threadCount>10</threadCount>
|
||||
<excludedGroups>java.net.HttpURLConnection</excludedGroups>
|
||||
<excludedGroups>requires-network</excludedGroups>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -203,9 +203,9 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
Loading…
Reference in New Issue