From abeb7a047e7bd58e05fb5b07309d8e61fce15be1 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 16 Mar 2026 08:26:52 +0000 Subject: [PATCH] test(fetch): expand issue-4897 coverage for URL credentials --- test/fetch/issue-4897.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/test/fetch/issue-4897.js b/test/fetch/issue-4897.js index aa307cc82d7..2146ddf0394 100644 --- a/test/fetch/issue-4897.js +++ b/test/fetch/issue-4897.js @@ -22,15 +22,33 @@ async function assertPath (t, url, expectedPath) { }) } +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 host of hosts) { - await t.test(`${scheme}://${host}/test?a=b#frag`, async (t) => { - await assertPath(t, `${scheme}://${host}/test?a=b#frag`, '/test?a=b') - }) + 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') + } + }) + } } } })