Skip to content

Commit 4bf7ca9

Browse files
bdellegrazieuttam282005
authored andcommitted
fix(parser): cognito schema preferredRole may be null (aws-powertools#4259)
1 parent 0b0189d commit 4bf7ca9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/parser/src/schemas/cognito.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const PostAuthenticationTriggerSchema = CognitoTriggerBaseSchema.extend({
192192
const PreTokenGenerationTriggerGroupConfigurationSchema = z.object({
193193
groupsToOverride: z.array(z.string()),
194194
iamRolesToOverride: z.array(z.string()),
195-
preferredRole: z.string().optional(),
195+
preferredRole: z.string().nullable(),
196196
});
197197

198198
/**

packages/parser/tests/unit/schema/cognito.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,29 @@ describe('Schemas: Cognito User Pool', () => {
396396
expect(result).toEqual(event);
397397
});
398398

399+
it('parses a valid pre-token generation event v1 with null preferredRole', () => {
400+
// Prepare
401+
const event = structuredClone(baseEvent);
402+
event.request = {
403+
userAttributes: {
404+
sub: '42051434-5091-70ec-4b71-7c26db407ea4',
405+
'cognito:user_status': 'CONFIRMED',
406+
},
407+
groupConfiguration: {
408+
groupsToOverride: ['group1', 'group2'],
409+
iamRolesToOverride: ['role1', 'role2'],
410+
preferredRole: null,
411+
},
412+
clientMetadata: { key: 'value' },
413+
};
414+
415+
// Act
416+
const result = PreTokenGenerationTriggerSchemaV1.parse(event);
417+
418+
// Assess
419+
expect(result).toEqual(event);
420+
});
421+
399422
it('throws if the pre-token generation event v1 is missing a required field', () => {
400423
// Prepare
401424
const event = structuredClone(baseEvent);

0 commit comments

Comments
 (0)