5
5
*/
6
6
import path from 'path' ;
7
7
import { App , Stack , Aspects } from 'aws-cdk-lib' ;
8
+ import { toBase64 } from '@aws-sdk/util-base64-node' ;
8
9
import { v4 } from 'uuid' ;
9
10
import {
10
11
generateUniqueName ,
@@ -44,8 +45,7 @@ const environmentName = generateUniqueName(RESOURCE_NAME_PREFIX, uuid, runtime,
44
45
const deploymentStrategyName = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'immediate' ) ;
45
46
const freeFormJsonName = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'freeFormJson' ) ;
46
47
const freeFormYamlName = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'freeFormYaml' ) ;
47
- const freeFormPlainTextNameA = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'freeFormPlainTextA' ) ;
48
- const freeFormPlainTextNameB = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'freeFormPlainTextB' ) ;
48
+ const freeFormBase64PlainTextName = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'freeFormBase64PlainText' ) ;
49
49
const featureFlagName = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'featureFlag' ) ;
50
50
51
51
const freeFormJsonValue = {
@@ -85,33 +85,30 @@ let stack: Stack;
85
85
* The parameters created are:
86
86
* - Free-form JSON
87
87
* - Free-form YAML
88
- * - 2x Free-form plain text
88
+ * - Free-form plain text base64-encoded string
89
89
* - Feature flag
90
90
*
91
91
* These parameters allow to retrieve the values and test some transformations.
92
92
*
93
93
* The tests are:
94
94
*
95
95
* Test 1
96
- * get a single parameter as-is (no transformation)
96
+ * get a single parameter as-is (no transformation - should return an Uint8Array )
97
97
*
98
98
* Test 2
99
- * get a free-form JSON and apply binary transformation (should return a stringified JSON )
99
+ * get a free-form JSON and apply json transformation (should return an object )
100
100
*
101
101
* Test 3
102
- * get a free-form YAML and apply binary transformation (should return a string-encoded YAML )
102
+ * get a free-form base64-encoded plain text and apply binary transformation (should return a decoded string )
103
103
*
104
104
* Test 4
105
- * get a free-form plain text and apply binary transformation (should return a string )
105
+ * get a feature flag and apply json transformation (should return an object )
106
106
*
107
107
* Test 5
108
- * get a feature flag and apply binary transformation (should return a stringified JSON)
109
- *
110
- * Test 6
111
108
* get parameter twice with middleware, which counts the number of requests,
112
109
* we check later if we only called AppConfig API once
113
110
*
114
- * Test 7
111
+ * Test 6
115
112
* get parameter twice, but force fetch 2nd time, we count number of SDK requests and
116
113
* check that we made two API calls
117
114
*
@@ -140,8 +137,7 @@ describe(`parameters E2E tests (appConfigProvider) for runtime ${runtime}`, () =
140
137
ENVIRONMENT_NAME : environmentName ,
141
138
FREEFORM_JSON_NAME : freeFormJsonName ,
142
139
FREEFORM_YAML_NAME : freeFormYamlName ,
143
- FREEFORM_PLAIN_TEXT_NAME_A : freeFormPlainTextNameA ,
144
- FREEFORM_PLAIN_TEXT_NAME_B : freeFormPlainTextNameB ,
140
+ FREEFORM_BASE64_ENCODED_PLAIN_TEXT_NAME : freeFormBase64PlainTextName ,
145
141
FEATURE_FLAG_NAME : featureFlagName ,
146
142
} ,
147
143
runtime,
@@ -187,33 +183,19 @@ describe(`parameters E2E tests (appConfigProvider) for runtime ${runtime}`, () =
187
183
} ) ;
188
184
freeFormYaml . node . addDependency ( freeFormJson ) ;
189
185
190
- const freeFormPlainTextA = createAppConfigConfigurationProfile ( {
186
+ const freeFormBase64PlainText = createAppConfigConfigurationProfile ( {
191
187
stack,
192
188
application,
193
189
environment,
194
190
deploymentStrategy,
195
- name : freeFormPlainTextNameA ,
191
+ name : freeFormBase64PlainTextName ,
196
192
type : 'AWS.Freeform' ,
197
193
content : {
198
- content : freeFormPlainTextValue ,
194
+ content : toBase64 ( new TextEncoder ( ) . encode ( freeFormPlainTextValue ) ) ,
199
195
contentType : 'text/plain' ,
200
196
}
201
197
} ) ;
202
- freeFormPlainTextA . node . addDependency ( freeFormYaml ) ;
203
-
204
- const freeFormPlainTextB = createAppConfigConfigurationProfile ( {
205
- stack,
206
- application,
207
- environment,
208
- deploymentStrategy,
209
- name : freeFormPlainTextNameB ,
210
- type : 'AWS.Freeform' ,
211
- content : {
212
- content : freeFormPlainTextValue ,
213
- contentType : 'text/plain' ,
214
- }
215
- } ) ;
216
- freeFormPlainTextB . node . addDependency ( freeFormPlainTextA ) ;
198
+ freeFormBase64PlainText . node . addDependency ( freeFormYaml ) ;
217
199
218
200
const featureFlag = createAppConfigConfigurationProfile ( {
219
201
stack,
@@ -227,14 +209,13 @@ describe(`parameters E2E tests (appConfigProvider) for runtime ${runtime}`, () =
227
209
contentType : 'application/json' ,
228
210
}
229
211
} ) ;
230
- featureFlag . node . addDependency ( freeFormPlainTextB ) ;
212
+ featureFlag . node . addDependency ( freeFormBase64PlainText ) ;
231
213
232
214
// Grant access to the Lambda function to the AppConfig resources.
233
215
Aspects . of ( stack ) . add ( new ResourceAccessGranter ( [
234
216
freeFormJson ,
235
217
freeFormYaml ,
236
- freeFormPlainTextA ,
237
- freeFormPlainTextB ,
218
+ freeFormBase64PlainText ,
238
219
featureFlag ,
239
220
] ) ) ;
240
221
@@ -248,8 +229,8 @@ describe(`parameters E2E tests (appConfigProvider) for runtime ${runtime}`, () =
248
229
249
230
describe ( 'AppConfigProvider usage' , ( ) => {
250
231
251
- // Test 1 - get a single parameter as-is (no transformation)
252
- it ( 'should retrieve single parameter' , ( ) => {
232
+ // Test 1 - get a single parameter as-is (no transformation - should return an Uint8Array )
233
+ it ( 'should retrieve single parameter as-is ' , ( ) => {
253
234
254
235
const logs = invocationLogs [ 0 ] . getFunctionLogs ( ) ;
255
236
const testLog = InvocationLogs . parseFunctionLog ( logs [ 0 ] ) ;
@@ -258,75 +239,59 @@ describe(`parameters E2E tests (appConfigProvider) for runtime ${runtime}`, () =
258
239
test : 'get' ,
259
240
value : JSON . parse (
260
241
JSON . stringify (
261
- encoder . encode ( freeFormPlainTextValue )
242
+ encoder . encode ( freeFormYamlValue )
262
243
)
263
244
) ,
264
245
} ) ;
265
246
266
247
} ) ;
267
248
268
- // Test 2 - get a free-form JSON and apply binary transformation
269
- // (should return a stringified JSON)
270
- it ( 'should retrieve single free-form JSON parameter with binary transformation' , ( ) => {
249
+ // Test 2 - get a free-form JSON and apply json transformation (should return an object)
250
+ it ( 'should retrieve a free-form JSON parameter with JSON transformation' , ( ) => {
271
251
272
252
const logs = invocationLogs [ 0 ] . getFunctionLogs ( ) ;
273
253
const testLog = InvocationLogs . parseFunctionLog ( logs [ 1 ] ) ;
274
254
275
255
expect ( testLog ) . toStrictEqual ( {
276
256
test : 'get-freeform-json-binary' ,
277
- value : JSON . stringify ( freeFormJsonValue ) ,
257
+ value : freeFormJsonValue ,
278
258
} ) ;
279
259
280
260
} ) ;
281
261
282
- // Test 3 - get a free-form YAML and apply binary transformation
283
- // (should return a string-encoded YAML )
284
- it ( 'should retrieve single free-form YAML parameter with binary transformation' , ( ) => {
262
+ // Test 3 - get a free-form base64-encoded plain text and apply binary transformation
263
+ // (should return a decoded string )
264
+ it ( 'should retrieve a base64-encoded plain text parameter with binary transformation' , ( ) => {
285
265
286
266
const logs = invocationLogs [ 0 ] . getFunctionLogs ( ) ;
287
267
const testLog = InvocationLogs . parseFunctionLog ( logs [ 2 ] ) ;
288
268
289
269
expect ( testLog ) . toStrictEqual ( {
290
- test : 'get-freeform-yaml-binary' ,
291
- value : freeFormYamlValue ,
292
- } ) ;
293
-
294
- } ) ;
295
-
296
- // Test 4 - get a free-form plain text and apply binary transformation
297
- // (should return a string)
298
- it ( 'should retrieve single free-form plain text parameter with binary transformation' , ( ) => {
299
-
300
- const logs = invocationLogs [ 0 ] . getFunctionLogs ( ) ;
301
- const testLog = InvocationLogs . parseFunctionLog ( logs [ 3 ] ) ;
302
-
303
- expect ( testLog ) . toStrictEqual ( {
304
- test : 'get-freeform-plain-text-binary' ,
270
+ test : 'get-freeform-base64-plaintext-binary' ,
305
271
value : freeFormPlainTextValue ,
306
272
} ) ;
307
273
308
274
} ) ;
309
275
310
- // Test 5 - get a feature flag and apply binary transformation
311
- // (should return a stringified JSON)
312
- it ( 'should retrieve single feature flag parameter with binary transformation' , ( ) => {
276
+ // Test 4 - get a feature flag and apply json transformation (should return an object)
277
+ it ( 'should retrieve a feature flag parameter with JSON transformation' , ( ) => {
313
278
314
279
const logs = invocationLogs [ 0 ] . getFunctionLogs ( ) ;
315
- const testLog = InvocationLogs . parseFunctionLog ( logs [ 4 ] ) ;
280
+ const testLog = InvocationLogs . parseFunctionLog ( logs [ 3 ] ) ;
316
281
317
282
expect ( testLog ) . toStrictEqual ( {
318
283
test : 'get-feature-flag-binary' ,
319
- value : JSON . stringify ( featureFlagValue . values ) ,
284
+ value : featureFlagValue . values ,
320
285
} ) ;
321
286
322
287
} ) ;
323
-
324
- // Test 6 - get parameter twice with middleware, which counts the number
288
+
289
+ // Test 5 - get parameter twice with middleware, which counts the number
325
290
// of requests, we check later if we only called AppConfig API once
326
291
it ( 'should retrieve single parameter cached' , ( ) => {
327
292
328
293
const logs = invocationLogs [ 0 ] . getFunctionLogs ( ) ;
329
- const testLog = InvocationLogs . parseFunctionLog ( logs [ 5 ] ) ;
294
+ const testLog = InvocationLogs . parseFunctionLog ( logs [ 4 ] ) ;
330
295
331
296
expect ( testLog ) . toStrictEqual ( {
332
297
test : 'get-cached' ,
@@ -335,12 +300,12 @@ describe(`parameters E2E tests (appConfigProvider) for runtime ${runtime}`, () =
335
300
336
301
} , TEST_CASE_TIMEOUT ) ;
337
302
338
- // Test 7 - get parameter twice, but force fetch 2nd time,
303
+ // Test 6 - get parameter twice, but force fetch 2nd time,
339
304
// we count number of SDK requests and check that we made two API calls
340
305
it ( 'should retrieve single parameter twice without caching' , async ( ) => {
341
306
342
307
const logs = invocationLogs [ 0 ] . getFunctionLogs ( ) ;
343
- const testLog = InvocationLogs . parseFunctionLog ( logs [ 6 ] ) ;
308
+ const testLog = InvocationLogs . parseFunctionLog ( logs [ 5 ] ) ;
344
309
345
310
expect ( testLog ) . toStrictEqual ( {
346
311
test : 'get-forced' ,
0 commit comments