Skip to content

Commit

Permalink
Add IT for Pebble profile
Browse files Browse the repository at this point in the history
  • Loading branch information
shred committed Jan 26, 2025
1 parent f6a3bd6 commit 6b0b0e6
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.shredzone.acme4j.AccountBuilder;
import org.shredzone.acme4j.Authorization;
import org.shredzone.acme4j.Certificate;
Expand All @@ -49,8 +52,10 @@ public class OrderIT extends PebbleITBase {
/**
* Test if a certificate can be ordered via http-01 challenge.
*/
@Test
public void testHttpValidation() throws Exception {
@ParameterizedTest
@NullSource
@ValueSource(strings = {"default", "shortlived"})
public void testHttpValidation(String profile) throws Exception {
orderCertificate(TEST_DOMAIN, auth -> {
var client = getBammBammClient();

Expand All @@ -61,14 +66,16 @@ public void testHttpValidation() throws Exception {
cleanup(() -> client.httpRemoveToken(challenge.getToken()));

return challenge;
}, OrderIT::standardRevoker);
}, OrderIT::standardRevoker, profile);
}

/**
* Test if a certificate can be ordered via dns-01 challenge.
*/
@Test
public void testDnsValidation() throws Exception {
@ParameterizedTest
@NullSource
@ValueSource(strings = {"default", "shortlived"})
public void testDnsValidation(String profile) throws Exception {
orderCertificate(TEST_DOMAIN, auth -> {
var client = getBammBammClient();

Expand All @@ -81,14 +88,16 @@ public void testDnsValidation() throws Exception {
cleanup(() -> client.dnsRemoveTxtRecord(challengeDomainName));

return challenge;
}, OrderIT::standardRevoker);
}, OrderIT::standardRevoker, profile);
}

/**
* Test if a certificate can be ordered via tns-alpn-01 challenge.
*/
@Test
public void testTlsAlpnValidation() throws Exception {
@ParameterizedTest
@NullSource
@ValueSource(strings = {"default", "shortlived"})
public void testTlsAlpnValidation(String profile) throws Exception {
orderCertificate(TEST_DOMAIN, auth -> {
var client = getBammBammClient();

Expand All @@ -101,7 +110,7 @@ public void testTlsAlpnValidation() throws Exception {
cleanup(() -> client.tlsAlpnRemoveCertificate(auth.getIdentifier().getDomain()));

return challenge;
}, OrderIT::standardRevoker);
}, OrderIT::standardRevoker, profile);
}

/**
Expand All @@ -119,7 +128,7 @@ public void testDomainKeyRevocation() throws Exception {
cleanup(() -> client.httpRemoveToken(challenge.getToken()));

return challenge;
}, OrderIT::domainKeyRevoker);
}, OrderIT::domainKeyRevoker, null);
}

/**
Expand All @@ -132,8 +141,10 @@ public void testDomainKeyRevocation() throws Exception {
* validation
* @param revoker
* {@link Revoker} that finally revokes the certificate
* @param profile
* Profile to be used, or {@code null} for no profile selection.
*/
private void orderCertificate(String domain, Validator validator, Revoker revoker)
private void orderCertificate(String domain, Validator validator, Revoker revoker, String profile)
throws Exception {
var keyPair = createKeyPair();
var session = new Session(pebbleURI());
Expand All @@ -148,15 +159,26 @@ private void orderCertificate(String domain, Validator validator, Revoker revoke
var notBefore = Instant.now().truncatedTo(ChronoUnit.SECONDS);
var notAfter = notBefore.plus(Duration.ofDays(20L));

var order = account.newOrder()
.domain(domain)
.notBefore(notBefore)
.notAfter(notAfter)
.create();
var orderBuilder = account.newOrder()
.domain(domain)
.notBefore(notBefore)
.notAfter(notAfter);

if (profile != null) {
orderBuilder.profile(profile);
}

var order = orderBuilder.create();
assertThat(order.getNotBefore().orElseThrow()).isEqualTo(notBefore);
assertThat(order.getNotAfter().orElseThrow()).isEqualTo(notAfter);
assertThat(order.getStatus()).isEqualTo(Status.PENDING);

if (profile != null) {
assertThat(order.getProfile()).contains(profile);
} else {
// FIXME: Pebble falls back to different values here, cannot be tested properly
}

for (var auth : order.getAuthorizations()) {
assertThat(auth.getIdentifier().getDomain()).isEqualTo(domain);
assertThat(auth.getStatus()).isEqualTo(Status.PENDING);
Expand Down

0 comments on commit 6b0b0e6

Please sign in to comment.