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, }; }; 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)); } } });