Skip to content

Commit 2cfc0a7

Browse files
committed
feflajsdf
1 parent f85baec commit 2cfc0a7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tests/credentials.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ describe("Credentials", () => {
8484
},
8585
])("$description", async ({ apiTokenIssuer, expectedUrl }) => {
8686
const parsedUrl = new URL(expectedUrl);
87-
const scope = nock(`${parsedUrl.protocol}//${parsedUrl.host}`)
87+
// Use hostname instead of host to avoid port issues, then add port explicitly if non-default
88+
const isDefaultPort = (parsedUrl.protocol === "https:" && parsedUrl.port === "") ||
89+
(parsedUrl.protocol === "http:" && parsedUrl.port === "");
90+
const baseUrl = isDefaultPort
91+
? `${parsedUrl.protocol}//${parsedUrl.hostname}`
92+
: `${parsedUrl.protocol}//${parsedUrl.hostname}:${parsedUrl.port}`;
93+
94+
const scope = nock(baseUrl)
8895
.post(parsedUrl.pathname + parsedUrl.search)
8996
.reply(200, {
9097
access_token: "test-token",
@@ -160,7 +167,14 @@ describe("Credentials", () => {
160167
}
161168
])("should normalize audience from apiTokenIssuer when using PrivateKeyJWT client credentials ($description)", async ({ apiTokenIssuer, expectedUrl, expectedAudience }) => {
162169
const parsedUrl = new URL(expectedUrl);
163-
const scope = nock(`${parsedUrl.protocol}//${parsedUrl.host}`)
170+
// Use hostname instead of host to avoid port issues, then add port explicitly if non-default
171+
const isDefaultPort = (parsedUrl.protocol === "https:" && parsedUrl.port === "") ||
172+
(parsedUrl.protocol === "http:" && parsedUrl.port === "");
173+
const baseUrl = isDefaultPort
174+
? `${parsedUrl.protocol}//${parsedUrl.hostname}`
175+
: `${parsedUrl.protocol}//${parsedUrl.hostname}:${parsedUrl.port}`;
176+
177+
const scope = nock(baseUrl)
164178
.post(parsedUrl.pathname, (body: string) => {
165179
const params = new URLSearchParams(body);
166180
const clientAssertion = params.get("client_assertion") as string;

0 commit comments

Comments
 (0)