Skip to content

Commit

Permalink
fix(util-endpoints): check for entire resource-path being empty (#6380)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Aug 13, 2024
1 parent e11e071 commit 08ad510
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions packages/util-endpoints/src/lib/aws/parseArn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down
15 changes: 11 additions & 4 deletions packages/util-endpoints/src/lib/aws/parseArn.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};
5 changes: 1 addition & 4 deletions tests/endpoints-2.0/endpoints-integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
});
Expand Down

0 comments on commit 08ad510

Please sign in to comment.