diff options
author | Luca Casonato <hello@lcas.dev> | 2024-09-27 16:07:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-27 14:07:20 +0000 |
commit | 3134abefa462ead8bb8e2e4aa8a5b57910f3d430 (patch) | |
tree | 0f01cca8ca91ea6fb06347f17a77091259749c28 /tests | |
parent | 88a4f8dd97704b8905d05def949b137a75286b18 (diff) |
BREAKING(ext/net): improved error code accuracy (#25383)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/js_unit_tests.rs | 15 | ||||
-rw-r--r-- | tests/integration/node_unit_tests.rs | 11 | ||||
-rw-r--r-- | tests/unit/http_test.ts | 6 | ||||
-rw-r--r-- | tests/unit/net_test.ts | 4 | ||||
-rw-r--r-- | tests/unit/tls_test.ts | 2 | ||||
-rw-r--r-- | tests/unit_node/http2_test.ts | 4 | ||||
-rw-r--r-- | tests/unit_node/tls_test.ts | 6 |
7 files changed, 31 insertions, 17 deletions
diff --git a/tests/integration/js_unit_tests.rs b/tests/integration/js_unit_tests.rs index 5efb0f268..577ca043c 100644 --- a/tests/integration/js_unit_tests.rs +++ b/tests/integration/js_unit_tests.rs @@ -143,8 +143,19 @@ fn js_unit_test(test: String) { deno = deno.arg("--unstable-worker-options"); } - // TODO(mmastrac): it would be better to just load a test CA for all tests - if test == "websocket_test" || test == "tls_sni_test" { + // Some tests require the root CA cert file to be loaded. + if test == "websocket_test" { + deno = deno.arg(format!( + "--cert={}", + util::testdata_path() + .join("tls") + .join("RootCA.pem") + .to_string_lossy() + )); + }; + + if test == "tls_sni_test" { + // TODO(lucacasonato): fix the SNI in the certs so that this is not needed deno = deno.arg("--unsafely-ignore-certificate-errors"); } diff --git a/tests/integration/node_unit_tests.rs b/tests/integration/node_unit_tests.rs index c8b5b25fb..d66db5a40 100644 --- a/tests/integration/node_unit_tests.rs +++ b/tests/integration/node_unit_tests.rs @@ -113,15 +113,18 @@ fn node_unit_test(test: String) { .arg("--no-lock") .arg("--unstable-broadcast-channel") .arg("--unstable-net") - // TODO(kt3k): This option is required to pass tls_test.ts, - // but this shouldn't be necessary. tls.connect currently doesn't - // pass hostname option correctly and it causes cert errors. - .arg("--unsafely-ignore-certificate-errors") .arg("-A"); + + // Some tests require the root CA cert file to be loaded. + if test == "http2_test" || test == "http_test" { + deno = deno.arg("--cert=./tests/testdata/tls/RootCA.pem"); + } + // Parallel tests for crypto if test.starts_with("crypto/") { deno = deno.arg("--parallel"); } + let mut deno = deno .arg( util::tests_path() diff --git a/tests/unit/http_test.ts b/tests/unit/http_test.ts index ea72806d3..355b155af 100644 --- a/tests/unit/http_test.ts +++ b/tests/unit/http_test.ts @@ -2305,7 +2305,7 @@ Deno.test( const buf = new Uint8Array(128); const readPromise = serverConn.read(buf); - assertThrows(() => Deno.serveHttp(serverConn), Deno.errors.BadResource); + assertThrows(() => Deno.serveHttp(serverConn), Deno.errors.Busy); clientConn.close(); listener.close(); @@ -2338,7 +2338,7 @@ Deno.test( const buf = new Uint8Array(128); const readPromise = serverConn.read(buf); - assertThrows(() => Deno.serveHttp(serverConn), Deno.errors.BadResource); + assertThrows(() => Deno.serveHttp(serverConn), Deno.errors.Busy); clientConn.close(); listener.close(); @@ -2362,7 +2362,7 @@ Deno.test( const buf = new Uint8Array(128); const readPromise = serverConn.read(buf); - assertThrows(() => Deno.serveHttp(serverConn), Deno.errors.BadResource); + assertThrows(() => Deno.serveHttp(serverConn), Deno.errors.Busy); clientConn.close(); listener.close(); diff --git a/tests/unit/net_test.ts b/tests/unit/net_test.ts index c243da47f..cfa42b3d3 100644 --- a/tests/unit/net_test.ts +++ b/tests/unit/net_test.ts @@ -126,8 +126,6 @@ Deno.test( const listener = Deno.listen({ port: listenPort }); const p = listener.accept(); listener.close(); - // TODO(piscisaureus): the error type should be `Interrupted` here, which - // gets thrown, but then ext/net catches it and rethrows `BadResource`. await assertRejects( () => p, Deno.errors.BadResource, @@ -168,7 +166,7 @@ Deno.test( } else if (e.message === "Another accept task is ongoing") { acceptErrCount++; } else { - throw new Error("Unexpected error message"); + throw e; } }; const p = listener.accept().catch(checkErr); diff --git a/tests/unit/tls_test.ts b/tests/unit/tls_test.ts index aba4d254c..219f4a450 100644 --- a/tests/unit/tls_test.ts +++ b/tests/unit/tls_test.ts @@ -81,7 +81,7 @@ Deno.test( // `Deno.startTls` cannot consume the connection. await assertRejects( () => Deno.startTls(clientConn, { hostname }), - Deno.errors.BadResource, + Deno.errors.Busy, ); serverConn.close(); diff --git a/tests/unit_node/http2_test.ts b/tests/unit_node/http2_test.ts index cb939646b..7473a487a 100644 --- a/tests/unit_node/http2_test.ts +++ b/tests/unit_node/http2_test.ts @@ -10,7 +10,7 @@ import * as net from "node:net"; import { assert, assertEquals } from "@std/assert"; import { curlRequest } from "../unit/test_util.ts"; -for (const url of ["http://127.0.0.1:4246", "https://127.0.0.1:4247"]) { +for (const url of ["http://localhost:4246", "https://localhost:4247"]) { Deno.test(`[node/http2 client] ${url}`, { ignore: Deno.build.os === "windows", }, async () => { @@ -155,7 +155,7 @@ Deno.test("[node/http2.createServer()]", { res.end(); }); server.listen(0); - const port = (<net.AddressInfo> server.address()).port; + const port = (server.address() as net.AddressInfo).port; const endpoint = `http://localhost:${port}`; const response = await curlRequest([ diff --git a/tests/unit_node/tls_test.ts b/tests/unit_node/tls_test.ts index 7daa544c7..93eacd5ec 100644 --- a/tests/unit_node/tls_test.ts +++ b/tests/unit_node/tls_test.ts @@ -149,10 +149,12 @@ Deno.test("tls.createServer creates a TLS server", async () => { }, ); server.listen(0, async () => { - const conn = await Deno.connectTls({ - hostname: "127.0.0.1", + const tcpConn = await Deno.connect({ // deno-lint-ignore no-explicit-any port: (server.address() as any).port, + }); + const conn = await Deno.startTls(tcpConn, { + hostname: "localhost", caCerts: [rootCaCert], }); |