diff options
author | 2023-09-05 19:21:34 -0300 | |
---|---|---|
committer | 2023-09-05 15:21:34 -0700 | |
commit | d268097ded4513abe3cff9ca0037f72e90c23a21 (patch) | |
tree | 2fa8090799c70cb0d057b71cff204d14433bb674 /test | |
parent | 1e998c1bf2e0c95fb182eb01806bf11eebe6fed3 (diff) | |
download | bun-d268097ded4513abe3cff9ca0037f72e90c23a21.tar.gz bun-d268097ded4513abe3cff9ca0037f72e90c23a21.tar.zst bun-d268097ded4513abe3cff9ca0037f72e90c23a21.zip |
fix SSL proxy tunneling on fetch (#4510)
Diffstat (limited to 'test')
-rw-r--r-- | test/js/bun/http/proxy.test.js | 38 |
1 files changed, 36 insertions, 2 deletions
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}`; |