Skip to content

Commit 8478cac

Browse files
authoredSep 3, 2024··
fix: respect baseUrl passed as part of request parameters (#641)
1 parent 447852f commit 8478cac

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
 

‎src/hook.ts

+1-1
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

+52
Original file line numberDiff line numberDiff line change
@@ -2416,3 +2416,55 @@ test("auth.hook() uses app auth even for requests with query strings. (#374)", a
24162416

24172417
expect(mock.done()).toBe(true);
24182418
});
2419+
2420+
test("auth.hook() respects `baseUrl` passed as part of request parameters #640", async () => {
2421+
const mock = fetchMock
2422+
.sandbox()
2423+
.postOnce(
2424+
"https://not-api.github.com/app/installations/123/access_tokens",
2425+
{
2426+
token: "secret123",
2427+
expires_at: "1970-01-01T01:00:00.000Z",
2428+
permissions: {
2429+
metadata: "read",
2430+
},
2431+
repository_selection: "all",
2432+
},
2433+
)
2434+
.get(
2435+
"https://not-api.github.com/repos/octocat/hello-world",
2436+
{ id: 123 },
2437+
{
2438+
headers: {
2439+
authorization: "token secret123",
2440+
},
2441+
repeat: 4,
2442+
},
2443+
);
2444+
2445+
const auth = createAppAuth({
2446+
appId: APP_ID,
2447+
privateKey: PRIVATE_KEY,
2448+
installationId: 123,
2449+
});
2450+
2451+
const requestWithMock = request.defaults({
2452+
headers: {
2453+
"user-agent": "test",
2454+
},
2455+
request: {
2456+
fetch: mock,
2457+
},
2458+
});
2459+
const requestWithAuth = requestWithMock.defaults({
2460+
request: {
2461+
hook: auth.hook,
2462+
},
2463+
});
2464+
2465+
const { data } = await requestWithAuth("GET /repos/octocat/hello-world", {
2466+
baseUrl: "https://not-api.github.com",
2467+
});
2468+
2469+
expect(data).toEqual({ id: 123 });
2470+
});

0 commit comments

Comments
 (0)
Please sign in to comment.