forked from panva/oauth4webapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue-13.test.ts
36 lines (31 loc) · 975 Bytes
/
issue-13.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// see https://github.com/panva/oauth4webapi/issues/13
// All browser navigator user-agent strings start with Mozilla/5.0
// It is unlikely to ever change too
// @ts-expect-error
delete globalThis.navigator
// @ts-expect-error
globalThis.navigator = { userAgent: 'Mozilla/5.0 foo' }
const lib = await import('../src/index.js')
import anyTest, { type TestFn } from 'ava'
import setup, { type Context, teardown, issuer, UA } from './_setup.js'
const test = anyTest as TestFn<Context>
test.before(setup)
test.after(teardown)
test('when in browser does not set custom user-agent', async (t) => {
const data = { ...issuer }
t.context
.intercept({
path: '/.well-known/openid-configuration',
method: 'GET',
headers(headers) {
if (UA.test(headers['user-agent'])) {
t.fail()
} else {
t.pass()
}
return true
},
})
.reply(200, data)
await lib.discoveryRequest(new URL(issuer.issuer))
})