Skip to content

Commit e0ecf3b

Browse files
authored
fix: respect baseUrl passed as part of request parameters (#642)
1 parent 8e46539 commit e0ecf3b

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export async function hook(
9292
state,
9393
// @ts-expect-error TBD
9494
{},
95-
request,
95+
request.defaults({ baseUrl: endpoint.baseUrl }),
9696
);
9797

9898
endpoint.headers.authorization = `token ${token}`;

test/index.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,3 +2393,55 @@ test("auth.hook() uses app auth even for requests with query strings. (#374)", a
23932393

23942394
expect(mock.done()).toBe(true);
23952395
});
2396+
2397+
test("auth.hook() respects `baseUrl` passed as part of request parameters #640", async () => {
2398+
const mock = fetchMock
2399+
.sandbox()
2400+
.postOnce(
2401+
"https://not-api.github.com/app/installations/123/access_tokens",
2402+
{
2403+
token: "secret123",
2404+
expires_at: "1970-01-01T01:00:00.000Z",
2405+
permissions: {
2406+
metadata: "read",
2407+
},
2408+
repository_selection: "all",
2409+
},
2410+
)
2411+
.get(
2412+
"https://not-api.github.com/repos/octocat/hello-world",
2413+
{ id: 123 },
2414+
{
2415+
headers: {
2416+
authorization: "token secret123",
2417+
},
2418+
repeat: 4,
2419+
},
2420+
);
2421+
2422+
const auth = createAppAuth({
2423+
appId: APP_ID,
2424+
privateKey: PRIVATE_KEY,
2425+
installationId: 123,
2426+
});
2427+
2428+
const requestWithMock = request.defaults({
2429+
headers: {
2430+
"user-agent": "test",
2431+
},
2432+
request: {
2433+
fetch: mock,
2434+
},
2435+
});
2436+
const requestWithAuth = requestWithMock.defaults({
2437+
request: {
2438+
hook: auth.hook,
2439+
},
2440+
});
2441+
2442+
const { data } = await requestWithAuth("GET /repos/octocat/hello-world", {
2443+
baseUrl: "https://not-api.github.com",
2444+
});
2445+
2446+
expect(data).toEqual({ id: 123 });
2447+
});

0 commit comments

Comments
 (0)