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:
Jarred Sumner
2023-09-06 22:33:55 -07:00
parent 99219d5e1c
commit 4b5233fc3a
15 changed files with 669 additions and 78 deletions

View File

@@ -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();
}
});
});

View File

@@ -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();
});