mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cognito): name a custom domain's CloudFront distribution like the others (#7486)
CreateUserPoolDomain built its CloudFrontDistribution by hand from 14 hex characters with no leading d, unlike the names an edge-optimized API Gateway domain and an AppSync custom domain get. Use CloudFrontEdgeDomain.create, so the name is d plus 13 hex on the partition's suffix. The name is stored, so existing domains keep theirs. Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
e46579ec03
commit
86f8434ef6
2 files changed
+16
-7
No files matched your search
@@ -1865,7 +1865,8 @@ public class CognitoService implements ResourceProvider {
|
||||
userPoolDomain.setCertificateArn(certificateArn);
|
||||
Object securityPolicy = customDomainConfig.get("SecurityPolicy");
|
||||
userPoolDomain.setSecurityPolicy(securityPolicy != null ? securityPolicy.toString() : "TLS_V1_2_2021");
|
||||
userPoolDomain.setCloudFrontDistribution(generateCloudFrontDomain());
|
||||
userPoolDomain.setCloudFrontDistribution(
|
||||
CloudFrontEdgeDomain.create(regionResolver.getPartition(), cloudFrontDomainSuffix).domainName());
|
||||
}
|
||||
|
||||
// Check and write as one step: two accounts racing for one name write to different
|
||||
@@ -2106,12 +2107,6 @@ public class CognitoService implements ResourceProvider {
|
||||
return AwsArnUtils.Arn.global(partition, "cloudfront", userPoolDomain.getAwsAccountId(), "distribution/" + id).toString();
|
||||
}
|
||||
|
||||
/** A distribution name on the configured CloudFront suffix, or the request partition's when none is. */
|
||||
private String generateCloudFrontDomain() {
|
||||
return UUID.randomUUID().toString().replace("-", "").substring(0, 14) + "."
|
||||
+ CloudFrontEdgeDomain.domainSuffix(cloudFrontDomainSuffix, regionResolver.getPartition());
|
||||
}
|
||||
|
||||
private String generateDomainVersion() {
|
||||
return DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
|
||||
.withZone(ZoneOffset.UTC)
|
||||
|
||||
+14
@@ -14,6 +14,7 @@ import java.util.Map;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -103,6 +104,7 @@ class CognitoCustomDomainPartitionTest {
|
||||
|
||||
UserPoolDomain created = service.createUserPoolDomain(CUSTOM_DOMAIN, poolId, CUSTOM, null);
|
||||
assertTrue(created.isCustomDomain());
|
||||
assertThat(created.getCloudFrontDistribution(), matchesPattern("d[0-9a-f]{13}\\.cloudfront\\.net"));
|
||||
|
||||
Map<String, Object> replacement =
|
||||
Map.of("CertificateArn", "arn:aws:acm:us-east-1:" + ACCOUNT + ":certificate/def");
|
||||
@@ -110,6 +112,18 @@ class CognitoCustomDomainPartitionTest {
|
||||
assertEquals(replacement.get("CertificateArn"), updated.getCertificateArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCustomDomainInChinaIsServedFromTheChinaCloudFrontSuffix() {
|
||||
CognitoService service = serviceIn("cn-north-1");
|
||||
String poolId = createPool(service, "cn-north-1");
|
||||
Map<String, Object> certificate =
|
||||
Map.of("CertificateArn", "arn:aws-cn:acm:us-east-1:" + ACCOUNT + ":certificate/abc");
|
||||
|
||||
UserPoolDomain created = service.createUserPoolDomain(CUSTOM_DOMAIN, poolId, certificate, null);
|
||||
|
||||
assertThat(created.getCloudFrontDistribution(), matchesPattern("d[0-9a-f]{13}\\.cloudfront\\.cn"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"arn:aws-cn:acm:us-east-1:000000000000:certificate/abc",
|
||||
|
||||
Reference in new issue
Block a user