@@ -162,6 +162,49 @@ const serverlessConfigurationExtension = {
162162 } ,
163163} ;
164164
165+ const preTokenGenerationConfigurationExtension = {
166+ configValidationMode : 'off' ,
167+ functions : {
168+ preTokenGenerationV2 : {
169+ handler : 'index.js' ,
170+ events : [
171+ {
172+ cognitoUserPool : {
173+ pool : 'PreTokenGenerationV2Pool' ,
174+ trigger : 'PreTokenGeneration' ,
175+ lambdaVersion : 'V2_0' ,
176+ } ,
177+ } ,
178+ ] ,
179+ } ,
180+ preTokenGenerationV3 : {
181+ handler : 'index.js' ,
182+ events : [
183+ {
184+ cognitoUserPool : {
185+ pool : 'PreTokenGenerationV3Pool' ,
186+ trigger : 'PreTokenGeneration' ,
187+ lambdaVersion : 'V3_0' ,
188+ } ,
189+ } ,
190+ ] ,
191+ } ,
192+ preTokenGenerationV2Existing : {
193+ handler : 'index.js' ,
194+ events : [
195+ {
196+ cognitoUserPool : {
197+ pool : 'PreTokenGenerationV2PoolExisting' ,
198+ trigger : 'PreTokenGeneration' ,
199+ lambdaVersion : 'V2_0' ,
200+ existing : true ,
201+ } ,
202+ } ,
203+ ] ,
204+ } ,
205+ } ,
206+ } ;
207+
165208describe ( 'AwsCompileCognitoUserPoolEvents' , ( ) => {
166209 let serverless ;
167210 let awsCompileCognitoUserPoolEvents ;
@@ -1385,4 +1428,64 @@ describe('lib/plugins/aws/package/compile/events/cognito-user-pool.test.js', ()
13851428 } ) ;
13861429 } ) ;
13871430 } ) ;
1431+
1432+ describe ( 'PreTokenGeneration Lambda Versions' , ( ) => {
1433+ describe ( 'New Pools' , ( ) => {
1434+ it ( 'should create PreTokenGenerationConfig for V2_0' , async ( ) => {
1435+ const { cfTemplate } = await runServerless ( {
1436+ fixture : 'cognito-user-pool' ,
1437+ configExt : preTokenGenerationConfigurationExtension ,
1438+ command : 'package' ,
1439+ } ) ;
1440+
1441+ const userPoolResource = cfTemplate . Resources . CognitoUserPoolPreTokenGenerationV2Pool ;
1442+ expect ( userPoolResource . Properties . LambdaConfig ) . to . have . property (
1443+ 'PreTokenGenerationConfig'
1444+ ) ;
1445+ expect (
1446+ userPoolResource . Properties . LambdaConfig . PreTokenGenerationConfig . LambdaVersion
1447+ ) . to . equal ( 'V2_0' ) ;
1448+ expect ( userPoolResource . Properties . LambdaConfig ) . to . not . have . property ( 'PreTokenGeneration' ) ;
1449+ } ) ;
1450+
1451+ it ( 'should create PreTokenGenerationConfig for V3_0' , async ( ) => {
1452+ const { cfTemplate } = await runServerless ( {
1453+ fixture : 'cognito-user-pool' ,
1454+ configExt : preTokenGenerationConfigurationExtension ,
1455+ command : 'package' ,
1456+ } ) ;
1457+
1458+ const userPoolResource = cfTemplate . Resources . CognitoUserPoolPreTokenGenerationV3Pool ;
1459+ expect ( userPoolResource . Properties . LambdaConfig ) . to . have . property (
1460+ 'PreTokenGenerationConfig'
1461+ ) ;
1462+ expect (
1463+ userPoolResource . Properties . LambdaConfig . PreTokenGenerationConfig . LambdaVersion
1464+ ) . to . equal ( 'V3_0' ) ;
1465+ expect ( userPoolResource . Properties . LambdaConfig ) . to . not . have . property ( 'PreTokenGeneration' ) ;
1466+ } ) ;
1467+ } ) ;
1468+
1469+ describe ( 'Existing Pools' , ( ) => {
1470+ it ( 'should create correct UserPoolConfigs for V2_0' , async ( ) => {
1471+ const { cfTemplate } = await runServerless ( {
1472+ fixture : 'cognito-user-pool' ,
1473+ configExt : preTokenGenerationConfigurationExtension ,
1474+ command : 'package' ,
1475+ } ) ;
1476+
1477+ const customResources = Object . values ( cfTemplate . Resources ) . filter (
1478+ ( resource ) => resource . Type === 'Custom::CognitoUserPool'
1479+ ) ;
1480+ const v2Resource = customResources . find (
1481+ ( resource ) => resource . Properties . UserPoolName === 'PreTokenGenerationV2PoolExisting'
1482+ ) ;
1483+
1484+ expect ( v2Resource . Properties . UserPoolConfigs [ 0 ] ) . to . deep . include ( {
1485+ Trigger : 'PreTokenGeneration' ,
1486+ LambdaVersion : 'V2_0' ,
1487+ } ) ;
1488+ } ) ;
1489+ } ) ;
1490+ } ) ;
13881491} ) ;
0 commit comments