fix(cognito): do not return optional blocks in CreateUserPoolClient when they are not set#1615
Conversation
…hen they are not set
|
| Filename | Overview |
|---|---|
| src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java | Core fix: replaces empty-map fallback with Optional.ifPresent for AnalyticsConfiguration, TokenValidityUnits, and RefreshTokenRotation in clientToNode; applies correctly to all three client operations (Create/Describe/Update) since they share this method. |
| src/test/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandlerTest.java | New test createUserPoolClientDoesNotReturnOptionalBlockKeysWhenNotSet verifies that absent fields are omitted from the serialized JSON response; covers the serialization layer accurately. |
| src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java | New test createUserPoolClientWithNoOptionalBlocksLeavesThemNull confirms the service model layer returns null for the three optional fields when not provided; logically sound. |
| compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CognitoFeaturesTest.java | SDK compatibility test verifies AWS Java SDK correctly deserializes a response with absent optional blocks as null; cleanup correctly deletes the new client before the pool. |
| compatibility-tests/compat-terraform/main.tf | Adds aws_cognito_user_pool_client resource referencing the pre-existing pool, enabling the end-to-end Terraform apply test. |
| compatibility-tests/compat-terraform/test/terraform.bats | Bats test verifies the pool client was successfully created (non-empty, non-None ClientId), including the non-empty guard requested in prior review feedback. |
| compatibility-tests/compat-opentofu/main.tf | Adds both the Cognito user pool and its client resource to the OpenTofu configuration; names match what the bats test queries for. |
| compatibility-tests/compat-opentofu/test/opentofu.bats | Mirrors the Terraform bats test; verifies client existence after apply with non-empty and non-None guards. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Client as AWS SDK / Terraform
participant Handler as CognitoJsonHandler
participant Service as CognitoService
participant Model as UserPoolClient (model)
Client->>Handler: CreateUserPoolClient (no optional blocks)
Handler->>Service: createUserPoolClient(poolId, name, ...)
Service->>Model: "new UserPoolClient (analyticsConfiguration=null, tokenValidityUnits=null, refreshTokenRotation=null)"
Service-->>Handler: UserPoolClient
Handler->>Handler: clientToNode(client)
Note over Handler: Optional.ofNullable(null).ifPresent(...) fields are OMITTED (not emitted as {})
Handler-->>Client: "{UserPoolClient: {ClientId: ...}} (no AnalyticsConfiguration, TokenValidityUnits, RefreshTokenRotation keys)"
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Client as AWS SDK / Terraform
participant Handler as CognitoJsonHandler
participant Service as CognitoService
participant Model as UserPoolClient (model)
Client->>Handler: CreateUserPoolClient (no optional blocks)
Handler->>Service: createUserPoolClient(poolId, name, ...)
Service->>Model: "new UserPoolClient (analyticsConfiguration=null, tokenValidityUnits=null, refreshTokenRotation=null)"
Service-->>Handler: UserPoolClient
Handler->>Handler: clientToNode(client)
Note over Handler: Optional.ofNullable(null).ifPresent(...) fields are OMITTED (not emitted as {})
Handler-->>Client: "{UserPoolClient: {ClientId: ...}} (no AnalyticsConfiguration, TokenValidityUnits, RefreshTokenRotation keys)"
Reviews (2): Last reviewed commit: "fix(cognito): improve bats assertions" | Re-trigger Greptile
|
https://github.com/floci-io/floci/actions/runs/28461093249/job/84350196672?pr=1615 - seems like a Docker build cache issue not related to my changes |
hectorvent
left a comment
There was a problem hiding this comment.
Thanks @b6k-dev,
Solid fix
Summary
Closes #1505
Changes summary:
Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
Incorrect behavior: CreateUserPoolClient returned "AnalyticsConfiguration": {} , "TokenValidityUnits": {} , and "RefreshTokenRotation": {} in the response body when those fields were not configured.
Fixed behavior: Optional block fields are now omitted from the CreateUserPoolClient response when not set.
Checklist
./mvnw testpasses locally