1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

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

This commit is contained in:
Yoshiya Hinosawa 2024-09-11 19:19:02 +09:00 committed by GitHub
parent ad30703e8e
commit 200145a09a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View file

@ -38,6 +38,7 @@ import { TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { Buffer } from "node:buffer"; import { Buffer } from "node:buffer";
import { notImplemented } from "ext:deno_node/_utils.ts"; import { notImplemented } from "ext:deno_node/_utils.ts";
import { HandleWrap } from "ext:deno_node/internal_binding/handle_wrap.ts"; import { HandleWrap } from "ext:deno_node/internal_binding/handle_wrap.ts";
import { ownerSymbol } from "ext:deno_node/internal/async_hooks.ts";
import { import {
AsyncWrap, AsyncWrap,
providerType, providerType,
@ -343,7 +344,8 @@ export class LibuvStreamWrap extends HandleWrap {
) { ) {
nread = codeMap.get("ECONNRESET")!; nread = codeMap.get("ECONNRESET")!;
} else { } else {
nread = codeMap.get("UNKNOWN")!; this[ownerSymbol].destroy(e);
return;
} }
} }

View file

@ -1,11 +1,16 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // 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 { delay } from "@std/async/delay";
import { fromFileUrl, join } from "@std/path"; import { fromFileUrl, join } from "@std/path";
import * as tls from "node:tls"; import * as tls from "node:tls";
import * as net from "node:net"; import * as net from "node:net";
import * as stream from "node:stream"; import * as stream from "node:stream";
import { execCode } from "../unit/test_util.ts";
const tlsTestdataDir = fromFileUrl( const tlsTestdataDir = fromFileUrl(
new URL("../testdata/tls", import.meta.url), new URL("../testdata/tls", import.meta.url),
@ -189,3 +194,24 @@ Deno.test("tlssocket._handle._parentWrap is set", () => {
._parentWrap; ._parentWrap;
assertInstanceOf(parentWrap, stream.PassThrough); 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",
);
});