From d59599fc187c559ee231882773e1c5a2b932fc3d Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 16 Oct 2024 20:58:44 +0900 Subject: fix(ext/node): fix dns.lookup result ordering (#26264) partially unblocks #25470 This PR aligns the resolution of `localhost` hostname to Node.js behavior. In Node.js `dns.lookup("localhost", (_, addr) => console.log(addr))` prints ipv6 address `::1`, but it prints ipv4 address `127.0.0.1` in Deno. That difference causes some errors in the work of enabling `createConnection` option in `http.request` (#25470). This PR fixes the issue by aligning `dns.lookup` behavior to Node.js. This PR also changes the following behaviors (resolving TODOs): - `http.createServer` now listens on ipv6 address `[::]` by default on linux/mac - `net.createServer` now listens on ipv6 address `[::]` by default on linux/mac These changes are also alignments to Node.js behaviors. --- tests/unit_node/tls_test.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests/unit_node/tls_test.ts') diff --git a/tests/unit_node/tls_test.ts b/tests/unit_node/tls_test.ts index 93eacd5ec..847ec2dde 100644 --- a/tests/unit_node/tls_test.ts +++ b/tests/unit_node/tls_test.ts @@ -32,13 +32,15 @@ for ( ) { Deno.test(`tls.connect sends correct ALPN: '${alpnServer}' + '${alpnClient}' = '${expected}'`, async () => { const listener = Deno.listenTls({ + hostname: "localhost", port: 0, key, cert, alpnProtocols: alpnServer, }); const outgoing = tls.connect({ - host: "localhost", + host: "::1", + servername: "localhost", port: listener.addr.port, ALPNProtocols: alpnClient, secureContext: { @@ -61,6 +63,7 @@ Deno.test("tls.connect makes tls connection", async () => { const ctl = new AbortController(); let port; const serve = Deno.serve({ + hostname: "localhost", port: 0, key, cert, @@ -71,7 +74,8 @@ Deno.test("tls.connect makes tls connection", async () => { await delay(200); const conn = tls.connect({ - host: "localhost", + host: "::1", + servername: "localhost", port, secureContext: { ca: rootCaCert, @@ -102,6 +106,7 @@ Deno.test("tls.connect mid-read tcp->tls upgrade", async () => { const { promise, resolve } = Promise.withResolvers(); const ctl = new AbortController(); const serve = Deno.serve({ + hostname: "localhost", port: 8443, key, cert, @@ -111,7 +116,8 @@ Deno.test("tls.connect mid-read tcp->tls upgrade", async () => { await delay(200); const conn = tls.connect({ - host: "localhost", + host: "::1", + servername: "localhost", port: 8443, secureContext: { ca: rootCaCert, -- cgit v1.2.3 From 92ed4d38dbef98b9353d6dd6d96abb400be56f9f Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Wed, 23 Oct 2024 13:17:43 +0530 Subject: fix(node:tls): set TLSSocket.alpnProtocol for client connections (#26476) Towards https://github.com/denoland/deno/issues/26127 --- tests/unit_node/tls_test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/unit_node/tls_test.ts') diff --git a/tests/unit_node/tls_test.ts b/tests/unit_node/tls_test.ts index 847ec2dde..236dab208 100644 --- a/tests/unit_node/tls_test.ts +++ b/tests/unit_node/tls_test.ts @@ -235,3 +235,31 @@ Deno.test("tls.rootCertificates is not empty", () => { (tls.rootCertificates as string[]).push("new cert"); }, TypeError); }); + +Deno.test("TLSSocket.alpnProtocol is set for client", async () => { + const listener = Deno.listenTls({ + hostname: "localhost", + port: 0, + key, + cert, + alpnProtocols: ["a"], + }); + const outgoing = tls.connect({ + host: "::1", + servername: "localhost", + port: listener.addr.port, + ALPNProtocols: ["a"], + secureContext: { + ca: rootCaCert, + // deno-lint-ignore no-explicit-any + } as any, + }); + + const conn = await listener.accept(); + const handshake = await conn.handshake(); + assertEquals(handshake.alpnProtocol, "a"); + conn.close(); + outgoing.destroy(); + listener.close(); + await new Promise((resolve) => outgoing.on("close", resolve)); +}); -- cgit v1.2.3 From a69224ea5bd02f08108aac867c492754095f2d34 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 30 Oct 2024 02:41:16 +0900 Subject: Revert "fix(ext/node): fix dns.lookup result ordering (#26264)" (#26621) This reverts commit d59599fc187c559ee231882773e1c5a2b932fc3d. Closes #26588 --- tests/unit_node/tls_test.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'tests/unit_node/tls_test.ts') diff --git a/tests/unit_node/tls_test.ts b/tests/unit_node/tls_test.ts index 236dab208..43d6205b0 100644 --- a/tests/unit_node/tls_test.ts +++ b/tests/unit_node/tls_test.ts @@ -32,15 +32,13 @@ for ( ) { Deno.test(`tls.connect sends correct ALPN: '${alpnServer}' + '${alpnClient}' = '${expected}'`, async () => { const listener = Deno.listenTls({ - hostname: "localhost", port: 0, key, cert, alpnProtocols: alpnServer, }); const outgoing = tls.connect({ - host: "::1", - servername: "localhost", + host: "localhost", port: listener.addr.port, ALPNProtocols: alpnClient, secureContext: { @@ -63,7 +61,6 @@ Deno.test("tls.connect makes tls connection", async () => { const ctl = new AbortController(); let port; const serve = Deno.serve({ - hostname: "localhost", port: 0, key, cert, @@ -74,8 +71,7 @@ Deno.test("tls.connect makes tls connection", async () => { await delay(200); const conn = tls.connect({ - host: "::1", - servername: "localhost", + host: "localhost", port, secureContext: { ca: rootCaCert, @@ -106,7 +102,6 @@ Deno.test("tls.connect mid-read tcp->tls upgrade", async () => { const { promise, resolve } = Promise.withResolvers(); const ctl = new AbortController(); const serve = Deno.serve({ - hostname: "localhost", port: 8443, key, cert, @@ -116,8 +111,7 @@ Deno.test("tls.connect mid-read tcp->tls upgrade", async () => { await delay(200); const conn = tls.connect({ - host: "::1", - servername: "localhost", + host: "localhost", port: 8443, secureContext: { ca: rootCaCert, -- cgit v1.2.3