Skip to content

Commit c95fc56

Browse files
committed
Refine the transform interceptor to only match amazon location service urls
1 parent 05a548e commit c95fc56

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/cognito/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe("AuthHelper for Cognito", () => {
1414
const cognitoIdentityPoolId = `${region}:TEST-IDENTITY-POOL-ID`;
1515
const url = "https://maps.geo.us-west-2.amazonaws.com/";
1616
const nonAWSUrl = "https://example.com/";
17+
const nonLocationAWSUrl = "https://my.cool.service.us-west-2.amazonaws.com/";
1718
const mockedCredentials = {
1819
identityId: "identityId",
1920
accessKeyId: "accessKeyId",
@@ -171,6 +172,15 @@ describe("AuthHelper for Cognito", () => {
171172
});
172173
});
173174

175+
it("getMapAuthenticationOptions transformRequest function should pass-through AWS Urls that aren't for the Amazon Location Service unchanged", async () => {
176+
const authHelper = await withIdentityPoolId(cognitoIdentityPoolId);
177+
const transformRequest = authHelper.getMapAuthenticationOptions().transformRequest;
178+
179+
expect(transformRequest(nonLocationAWSUrl)).toStrictEqual({
180+
url: nonLocationAWSUrl,
181+
});
182+
});
183+
174184
it("getLocationClientConfig should provide credentials from cognito", async () => {
175185
const authHelper = await withIdentityPoolId(cognitoIdentityPoolId);
176186
const additionalLocationClientConfig = authHelper.getLocationClientConfig();

src/cognito/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export async function withIdentityPoolId(
4242
return {
4343
getMapAuthenticationOptions: () => ({
4444
transformRequest: (url: string) => {
45-
// Only sign aws URLs
46-
if (url.includes("amazonaws.com")) {
45+
// Only sign aws location service URLs
46+
if (url.match("(http|https)://(.*).geo.(.*).amazonaws.com")) {
4747
return {
4848
url: Signer.signUrl(url, region, {
4949
access_key: credentials.accessKeyId,

0 commit comments

Comments
 (0)