getCertificate() is not Optional

getCertificate() would only return Optional.empty() if it was invoked
before the order was finalized. In order to keep the API simple, that
state will now throw an IllegalStateException, and getCertificate()
directly returns a non-null Certificate now.
This commit is contained in:
Richard Körber
2023-05-06 17:11:36 +02:00
parent 1907545e5d
commit 5bbf1b5966
6 changed files with 17 additions and 18 deletions

View File

@@ -23,7 +23,6 @@ import java.security.KeyPair;
import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.AccountBuilder;
import org.shredzone.acme4j.Authorization;
import org.shredzone.acme4j.Certificate;
import org.shredzone.acme4j.Order;
import org.shredzone.acme4j.Session;
import org.shredzone.acme4j.Status;
@@ -93,9 +92,7 @@ public class OrderHttpIT {
.conditionEvaluationListener(cond -> updateOrder(order))
.untilAsserted(() -> assertThat(order.getStatus()).isNotIn(Status.PENDING, Status.PROCESSING));
var cert = order.getCertificate()
.map(Certificate::getCertificate)
.orElseThrow();
var cert = order.getCertificate().getCertificate();
assertThat(cert.getNotAfter()).isNotNull();
assertThat(cert.getNotBefore()).isNotNull();
assertThat(cert.getSubjectX500Principal().getName()).contains("CN=" + TEST_DOMAIN);

View File

@@ -195,7 +195,7 @@ public class OrderIT extends PebbleITBase {
assertThat(order.getStatus()).isEqualTo(Status.VALID);
var certificate = order.getCertificate().orElseThrow();
var certificate = order.getCertificate();
var cert = certificate.getCertificate();
assertThat(cert).isNotNull();
assertThat(cert.getNotBefore().toInstant()).isEqualTo(notBefore);

View File

@@ -25,7 +25,6 @@ import java.time.temporal.ChronoUnit;
import org.bouncycastle.asn1.x509.GeneralName;
import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.AccountBuilder;
import org.shredzone.acme4j.Certificate;
import org.shredzone.acme4j.Session;
import org.shredzone.acme4j.Status;
import org.shredzone.acme4j.challenge.Dns01Challenge;
@@ -112,9 +111,7 @@ public class OrderWildcardIT extends PebbleITBase {
order.getStatus()).isNotIn(Status.PENDING, Status.PROCESSING));
var cert = order.getCertificate()
.map(Certificate::getCertificate)
.orElseThrow();
var cert = order.getCertificate().getCertificate();
assertThat(cert).isNotNull();
assertThat(cert.getNotAfter()).isNotEqualTo(notBefore);
assertThat(cert.getNotBefore()).isNotEqualTo(notAfter);