From 5db2f6856d4e80268f74393ebc9c2d43fc2b1370 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:24:15 +0000 Subject: [PATCH 1/4] fix(util-endpoints): check for entire resource-path being empty --- .../util-endpoints/src/lib/aws/parseArn.spec.ts | 10 ++++++++++ packages/util-endpoints/src/lib/aws/parseArn.ts | 15 +++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/util-endpoints/src/lib/aws/parseArn.spec.ts b/packages/util-endpoints/src/lib/aws/parseArn.spec.ts index baf39be11c37..3b715868c92f 100644 --- a/packages/util-endpoints/src/lib/aws/parseArn.spec.ts +++ b/packages/util-endpoints/src/lib/aws/parseArn.spec.ts @@ -14,6 +14,16 @@ describe(parseArn.name, () => { resourceId: ["accesspoint", "myendpoint"], }, ], + [ + "arn:aws:s3:us-west-2:123456789012::myendpoint", + { + partition: "aws", + service: "s3", + region: "us-west-2", + accountId: "123456789012", + resourceId: ["", "myendpoint"], + }, + ], [ "arn:aws:s3:us-west-2:123456789012:accesspoint/myendpoint", { diff --git a/packages/util-endpoints/src/lib/aws/parseArn.ts b/packages/util-endpoints/src/lib/aws/parseArn.ts index 798d9097b2ed..99ce11f55c65 100644 --- a/packages/util-endpoints/src/lib/aws/parseArn.ts +++ b/packages/util-endpoints/src/lib/aws/parseArn.ts @@ -1,24 +1,31 @@ import { EndpointARN } from "@smithy/types"; +const ARN_DELIMITER = ":"; +const RESOURCE_DELIMITER = "/"; + /** * Evaluates a single string argument value, and returns an object containing * details about the parsed ARN. * If the input was not a valid ARN, the function returns null. */ export const parseArn = (value: string): EndpointARN | null => { - const segments = value.split(":"); + const segments = value.split(ARN_DELIMITER); if (segments.length < 6) return null; - const [arn, partition, service, region, accountId, ...resourceId] = segments; + const [arn, partition, service, region, accountId, ...resourcePath] = segments; + + if (arn !== "arn" || partition === "" || service === "" || resourcePath.join(ARN_DELIMITER) === "") return null; - if (arn !== "arn" || partition === "" || service === "" || resourceId[0] === "") return null; + const resourceId = resourcePath[0].includes(RESOURCE_DELIMITER) + ? resourcePath[0].split(RESOURCE_DELIMITER) + : resourcePath; return { partition, service, region, accountId, - resourceId: resourceId[0].includes("/") ? resourceId[0].split("/") : resourceId, + resourceId, }; }; From 7d9d9ad7fe3ad2910d40095f339671d793fb9498 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:25:46 +0000 Subject: [PATCH 2/4] test(endpoint): enable test for s3 empty arn type --- tests/endpoints-2.0/endpoints-integration.spec.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/endpoints-2.0/endpoints-integration.spec.ts b/tests/endpoints-2.0/endpoints-integration.spec.ts index 2b6376043245..cae14cbd475d 100644 --- a/tests/endpoints-2.0/endpoints-integration.spec.ts +++ b/tests/endpoints-2.0/endpoints-integration.spec.ts @@ -82,10 +82,7 @@ function runTestCases(service: ServiceModel, namespace: ServiceNamespace) { const observedError = await (async () => defaultEndpointResolver(endpointParams as any))().catch(pass); expect(observedError).not.toBeUndefined(); expect(observedError?.url).toBeUndefined(); - // ToDo: debug why 'client-s3 > empty arn type' test case is failing - if (serviceId !== "s3" && documentation !== "empty arn type") { - expect(normalizeQuotes(String(observedError))).toContain(normalizeQuotes(error)); - } + expect(normalizeQuotes(String(observedError))).toContain(normalizeQuotes(error)); } } }); From 855f1fa613997ff2c2c0a08412e58c041911e834 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:15:29 +0000 Subject: [PATCH 3/4] fix(util-endpoints): handle case when resourcePath contains both delimiters --- packages/util-endpoints/src/lib/aws/parseArn.spec.ts | 10 ++++++++++ packages/util-endpoints/src/lib/aws/parseArn.ts | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/util-endpoints/src/lib/aws/parseArn.spec.ts b/packages/util-endpoints/src/lib/aws/parseArn.spec.ts index 3b715868c92f..16e0342dae98 100644 --- a/packages/util-endpoints/src/lib/aws/parseArn.spec.ts +++ b/packages/util-endpoints/src/lib/aws/parseArn.spec.ts @@ -74,6 +74,16 @@ describe(parseArn.name, () => { resourceId: ["myTopic"], }, ], + [ + "arn:aws:s3:us-west-2:123456789012:my:folder/my:file", + { + partition: "aws", + service: "s3", + region: "us-west-2", + accountId: "123456789012", + resourceId: ["my", "folder", "my", "file"], + }, + ], ]; it.each(VALID_TEST_CASES)("returns for valid arn %s", (input: string, outout: EndpointARN) => { diff --git a/packages/util-endpoints/src/lib/aws/parseArn.ts b/packages/util-endpoints/src/lib/aws/parseArn.ts index 99ce11f55c65..2c6078b647b5 100644 --- a/packages/util-endpoints/src/lib/aws/parseArn.ts +++ b/packages/util-endpoints/src/lib/aws/parseArn.ts @@ -17,9 +17,7 @@ export const parseArn = (value: string): EndpointARN | null => { if (arn !== "arn" || partition === "" || service === "" || resourcePath.join(ARN_DELIMITER) === "") return null; - const resourceId = resourcePath[0].includes(RESOURCE_DELIMITER) - ? resourcePath[0].split(RESOURCE_DELIMITER) - : resourcePath; + const resourceId = resourcePath.map((resource) => resource.split(RESOURCE_DELIMITER)).flat(); return { partition, From 3937a6a4783c320a08aa74ba7b1ea41cc8a2275e Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:08:06 +0000 Subject: [PATCH 4/4] fix(util-endpoints): revert handling case when resourcePath contains both delimiters This reverts commit 855f1fa613997ff2c2c0a08412e58c041911e834. It'll be added, if needed, in a separate PR. --- packages/util-endpoints/src/lib/aws/parseArn.spec.ts | 10 ---------- packages/util-endpoints/src/lib/aws/parseArn.ts | 4 +++- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/util-endpoints/src/lib/aws/parseArn.spec.ts b/packages/util-endpoints/src/lib/aws/parseArn.spec.ts index 16e0342dae98..3b715868c92f 100644 --- a/packages/util-endpoints/src/lib/aws/parseArn.spec.ts +++ b/packages/util-endpoints/src/lib/aws/parseArn.spec.ts @@ -74,16 +74,6 @@ describe(parseArn.name, () => { resourceId: ["myTopic"], }, ], - [ - "arn:aws:s3:us-west-2:123456789012:my:folder/my:file", - { - partition: "aws", - service: "s3", - region: "us-west-2", - accountId: "123456789012", - resourceId: ["my", "folder", "my", "file"], - }, - ], ]; it.each(VALID_TEST_CASES)("returns for valid arn %s", (input: string, outout: EndpointARN) => { diff --git a/packages/util-endpoints/src/lib/aws/parseArn.ts b/packages/util-endpoints/src/lib/aws/parseArn.ts index 2c6078b647b5..99ce11f55c65 100644 --- a/packages/util-endpoints/src/lib/aws/parseArn.ts +++ b/packages/util-endpoints/src/lib/aws/parseArn.ts @@ -17,7 +17,9 @@ export const parseArn = (value: string): EndpointARN | null => { if (arn !== "arn" || partition === "" || service === "" || resourcePath.join(ARN_DELIMITER) === "") return null; - const resourceId = resourcePath.map((resource) => resource.split(RESOURCE_DELIMITER)).flat(); + const resourceId = resourcePath[0].includes(RESOURCE_DELIMITER) + ? resourcePath[0].split(RESOURCE_DELIMITER) + : resourcePath; return { partition,