mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat: add ACM support (#21)
* feat: add ACM support * fix: address code review issues - pagination, idempotency TTL, AES-256 - BouncyCastle static initialization to prevent race conditions - Cursor-based pagination for ListCertificates - Idempotency token 1-hour TTL with lazy expiration - AES-256-CBC encryption replacing Triple-DES - 58 tests passing with new edge case coverage * fix: address PR #21 review feedback - Add GraalVM native image hints for BouncyCastle (initialize-at-run-time, reflection config) - Add runtime initialization for AcmService and CertificateGenerator (SecureRandom fix) - Log security warning lazily on first certificate creation/import (not at startup) - Add AcmStorageConfig interface for consistency with other services --- 🎉 Merged! Thank you so much, @cahna! This is exactly the kind of contribution that helps Floci grow — your work is genuinely appreciated. If you're up for it, there's plenty more to dig into: - 👀 Check out the open issues — some are tagged as good first steps for contributors - 💬 If you have ideas or ran into something while working on this, feel free to open an issue or start a discussion - 🔧 PRs for documentation, tests, and bug fixes are always welcome Hoping to see your name pop up again soon. Welcome to the Floci community! 🙌
This commit is contained in:
1 parent
9105d85a6f
commit
8a8d55d972
30 files changed
+3847
-4
No files matched your search
@@ -0,0 +1,325 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.config.EncoderConfig;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Tests for edge cases: wildcard domains, max SANs (100), max tags (50).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class AcmEdgeCaseTest {
|
||||
|
||||
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssured.config = RestAssured.config().encoderConfig(
|
||||
EncoderConfig.encoderConfig()
|
||||
.encodeContentTypeAs(ACM_CONTENT_TYPE, ContentType.TEXT));
|
||||
}
|
||||
|
||||
// ==================== Wildcard Domain Tests ====================
|
||||
|
||||
@Test
|
||||
void wildcardDomainAsPrimary() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "*.example.com"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void wildcardDomainAsSan() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "example.com",
|
||||
"SubjectAlternativeNames": ["*.example.com", "www.example.com"]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nestedWildcardDomain() {
|
||||
// AWS allows wildcards only at the leftmost position
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "*.api.example.com"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
// ==================== Max SANs Tests ====================
|
||||
|
||||
@Test
|
||||
void exactlyMaxSans() {
|
||||
// 100 SANs is the maximum
|
||||
List<String> sans = IntStream.range(0, 99)
|
||||
.mapToObj(i -> "san" + i + ".example.com")
|
||||
.collect(Collectors.toList());
|
||||
|
||||
String sansJson = sans.stream()
|
||||
.map(s -> "\"" + s + "\"")
|
||||
.collect(Collectors.joining(", ", "[", "]"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "max-sans.example.com",
|
||||
"SubjectAlternativeNames": %s
|
||||
}
|
||||
""".formatted(sansJson))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exceedMaxSans() {
|
||||
// 101 SANs should fail (primary domain + 100 SANs = 101 total)
|
||||
List<String> sans = IntStream.range(0, 101)
|
||||
.mapToObj(i -> "san" + i + ".example.com")
|
||||
.collect(Collectors.toList());
|
||||
|
||||
String sansJson = sans.stream()
|
||||
.map(s -> "\"" + s + "\"")
|
||||
.collect(Collectors.joining(", ", "[", "]"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "exceed-sans.example.com",
|
||||
"SubjectAlternativeNames": %s
|
||||
}
|
||||
""".formatted(sansJson))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
// ==================== Max Tags Tests ====================
|
||||
|
||||
@Test
|
||||
void exactlyMaxTags() {
|
||||
// 50 tags is the maximum
|
||||
String tagsJson = IntStream.range(0, 50)
|
||||
.mapToObj(i -> "{\"Key\": \"Tag" + i + "\", \"Value\": \"Value" + i + "\"}")
|
||||
.collect(Collectors.joining(", ", "[", "]"));
|
||||
|
||||
String arn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "max-tags-%s.example.com",
|
||||
"Tags": %s
|
||||
}
|
||||
""".formatted(UUID.randomUUID(), tagsJson))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// Verify tags were applied
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListTagsForCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(arn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.size()", equalTo(50));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exceedMaxTags() {
|
||||
// 51 tags should fail
|
||||
String tagsJson = IntStream.range(0, 51)
|
||||
.mapToObj(i -> "{\"Key\": \"Tag" + i + "\", \"Value\": \"Value" + i + "\"}")
|
||||
.collect(Collectors.joining(", ", "[", "]"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "exceed-tags.example.com",
|
||||
"Tags": %s
|
||||
}
|
||||
""".formatted(tagsJson))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
// ==================== Validation Method Tests ====================
|
||||
|
||||
@Test
|
||||
void invalidValidationMethodThrowsException() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "invalid-validation.example.com",
|
||||
"ValidationMethod": "INVALID_METHOD"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
// ==================== Domain Name Validation Tests ====================
|
||||
|
||||
@Test
|
||||
void emptyDomainNameFails() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": ""
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void domainNameTooLong() {
|
||||
// Max domain length is 253 characters
|
||||
String longDomain = "a".repeat(254) + ".example.com";
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s"
|
||||
}
|
||||
""".formatted(longDomain))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
// ==================== Tag Validation Tests ====================
|
||||
|
||||
@Test
|
||||
void awsPrefixedTagKeyFails() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "aws-tag.example.com",
|
||||
"Tags": [{"Key": "aws:reserved", "Value": "test"}]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyTagKeyFails() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.AddTagsToCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/test",
|
||||
"Tags": [{"Key": "", "Value": "test"}]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(400), equalTo(404)));
|
||||
}
|
||||
|
||||
// ==================== Key Algorithm Tests ====================
|
||||
|
||||
@Test
|
||||
void allKeyAlgorithmsSupported() {
|
||||
String[] algorithms = {"RSA_2048", "RSA_3072", "RSA_4096", "EC_prime256v1", "EC_secp384r1", "EC_secp521r1"};
|
||||
|
||||
for (String algo : algorithms) {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s.example.com",
|
||||
"KeyAlgorithm": "%s"
|
||||
}
|
||||
""".formatted(algo.toLowerCase().replace("_", "-"), algo))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.config.EncoderConfig;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Tests for idempotency token functionality with 1-hour TTL.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class AcmIdempotencyTest {
|
||||
|
||||
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssured.config = RestAssured.config().encoderConfig(
|
||||
EncoderConfig.encoderConfig()
|
||||
.encodeContentTypeAs(ACM_CONTENT_TYPE, ContentType.TEXT));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void sameTokenReturnsExistingCertificate() {
|
||||
String token = "idempotency-test-" + UUID.randomUUID();
|
||||
String domain = "idempotent-" + UUID.randomUUID() + ".example.com";
|
||||
|
||||
// First request
|
||||
String firstArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s",
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(domain, token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// Second request with same token should return same ARN
|
||||
String secondArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s",
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(domain, token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", equalTo(firstArn))
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// ARNs should match
|
||||
org.junit.jupiter.api.Assertions.assertEquals(firstArn, secondArn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void differentTokenCreatesNewCertificate() {
|
||||
String domain = "multi-token-" + UUID.randomUUID() + ".example.com";
|
||||
|
||||
// First request
|
||||
String firstArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s",
|
||||
"IdempotencyToken": "token-1-%s"
|
||||
}
|
||||
""".formatted(domain, UUID.randomUUID()))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// Second request with different token should create new certificate
|
||||
String secondArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s",
|
||||
"IdempotencyToken": "token-2-%s"
|
||||
}
|
||||
""".formatted(domain, UUID.randomUUID()))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// ARNs should be different
|
||||
org.junit.jupiter.api.Assertions.assertNotEquals(firstArn, secondArn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void sameTokenDifferentParamsThrowsIdempotencyException() {
|
||||
String token = "param-mismatch-" + UUID.randomUUID();
|
||||
|
||||
// First request with domain A
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "domain-a-%s.example.com",
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(UUID.randomUUID(), token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Second request with same token but different domain - should fail
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "domain-b-%s.example.com",
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(UUID.randomUUID(), token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("IdempotencyException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void sameTokenDifferentKeyAlgorithmThrowsIdempotencyException() {
|
||||
String token = "key-algo-mismatch-" + UUID.randomUUID();
|
||||
String domain = "key-algo-" + UUID.randomUUID() + ".example.com";
|
||||
|
||||
// First request with RSA-2048
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s",
|
||||
"KeyAlgorithm": "RSA_2048",
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(domain, token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Second request with same token but different key algorithm - should fail
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s",
|
||||
"KeyAlgorithm": "EC_prime256v1",
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(domain, token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("IdempotencyException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void noTokenAlwaysCreatesNewCertificate() {
|
||||
String domain = "no-token-" + UUID.randomUUID() + ".example.com";
|
||||
|
||||
// First request without token
|
||||
String firstArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s"
|
||||
}
|
||||
""".formatted(domain))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// Second request without token should create new certificate
|
||||
String secondArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s"
|
||||
}
|
||||
""".formatted(domain))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertNotEquals(firstArn, secondArn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void sameTokenSameSansReturnsExistingCertificate() {
|
||||
String token = "sans-match-" + UUID.randomUUID();
|
||||
String domain = "sans-" + UUID.randomUUID() + ".example.com";
|
||||
|
||||
// First request with SANs
|
||||
String firstArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s",
|
||||
"SubjectAlternativeNames": ["www.%s", "api.%s"],
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(domain, domain, domain, token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// Same request should return same ARN
|
||||
String secondArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s",
|
||||
"SubjectAlternativeNames": ["www.%s", "api.%s"],
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(domain, domain, domain, token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertEquals(firstArn, secondArn);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.config.EncoderConfig;
|
||||
import io.restassured.http.ContentType;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class AcmImportExportTest {
|
||||
|
||||
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@Inject
|
||||
CertificateGenerator certificateGenerator;
|
||||
|
||||
// Generated test certificate data
|
||||
private String validTestCertificate;
|
||||
private String validTestPrivateKey;
|
||||
|
||||
private String importedCertificateArn;
|
||||
private String exportableCertificateArn;
|
||||
|
||||
@BeforeAll
|
||||
void setupTestCertificates() {
|
||||
RestAssured.config = RestAssured.config().encoderConfig(
|
||||
EncoderConfig.encoderConfig()
|
||||
.encodeContentTypeAs(ACM_CONTENT_TYPE, ContentType.TEXT));
|
||||
|
||||
// Generate a valid test certificate using CertificateGenerator
|
||||
CertificateGenerator.GeneratedCertificate generated = certificateGenerator.generateCertificate(
|
||||
"test-import.example.com",
|
||||
List.of("www.test-import.example.com"),
|
||||
KeyAlgorithm.RSA_2048
|
||||
);
|
||||
|
||||
validTestCertificate = generated.certificatePem();
|
||||
validTestPrivateKey = generated.privateKeyPem();
|
||||
}
|
||||
|
||||
// ==================== ImportCertificate Tests ====================
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void importCertificateBasic() {
|
||||
// Escape newlines for JSON
|
||||
String certJson = validTestCertificate.replace("\n", "\\n");
|
||||
String keyJson = validTestPrivateKey.replace("\n", "\\n");
|
||||
|
||||
importedCertificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.ImportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Certificate": "%s",
|
||||
"PrivateKey": "%s"
|
||||
}
|
||||
""".formatted(certJson, keyJson))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"))
|
||||
.body("CertificateArn", containsString(":certificate/"))
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void verifyImportedCertificate() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(importedCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Certificate.CertificateArn", equalTo(importedCertificateArn))
|
||||
.body("Certificate.DomainName", equalTo("test-import.example.com"))
|
||||
.body("Certificate.Status", equalTo("ISSUED"))
|
||||
.body("Certificate.Type", equalTo("IMPORTED"))
|
||||
.body("Certificate.KeyAlgorithm", equalTo("RSA-2048"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void importCertificateWithTags() {
|
||||
String certJson = validTestCertificate.replace("\n", "\\n");
|
||||
String keyJson = validTestPrivateKey.replace("\n", "\\n");
|
||||
|
||||
String taggedArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.ImportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Certificate": "%s",
|
||||
"PrivateKey": "%s",
|
||||
"Tags": [
|
||||
{"Key": "Environment", "Value": "test"},
|
||||
{"Key": "ImportTest", "Value": "true"}
|
||||
]
|
||||
}
|
||||
""".formatted(certJson, keyJson))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"))
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// Verify tags were applied
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListTagsForCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(taggedArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.size()", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void importCertificateReimport() {
|
||||
String certJson = validTestCertificate.replace("\n", "\\n");
|
||||
String keyJson = validTestPrivateKey.replace("\n", "\\n");
|
||||
|
||||
// Re-import to the same ARN should succeed
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ImportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Certificate": "%s",
|
||||
"PrivateKey": "%s",
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(certJson, keyJson, importedCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", equalTo(importedCertificateArn));
|
||||
}
|
||||
|
||||
// ==================== ExportCertificate Tests ====================
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void requestExportableCertificate() {
|
||||
// Create a PRIVATE type certificate that can be exported
|
||||
exportableCertificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "exportable.example.com",
|
||||
"CertificateAuthorityArn": "arn:aws:acm-pca:us-east-1:123456789012:certificate-authority/12345678-1234-1234-1234-123456789012"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"))
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void exportCertificate() {
|
||||
String passphrase = Base64.getEncoder().encodeToString("testpassphrase".getBytes());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ExportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s",
|
||||
"Passphrase": "%s"
|
||||
}
|
||||
""".formatted(exportableCertificateArn, passphrase))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Certificate", startsWith("-----BEGIN CERTIFICATE-----"))
|
||||
.body("PrivateKey", startsWith("-----BEGIN ENCRYPTED PRIVATE KEY-----"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void exportCertificateShortPassphraseFails() {
|
||||
String shortPassphrase = Base64.getEncoder().encodeToString("abc".getBytes());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ExportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s",
|
||||
"Passphrase": "%s"
|
||||
}
|
||||
""".formatted(exportableCertificateArn, shortPassphrase))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void exportNonExportableCertificateFails() {
|
||||
// Create a non-exportable certificate (AMAZON_ISSUED without Export option)
|
||||
String nonExportableArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "non-exportable.example.com"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
String passphrase = Base64.getEncoder().encodeToString("testpassphrase".getBytes());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ExportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s",
|
||||
"Passphrase": "%s"
|
||||
}
|
||||
""".formatted(nonExportableArn, passphrase))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void exportCertificateNotFoundFails() {
|
||||
String passphrase = Base64.getEncoder().encodeToString("testpassphrase".getBytes());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ExportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/nonexistent",
|
||||
"Passphrase": "%s"
|
||||
}
|
||||
""".formatted(passphrase))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void importInvalidCertificateFails() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ImportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Certificate": "not-a-valid-certificate",
|
||||
"PrivateKey": "not-a-valid-key"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,558 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.config.EncoderConfig;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class AcmIntegrationTest {
|
||||
|
||||
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static String createdCertificateArn;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssured.config = RestAssured.config().encoderConfig(
|
||||
EncoderConfig.encoderConfig()
|
||||
.encodeContentTypeAs(ACM_CONTENT_TYPE, ContentType.TEXT));
|
||||
}
|
||||
|
||||
// ==================== User Story 1: RequestCertificate ====================
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void requestCertificateBasic() {
|
||||
createdCertificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "example.com"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"))
|
||||
.body("CertificateArn", containsString(":certificate/"))
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void requestCertificateWithSans() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "api.example.com",
|
||||
"SubjectAlternativeNames": ["www.example.com", "*.example.com"]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void requestCertificateWithDnsValidation() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "dns-validated.example.com",
|
||||
"ValidationMethod": "DNS"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void requestCertificateWithEmailValidation() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "email-validated.example.com",
|
||||
"ValidationMethod": "EMAIL"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void requestCertificateWithKeyAlgorithm() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "ec-cert.example.com",
|
||||
"KeyAlgorithm": "EC_prime256v1"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void requestCertificateWithIdempotencyToken() {
|
||||
String token = "test-idempotency-token-123";
|
||||
|
||||
// First request
|
||||
String arn1 = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "idempotent.example.com",
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// Second request with same token should return same ARN
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "idempotent.example.com",
|
||||
"IdempotencyToken": "%s"
|
||||
}
|
||||
""".formatted(token))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", equalTo(arn1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void requestCertificateWithTags() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "tagged.example.com",
|
||||
"Tags": [
|
||||
{"Key": "Environment", "Value": "test"},
|
||||
{"Key": "Project", "Value": "demo"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void requestCertificateEmptyDomainFails() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": ""
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
// ==================== User Story 2: DescribeCertificate ====================
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void describeCertificate() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Certificate.CertificateArn", equalTo(createdCertificateArn))
|
||||
.body("Certificate.DomainName", equalTo("example.com"))
|
||||
.body("Certificate.Status", equalTo("ISSUED"))
|
||||
.body("Certificate.Type", equalTo("AMAZON_ISSUED"))
|
||||
.body("Certificate.Serial", notNullValue())
|
||||
.body("Certificate.Subject", startsWith("CN="))
|
||||
.body("Certificate.Issuer", notNullValue())
|
||||
.body("Certificate.KeyAlgorithm", equalTo("RSA-2048"))
|
||||
.body("Certificate.NotBefore", notNullValue())
|
||||
.body("Certificate.NotAfter", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void describeCertificateNotFound() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/nonexistent"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ==================== User Story 2: GetCertificate ====================
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void getCertificate() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.GetCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Certificate", startsWith("-----BEGIN CERTIFICATE-----"))
|
||||
.body("CertificateChain", startsWith("-----BEGIN CERTIFICATE-----"));
|
||||
}
|
||||
|
||||
// ==================== User Story 2: ListCertificates ====================
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void listCertificates() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateSummaryList", notNullValue())
|
||||
.body("CertificateSummaryList.size()", greaterThanOrEqualTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void listCertificatesWithStatusFilter() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateStatuses": ["ISSUED"]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateSummaryList", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void listCertificatesWithKeyTypeFilter() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Includes": {
|
||||
"keyTypes": ["RSA_2048"]
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateSummaryList", notNullValue());
|
||||
}
|
||||
|
||||
// ==================== User Story 5: Tagging ====================
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void addTagsToCertificate() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.AddTagsToCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s",
|
||||
"Tags": [
|
||||
{"Key": "Team", "Value": "Engineering"},
|
||||
{"Key": "Cost-Center", "Value": "12345"}
|
||||
]
|
||||
}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void listTagsForCertificate() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListTagsForCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", notNullValue())
|
||||
.body("Tags.size()", greaterThanOrEqualTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(22)
|
||||
void removeTagsFromCertificate() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RemoveTagsFromCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s",
|
||||
"Tags": [
|
||||
{"Key": "Cost-Center"}
|
||||
]
|
||||
}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Verify tag was removed
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListTagsForCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.find { it.Key == 'Cost-Center' }", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void addTagsInvalidKeyFails() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.AddTagsToCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s",
|
||||
"Tags": [
|
||||
{"Key": "aws:reserved", "Value": "not-allowed"}
|
||||
]
|
||||
}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
// ==================== Account Configuration ====================
|
||||
|
||||
@Test
|
||||
@Order(30)
|
||||
void getAccountConfiguration() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.GetAccountConfiguration")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ExpiryEvents.DaysBeforeExpiry", equalTo(45));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(31)
|
||||
void putAccountConfiguration() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.PutAccountConfiguration")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"ExpiryEvents": {
|
||||
"DaysBeforeExpiry": 30
|
||||
},
|
||||
"IdempotencyToken": "config-token-123"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Verify configuration was updated
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.GetAccountConfiguration")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ExpiryEvents.DaysBeforeExpiry", equalTo(30));
|
||||
}
|
||||
|
||||
// ==================== User Story 3: DeleteCertificate ====================
|
||||
|
||||
@Test
|
||||
@Order(100)
|
||||
void deleteCertificate() {
|
||||
// Create a certificate to delete
|
||||
String arnToDelete = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "to-delete.example.com"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
// Delete it
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.DeleteCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(arnToDelete))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Verify it's gone
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
""".formatted(arnToDelete))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(101)
|
||||
void deleteCertificateNotFound() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.DeleteCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/nonexistent"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ==================== Unsupported Operation ====================
|
||||
|
||||
@Test
|
||||
void unsupportedOperation() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.UnsupportedAction")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("UnsupportedOperation"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.config.EncoderConfig;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests for ListCertificates pagination functionality.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class AcmPaginationTest {
|
||||
|
||||
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final int TOTAL_CERTS = 15;
|
||||
private final List<String> createdArns = new ArrayList<>();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssured.config = RestAssured.config().encoderConfig(
|
||||
EncoderConfig.encoderConfig()
|
||||
.encodeContentTypeAs(ACM_CONTENT_TYPE, ContentType.TEXT));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createMultipleCertificates() {
|
||||
// Create 15 certificates for pagination testing
|
||||
for (int i = 0; i < TOTAL_CERTS; i++) {
|
||||
String arn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "pagination-test-%d.example.com"
|
||||
}
|
||||
""".formatted(i))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
createdArns.add(arn);
|
||||
}
|
||||
|
||||
assertEquals(TOTAL_CERTS, createdArns.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void listWithMaxItems() {
|
||||
// List with maxItems=5, expect nextToken
|
||||
Response response = given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"MaxItems": 5
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateSummaryList.size()", equalTo(5))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().response();
|
||||
|
||||
String nextToken = response.jsonPath().getString("NextToken");
|
||||
assertNotNull(nextToken, "NextToken should be present when there are more pages");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void paginateThroughAllCertificates() {
|
||||
Set<String> allArns = new HashSet<>();
|
||||
String nextToken = null;
|
||||
int pageCount = 0;
|
||||
int maxPages = 10; // Safety limit
|
||||
|
||||
do {
|
||||
String body = nextToken == null
|
||||
? "{\"MaxItems\": 5}"
|
||||
: "{\"MaxItems\": 5, \"NextToken\": \"" + nextToken + "\"}";
|
||||
|
||||
Response response = given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().response();
|
||||
|
||||
List<String> pageArns = response.jsonPath().getList("CertificateSummaryList.CertificateArn");
|
||||
allArns.addAll(pageArns);
|
||||
nextToken = response.jsonPath().getString("NextToken");
|
||||
pageCount++;
|
||||
|
||||
} while (nextToken != null && pageCount < maxPages);
|
||||
|
||||
// Should have retrieved all created certificates (plus possibly others from other tests)
|
||||
assertTrue(allArns.containsAll(createdArns), "All created certificates should be retrievable via pagination");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void invalidNextToken() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"NextToken": "invalid-token-not-base64"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidNextTokenException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void emptyListReturnsNoNextToken() {
|
||||
// List with a filter that matches nothing
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateStatuses": ["REVOKED"]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateSummaryList", empty())
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void maxItemsLimit() {
|
||||
// MaxItems should be capped at 1000
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"MaxItems": 2000
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateSummaryList.size()", lessThanOrEqualTo(1000));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user