From d268097ded4513abe3cff9ca0037f72e90c23a21 Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Tue, 5 Sep 2023 19:21:34 -0300 Subject: fix SSL proxy tunneling on fetch (#4510) --- test/js/bun/http/proxy.test.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'test/js') diff --git a/test/js/bun/http/proxy.test.js b/test/js/bun/http/proxy.test.js index 85bb7ecf3..48595a2ac 100644 --- a/test/js/bun/http/proxy.test.js +++ b/test/js/bun/http/proxy.test.js @@ -1,10 +1,10 @@ import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import { gc } from "harness"; +import fs from "fs"; +import path from "path"; let proxy, auth_proxy, server; -// TODO: Proxy with TLS requests - beforeAll(() => { proxy = Bun.serve({ port: 0, @@ -76,6 +76,40 @@ afterAll(() => { auth_proxy.stop(); }); +const test = process.env.PROXY_URL ? it : it.skip; + +test("should be able to post on TLS", async () => { + const data = JSON.stringify({ + "name": "bun", + }); + + const result = await fetch("https://httpbin.org/post", { + method: "POST", + proxy: process.env.PROXY_URL, + verbose: true, + headers: { + "Content-Type": "application/json", + }, + body: data, + }).then(res => res.json()); + + expect(result.data).toBe(data); +}); + +test("should be able to post bigger on TLS", async () => { + const data = fs.readFileSync(path.join(import.meta.dir, "fetch.json")).toString("utf8"); + const result = await fetch("https://httpbin.org/post", { + method: "POST", + proxy: process.env.PROXY_URL, + verbose: true, + headers: { + "Content-Type": "application/json", + }, + body: data, + }).then(res => res.json()); + expect(result.data).toBe(data); +}); + it("proxy non-TLS", async () => { const url = `http://localhost:${server.port}`; const auth_proxy_url = `http://squid_user:ASD123%40123asd@localhost:${auth_proxy.port}`; -- cgit v1.2.3