@@ -7,6 +7,7 @@ import path from 'path';
7
7
import { StackMetadataBackendOutputStorageStrategy } from '@aws-amplify/backend-output-storage' ;
8
8
import { ApplicationLogLevel } from 'aws-cdk-lib/aws-lambda' ;
9
9
import { RetentionDays } from 'aws-cdk-lib/aws-logs' ;
10
+ import transform from 'lodash.transform' ;
10
11
11
12
void describe ( 'Conversation Handler Function construct' , ( ) => {
12
13
void it ( 'creates handler with log group with JWT token redacting policy' , ( ) => {
@@ -20,40 +21,68 @@ void describe('Conversation Handler Function construct', () => {
20
21
assert . strictEqual ( Object . values ( logGroups ) . length , 1 ) ;
21
22
const logGroupLogicalId = Object . keys ( logGroups ) [ 0 ] ;
22
23
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 : [
29
30
{
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-_.+/=]*' ,
32
33
} ,
33
34
] ,
34
35
} ,
35
- statement : [
36
+ Statement : [
36
37
{
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 : { } ,
42
43
} ,
43
44
} ,
44
45
} ,
45
46
{
46
- sid : 'redact-statement-cdk' ,
47
- dataIdentifier : [ 'JWTToken' ] ,
48
- operation : {
47
+ Sid : 'redact-statement-cdk' ,
48
+ DataIdentifier : [ 'JWTToken' ] ,
49
+ Operation : {
49
50
// eslint-disable-next-line spellcheck/spell-checker
50
- deidentify : {
51
- maskConfig : { } ,
51
+ Deidentify : {
52
+ MaskConfig : { } ,
52
53
} ,
53
54
} ,
54
55
} ,
55
56
] ,
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
+ ) ;
57
86
template . hasResourceProperties ( 'AWS::Lambda::Function' , {
58
87
Handler : 'index.handler' ,
59
88
LoggingConfig : {
0 commit comments