From cd7fcb8fad8d236775c1ebf733ca51dc86a96647 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 19 Nov 2023 02:55:30 -0800 Subject: [PATCH] Update c-ares --- src/deps/c-ares | 2 +- test/js/bun/dns/resolve-dns.test.ts | 35 +++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/deps/c-ares b/src/deps/c-ares index 0e7a5dee0f..36466bb240 160000 --- a/src/deps/c-ares +++ b/src/deps/c-ares @@ -1 +1 @@ -Subproject commit 0e7a5dee0fbb04080750cf6eabbe89d8bae87faa +Subproject commit 36466bb240661fa8fdc2ffa47d229d92ac762286 diff --git a/test/js/bun/dns/resolve-dns.test.ts b/test/js/bun/dns/resolve-dns.test.ts index 57b3a50c7d..503f1fcc34 100644 --- a/test/js/bun/dns/resolve-dns.test.ts +++ b/test/js/bun/dns/resolve-dns.test.ts @@ -3,10 +3,18 @@ import { describe, expect, it, test } from "bun:test"; import { withoutAggressiveGC } from "harness"; import { isIP, isIPv4, isIPv6 } from "node:net"; -const backends = ["system", "libc", "c-ares"]; +const backends = ["system", "libc", "c-ares"] as const; const validHostnames = ["localhost", "example.com"]; const invalidHostnames = [`this-should-not-exist-${Math.floor(Math.random() * 99999)}.com`]; const malformedHostnames = ["", " ", ".", " .", "localhost:80", "this is not a hostname"]; +const malformedHostnameCodes = [ + "ERR_INVALID_ARG_TYPE", + "DNS_ENOTFOUND", + "DNS_ENOTFOUND", + "DNS_ENOTFOUND", + "DNS_ENOTFOUND", + "DNS_ENOTFOUND", +]; describe("dns", () => { describe.each(backends)("lookup() [backend: %s]", backend => { @@ -80,17 +88,26 @@ describe("dns", () => { }); }); test.each(invalidHostnames)("%s", hostname => { - // @ts-expect-error expect(dns.lookup(hostname, { backend })).rejects.toMatchObject({ code: "DNS_ENOTFOUND", }); }); - // TODO: causes segfaults - // test.each(malformedHostnames)("%s", (hostname) => { - // // @ts-expect-error - // expect(dns.lookup(hostname, { backend })).rejects.toMatchObject({ - // code: "DNS_ENOTFOUND", - // }); - // }); + test.each(malformedHostnames)("%s", async hostname => { + let code = malformedHostnameCodes[malformedHostnames.indexOf(hostname)]; + + // c-ares reports a different error here... + if (backend === "c-ares" && hostname === ".") { + code = "DNS_ENODATA"; + } + + try { + await dns.lookup(hostname, { backend }); + expect.unreachable(); + } catch (e) { + expect(e).toMatchObject({ + code, + }); + } + }); }); });