Skip to content

Commit 2af5eb8

Browse files
committed
test: more discovery coverage
1 parent aed5e0b commit 2af5eb8

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

tap/end2end.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ export default (QUnit: QUnit) => {
140140
execute.push(client.useIdTokenResponseType)
141141
}
142142
const config = await client.discovery(
143-
issuerIdentifier,
143+
random()
144+
? new URL(issuerIdentifier.origin)
145+
: new URL(
146+
`${issuerIdentifier.origin}/${
147+
random()
148+
? '.well-known/openid-configuration'
149+
: '.well-known/oauth-authorization-server'
150+
}`,
151+
),
144152
metadata.client_id,
145153
metadata,
146154
undefined,

tap/helper.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,17 @@ export async function setup(
129129
}
130130

131131
const configuration = await lib.dynamicClientRegistration(
132-
new URL('http://localhost:3000'),
132+
new URL(
133+
random()
134+
? 'http://localhost:3000'
135+
: random()
136+
? 'http://localhost:3000/.well-known/openid-configuration'
137+
: 'http://localhost:3000/.well-known/oauth-authorization-server',
138+
),
133139
metadata,
134140
undefined,
135141
{
142+
algorithm: random() ? 'oauth2' : 'oidc',
136143
execute: [lib.allowInsecureRequests],
137144
},
138145
)
@@ -151,6 +158,6 @@ export async function setup(
151158
kid: clientEncJwk.kid,
152159
key: encKp.privateKey,
153160
},
154-
issuerIdentifier: new URL('http://localhost:3000'),
161+
issuerIdentifier: new URL(configuration.serverMetadata().issuer),
155162
}
156163
}

test/issuer-check.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import test from 'ava'
2+
import * as client from '../src/index.js'
3+
import * as undici from 'undici'
4+
5+
test('issuer discovery matching', async (t) => {
6+
let agent = new undici.MockAgent()
7+
agent.disableNetConnect()
8+
9+
const url = new URL('https://op.example.com')
10+
11+
const mockAgent = agent.get(url.origin)
12+
let i = 0
13+
14+
mockAgent
15+
.intercept({
16+
method: 'GET',
17+
path: '.well-known/openid-configuration',
18+
})
19+
.reply(
20+
200,
21+
function () {
22+
switch (i++) {
23+
case 0:
24+
return { issuer: 'https://op.example.com/' }
25+
case 1:
26+
return { issuer: 'https://op.example.com' }
27+
case 2:
28+
return { issuer: 'https://op.example.com/pathname' }
29+
case 3:
30+
return { issuer: 'https://op.example.com/pathname' }
31+
}
32+
},
33+
{
34+
headers: {
35+
'content-type': 'application/json',
36+
},
37+
},
38+
)
39+
.times(4)
40+
41+
await t.notThrowsAsync(
42+
client.discovery(url, 'decoy', 'decoy', undefined, {
43+
// @ts-ignore
44+
[client.customFetch](url, options) {
45+
return undici.fetch(url, { ...options, dispatcher: agent })
46+
},
47+
}),
48+
)
49+
50+
await t.notThrowsAsync(
51+
client.discovery(url, 'decoy', 'decoy', undefined, {
52+
// @ts-ignore
53+
[client.customFetch](url, options) {
54+
return undici.fetch(url, { ...options, dispatcher: agent })
55+
},
56+
}),
57+
)
58+
59+
await t.throwsAsync(
60+
client.discovery(url, 'decoy', 'decoy', undefined, {
61+
// @ts-ignore
62+
[client.customFetch](url, options) {
63+
return undici.fetch(url, { ...options, dispatcher: agent })
64+
},
65+
}),
66+
)
67+
68+
await t.notThrowsAsync(
69+
client.discovery(
70+
new URL('https://op.example.com/.well-known/openid-configuration'),
71+
'decoy',
72+
'decoy',
73+
undefined,
74+
{
75+
// @ts-ignore
76+
[client.customFetch](url, options) {
77+
return undici.fetch(url, { ...options, dispatcher: agent })
78+
},
79+
},
80+
),
81+
)
82+
83+
t.notThrows(() => agent.assertNoPendingInterceptors())
84+
})

0 commit comments

Comments
 (0)