Single method to get the certificate

This commit is contained in:
Richard Körber
2024-10-21 07:11:09 +02:00
parent 6a24d85364
commit 318aeaab9d
4 changed files with 23 additions and 6 deletions

View File

@@ -143,7 +143,9 @@ public class Order extends AcmeJsonResource implements PollableResource {
@SuppressFBWarnings("EI_EXPOSE_REP") // behavior is intended
public Certificate getCertificate() {
if (certificate == null) {
certificate = getJSON().get("certificate")
certificate = getJSON().get("star-certificate")
.optional()
.or(() -> getJSON().get("certificate").optional())
.map(Value::asURL)
.map(getLogin()::bindCertificate)
.orElseThrow(() -> new IllegalStateException("Order is not completed"));
@@ -159,7 +161,9 @@ public class Order extends AcmeJsonResource implements PollableResource {
* if the order is not ready yet. You must finalize the order first, and wait
* for the status to become {@link Status#VALID}. It is also thrown if the
* order has been {@link Status#CANCELED}.
* @deprecated Use {@link #getCertificate()} for STAR certificates as well.
*/
@Deprecated
@SuppressFBWarnings("EI_EXPOSE_REP") // behavior is intended
public Certificate getAutoRenewalCertificate() {
if (autoRenewalCertificate == null) {
@@ -172,6 +176,16 @@ public class Order extends AcmeJsonResource implements PollableResource {
return autoRenewalCertificate;
}
/**
* Returns whether this is a STAR certificate ({@code true}) or a standard certificate
* ({@code false}).
*
* @since 3.5.0
*/
public boolean isAutoRenewalCertificate() {
return getJSON().contains("star-certificate");
}
/**
* Finalizes the order.
* <p>

View File

@@ -201,6 +201,7 @@ public class OrderTest {
.isEqualTo("2016-01-01T00:00:00Z");
softly.assertThat(order.getNotAfter().orElseThrow())
.isEqualTo("2016-01-08T00:00:00Z");
softly.assertThat(order.isAutoRenewalCertificate()).isFalse();
softly.assertThat(order.getCertificate().getLocation())
.isEqualTo(url("https://example.com/acme/cert/1234"));
softly.assertThatIllegalStateException()
@@ -284,8 +285,9 @@ public class OrderTest {
var order = login.bindOrder(locationUrl);
try (var softly = new AutoCloseableSoftAssertions()) {
softly.assertThatIllegalStateException()
.isThrownBy(order::getCertificate);
softly.assertThat(order.isAutoRenewalCertificate()).isTrue();
softly.assertThat(order.getCertificate().getLocation())
.isEqualTo(url("https://example.com/acme/cert/1234"));
softly.assertThat(order.getAutoRenewalCertificate().getLocation())
.isEqualTo(url("https://example.com/acme/cert/1234"));
softly.assertThat(order.isAutoRenewing()).isTrue();