-
-
Notifications
You must be signed in to change notification settings - Fork 756
Expand file tree
/
Copy pathissue-4897.js
More file actions
54 lines (45 loc) · 1.49 KB
/
issue-4897.js
File metadata and controls
54 lines (45 loc) · 1.49 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
const { test } = require('node:test')
const { fetch } = require('../..')
function createAssertingDispatcher (t, expectedPath) {
return {
dispatch (opts, handler) {
t.assert.strictEqual(opts.path, expectedPath)
handler.onError(new Error('stop'))
return true
}
}
}
async function assertPath (t, url, expectedPath) {
const dispatcher = createAssertingDispatcher(t, expectedPath)
await t.assert.rejects(fetch(url, { dispatcher }), (err) => {
t.assert.strictEqual(err.cause?.message, 'stop')
return true
})
}
async function assertCredentialsRejected (t, url) {
const dispatcher = createAssertingDispatcher(t, '/test?a=b')
await t.assert.rejects(fetch(url, { dispatcher }), (err) => {
t.assert.strictEqual(err.name, 'TypeError')
t.assert.match(err.message, /includes credentials/)
return true
})
}
// https://github.com/nodejs/undici/issues/4897
test('fetch path extraction does not match hostnames inside scheme', async (t) => {
const hosts = ['h', 't', 'p', 'ht', 'tp', 'tt']
for (const scheme of ['http', 'https']) {
for (const userinfo of ['', 'user:pass@']) {
for (const host of hosts) {
await t.test(`${scheme}://${userinfo}${host}/test?a=b#frag`, async (t) => {
const url = `${scheme}://${userinfo}${host}/test?a=b#frag`
if (userinfo) {
await assertCredentialsRejected(t, url)
} else {
await assertPath(t, url, '/test?a=b')
}
})
}
}
}
})