Skip to content

Commit

Permalink
fix: respect baseUrl passed as part of request parameters (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored Sep 3, 2024
1 parent 447852f commit 8478cac
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function hook(
state,
// @ts-expect-error TBD
{},
request,
request.defaults({ baseUrl: endpoint.baseUrl }),
);

endpoint.headers.authorization = `token ${token}`;
Expand Down
52 changes: 52 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2416,3 +2416,55 @@ test("auth.hook() uses app auth even for requests with query strings. (#374)", a

expect(mock.done()).toBe(true);
});

test("auth.hook() respects `baseUrl` passed as part of request parameters #640", async () => {
const mock = fetchMock
.sandbox()
.postOnce(
"https://not-api.github.com/app/installations/123/access_tokens",
{
token: "secret123",
expires_at: "1970-01-01T01:00:00.000Z",
permissions: {
metadata: "read",
},
repository_selection: "all",
},
)
.get(
"https://not-api.github.com/repos/octocat/hello-world",
{ id: 123 },
{
headers: {
authorization: "token secret123",
},
repeat: 4,
},
);

const auth = createAppAuth({
appId: APP_ID,
privateKey: PRIVATE_KEY,
installationId: 123,
});

const requestWithMock = request.defaults({
headers: {
"user-agent": "test",
},
request: {
fetch: mock,
},
});
const requestWithAuth = requestWithMock.defaults({
request: {
hook: auth.hook,
},
});

const { data } = await requestWithAuth("GET /repos/octocat/hello-world", {
baseUrl: "https://not-api.github.com",
});

expect(data).toEqual({ id: 123 });
});

0 comments on commit 8478cac

Please sign in to comment.