Skip to content

Commit

Permalink
fix: allow using baseURL with empty url (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmbourne committed Mar 12, 2024
1 parent 938573a commit 8c4782d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions src/interceptor.test.ts
Expand Up @@ -501,4 +501,51 @@ describe("credentials", () => {
}
);
});

it("allows empty URL when baseURL is set", async () => {
// Arrange
const request: InternalAxiosRequestConfig = {
method: "GET",
url: "",
headers: getDefaultHeaders(),
transformRequest: getDefaultTransformRequest(),
};

const client = axios.create({
baseURL: "https://example.com",
});

const interceptor = aws4Interceptor({
options: {
region: "local",
service: "execute-api",
assumeRoleArn: "arn:aws:iam::111111111111:role/MockRole",
},
credentials: {
accessKeyId: "access-key-id",
secretAccessKey: "secret-access-key",
sessionToken: "session-token",
},
instance: client,
});

// Act
await expect(interceptor(request)).resolves.toBeDefined();
expect(sign).toBeCalledWith(
{
service: "execute-api",
path: "/",
method: "GET",
region: "local",
host: "example.com",
headers: {},
signQuery: undefined,
},
{
accessKeyId: "access-key-id",
secretAccessKey: "secret-access-key",
sessionToken: "session-token",
}
);
});
});
2 changes: 1 addition & 1 deletion src/interceptor.ts
Expand Up @@ -123,7 +123,7 @@ export const aws4Interceptor = <D = any>({
return async (config) => {
const url = instance.getUri(config);

if (!config.url) {
if (!url) {
throw new Error(
"No URL present in request config, unable to sign request"
);
Expand Down

0 comments on commit 8c4782d

Please sign in to comment.