From 1fad6eb2acc993714fad9d333f409495f5b3d6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 Jul 2024 22:22:43 +0100 Subject: fix(ext/fetch): respect authority from URL (#24705) This commit fixes handling of "authority" in the URL by properly sending "Authorization Basic..." header in `fetch` API. This is a regression from https://github.com/denoland/deno/pull/24593 Fixes https://github.com/denoland/deno/issues/24697 CC @seanmonstar --- tests/unit/fetch_test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index bc3822d99..39cadcb44 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -2042,3 +2042,21 @@ Deno.test("Response with subarray TypedArray body", async () => { const expected = new Uint8Array([2, 3, 4, 5]); assertEquals(actual, expected); }); + +// Regression test for https://github.com/denoland/deno/issues/24697 +Deno.test("URL authority is used as 'Authorization' header", async () => { + const deferred = Promise.withResolvers(); + const ac = new AbortController(); + + const server = Deno.serve({ port: 4502, signal: ac.signal }, (req) => { + deferred.resolve(req.headers.get("authorization")); + return new Response("Hello world"); + }); + + const res = await fetch("http://deno:land@localhost:4502"); + await res.text(); + const authHeader = await deferred.promise; + ac.abort(); + await server.finished; + assertEquals(authHeader, "Basic ZGVubzpsYW5k"); +}); -- cgit v1.2.3