mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cognito): implement managed login branding (#2869)
* feat(cognito): implement managed login branding CreateManagedLoginBranding, DescribeManagedLoginBranding, DescribeManagedLoginBrandingByClient, UpdateManagedLoginBranding and DeleteManagedLoginBranding were unsupported, so a config declaring `aws_cognito_managed_login_branding` could not be applied against Floci. A branding belongs to one app client and is stored on it. Behaviour matches what the live API does: - a second branding for the same client raises ManagedLoginBrandingExistsException - ManagedLoginBrandingId must be a version 4 UUID, checked before the lookup - Settings is omitted from the response when the caller supplied none, while Assets is always returned - members an update omits are left unchanged Settings is stored opaquely rather than validated against AWS's unpublished schema, and ReturnMergedResources does not merge Cognito's default corpus. Closes #2856 * fix(cognito): reject malformed CreateManagedLoginBranding members Create coerced an absent UseCognitoProvidedValues to false and silently ignored a wrongly typed Settings or Assets, so a malformed request produced persisted state. Measured against AWS: neither UseCognitoProvidedValues nor Settings -> InvalidParameterException: useCognitoProvidedValues or settings should be specified (but not both) Assets of the wrong type -> SerializationException: Unexpected field type UseCognitoProvidedValues of the wrong type -> accepted, not rejected Create now enforces the first rule and type-checks Settings and Assets. A non-boolean UseCognitoProvidedValues is still accepted, because AWS accepts it. AWS answers a wrongly typed Settings with a 500 InternalErrorException; Floci returns the same client error it returns for Assets rather than reproducing that, and the divergence is documented. * fix(cognito): check Assets elements before converting them The Assets reader validated only the outer array, so a scalar element reached Jackson's convertValue and escaped as a 500 InternalFailure. This is the same class of bug as the LogConfigurations one, which I fixed in that reader without applying it here. AWS separates the two failures, and they differ from the LogConfigurations rules: [1, 2] / ["str"] -> SerializationException: Unexpected value type in payload [null] -> InvalidParameterException: 1 validation error detected: Value '[null]' at 'assets' failed to satisfy constraint: Member must satisfy constraint: [Member must not be null] A null element is rejected here, where LogConfigurations drops it. * fix(cognito): match AWS branding source validation A managed login branding request must select exactly one source of branding, and the same rule governs create and update. Measured against Cognito in ap-southeast-1: useCognitoProvidedValues settings result absent absent InvalidParameterException true absent accepted false absent InvalidParameterException absent present accepted true present InvalidParameterException false present accepted Create rejected only the neither case, update validated nothing at all, so naming both members and updating with no source both succeeded where the service rejects them. Presence of the member is not the test: false selects no source, which is why it needs settings alongside it. Reading the flag had to move with it. AWS coerces a JSON string rather than rejecting it, storing true for "true" and for "yes" and false for "false", while Jackson maps every string except "true" to false. That turned "yes" into a request selecting no source, so the coercion now follows the service. * fix(cognito): reject malformed UseCognitoProvidedValues types Jackson's asBoolean() maps a number, a JSON null, an object and an array all to false, so a malformed flag alongside valid Settings passed source validation and persisted as branding state that was never requested. Measured against Cognito in ap-southeast-1: 1, null, {} and [] are each a SerializationException, with or without Settings, while omitting the member is accepted and stores false. Only booleans and strings are read now, strings still coerced the way the service coerces them, and everything else raises SerializationException the way SesController already does. * fix(cognito): bound managed login branding assets at 40 Neither create nor update checked the documented 40-item maximum on Assets, so an oversized request was accepted and stored where AWS rejects it. Measured against Cognito in ap-southeast-1: create 40 assets passes the bound, reaches the source rule create 41 assets InvalidParameterException, length constraint create 41 + unknown client the length error, not the missing client update 41 + malformed id 2 validation errors, the length one first update malformed id alone 1 validation error, before the pool lookup The asset and branding-id checks now run before anything is looked up and share one message, matching those last three rows. DescribeManagedLoginBranding ran its pool lookup ahead of the branding-id check, which the fourth row shows is the wrong way round, so it moved with them. The length message embeds the request model's toString. The blob renders as the decoded buffer, confirmed at three payload sizes; the decoder used here is the lenient one so that building a rejection cannot itself fail.
This commit is contained in:
1 parent
b8f1e22c74
commit
1e4e8b9ee8
6 files changed
+1090
No files matched your search
+661
@@ -0,0 +1,661 @@
|
||||
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.assertTrue;
|
||||
|
||||
/**
|
||||
* Covers CreateManagedLoginBranding, DescribeManagedLoginBranding,
|
||||
* DescribeManagedLoginBrandingByClient, UpdateManagedLoginBranding and
|
||||
* DeleteManagedLoginBranding.
|
||||
*
|
||||
* <p>Response shapes and error messages were measured against the live Cognito API. In
|
||||
* particular {@code Settings} is omitted entirely when the caller supplied none, while
|
||||
* {@code Assets} is always returned.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class CognitoManagedLoginBrandingIntegrationTest {
|
||||
|
||||
private static String poolId;
|
||||
private static String clientId;
|
||||
private static String brandingId;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createPoolAndClient() throws Exception {
|
||||
poolId = cognitoJson("CreateUserPool", """
|
||||
{
|
||||
"PoolName": "BrandingTestPool"
|
||||
}
|
||||
""").path("UserPool").path("Id").asText();
|
||||
|
||||
clientId = cognitoJson("CreateUserPoolClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientName": "branding-client"
|
||||
}
|
||||
""".formatted(poolId)).path("UserPoolClient").path("ClientId").asText();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void describeByClientBeforeAnyBrandingExists() {
|
||||
cognitoAction("DescribeManagedLoginBrandingByClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s"
|
||||
}
|
||||
""".formatted(poolId, clientId))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"))
|
||||
.body("message", equalTo(
|
||||
"ManagedLoginBranding for client " + clientId + " does not exist."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createWithCognitoProvidedValuesOmitsSettings() throws Exception {
|
||||
JsonNode branding = cognitoJson("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": true
|
||||
}
|
||||
""".formatted(poolId, clientId)).path("ManagedLoginBranding");
|
||||
|
||||
brandingId = branding.path("ManagedLoginBrandingId").asText();
|
||||
assertTrue(branding.path("Settings").isMissingNode(),
|
||||
"AWS omits Settings when the caller supplied none");
|
||||
assertTrue(branding.path("Assets").isArray(), "Assets is always returned");
|
||||
assertEquals(0, branding.path("Assets").size());
|
||||
assertTrue(branding.path("UseCognitoProvidedValues").asBoolean());
|
||||
assertEquals(poolId, branding.path("UserPoolId").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void createRejectsASecondBrandingForTheSameClient() {
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": true
|
||||
}
|
||||
""".formatted(poolId, clientId))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ManagedLoginBrandingExistsException"))
|
||||
.body("message", equalTo(
|
||||
"A ManagedLoginBranding already exists for client " + clientId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void describeByIdReturnsTheSameBranding() throws Exception {
|
||||
JsonNode branding = cognitoJson("DescribeManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s"
|
||||
}
|
||||
""".formatted(poolId, brandingId)).path("ManagedLoginBranding");
|
||||
|
||||
assertEquals(brandingId, branding.path("ManagedLoginBrandingId").asText());
|
||||
assertTrue(branding.path("Settings").isMissingNode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void describeRejectsAnIdThatIsNotAVersion4Uuid() {
|
||||
cognitoAction("DescribeManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "00000000-0000-0000-0000-000000000000"
|
||||
}
|
||||
""".formatted(poolId))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void describeReportsAWellFormedButUnknownId() {
|
||||
cognitoAction("DescribeManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s"
|
||||
}
|
||||
""".formatted(poolId, UUID.randomUUID()))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"))
|
||||
.body("message", equalTo("ManagedLoginBranding does not exist."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void updateSetsSettingsAndAssets() throws Exception {
|
||||
JsonNode branding = cognitoJson("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s",
|
||||
"UseCognitoProvidedValues": false,
|
||||
"Settings": {"components": {}},
|
||||
"Assets": [
|
||||
{"Category": "FAVICON_SVG", "ColorMode": "DARK", "Extension": "SVG", "Bytes": "PHN2Zy8+"}
|
||||
]
|
||||
}
|
||||
""".formatted(poolId, brandingId)).path("ManagedLoginBranding");
|
||||
|
||||
assertTrue(branding.path("Settings").isObject());
|
||||
assertEquals(1, branding.path("Assets").size());
|
||||
assertEquals("FAVICON_SVG", branding.path("Assets").get(0).path("Category").asText());
|
||||
|
||||
JsonNode readBack = cognitoJson("DescribeManagedLoginBrandingByClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s"
|
||||
}
|
||||
""".formatted(poolId, clientId)).path("ManagedLoginBranding");
|
||||
assertEquals(1, readBack.path("Assets").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void updateLeavesOmittedMembersAlone() throws Exception {
|
||||
// Settings alone is the legal way to touch one member: AWS rejects an update whose
|
||||
// only branding member is UseCognitoProvidedValues=false, because false selects no
|
||||
// source. See validateBrandingSource for the measured matrix.
|
||||
cognitoJson("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s",
|
||||
"Settings": {"components": {}}
|
||||
}
|
||||
""".formatted(poolId, brandingId));
|
||||
|
||||
JsonNode branding = cognitoJson("DescribeManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s"
|
||||
}
|
||||
""".formatted(poolId, brandingId)).path("ManagedLoginBranding");
|
||||
|
||||
assertEquals(1, branding.path("Assets").size(), "omitting Assets must not clear them");
|
||||
assertTrue(branding.path("Settings").isObject(), "omitting Settings must not clear it");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void createRejectsAnUnknownClient() {
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "nosuchclientid",
|
||||
"UseCognitoProvidedValues": true
|
||||
}
|
||||
""".formatted(poolId))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Measured against AWS: a create naming neither member is rejected, a wrongly typed Assets
|
||||
* is a deserialization failure, and a non-boolean UseCognitoProvidedValues is accepted
|
||||
* rather than rejected.
|
||||
*/
|
||||
@Test
|
||||
@Order(11)
|
||||
void malformedCreateMembersMatchAwsHandling() throws Exception {
|
||||
String otherClient = cognitoJson("CreateUserPoolClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientName": "branding-client-2"
|
||||
}
|
||||
""".formatted(poolId)).path("UserPoolClient").path("ClientId").asText();
|
||||
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s"
|
||||
}
|
||||
""".formatted(poolId, otherClient))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo(
|
||||
"useCognitoProvidedValues or settings should be specified (but not both)"));
|
||||
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": true,
|
||||
"Assets": "nope"
|
||||
}
|
||||
""".formatted(poolId, otherClient))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": true,
|
||||
"Assets": [1, 2]
|
||||
}
|
||||
""".formatted(poolId, otherClient))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Unexpected value type in payload"));
|
||||
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": true,
|
||||
"Assets": [null]
|
||||
}
|
||||
""".formatted(poolId, otherClient))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo(
|
||||
"1 validation error detected: Value '[null]' at 'assets' failed to satisfy "
|
||||
+ "constraint: Member must satisfy constraint: [Member must not be null]"));
|
||||
|
||||
JsonNode coerced = cognitoJson("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": "yes"
|
||||
}
|
||||
""".formatted(poolId, otherClient)).path("ManagedLoginBranding");
|
||||
assertTrue(coerced.path("ManagedLoginBrandingId").isTextual(),
|
||||
"AWS accepts a non-boolean UseCognitoProvidedValues rather than rejecting it");
|
||||
|
||||
cognitoAction("DeleteManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s"
|
||||
}
|
||||
""".formatted(poolId, coerced.path("ManagedLoginBrandingId").asText()))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void deleteRemovesTheBranding() {
|
||||
cognitoAction("DeleteManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s"
|
||||
}
|
||||
""".formatted(poolId, brandingId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
cognitoAction("DescribeManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s"
|
||||
}
|
||||
""".formatted(poolId, brandingId))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A branding request must select exactly one source. Measured against Cognito in
|
||||
* ap-southeast-1: naming both, naming neither, and naming only
|
||||
* {@code UseCognitoProvidedValues=false} are all rejected with the same message,
|
||||
* on create and on update alike.
|
||||
*/
|
||||
@Test
|
||||
@Order(13)
|
||||
void brandingSourceMustBeExactlyOne() throws Exception {
|
||||
String message = "useCognitoProvidedValues or settings should be specified (but not both)";
|
||||
|
||||
String freshClient = cognitoJson("CreateUserPoolClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientName": "branding-source-client"
|
||||
}
|
||||
""".formatted(poolId)).path("UserPoolClient").path("ClientId").asText();
|
||||
|
||||
// Own the branding this test updates: the shared brandingId is deleted earlier.
|
||||
String ownBrandingId = cognitoJson("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": true
|
||||
}
|
||||
""".formatted(poolId, freshClient))
|
||||
.path("ManagedLoginBranding").path("ManagedLoginBrandingId").asText();
|
||||
|
||||
String bareClient = cognitoJson("CreateUserPoolClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientName": "branding-source-bare"
|
||||
}
|
||||
""".formatted(poolId)).path("UserPoolClient").path("ClientId").asText();
|
||||
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": true,
|
||||
"Settings": {"components": {}}
|
||||
}
|
||||
""".formatted(poolId, bareClient))
|
||||
.then().statusCode(400).body("message", equalTo(message));
|
||||
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": false
|
||||
}
|
||||
""".formatted(poolId, bareClient))
|
||||
.then().statusCode(400).body("message", equalTo(message));
|
||||
|
||||
cognitoAction("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s",
|
||||
"UseCognitoProvidedValues": true,
|
||||
"Settings": {"components": {}}
|
||||
}
|
||||
""".formatted(poolId, ownBrandingId))
|
||||
.then().statusCode(400).body("message", equalTo(message));
|
||||
|
||||
cognitoAction("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s"
|
||||
}
|
||||
""".formatted(poolId, ownBrandingId))
|
||||
.then().statusCode(400).body("message", equalTo(message));
|
||||
|
||||
cognitoAction("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s",
|
||||
"Assets": []
|
||||
}
|
||||
""".formatted(poolId, ownBrandingId))
|
||||
.then().statusCode(400).body("message", equalTo(message));
|
||||
|
||||
// false plus settings selects settings, so it is accepted.
|
||||
cognitoAction("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s",
|
||||
"UseCognitoProvidedValues": false,
|
||||
"Settings": {"components": {}}
|
||||
}
|
||||
""".formatted(poolId, ownBrandingId))
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every non-boolean, non-string type in this member is a SerializationException at
|
||||
* the service, including alongside otherwise valid Settings. Measured in
|
||||
* ap-southeast-1: 1, JSON null, {} and [] are all rejected, while omitting the
|
||||
* member entirely is accepted and stores false.
|
||||
*/
|
||||
@Test
|
||||
@Order(14)
|
||||
void malformedUseCognitoProvidedValuesTypesAreRejected() throws Exception {
|
||||
for (String malformed : new String[] {"1", "null", "{}", "[]"}) {
|
||||
String client = cognitoJson("CreateUserPoolClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientName": "malformed-flag-%s"
|
||||
}
|
||||
""".formatted(poolId, Integer.toHexString(malformed.hashCode())))
|
||||
.path("UserPoolClient").path("ClientId").asText();
|
||||
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"UseCognitoProvidedValues": %s,
|
||||
"Settings": {"components": {}}
|
||||
}
|
||||
""".formatted(poolId, client, malformed))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
}
|
||||
|
||||
// Omitting the member is not malformed: settings alone select the source.
|
||||
String ok = cognitoJson("CreateUserPoolClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientName": "malformed-flag-control"
|
||||
}
|
||||
""".formatted(poolId)).path("UserPoolClient").path("ClientId").asText();
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"Settings": {"components": {}}
|
||||
}
|
||||
""".formatted(poolId, ok))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void createRejectsMoreThanFortyAssets() {
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"Settings": {"components": {}},
|
||||
"Assets": %s
|
||||
}
|
||||
""".formatted(poolId, clientId, assetArray(41)))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo(
|
||||
"1 validation error detected: Value '" + renderedAssets(41)
|
||||
+ "' at 'assets' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 40"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void fortyAssetsAreAccepted() throws Exception {
|
||||
String extraClient = cognitoJson("CreateUserPoolClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientName": "forty-asset-client"
|
||||
}
|
||||
""".formatted(poolId)).path("UserPoolClient").path("ClientId").asText();
|
||||
|
||||
cognitoAction("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"Settings": {"components": {}},
|
||||
"Assets": %s
|
||||
}
|
||||
""".formatted(poolId, extraClient, assetArray(40)))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ManagedLoginBranding.Assets.size()", equalTo(40));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void updateRejectsMoreThanFortyAssets() {
|
||||
cognitoAction("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s",
|
||||
"Settings": {"components": {}},
|
||||
"Assets": %s
|
||||
}
|
||||
""".formatted(poolId, brandingId, assetArray(41)))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo(
|
||||
"1 validation error detected: Value '" + renderedAssets(41)
|
||||
+ "' at 'assets' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 40"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void theAssetViolationIsReportedAheadOfTheBrandingIdViolation() {
|
||||
cognitoAction("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "not-a-uuid",
|
||||
"Settings": {"components": {}},
|
||||
"Assets": %s
|
||||
}
|
||||
""".formatted(poolId, assetArray(41)))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo(
|
||||
"2 validation errors detected: Value '" + renderedAssets(41)
|
||||
+ "' at 'assets' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 40; "
|
||||
+ "Value 'not-a-uuid' at 'managedLoginBrandingId' failed to satisfy "
|
||||
+ "constraint: Member must satisfy regular expression pattern: "
|
||||
+ BRANDING_ID_PATTERN));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void shapeViolationsAreReportedBeforeTheMissingPool() {
|
||||
cognitoAction("DescribeManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "us-east-1_nosuchpool",
|
||||
"ManagedLoginBrandingId": "not-a-uuid"
|
||||
}
|
||||
""")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo(
|
||||
"1 validation error detected: Value 'not-a-uuid' at 'managedLoginBrandingId' "
|
||||
+ "failed to satisfy constraint: Member must satisfy regular expression "
|
||||
+ "pattern: " + BRANDING_ID_PATTERN));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void aRejectedUpdateLeavesTheAssetsAlone() throws Exception {
|
||||
String client = cognitoJson("CreateUserPoolClient", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientName": "rejected-update-client"
|
||||
}
|
||||
""".formatted(poolId)).path("UserPoolClient").path("ClientId").asText();
|
||||
String branding = cognitoJson("CreateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"Settings": {"components": {}},
|
||||
"Assets": %s
|
||||
}
|
||||
""".formatted(poolId, client, assetArray(1)))
|
||||
.path("ManagedLoginBranding").path("ManagedLoginBrandingId").asText();
|
||||
|
||||
cognitoAction("UpdateManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s",
|
||||
"Settings": {"components": {}},
|
||||
"Assets": %s
|
||||
}
|
||||
""".formatted(poolId, branding, assetArray(41)))
|
||||
.then()
|
||||
.statusCode(400);
|
||||
|
||||
JsonNode readBack = cognitoJson("DescribeManagedLoginBranding", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ManagedLoginBrandingId": "%s"
|
||||
}
|
||||
""".formatted(poolId, branding)).path("ManagedLoginBranding");
|
||||
assertEquals(1, readBack.path("Assets").size(), "a rejected update must not replace the assets");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void deletePool() {
|
||||
cognitoAction("DeleteUserPool", """
|
||||
{
|
||||
"UserPoolId": "%s"
|
||||
}
|
||||
""".formatted(poolId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static final String BRANDING_ID_PATTERN =
|
||||
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[4][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$";
|
||||
|
||||
/** A one-byte payload, so the rendered buffer length stays easy to read. */
|
||||
private static final String ASSET_BYTES = "AA==";
|
||||
|
||||
private static String assetArray(int count) {
|
||||
StringBuilder json = new StringBuilder("[");
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (i > 0) {
|
||||
json.append(", ");
|
||||
}
|
||||
json.append("{\"Category\": \"PAGE_HEADER_LOGO\", \"ColorMode\": \"LIGHT\", ")
|
||||
.append("\"Extension\": \"PNG\", \"Bytes\": \"").append(ASSET_BYTES)
|
||||
.append("\", \"ResourceId\": \"asset-").append(i).append("\"}");
|
||||
}
|
||||
return json.append("]").toString();
|
||||
}
|
||||
|
||||
private static String renderedAssets(int count) {
|
||||
StringBuilder rendered = new StringBuilder("[");
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (i > 0) {
|
||||
rendered.append(", ");
|
||||
}
|
||||
rendered.append("AssetType(category=PAGE_HEADER_LOGO, colorMode=LIGHT, extension=PNG, ")
|
||||
.append("bytes=java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], resourceId=asset-")
|
||||
.append(i).append(")");
|
||||
}
|
||||
return rendered.append("]").toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user