From d5d1ac7b45e64080b1c4f828cc6be6eb9d23fe0f Mon Sep 17 00:00:00 2001 From: Mike Friesen Date: Mon, 22 Apr 2024 20:43:11 -0500 Subject: [PATCH] V1.14.1 (#219) * Update Console to 3.5.0 * #220 - OCR Processor fails to create with using a long appenvironment name #220 --- build.gradle | 2 +- .../console/awstest/AwsResourceTest.java | 2 +- .../stacks/console/ConsoleInstallHandler.java | 9 +- .../resources/cloudformation/template.yaml | 2 +- .../console/ConsoleInstallHandlerTest.java | 97 +++++++++++++++++-- docs/openapi/openapi-iam.yaml | 2 +- docs/openapi/openapi-jwt.yaml | 2 +- docs/openapi/openapi-key.yaml | 2 +- .../cloudformation/template-ocr.yaml | 2 - 9 files changed, 102 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 3e8707f73..3eada4394 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ def getCmdParam() { repositories { mavenCentral() } allprojects { - version = '1.14.0' + version = '1.14.1' ext.awsCognitoVersion = '1.5.3' group = 'com.formkiq.stacks' diff --git a/console/src/integration/java/com/formkiq/stacks/console/awstest/AwsResourceTest.java b/console/src/integration/java/com/formkiq/stacks/console/awstest/AwsResourceTest.java index 099a2f753..ec6fb5bb4 100644 --- a/console/src/integration/java/com/formkiq/stacks/console/awstest/AwsResourceTest.java +++ b/console/src/integration/java/com/formkiq/stacks/console/awstest/AwsResourceTest.java @@ -201,7 +201,7 @@ public void testS3Buckets() { */ @Test public void testSsmParameters() { - assertEquals("v3.4.0", + assertEquals("v3.5.0", ssmService.getParameterValue("/formkiq/" + appenvironment + "/console/version")); assertTrue(ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/Console") .contains(appenvironment + "-console-")); diff --git a/console/src/main/java/com/formkiq/stacks/console/ConsoleInstallHandler.java b/console/src/main/java/com/formkiq/stacks/console/ConsoleInstallHandler.java index b58afcf3f..ec6212d55 100644 --- a/console/src/main/java/com/formkiq/stacks/console/ConsoleInstallHandler.java +++ b/console/src/main/java/com/formkiq/stacks/console/ConsoleInstallHandler.java @@ -108,14 +108,19 @@ private void createCognitoConfig(final LambdaLogger logger) { String congitoClientId = this.environmentMap.get("COGNITO_USER_POOL_CLIENT_ID"); String documentApi = this.environmentMap.get("API_URL"); + String cognitoSingleSignOnUrl = this.environmentMap.get("COGNITO_SINGLE_SIGN_ON_URL"); + if (cognitoSingleSignOnUrl == null) { + cognitoSingleSignOnUrl = ""; + } String json = String.format( "{%n" + " \"documentApi\": \"%s\",%n" + " \"userPoolId\": \"%s\",%n" + " \"clientId\": \"%s\",%n" + " \"consoleVersion\": \"%s\",%n" + " \"brand\": \"%s\",%n" + " \"userAuthentication\": \"%s\",%n" - + " \"authApi\": \"%s\",%n" + " \"cognitoHostedUi\": \"%s\"%n" + "}", + + " \"authApi\": \"%s\",%n" + " \"cognitoHostedUi\": \"%s\",%n" + + " \"cognitoSingleSignOnUrl\": \"%s\"%n" + "}", documentApi, cognitoUserPoolId, congitoClientId, consoleVersion, brand, userAuthentication, - authApi, cognitoHostedUi); + authApi, cognitoHostedUi, cognitoSingleSignOnUrl); String fileName = consoleVersion + "/assets/config.json"; diff --git a/console/src/main/resources/cloudformation/template.yaml b/console/src/main/resources/cloudformation/template.yaml index 041e6a993..7605c6afc 100644 --- a/console/src/main/resources/cloudformation/template.yaml +++ b/console/src/main/resources/cloudformation/template.yaml @@ -17,7 +17,7 @@ Parameters: ConsoleVersion: Type: String Description: Version of FormKiQ console to deploy - Default: v3.4.0 + Default: v3.5.0 FormKiQType: Description: The type of FormKiQ installation diff --git a/console/src/test/java/com/formkiq/stacks/console/ConsoleInstallHandlerTest.java b/console/src/test/java/com/formkiq/stacks/console/ConsoleInstallHandlerTest.java index 8d7def4ce..95dddd25f 100644 --- a/console/src/test/java/com/formkiq/stacks/console/ConsoleInstallHandlerTest.java +++ b/console/src/test/java/com/formkiq/stacks/console/ConsoleInstallHandlerTest.java @@ -114,7 +114,11 @@ public static void beforeClass() throws IOException, URISyntaxException, Interru /** before. */ @BeforeEach public void before() { + Map map = createEnvironment(); + createHandler(map); + } + private Map createEnvironment() { Map map = new HashMap<>(); map.put("CONSOLE_VERSION", "0.1"); map.put("REGION", "us-east-1"); @@ -132,7 +136,10 @@ public void before() { map.put("DOMAIN", "dev"); map.put("COGNITO_USER_POOL_ID", "us-east-2_blGeBpyLg"); map.put("COGNITO_USER_POOL_CLIENT_ID", "7223423m2pfgf34qnfokb2po2l"); + return map; + } + private void createHandler(final Map map) { this.handler = new ConsoleInstallHandler(map, s3Connection, s3Connection) { @Override @@ -185,19 +192,16 @@ public void testHandleRequest01() throws Exception { this.logger.log("sending SUCCESS to https://cloudformation-custom-resource"); this.logger.log("Request Create was successful!"); - - // replayAll(); this.handler.handleRequest(input, this.context); // then verifySendResponse(contentlength); - verifyConfigWritten(); + verifyConfigWritten(""); verifyCognitoConfig(); assertTrue(connection.contains("\"Status\":\"SUCCESS\"")); assertTrue(connection.contains("\"Data\":{\"Message\":\"Request Create was successful!\"")); - assertEquals("font/woff2", s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/font.woff2", null).getContentType()); @@ -252,7 +256,7 @@ public void testHandleRequest02() throws Exception { // then verifySendResponse(contentlength); - verifyConfigWritten(); + verifyConfigWritten(""); verifyCognitoConfig(); assertTrue(this.logger.containsString( @@ -360,18 +364,95 @@ public void testHandleRequest04() throws Exception { assertTrue(connection.contains("\"Status\":\"FAILURE\"")); } + /** + * Test Handle Request 'CREATE'. + * + * @throws Exception Exception + */ + @Test + public void testHandleRequest05() throws Exception { + // given + String cognitoSingleSignOnUrl = + "https://something.auth.us-east-2.amazoncognito.com/oauth2/authorize"; + Map map = createEnvironment(); + map.put("COGNITO_SINGLE_SIGN_ON_URL", cognitoSingleSignOnUrl); + createHandler(map); + + final int contentlength = 105; + Map input = createInput("Create"); + input.put("CONSOLE_BUCKET", CONSOLE_BUCKET); + + // when + this.logger.log( + "received input: {ResponseURL=https://cloudformation-custom-resource, RequestType=Create}"); + this.logger.log("unpacking formkiq-console/0.1/formkiq-console.zip " + + "from bucket distrobucket to bucket destbucket"); + this.logger.log("sending SUCCESS to https://cloudformation-custom-resource"); + this.logger.log("Request Create was successful!"); + + this.handler.handleRequest(input, this.context); + + // then + verifySendResponse(contentlength); + verifyConfigWritten(cognitoSingleSignOnUrl); + verifyCognitoConfig(); + + assertTrue(connection.contains("\"Status\":\"SUCCESS\"")); + assertTrue(connection.contains("\"Data\":{\"Message\":\"Request Create was successful!\"")); + + assertEquals("font/woff2", + s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/font.woff2", null).getContentType()); + + assertEquals("text/css", + s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/test.css", null).getContentType()); + + assertEquals("application/vnd.ms-fontobject", + s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/test.eot", null).getContentType()); + + assertEquals("image/x-icon", + s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/test.ico", null).getContentType()); + + assertTrue(s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/test.js", null).getContentType() + .endsWith("/javascript")); + + assertEquals("image/svg+xml", + s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/test.svg", null).getContentType()); + + assertEquals("font/ttf", + s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/test.ttf", null).getContentType()); + + assertEquals("text/plain", + s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/test.txt", null).getContentType()); + + assertEquals("font/woff", + s3.getObjectMetadata(CONSOLE_BUCKET, "0.1/test.woff", null).getContentType()); + + // given + input = createInput("Delete"); + input.put("CONSOLE_BUCKET", CONSOLE_BUCKET); + + // when + this.handler.handleRequest(input, this.context); + + // then + assertTrue(s3.listObjects(CONSOLE_BUCKET, null).contents().isEmpty()); + } + /** * Verify Config File is written. + * + * @param cognitoSingleSignOnUrl {@link String} */ - private void verifyConfigWritten() { + private void verifyConfigWritten(final String cognitoSingleSignOnUrl) { + String config = String.format("{%n" + " \"documentApi\": \"https://chartapi.24hourcharts.com.execute-api.us-east-1.amazonaws.com/prod/\",%n" + " \"userPoolId\": \"us-east-2_blGeBpyLg\",%n" + " \"clientId\": \"7223423m2pfgf34qnfokb2po2l\",%n" + " \"consoleVersion\": \"0.1\",%n" + " \"brand\": \"24hourcharts\",%n" + " \"userAuthentication\": \"cognito\",%n" + " \"authApi\": \"https://auth.execute-api.us-east-1.amazonaws.com/prod/\",%n" - + " \"cognitoHostedUi\": \"https://test2111111111111111.auth.us-east-2.amazoncognito.com\"%n" - + "}"); + + " \"cognitoHostedUi\": \"https://test2111111111111111.auth.us-east-2.amazoncognito.com\",%n" + + " \"cognitoSingleSignOnUrl\": \"" + cognitoSingleSignOnUrl + "\"%n" + "}"); assertTrue(this.logger.containsString("writing Cognito config: " + config)); } diff --git a/docs/openapi/openapi-iam.yaml b/docs/openapi/openapi-iam.yaml index b95864928..b94cb1578 100644 --- a/docs/openapi/openapi-iam.yaml +++ b/docs/openapi/openapi-iam.yaml @@ -32,7 +32,7 @@ - OAuth(JWT) - AWS IAM - API Key - version: 1.14.0 + version: 1.14.1 tags: - name: documents description: API for the add, updating and fetching of documents diff --git a/docs/openapi/openapi-jwt.yaml b/docs/openapi/openapi-jwt.yaml index 052274f7b..af302b94f 100644 --- a/docs/openapi/openapi-jwt.yaml +++ b/docs/openapi/openapi-jwt.yaml @@ -32,7 +32,7 @@ - OAuth(JWT) - AWS IAM - API Key - version: 1.14.0 + version: 1.14.1 tags: - name: documents description: API for the add, updating and fetching of documents diff --git a/docs/openapi/openapi-key.yaml b/docs/openapi/openapi-key.yaml index 523d3eb5c..3e8a9a62c 100644 --- a/docs/openapi/openapi-key.yaml +++ b/docs/openapi/openapi-key.yaml @@ -32,7 +32,7 @@ - OAuth(JWT) - AWS IAM - API Key - version: 1.14.0 + version: 1.14.1 tags: - name: documents description: API for the add, updating and fetching of documents diff --git a/lambda-ocr-tesseract/src/main/resources/cloudformation/template-ocr.yaml b/lambda-ocr-tesseract/src/main/resources/cloudformation/template-ocr.yaml index 171a9c207..79d921768 100644 --- a/lambda-ocr-tesseract/src/main/resources/cloudformation/template-ocr.yaml +++ b/lambda-ocr-tesseract/src/main/resources/cloudformation/template-ocr.yaml @@ -47,8 +47,6 @@ Resources: Type: AWS::Serverless::LayerVersion Properties: Description: Lambda Layer containing Tesseract binary - LayerName: - Fn::Sub: "${AWS::StackName}-${AppEnvironment}-tesseract-layer" ContentUri: ./layer-tesseract-5.3.1.zip OcrProcessorApiInvokePermission: