Skip to content

Commit

Permalink
Refine the transform interceptor to only match amazon location servic…
Browse files Browse the repository at this point in the history
…e urls
  • Loading branch information
cgalvan committed Jul 17, 2024
1 parent 849404a commit d914d8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/cognito/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe("AuthHelper for Cognito", () => {
const cognitoIdentityPoolId = `${region}:TEST-IDENTITY-POOL-ID`;
const url = "https://maps.geo.us-west-2.amazonaws.com/";
const nonAWSUrl = "https://example.com/";
const nonLocationAWSUrl = "https://my.cool.service.us-west-2.amazonaws.com/";
const mockedCredentials = {
identityId: "identityId",
accessKeyId: "accessKeyId",
Expand Down Expand Up @@ -171,6 +172,15 @@ describe("AuthHelper for Cognito", () => {
});
});

it("getMapAuthenticationOptions transformRequest function should pass-through AWS Urls that aren't for the Amazon Location Service unchanged", async () => {
const authHelper = await withIdentityPoolId(cognitoIdentityPoolId);
const transformRequest = authHelper.getMapAuthenticationOptions().transformRequest;

expect(transformRequest(nonLocationAWSUrl)).toStrictEqual({
url: nonLocationAWSUrl,
});
});

it("getLocationClientConfig should provide credentials from cognito", async () => {
const authHelper = await withIdentityPoolId(cognitoIdentityPoolId);
const additionalLocationClientConfig = authHelper.getLocationClientConfig();
Expand Down
4 changes: 2 additions & 2 deletions src/cognito/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export async function withIdentityPoolId(
return {
getMapAuthenticationOptions: () => ({
transformRequest: (url: string) => {
// Only sign aws URLs
if (url.includes("amazonaws.com")) {
// Only sign aws location service URLs
if (url.match("(http|https)://(.*).geo.(.*).amazonaws.com")) {
return {
url: Signer.signUrl(url, region, {
access_key: credentials.accessKeyId,
Expand Down

0 comments on commit d914d8a

Please sign in to comment.