mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +00:00
feat(fetch) rejectUnauthorized and checkServerIdentity (#4514)
* enable root certs on fetch * rebase * fix lookup * some fixes and improvements * fmt * more fixes * more fixes * check detached onHandshake * fix promise case * fix cert non-Native * add fetch tls tests * more one test
This commit is contained in:
@@ -807,6 +807,8 @@ describe("node:http", () => {
|
||||
done();
|
||||
} catch (error) {
|
||||
done(error);
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -823,20 +825,12 @@ describe("node:http", () => {
|
||||
});
|
||||
} catch (err) {
|
||||
done(err);
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
test("should not decompress gzip, issue#4397", async () => {
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
request("https://bun.sh/", { headers: { "accept-encoding": "gzip" } }, res => {
|
||||
res.on("data", function cb(chunk) {
|
||||
resolve(chunk);
|
||||
res.off("data", cb);
|
||||
});
|
||||
}).end();
|
||||
const chunk = await promise;
|
||||
expect(chunk.toString()).not.toContain("<html");
|
||||
});
|
||||
|
||||
test("test unix socket server", done => {
|
||||
const socketPath = `${tmpdir()}/bun-server-${Math.random().toString(32)}.sock`;
|
||||
const server = createServer((req, res) => {
|
||||
@@ -850,6 +844,18 @@ describe("node:http", () => {
|
||||
res.end();
|
||||
});
|
||||
|
||||
test("should not decompress gzip, issue#4397", async () => {
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
request("https://bun.sh/", { headers: { "accept-encoding": "gzip" } }, res => {
|
||||
res.on("data", function cb(chunk) {
|
||||
resolve(chunk);
|
||||
res.off("data", cb);
|
||||
});
|
||||
}).end();
|
||||
const chunk = await promise;
|
||||
expect(chunk.toString()).not.toContain("<html");
|
||||
});
|
||||
|
||||
server.listen(socketPath, () => {
|
||||
// TODO: unix socket is not implemented in fetch.
|
||||
const output = spawnSync("curl", ["--unix-socket", socketPath, "http://localhost/bun?a=1"]);
|
||||
@@ -858,6 +864,8 @@ describe("node:http", () => {
|
||||
done();
|
||||
} catch (err) {
|
||||
done(err);
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ it("Bun.serve() should work with tls and Bun.file()", async () => {
|
||||
key: COMMON_CERT.key,
|
||||
},
|
||||
});
|
||||
const res = await fetch(`https://${server.hostname}:${server.port}/`);
|
||||
const res = await fetch(`https://${server.hostname}:${server.port}/`, { tls: { rejectUnauthorized: false } });
|
||||
expect(await res.text()).toBe("<h1>HELLO</h1>");
|
||||
server.stop();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user