aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/http/node-http.test.ts
diff options
context:
space:
mode:
authorGravatar Liz <accs@liz3.net> 2023-09-22 03:44:05 +0200
committerGravatar GitHub <noreply@github.com> 2023-09-21 18:44:05 -0700
commitb297fabd1786bbc72185b45aed3de1b08b7352e6 (patch)
treebb727f2ae9ddac2730d4b83b2d1036d9cf531c2a /test/js/node/http/node-http.test.ts
parentb05e10cd8b0f388b766819e263ff3f478888ed96 (diff)
downloadbun-b297fabd1786bbc72185b45aed3de1b08b7352e6.tar.gz
bun-b297fabd1786bbc72185b45aed3de1b08b7352e6.tar.zst
bun-b297fabd1786bbc72185b45aed3de1b08b7352e6.zip
fix: correctly pass the encrypted(bool) property on "Socket" for express.js (#5878)
* fix: correctly pass the encrypted property on "Socket" for express.js Express relies on this for setting the requests protocol. Since this is on a dummy object, a property is simply set with the actual value. Which seams okay as a workaround. * chore: add generated files * chore: add test * refactor: set property directly rather then through a getter
Diffstat (limited to 'test/js/node/http/node-http.test.ts')
-rw-r--r--test/js/node/http/node-http.test.ts57
1 files changed, 54 insertions, 3 deletions
diff --git a/test/js/node/http/node-http.test.ts b/test/js/node/http/node-http.test.ts
index 326699665..206e6dc8c 100644
--- a/test/js/node/http/node-http.test.ts
+++ b/test/js/node/http/node-http.test.ts
@@ -10,19 +10,22 @@ import {
validateHeaderValue,
ServerResponse,
} from "node:http";
+import { createServer as createHttpsServer } from "node:https";
import { createTest } from "node-harness";
import url from "node:url";
import { tmpdir } from "node:os";
import { spawnSync } from "node:child_process";
+import nodefs from "node:fs";
+import { join as joinPath } from "node:path";
const { describe, expect, it, beforeAll, afterAll, createDoneDotAll } = createTest(import.meta.path);
-function listen(server: Server): Promise<URL> {
+function listen(server: Server, protocol: string = "http"): Promise<URL> {
return new Promise((resolve, reject) => {
server.listen({ port: 0 }, (err, hostname, port) => {
if (err) {
reject(err);
} else {
- resolve(new URL(`http://${hostname}:${port}`));
+ resolve(new URL(`${protocol}://${hostname}:${port}`));
}
});
setTimeout(() => reject("Timed out"), 5000);
@@ -47,7 +50,22 @@ describe("node:http", () => {
server.close();
}
});
-
+ it("is not marked encrypted (#5867)", async () => {
+ try {
+ var server = createServer((req, res) => {
+ expect(req.connection.encrypted).toBe(undefined);
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("Hello World");
+ });
+ const url = await listen(server);
+ const res = await fetch(new URL("", url));
+ expect(await res.text()).toBe("Hello World");
+ } catch (e) {
+ throw e;
+ } finally {
+ server.close();
+ }
+ });
it("request & response body streaming (large)", async () => {
try {
const bodyBlob = new Blob(["hello world", "hello world".repeat(9000)]);
@@ -943,3 +961,36 @@ describe("node:http", () => {
});
});
});
+describe("node https server", async () => {
+ const httpsOptions = {
+ key: nodefs.readFileSync(joinPath(import.meta.dir, "fixtures", "cert.key")),
+ cert: nodefs.readFileSync(joinPath(import.meta.dir, "fixtures", "cert.pem")),
+ };
+ const createServer = onRequest => {
+ return new Promise(resolve => {
+ const server = createHttpsServer(httpsOptions, (req, res) => {
+ onRequest(req, res);
+ });
+ listen(server, "https").then(url => {
+ resolve({
+ server,
+ done: () => server.close(),
+ url,
+ });
+ });
+ });
+ };
+ it("is marked encrypted (#5867)", async () => {
+ const { server, url, done } = await createServer(async (req, res) => {
+ expect(req.connection.encrypted).toBe(true);
+ res.end();
+ });
+ try {
+ await fetch(url);
+ } catch (e) {
+ throw e;
+ } finally {
+ done();
+ }
+ });
+});