mirror of
https://github.com/shred/acme4j.git
synced 2025-12-13 11:14:02 +08:00
Upgrade all tests to JUnit 5
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user