aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/tls/node-tls-internals.test.ts
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-07-28 19:43:15 -0300
committerGravatar GitHub <noreply@github.com> 2023-07-28 15:43:15 -0700
commite7c80b90b81847be158a6e87d0200a8df4121a37 (patch)
treee784c2311f88206ce9832447a113d81aea87afbf /test/js/node/tls/node-tls-internals.test.ts
parente110ccf84d8d9034e82a79bf7abf1fa92b2370be (diff)
downloadbun-e7c80b90b81847be158a6e87d0200a8df4121a37.tar.gz
bun-e7c80b90b81847be158a6e87d0200a8df4121a37.tar.zst
bun-e7c80b90b81847be158a6e87d0200a8df4121a37.zip
fix(tls) exposes native canonicalizeIP and fix rootCertificates (#3866)
* exposes native canonicalizeIP * remove unintended duplicate * add tests * add tests for debug builds * add rootCertificates test and fix len * just randomize test ids on prisma * remove work around and bump usockets with the actual fix * fix case * bump uws
Diffstat (limited to 'test/js/node/tls/node-tls-internals.test.ts')
-rw-r--r--test/js/node/tls/node-tls-internals.test.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/js/node/tls/node-tls-internals.test.ts b/test/js/node/tls/node-tls-internals.test.ts
new file mode 100644
index 000000000..f67c39e23
--- /dev/null
+++ b/test/js/node/tls/node-tls-internals.test.ts
@@ -0,0 +1,42 @@
+import { createTest } from "node-harness";
+const { describe, expect, it } = createTest(import.meta.path);
+//@ts-ignore
+const $lazy = globalThis[Symbol.for("Bun.lazy")];
+const tlsInternals = $lazy("internal/tls");
+
+describe("node/tls", () => {
+ // this is only exposed on debug builds so we skip on release builds
+ const test = tlsInternals ? it : it.skip;
+
+ test("canonicalizeIP", () => {
+ const { canonicalizeIP } = tlsInternals;
+ expect(canonicalizeIP("127.0.0.1")).toBe("127.0.0.1");
+ expect(canonicalizeIP("10.1.0.1")).toBe("10.1.0.1");
+ expect(canonicalizeIP("::1")).toBe("::1");
+ expect(canonicalizeIP("fe80:0:0:0:0:0:0:1")).toBe("fe80::1");
+ expect(canonicalizeIP("fe80:0:0:0:0:0:0:0")).toBe("fe80::");
+ expect(canonicalizeIP("fe80::0000:0010:0001")).toBe("fe80::10:1");
+ expect(canonicalizeIP("0001:2222:3333:4444:5555:6666:7777:0088")).toBe("1:2222:3333:4444:5555:6666:7777:88");
+
+ expect(canonicalizeIP("0001:2222:3333:4444:5555:6666::")).toBe("1:2222:3333:4444:5555:6666::");
+
+ expect(canonicalizeIP("a002:B12:00Ba:4444:5555:6666:0:0")).toBe("a002:b12:ba:4444:5555:6666::");
+
+ // IPv4 address represented in IPv6
+ expect(canonicalizeIP("0:0:0:0:0:ffff:c0a8:101")).toBe("::ffff:192.168.1.1");
+
+ expect(canonicalizeIP("::ffff:192.168.1.1")).toBe("::ffff:192.168.1.1");
+ });
+
+ test("rootCertificates", () => {
+ const { rootCertificates } = tlsInternals;
+ expect(rootCertificates).toBeInstanceOf(Array);
+ expect(rootCertificates.length).toBeGreaterThan(0);
+ expect(typeof rootCertificates[0]).toBe("string");
+
+ for (const cert of rootCertificates) {
+ expect(cert).toStartWith("-----BEGIN CERTIFICATE-----");
+ expect(cert).toEndWith("-----END CERTIFICATE-----");
+ }
+ });
+});