mirror of https://github.com/shred/acme4j
				
				
				
			Add IT for Pebble profile
							parent
							
								
									f6a3bd618b
								
							
						
					
					
						commit
						6b0b0e68b6
					
				|  | @ -24,6 +24,9 @@ import java.time.Instant; | ||||||
| import java.time.temporal.ChronoUnit; | import java.time.temporal.ChronoUnit; | ||||||
| 
 | 
 | ||||||
| import org.junit.jupiter.api.Test; | 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.AccountBuilder; | ||||||
| import org.shredzone.acme4j.Authorization; | import org.shredzone.acme4j.Authorization; | ||||||
| import org.shredzone.acme4j.Certificate; | import org.shredzone.acme4j.Certificate; | ||||||
|  | @ -49,8 +52,10 @@ public class OrderIT extends PebbleITBase { | ||||||
|     /** |     /** | ||||||
|      * Test if a certificate can be ordered via http-01 challenge. |      * Test if a certificate can be ordered via http-01 challenge. | ||||||
|      */ |      */ | ||||||
|     @Test |     @ParameterizedTest | ||||||
|     public void testHttpValidation() throws Exception { |     @NullSource | ||||||
|  |     @ValueSource(strings = {"default", "shortlived"}) | ||||||
|  |     public void testHttpValidation(String profile) throws Exception { | ||||||
|         orderCertificate(TEST_DOMAIN, auth -> { |         orderCertificate(TEST_DOMAIN, auth -> { | ||||||
|             var client = getBammBammClient(); |             var client = getBammBammClient(); | ||||||
| 
 | 
 | ||||||
|  | @ -61,14 +66,16 @@ public class OrderIT extends PebbleITBase { | ||||||
|             cleanup(() -> client.httpRemoveToken(challenge.getToken())); |             cleanup(() -> client.httpRemoveToken(challenge.getToken())); | ||||||
| 
 | 
 | ||||||
|             return challenge; |             return challenge; | ||||||
|         }, OrderIT::standardRevoker); |         }, OrderIT::standardRevoker, profile); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Test if a certificate can be ordered via dns-01 challenge. |      * Test if a certificate can be ordered via dns-01 challenge. | ||||||
|      */ |      */ | ||||||
|     @Test |     @ParameterizedTest | ||||||
|     public void testDnsValidation() throws Exception { |     @NullSource | ||||||
|  |     @ValueSource(strings = {"default", "shortlived"}) | ||||||
|  |     public void testDnsValidation(String profile) throws Exception { | ||||||
|         orderCertificate(TEST_DOMAIN, auth -> { |         orderCertificate(TEST_DOMAIN, auth -> { | ||||||
|             var client = getBammBammClient(); |             var client = getBammBammClient(); | ||||||
| 
 | 
 | ||||||
|  | @ -81,14 +88,16 @@ public class OrderIT extends PebbleITBase { | ||||||
|             cleanup(() -> client.dnsRemoveTxtRecord(challengeDomainName)); |             cleanup(() -> client.dnsRemoveTxtRecord(challengeDomainName)); | ||||||
| 
 | 
 | ||||||
|             return challenge; |             return challenge; | ||||||
|         }, OrderIT::standardRevoker); |         }, OrderIT::standardRevoker, profile); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Test if a certificate can be ordered via tns-alpn-01 challenge. |      * Test if a certificate can be ordered via tns-alpn-01 challenge. | ||||||
|      */ |      */ | ||||||
|     @Test |     @ParameterizedTest | ||||||
|     public void testTlsAlpnValidation() throws Exception { |     @NullSource | ||||||
|  |     @ValueSource(strings = {"default", "shortlived"}) | ||||||
|  |     public void testTlsAlpnValidation(String profile) throws Exception { | ||||||
|         orderCertificate(TEST_DOMAIN, auth -> { |         orderCertificate(TEST_DOMAIN, auth -> { | ||||||
|             var client = getBammBammClient(); |             var client = getBammBammClient(); | ||||||
| 
 | 
 | ||||||
|  | @ -101,7 +110,7 @@ public class OrderIT extends PebbleITBase { | ||||||
|             cleanup(() -> client.tlsAlpnRemoveCertificate(auth.getIdentifier().getDomain())); |             cleanup(() -> client.tlsAlpnRemoveCertificate(auth.getIdentifier().getDomain())); | ||||||
| 
 | 
 | ||||||
|             return challenge; |             return challenge; | ||||||
|         }, OrderIT::standardRevoker); |         }, OrderIT::standardRevoker, profile); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -119,7 +128,7 @@ public class OrderIT extends PebbleITBase { | ||||||
|             cleanup(() -> client.httpRemoveToken(challenge.getToken())); |             cleanup(() -> client.httpRemoveToken(challenge.getToken())); | ||||||
| 
 | 
 | ||||||
|             return challenge; |             return challenge; | ||||||
|         }, OrderIT::domainKeyRevoker); |         }, OrderIT::domainKeyRevoker, null); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -132,8 +141,10 @@ public class OrderIT extends PebbleITBase { | ||||||
|      *            validation |      *            validation | ||||||
|      * @param revoker |      * @param revoker | ||||||
|      *            {@link Revoker} that finally revokes the certificate |      *            {@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 { |             throws Exception { | ||||||
|         var keyPair = createKeyPair(); |         var keyPair = createKeyPair(); | ||||||
|         var session = new Session(pebbleURI()); |         var session = new Session(pebbleURI()); | ||||||
|  | @ -148,15 +159,26 @@ public class OrderIT extends PebbleITBase { | ||||||
|         var notBefore = Instant.now().truncatedTo(ChronoUnit.SECONDS); |         var notBefore = Instant.now().truncatedTo(ChronoUnit.SECONDS); | ||||||
|         var notAfter = notBefore.plus(Duration.ofDays(20L)); |         var notAfter = notBefore.plus(Duration.ofDays(20L)); | ||||||
| 
 | 
 | ||||||
|         var order = account.newOrder() |         var orderBuilder = account.newOrder() | ||||||
|                     .domain(domain) |                 .domain(domain) | ||||||
|                     .notBefore(notBefore) |                 .notBefore(notBefore) | ||||||
|                     .notAfter(notAfter) |                 .notAfter(notAfter); | ||||||
|                     .create(); | 
 | ||||||
|  |         if (profile != null) { | ||||||
|  |             orderBuilder.profile(profile); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         var order = orderBuilder.create(); | ||||||
|         assertThat(order.getNotBefore().orElseThrow()).isEqualTo(notBefore); |         assertThat(order.getNotBefore().orElseThrow()).isEqualTo(notBefore); | ||||||
|         assertThat(order.getNotAfter().orElseThrow()).isEqualTo(notAfter); |         assertThat(order.getNotAfter().orElseThrow()).isEqualTo(notAfter); | ||||||
|         assertThat(order.getStatus()).isEqualTo(Status.PENDING); |         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()) { |         for (var auth : order.getAuthorizations()) { | ||||||
|             assertThat(auth.getIdentifier().getDomain()).isEqualTo(domain); |             assertThat(auth.getIdentifier().getDomain()).isEqualTo(domain); | ||||||
|             assertThat(auth.getStatus()).isEqualTo(Status.PENDING); |             assertThat(auth.getStatus()).isEqualTo(Status.PENDING); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Richard Körber
						Richard Körber