mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(acm): reflect the requested ValidationDomain in DescribeCertificate (#3264)
* fix(acm): reflect the requested ValidationDomain in DescribeCertificate RequestCertificate ignored DomainValidationOptions entirely: the handler never read the field, and generateDomainValidation hardcoded ValidationDomain to the certificate domain. A caller that asked for ValidationDomain=db.de read back the FQDN and could not tell whether the request was accepted as sent, even though the value decides which mailboxes may approve the certificate. Carry the requested ValidationDomain per DomainName through to the stored DomainValidation, and reject the entries AWS rejects: a DomainName that is not part of the request, and a ValidationDomain that is neither the domain itself nor one of its superdomains. That superdomain rule already backed ResendValidationEmail, so it moves to a shared helper rather than being written twice. Domains with no requested entry keep validating against themselves, which is what AWS reports when the caller supplies nothing. * fix(acm): reject incomplete DomainValidationOptions entries Both DomainName and ValidationDomain are required members of DomainValidationOption, but the parser skipped an entry missing either one, so RequestCertificate returned 200 and the domain quietly fell back to validating against itself. Reject those entries with the same InvalidDomainValidationOptionsException the other bad entries already get. Also brace the array guard, per the repository style rule.
This commit is contained in:
1 parent
141b15939f
commit
922eb0b9e5
3 files changed
+231
-9
No files matched your search
+141
@@ -0,0 +1,141 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
|
||||
/**
|
||||
* DescribeCertificate reports the ValidationDomain the caller asked for on RequestCertificate: it
|
||||
* is the suffix of the mailboxes ACM accepts an approval from, so a caller reading it back has to
|
||||
* be able to tell whether the request was taken as sent.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class AcmValidationDomainIntegrationTest {
|
||||
|
||||
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestedValidationDomainIsReflectedPerDomain() {
|
||||
String certificateArn = requestCertificate("""
|
||||
{
|
||||
"DomainName": "probe.example.validation-domain.test",
|
||||
"SubjectAlternativeNames": ["www.other.validation-domain.test"],
|
||||
"ValidationMethod": "EMAIL",
|
||||
"DomainValidationOptions": [
|
||||
{"DomainName": "probe.example.validation-domain.test", "ValidationDomain": "validation-domain.test"},
|
||||
{"DomainName": "www.other.validation-domain.test", "ValidationDomain": "other.validation-domain.test"}
|
||||
]
|
||||
}
|
||||
""").statusCode(200).extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
describeCertificate(certificateArn)
|
||||
.body("Certificate.DomainValidationOptions.find { it.DomainName == 'probe.example.validation-domain.test' }.ValidationDomain",
|
||||
Matchers.equalTo("validation-domain.test"))
|
||||
.body("Certificate.DomainValidationOptions.find { it.DomainName == 'www.other.validation-domain.test' }.ValidationDomain",
|
||||
Matchers.equalTo("other.validation-domain.test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void domainWithoutRequestedValidationDomainValidatesAgainstItself() {
|
||||
String certificateArn = requestCertificate("""
|
||||
{
|
||||
"DomainName": "probe.default.validation-domain.test",
|
||||
"ValidationMethod": "EMAIL"
|
||||
}
|
||||
""").statusCode(200).extract().jsonPath().getString("CertificateArn");
|
||||
|
||||
describeCertificate(certificateArn)
|
||||
.body("Certificate.DomainValidationOptions[0].ValidationDomain",
|
||||
Matchers.equalTo("probe.default.validation-domain.test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validationDomainThatIsNotASuperdomainIsRejected() {
|
||||
requestCertificate("""
|
||||
{
|
||||
"DomainName": "probe.reject.validation-domain.test",
|
||||
"ValidationMethod": "EMAIL",
|
||||
"DomainValidationOptions": [
|
||||
{"DomainName": "probe.reject.validation-domain.test", "ValidationDomain": "unrelated.example.net"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.statusCode(400)
|
||||
.body("__type", Matchers.equalTo("InvalidDomainValidationOptionsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validationDomainForADomainOutsideTheRequestIsRejected() {
|
||||
requestCertificate("""
|
||||
{
|
||||
"DomainName": "probe.unknown.validation-domain.test",
|
||||
"ValidationMethod": "EMAIL",
|
||||
"DomainValidationOptions": [
|
||||
{"DomainName": "absent.validation-domain.test", "ValidationDomain": "validation-domain.test"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.statusCode(400)
|
||||
.body("__type", Matchers.equalTo("InvalidDomainValidationOptionsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void entryWithoutAValidationDomainIsRejected() {
|
||||
requestCertificate("""
|
||||
{
|
||||
"DomainName": "probe.incomplete.validation-domain.test",
|
||||
"ValidationMethod": "EMAIL",
|
||||
"DomainValidationOptions": [
|
||||
{"DomainName": "probe.incomplete.validation-domain.test"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.statusCode(400)
|
||||
.body("__type", Matchers.equalTo("InvalidDomainValidationOptionsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void entryWithoutADomainNameIsRejected() {
|
||||
requestCertificate("""
|
||||
{
|
||||
"DomainName": "probe.nameless.validation-domain.test",
|
||||
"ValidationMethod": "EMAIL",
|
||||
"DomainValidationOptions": [
|
||||
{"ValidationDomain": "validation-domain.test"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.statusCode(400)
|
||||
.body("__type", Matchers.equalTo("InvalidDomainValidationOptionsException"));
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse requestCertificate(String body) {
|
||||
return given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/")
|
||||
.then();
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse describeCertificate(String certificateArn) {
|
||||
return given()
|
||||
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("{\"CertificateArn\":\"" + certificateArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user