mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(acm): certificate validation records and revocation (#2655)
* feat(acm): add certificate revocation, renewal, options and email resend Adds RevokeCertificate, RenewCertificate, UpdateCertificateOptions and ResendValidationEmail, with a RevocationReason enum modelling the accepted values. Limitations documented in docs/services/acm.md. * test(acm): stop asserting global-empty state in the pagination filter test Other classes sharing the full-suite JVM revoke certificates of their own, so a REVOKED filter is not globally empty. Assert instead that none of this class's own certificates appear, which is what the test is actually about. * feat(acm): add ResendValidationEmail and certificate revocation reasons * fix(acm): validate Domain/ValidationDomain on ResendValidationEmail Domain and ValidationDomain were accepted verbatim after a null/blank check, so any value round-tripped as 200 OK - a client could resend against an unrelated domain and get success back. Domain must now match the certificate's DomainName or one of its SubjectAlternativeNames, and ValidationDomain must equal Domain or be one of its superdomains, matching botocore's InvalidDomainValidationOptionsException semantics for this operation. Also drops the now-unneeded manual UTF-8 byte encoding in the resend test now that RestAssuredJsonUtils configures the AWS content types. * fix(acm): require Options.Export=ENABLED to revoke a certificate revokeCertificate gated on Certificate.canExport(), which returns true for any PRIVATE or IMPORTED certificate regardless of its Export option - so an imported certificate with Export left at the default DISABLED could still be revoked, bypassing the export-enabled guard the operation is meant to enforce. Check Options.Export directly instead. * fix(acm): use ValidationException for a not-export-enabled revoke RevokeCertificate's own modeled Errors list is AccessDeniedException, ConflictException, InvalidArnException, ResourceInUseException, ResourceNotFoundException, ThrottlingException, and ValidationException. InvalidStateException isn't among them - it's modeled on UpdateCertificateOptions instead, which is likely where it got picked up from. ValidationException is the operation's own general "input failed to satisfy constraints" code, and the better fit here.
This commit is contained in:
1 parent
97ff0bc3e9
commit
3bd9bcc62b
9 files changed
+491
-4
No files matched your search
@@ -537,6 +537,150 @@ class AcmIntegrationTest {
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(40)
|
||||
void updateCertificateOptions() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.UpdateCertificateOptions")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"CertificateArn": "%s",
|
||||
"Options": {"Export": "ENABLED"}
|
||||
}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"CertificateArn": "%s"}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Certificate.Options.Export", equalTo("ENABLED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(41)
|
||||
void updateCertificateOptionsRequiresOptions() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.UpdateCertificateOptions")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"CertificateArn": "%s"}
|
||||
""".formatted(createdCertificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(42)
|
||||
void revokeCertificate() {
|
||||
String certificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"DomainName": "revocable.example.com"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.UpdateCertificateOptions")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"CertificateArn": "%s", "Options": {"Export": "ENABLED"}}
|
||||
""".formatted(certificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RevokeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"CertificateArn": "%s", "RevocationReason": "KEY_COMPROMISE"}
|
||||
""".formatted(certificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateArn", equalTo(certificateArn));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"CertificateArn": "%s"}
|
||||
""".formatted(certificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Certificate.Status", equalTo("REVOKED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(43)
|
||||
void renewPrivateCertificate() {
|
||||
String certificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "renewable-private.example.com",
|
||||
"CertificateAuthorityArn": "arn:aws:acm-pca:us-east-1:000000000000:certificate-authority/test"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RenewCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"CertificateArn": "%s"}
|
||||
""".formatted(certificateArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("{}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(44)
|
||||
void renewCertificateNotFound() {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RenewCertificate")
|
||||
.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
|
||||
|
||||
@@ -140,8 +140,12 @@ class AcmPaginationTest {
|
||||
@Test
|
||||
@Order(5)
|
||||
void emptyListReturnsNoNextToken() {
|
||||
// List with a filter that matches nothing
|
||||
given()
|
||||
// Filter by a status none of this class's own certificates ever have. Can't assert the
|
||||
// whole result is empty -- other test classes in the shared full-suite JVM (e.g.
|
||||
// AcmIntegrationTest) revoke certificates of their own, and that state persists across
|
||||
// classes. What this test actually verifies -- filtering excludes non-matching
|
||||
// certificates and a small result page carries no NextToken -- holds regardless.
|
||||
Response response = given()
|
||||
.header("X-Amz-Target", "CertificateManager.ListCertificates")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
@@ -153,8 +157,12 @@ class AcmPaginationTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CertificateSummaryList", empty())
|
||||
.body("NextToken", nullValue());
|
||||
.extract().response();
|
||||
|
||||
List<String> revokedArns = response.jsonPath().getList("CertificateSummaryList.CertificateArn");
|
||||
assertTrue(createdArns.stream().noneMatch(revokedArns::contains),
|
||||
"none of this class's own (always-ISSUED) certificates should appear under a REVOKED filter");
|
||||
assertNull(response.jsonPath().get("NextToken"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
|
||||
@QuarkusTest
|
||||
class AcmResendValidationEmailIntegrationTest {
|
||||
|
||||
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResendValidationEmailNotFound() {
|
||||
String requestBody = "{\"CertificateArn\":\"arn:aws:acm:us-east-1:000000000000:certificate/nonexistent\",\"Domain\":\"example.com\",\"ValidationDomain\":\"example.com\"}";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ResendValidationEmail")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body(requestBody)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResendValidationEmailRejectsUnrelatedDomain() {
|
||||
String certificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{\"DomainName\":\"resend-validation.example.com\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
String requestBody = "{\"CertificateArn\":\"" + certificateArn
|
||||
+ "\",\"Domain\":\"totally-unrelated.example.org\",\"ValidationDomain\":\"totally-unrelated.example.org\"}";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ResendValidationEmail")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body(requestBody)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", org.hamcrest.Matchers.equalTo("InvalidDomainValidationOptionsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResendValidationEmailRejectsValidationDomainNotASuperdomain() {
|
||||
String certificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{\"DomainName\":\"site.subdomain.resend-superdomain.example.com\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
String requestBody = "{\"CertificateArn\":\"" + certificateArn
|
||||
+ "\",\"Domain\":\"site.subdomain.resend-superdomain.example.com\",\"ValidationDomain\":\"unrelated.example.net\"}";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ResendValidationEmail")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body(requestBody)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", org.hamcrest.Matchers.equalTo("InvalidDomainValidationOptionsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResendValidationEmailAcceptsMatchingDomainAndSuperdomain() {
|
||||
String certificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{\"DomainName\":\"site.subdomain.resend-ok.example.com\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
String requestBody = "{\"CertificateArn\":\"" + certificateArn
|
||||
+ "\",\"Domain\":\"site.subdomain.resend-ok.example.com\",\"ValidationDomain\":\"subdomain.resend-ok.example.com\"}";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.ResendValidationEmail")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body(requestBody)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class AcmRevokeCertificateGuardTest {
|
||||
|
||||
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@Inject
|
||||
CertificateGenerator certificateGenerator;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void revokeCertificateRejectsImportedCertificateWithoutExportEnabled() {
|
||||
CertificateGenerator.GeneratedCertificate generated = certificateGenerator.generateCertificate(
|
||||
"revoke-guard-imported.example.com", List.of(), KeyAlgorithm.RSA_2048);
|
||||
String certJson = generated.certificatePem().replace("\r\n", "\n").replace("\n", "\\n");
|
||||
String keyJson = generated.privateKeyPem().replace("\r\n", "\n").replace("\n", "\\n");
|
||||
|
||||
String certificateArn = given()
|
||||
.header("X-Amz-Target", "CertificateManager.ImportCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{\"Certificate\":\"" + certJson + "\",\"PrivateKey\":\"" + keyJson + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RevokeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{\"CertificateArn\":\"" + certificateArn + "\",\"RevocationReason\":\"KEY_COMPROMISE\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user