Skip to content

Commit 08ad510

Browse files
authored
fix(util-endpoints): check for entire resource-path being empty (#6380)
1 parent e11e071 commit 08ad510

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

packages/util-endpoints/src/lib/aws/parseArn.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ describe(parseArn.name, () => {
1414
resourceId: ["accesspoint", "myendpoint"],
1515
},
1616
],
17+
[
18+
"arn:aws:s3:us-west-2:123456789012::myendpoint",
19+
{
20+
partition: "aws",
21+
service: "s3",
22+
region: "us-west-2",
23+
accountId: "123456789012",
24+
resourceId: ["", "myendpoint"],
25+
},
26+
],
1727
[
1828
"arn:aws:s3:us-west-2:123456789012:accesspoint/myendpoint",
1929
{
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import { EndpointARN } from "@smithy/types";
22

3+
const ARN_DELIMITER = ":";
4+
const RESOURCE_DELIMITER = "/";
5+
36
/**
47
* Evaluates a single string argument value, and returns an object containing
58
* details about the parsed ARN.
69
* If the input was not a valid ARN, the function returns null.
710
*/
811
export const parseArn = (value: string): EndpointARN | null => {
9-
const segments = value.split(":");
12+
const segments = value.split(ARN_DELIMITER);
1013

1114
if (segments.length < 6) return null;
1215

13-
const [arn, partition, service, region, accountId, ...resourceId] = segments;
16+
const [arn, partition, service, region, accountId, ...resourcePath] = segments;
17+
18+
if (arn !== "arn" || partition === "" || service === "" || resourcePath.join(ARN_DELIMITER) === "") return null;
1419

15-
if (arn !== "arn" || partition === "" || service === "" || resourceId[0] === "") return null;
20+
const resourceId = resourcePath[0].includes(RESOURCE_DELIMITER)
21+
? resourcePath[0].split(RESOURCE_DELIMITER)
22+
: resourcePath;
1623

1724
return {
1825
partition,
1926
service,
2027
region,
2128
accountId,
22-
resourceId: resourceId[0].includes("/") ? resourceId[0].split("/") : resourceId,
29+
resourceId,
2330
};
2431
};

tests/endpoints-2.0/endpoints-integration.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ function runTestCases(service: ServiceModel, namespace: ServiceNamespace) {
8282
const observedError = await (async () => defaultEndpointResolver(endpointParams as any))().catch(pass);
8383
expect(observedError).not.toBeUndefined();
8484
expect(observedError?.url).toBeUndefined();
85-
// ToDo: debug why 'client-s3 > empty arn type' test case is failing
86-
if (serviceId !== "s3" && documentation !== "empty arn type") {
87-
expect(normalizeQuotes(String(observedError))).toContain(normalizeQuotes(error));
88-
}
85+
expect(normalizeQuotes(String(observedError))).toContain(normalizeQuotes(error));
8986
}
9087
}
9188
});

0 commit comments

Comments
 (0)