@@ -114,7 +114,11 @@ public static void beforeClass() throws IOException, URISyntaxException, Interru
114
114
/** before. */
115
115
@ BeforeEach
116
116
public void before () {
117
+ Map <String , String > map = createEnvironment ();
118
+ createHandler (map );
119
+ }
117
120
121
+ private Map <String , String > createEnvironment () {
118
122
Map <String , String > map = new HashMap <>();
119
123
map .put ("CONSOLE_VERSION" , "0.1" );
120
124
map .put ("REGION" , "us-east-1" );
@@ -132,7 +136,10 @@ public void before() {
132
136
map .put ("DOMAIN" , "dev" );
133
137
map .put ("COGNITO_USER_POOL_ID" , "us-east-2_blGeBpyLg" );
134
138
map .put ("COGNITO_USER_POOL_CLIENT_ID" , "7223423m2pfgf34qnfokb2po2l" );
139
+ return map ;
140
+ }
135
141
142
+ private void createHandler (final Map <String , String > map ) {
136
143
this .handler = new ConsoleInstallHandler (map , s3Connection , s3Connection ) {
137
144
138
145
@ Override
@@ -185,19 +192,16 @@ public void testHandleRequest01() throws Exception {
185
192
this .logger .log ("sending SUCCESS to https://cloudformation-custom-resource" );
186
193
this .logger .log ("Request Create was successful!" );
187
194
188
-
189
- // replayAll();
190
195
this .handler .handleRequest (input , this .context );
191
196
192
197
// then
193
198
verifySendResponse (contentlength );
194
- verifyConfigWritten ();
199
+ verifyConfigWritten ("" );
195
200
verifyCognitoConfig ();
196
201
197
202
assertTrue (connection .contains ("\" Status\" :\" SUCCESS\" " ));
198
203
assertTrue (connection .contains ("\" Data\" :{\" Message\" :\" Request Create was successful!\" " ));
199
204
200
-
201
205
assertEquals ("font/woff2" ,
202
206
s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/font.woff2" , null ).getContentType ());
203
207
@@ -252,7 +256,7 @@ public void testHandleRequest02() throws Exception {
252
256
253
257
// then
254
258
verifySendResponse (contentlength );
255
- verifyConfigWritten ();
259
+ verifyConfigWritten ("" );
256
260
verifyCognitoConfig ();
257
261
258
262
assertTrue (this .logger .containsString (
@@ -360,18 +364,95 @@ public void testHandleRequest04() throws Exception {
360
364
assertTrue (connection .contains ("\" Status\" :\" FAILURE\" " ));
361
365
}
362
366
367
+ /**
368
+ * Test Handle Request 'CREATE'.
369
+ *
370
+ * @throws Exception Exception
371
+ */
372
+ @ Test
373
+ public void testHandleRequest05 () throws Exception {
374
+ // given
375
+ String cognitoSingleSignOnUrl =
376
+ "https://something.auth.us-east-2.amazoncognito.com/oauth2/authorize" ;
377
+ Map <String , String > map = createEnvironment ();
378
+ map .put ("COGNITO_SINGLE_SIGN_ON_URL" , cognitoSingleSignOnUrl );
379
+ createHandler (map );
380
+
381
+ final int contentlength = 105 ;
382
+ Map <String , Object > input = createInput ("Create" );
383
+ input .put ("CONSOLE_BUCKET" , CONSOLE_BUCKET );
384
+
385
+ // when
386
+ this .logger .log (
387
+ "received input: {ResponseURL=https://cloudformation-custom-resource, RequestType=Create}" );
388
+ this .logger .log ("unpacking formkiq-console/0.1/formkiq-console.zip "
389
+ + "from bucket distrobucket to bucket destbucket" );
390
+ this .logger .log ("sending SUCCESS to https://cloudformation-custom-resource" );
391
+ this .logger .log ("Request Create was successful!" );
392
+
393
+ this .handler .handleRequest (input , this .context );
394
+
395
+ // then
396
+ verifySendResponse (contentlength );
397
+ verifyConfigWritten (cognitoSingleSignOnUrl );
398
+ verifyCognitoConfig ();
399
+
400
+ assertTrue (connection .contains ("\" Status\" :\" SUCCESS\" " ));
401
+ assertTrue (connection .contains ("\" Data\" :{\" Message\" :\" Request Create was successful!\" " ));
402
+
403
+ assertEquals ("font/woff2" ,
404
+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/font.woff2" , null ).getContentType ());
405
+
406
+ assertEquals ("text/css" ,
407
+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.css" , null ).getContentType ());
408
+
409
+ assertEquals ("application/vnd.ms-fontobject" ,
410
+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.eot" , null ).getContentType ());
411
+
412
+ assertEquals ("image/x-icon" ,
413
+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.ico" , null ).getContentType ());
414
+
415
+ assertTrue (s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.js" , null ).getContentType ()
416
+ .endsWith ("/javascript" ));
417
+
418
+ assertEquals ("image/svg+xml" ,
419
+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.svg" , null ).getContentType ());
420
+
421
+ assertEquals ("font/ttf" ,
422
+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.ttf" , null ).getContentType ());
423
+
424
+ assertEquals ("text/plain" ,
425
+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.txt" , null ).getContentType ());
426
+
427
+ assertEquals ("font/woff" ,
428
+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.woff" , null ).getContentType ());
429
+
430
+ // given
431
+ input = createInput ("Delete" );
432
+ input .put ("CONSOLE_BUCKET" , CONSOLE_BUCKET );
433
+
434
+ // when
435
+ this .handler .handleRequest (input , this .context );
436
+
437
+ // then
438
+ assertTrue (s3 .listObjects (CONSOLE_BUCKET , null ).contents ().isEmpty ());
439
+ }
440
+
363
441
/**
364
442
* Verify Config File is written.
443
+ *
444
+ * @param cognitoSingleSignOnUrl {@link String}
365
445
*/
366
- private void verifyConfigWritten () {
446
+ private void verifyConfigWritten (final String cognitoSingleSignOnUrl ) {
447
+
367
448
String config = String .format ("{%n"
368
449
+ " \" documentApi\" : \" https://chartapi.24hourcharts.com.execute-api.us-east-1.amazonaws.com/prod/\" ,%n"
369
450
+ " \" userPoolId\" : \" us-east-2_blGeBpyLg\" ,%n"
370
451
+ " \" clientId\" : \" 7223423m2pfgf34qnfokb2po2l\" ,%n" + " \" consoleVersion\" : \" 0.1\" ,%n"
371
452
+ " \" brand\" : \" 24hourcharts\" ,%n" + " \" userAuthentication\" : \" cognito\" ,%n"
372
453
+ " \" authApi\" : \" https://auth.execute-api.us-east-1.amazonaws.com/prod/\" ,%n"
373
- + " \" cognitoHostedUi\" : \" https://test2111111111111111.auth.us-east-2.amazoncognito.com\" %n"
374
- + "}" );
454
+ + " \" cognitoHostedUi\" : \" https://test2111111111111111.auth.us-east-2.amazoncognito.com\" , %n"
455
+ + " \" cognitoSingleSignOnUrl \" : \" " + cognitoSingleSignOnUrl + " \" %n" + " }" );
375
456
376
457
assertTrue (this .logger .containsString ("writing Cognito config: " + config ));
377
458
}
0 commit comments