@@ -7,6 +7,7 @@ import path from 'path';
77import { StackMetadataBackendOutputStorageStrategy } from '@aws-amplify/backend-output-storage' ;
88import { ApplicationLogLevel } from 'aws-cdk-lib/aws-lambda' ;
99import { RetentionDays } from 'aws-cdk-lib/aws-logs' ;
10+ import transform from 'lodash.transform' ;
1011
1112void describe ( 'Conversation Handler Function construct' , ( ) => {
1213 void it ( 'creates handler with log group with JWT token redacting policy' , ( ) => {
@@ -20,40 +21,68 @@ void describe('Conversation Handler Function construct', () => {
2021 assert . strictEqual ( Object . values ( logGroups ) . length , 1 ) ;
2122 const logGroupLogicalId = Object . keys ( logGroups ) [ 0 ] ;
2223 const logGroup = Object . values ( logGroups ) [ 0 ] ;
23- assert . deepStrictEqual ( logGroup . Properties . DataProtectionPolicy , {
24- name : 'data-protection-policy-cdk' ,
25- description : 'cdk generated data protection policy' ,
26- version : '2021-06-01' ,
27- configuration : {
28- customDataIdentifier : [
24+ let expectedDataProtectionPolicy : Record < string , unknown > = {
25+ Name : 'data-protection-policy-cdk' ,
26+ Description : 'cdk generated data protection policy' ,
27+ Version : '2021-06-01' ,
28+ Configuration : {
29+ CustomDataIdentifier : [
2930 {
30- name : 'JWTToken' ,
31- regex : 'ey[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*' ,
31+ Name : 'JWTToken' ,
32+ Regex : 'ey[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*' ,
3233 } ,
3334 ] ,
3435 } ,
35- statement : [
36+ Statement : [
3637 {
37- sid : 'audit-statement-cdk' ,
38- dataIdentifier : [ 'JWTToken' ] ,
39- operation : {
40- audit : {
41- findingsDestination : { } ,
38+ Sid : 'audit-statement-cdk' ,
39+ DataIdentifier : [ 'JWTToken' ] ,
40+ Operation : {
41+ Audit : {
42+ FindingsDestination : { } ,
4243 } ,
4344 } ,
4445 } ,
4546 {
46- sid : 'redact-statement-cdk' ,
47- dataIdentifier : [ 'JWTToken' ] ,
48- operation : {
47+ Sid : 'redact-statement-cdk' ,
48+ DataIdentifier : [ 'JWTToken' ] ,
49+ Operation : {
4950 // eslint-disable-next-line spellcheck/spell-checker
50- deidentify : {
51- maskConfig : { } ,
51+ Deidentify : {
52+ MaskConfig : { } ,
5253 } ,
5354 } ,
5455 } ,
5556 ] ,
56- } ) ;
57+ } ;
58+ if ( 'name' in logGroup . Properties . DataProtectionPolicy ) {
59+ // we may run some tests with older CDK version.
60+ // in that case the expected keys are all lower case, see https://github.com/aws/aws-cdk/pull/33462
61+ const keysToCamelCase = ( target : Record < string , unknown > ) =>
62+ transform (
63+ target ,
64+ (
65+ result : { [ x : string | number ] : unknown } ,
66+ val : unknown ,
67+ key : string | number
68+ ) => {
69+ if ( typeof val === 'object' ) {
70+ val = keysToCamelCase ( val as Record < string , unknown > ) ;
71+ }
72+ if ( typeof key === 'string' ) {
73+ key = `${ key . slice ( 0 , 1 ) . toLowerCase ( ) } ${ key . slice ( 1 ) } ` ;
74+ }
75+ result [ key ] = val ;
76+ }
77+ ) ;
78+ expectedDataProtectionPolicy = keysToCamelCase (
79+ expectedDataProtectionPolicy
80+ ) ;
81+ }
82+ assert . deepStrictEqual (
83+ logGroup . Properties . DataProtectionPolicy ,
84+ expectedDataProtectionPolicy
85+ ) ;
5786 template . hasResourceProperties ( 'AWS::Lambda::Function' , {
5887 Handler : 'index.handler' ,
5988 LoggingConfig : {
0 commit comments