Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(ext/node): avoid showing UNKNOWN error from TCP handle #25550

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/node/polyfills/internal_binding/stream_wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -343,7 +344,8 @@ export class LibuvStreamWrap extends HandleWrap {
) {
nread = codeMap.get("ECONNRESET")!;
} else {
nread = codeMap.get("UNKNOWN")!;
this[ownerSymbol].destroy(e);
return;
}
}

Expand Down
28 changes: 27 additions & 1 deletion tests/unit_node/tls_test.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down Expand Up @@ -191,3 +196,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",
);
});