mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cognito): user pool domain operations (Create/Describe/DeleteUserPoolDomain) (#2742)
* feat(cognito): user pool domain operations (Create/Describe/DeleteUserPoolDomain)
Adds the domain family Cognito was missing, which blocks any estate using
aws_cognito_user_pool_domain (e.g. an ALB authenticate-cognito listener).
Supports both an Amazon Cognito prefix domain and a custom domain backed by
an ACM certificate ARN, matching the documented request and response shapes.
Domain names are globally unique across pools; a missing domain reports
ResourceNotFoundException on Describe/Delete, consistent with the rest of
the Cognito handler's not-found behavior.
* fix(cognito): refuse DeleteUserPool while a domain is configured
The DeleteUserPool API reference documents this refusal: a pool with a
hosted UI or custom domain answers InvalidParameterException ("User pool
cannot be deleted. It has a domain configured that should be deleted
first.") rather than deleting and stranding the globally-unique domain
name.
This commit is contained in:
1 parent
fcc606799c
commit
ed167135ff
6 files changed
+458
-1
No files matched your search
@@ -1212,6 +1212,7 @@ class CognitoServiceTest {
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
"http://localhost:4566",
|
||||
regionResolver,
|
||||
null,
|
||||
@@ -1249,6 +1250,7 @@ class CognitoServiceTest {
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
"http://localhost:4566",
|
||||
regionResolver,
|
||||
null,
|
||||
@@ -2640,6 +2642,7 @@ class CognitoServiceTest {
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
"http://localhost:4566",
|
||||
regionResolver,
|
||||
null,
|
||||
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
package io.github.hectorvent.floci.services.cognito;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
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.TestMethodOrder;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.github.hectorvent.floci.services.cognito.CognitoRestAssuredUtils.cognitoAction;
|
||||
import static io.github.hectorvent.floci.services.cognito.CognitoRestAssuredUtils.cognitoJson;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* Covers CreateUserPoolDomain/DescribeUserPoolDomain/DeleteUserPoolDomain (lex00/floci#63)
|
||||
* for both an Amazon Cognito prefix domain and a custom domain fronted by an ACM certificate.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class CognitoUserPoolDomainIntegrationTest {
|
||||
|
||||
private static String poolId;
|
||||
private static String prefixDomain;
|
||||
private static String customDomain;
|
||||
private static final String CERTIFICATE_ARN =
|
||||
"arn:aws:acm:us-east-1:000000000000:certificate/" + UUID.randomUUID();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createPool() throws Exception {
|
||||
JsonNode poolResponse = cognitoJson("CreateUserPool", """
|
||||
{
|
||||
"PoolName": "DomainTestPool"
|
||||
}
|
||||
""");
|
||||
poolId = poolResponse.path("UserPool").path("Id").asText();
|
||||
prefixDomain = "floci-test-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
customDomain = "auth-" + UUID.randomUUID().toString().substring(0, 8) + ".example.com";
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createPrefixDomainSucceeds() throws Exception {
|
||||
JsonNode response = cognitoJson("CreateUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s",
|
||||
"UserPoolId": "%s"
|
||||
}
|
||||
""".formatted(prefixDomain, poolId));
|
||||
|
||||
// AWS returns CloudFrontDomain=null for a prefix domain; floci should not
|
||||
// fabricate one, so the field is simply absent from the response.
|
||||
assertNull(response.get("CloudFrontDomain"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void describePrefixDomainReturnsMatchingFields() throws Exception {
|
||||
JsonNode response = cognitoJson("DescribeUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s"
|
||||
}
|
||||
""".formatted(prefixDomain));
|
||||
|
||||
JsonNode description = response.path("DomainDescription");
|
||||
assertEquals(prefixDomain, description.path("Domain").asText());
|
||||
assertEquals(poolId, description.path("UserPoolId").asText());
|
||||
assertEquals("ACTIVE", description.path("Status").asText());
|
||||
assertNull(description.get("CustomDomainConfig"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void deletePrefixDomainSucceeds() {
|
||||
cognitoAction("DeleteUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s",
|
||||
"UserPoolId": "%s"
|
||||
}
|
||||
""".formatted(prefixDomain, poolId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void describeDeletedPrefixDomainIsNotFound() {
|
||||
cognitoAction("DescribeUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s"
|
||||
}
|
||||
""".formatted(prefixDomain))
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void createCustomDomainReturnsCloudFrontDomain() throws Exception {
|
||||
JsonNode response = cognitoJson("CreateUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s",
|
||||
"UserPoolId": "%s",
|
||||
"CustomDomainConfig": {
|
||||
"CertificateArn": "%s"
|
||||
}
|
||||
}
|
||||
""".formatted(customDomain, poolId, CERTIFICATE_ARN));
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertTrue(response.path("CloudFrontDomain").isTextual());
|
||||
org.junit.jupiter.api.Assertions.assertFalse(response.path("CloudFrontDomain").asText().isBlank());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void describeCustomDomainReturnsCertificateArn() throws Exception {
|
||||
JsonNode response = cognitoJson("DescribeUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s"
|
||||
}
|
||||
""".formatted(customDomain));
|
||||
|
||||
JsonNode description = response.path("DomainDescription");
|
||||
assertEquals(customDomain, description.path("Domain").asText());
|
||||
assertEquals(poolId, description.path("UserPoolId").asText());
|
||||
assertEquals(CERTIFICATE_ARN, description.path("CustomDomainConfig").path("CertificateArn").asText());
|
||||
assertEquals("ACTIVE", description.path("Status").asText());
|
||||
org.junit.jupiter.api.Assertions.assertNotNull(description.path("CloudFrontDistribution").asText(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void createCustomDomainWithoutCertificateArnFails() {
|
||||
cognitoAction("CreateUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s",
|
||||
"UserPoolId": "%s",
|
||||
"CustomDomainConfig": {}
|
||||
}
|
||||
""".formatted("bad-" + UUID.randomUUID().toString().substring(0, 8) + ".example.com", poolId))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void deleteCustomDomainThenDescribeIsNotFound() {
|
||||
cognitoAction("DeleteUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s",
|
||||
"UserPoolId": "%s"
|
||||
}
|
||||
""".formatted(customDomain, poolId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
cognitoAction("DescribeUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s"
|
||||
}
|
||||
""".formatted(customDomain))
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void deleteUserPoolWithDomainIsRejected() throws Exception {
|
||||
// The DeleteUserPool API reference's own example documents this refusal verbatim.
|
||||
String blockingDomain = "floci-block-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
cognitoJson("CreateUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s",
|
||||
"UserPoolId": "%s"
|
||||
}
|
||||
""".formatted(blockingDomain, poolId));
|
||||
|
||||
cognitoAction("DeleteUserPool", """
|
||||
{
|
||||
"UserPoolId": "%s"
|
||||
}
|
||||
""".formatted(poolId))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo(
|
||||
"User pool cannot be deleted. It has a domain configured that should be deleted first."));
|
||||
|
||||
cognitoAction("DeleteUserPoolDomain", """
|
||||
{
|
||||
"Domain": "%s",
|
||||
"UserPoolId": "%s"
|
||||
}
|
||||
""".formatted(blockingDomain, poolId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void deleteUserPoolSucceedsOnceDomainIsGone() {
|
||||
cognitoAction("DeleteUserPool", """
|
||||
{
|
||||
"UserPoolId": "%s"
|
||||
}
|
||||
""".formatted(poolId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user