summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/polyfills/internal_binding/stream_wrap.ts4
-rw-r--r--tests/unit_node/tls_test.ts28
2 files changed, 30 insertions, 2 deletions
diff --git a/ext/node/polyfills/internal_binding/stream_wrap.ts b/ext/node/polyfills/internal_binding/stream_wrap.ts
index dc30bfdfe..7aea83d6f 100644
--- a/ext/node/polyfills/internal_binding/stream_wrap.ts
+++ b/ext/node/polyfills/internal_binding/stream_wrap.ts
@@ -38,6 +38,7 @@ import { TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { Buffer } from "node:buffer";
import { notImplemented } from "ext:deno_node/_utils.ts";
import { HandleWrap } from "ext:deno_node/internal_binding/handle_wrap.ts";
+import { ownerSymbol } from "ext:deno_node/internal/async_hooks.ts";
import {
AsyncWrap,
providerType,
@@ -343,7 +344,8 @@ export class LibuvStreamWrap extends HandleWrap {
) {
nread = codeMap.get("ECONNRESET")!;
} else {
- nread = codeMap.get("UNKNOWN")!;
+ this[ownerSymbol].destroy(e);
+ return;
}
}
diff --git a/tests/unit_node/tls_test.ts b/tests/unit_node/tls_test.ts
index 4ee622a67..6826ab84c 100644
--- a/tests/unit_node/tls_test.ts
+++ b/tests/unit_node/tls_test.ts
@@ -1,11 +1,16 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-import { assertEquals, assertInstanceOf } from "@std/assert";
+import {
+ assertEquals,
+ assertInstanceOf,
+ assertStringIncludes,
+} from "@std/assert";
import { delay } from "@std/async/delay";
import { fromFileUrl, join } from "@std/path";
import * as tls from "node:tls";
import * as net from "node:net";
import * as stream from "node:stream";
+import { execCode } from "../unit/test_util.ts";
const tlsTestdataDir = fromFileUrl(
new URL("../testdata/tls", import.meta.url),
@@ -189,3 +194,24 @@ Deno.test("tlssocket._handle._parentWrap is set", () => {
._parentWrap;
assertInstanceOf(parentWrap, stream.PassThrough);
});
+
+Deno.test("tls.connect() throws InvalidData when there's error in certificate", async () => {
+ // Uses execCode to avoid `--unsafely-ignore-certificate-errors` option applied
+ const [status, output] = await execCode(`
+ import tls from "node:tls";
+ const conn = tls.connect({
+ host: "localhost",
+ port: 4557,
+ });
+
+ conn.on("error", (err) => {
+ console.log(err);
+ });
+ `);
+
+ assertEquals(status, 0);
+ assertStringIncludes(
+ output,
+ "InvalidData: invalid peer certificate: UnknownIssuer",
+ );
+});