Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(util-endpoints): check for entire resource-path being empty #6380

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
trivikr marked this conversation as resolved.
Show resolved Hide resolved

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
Loading