aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-08-06 22:49:10 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-06 22:49:10 -0700
commit00a907c7de842787e87b0d0a42d8d33704c5aaae (patch)
treed7b29475801dced2597f3f7406c0b9deaabe81b8 /test/js
parent0665733b0302ac7e743e4c131c7697741fa923a5 (diff)
downloadbun-00a907c7de842787e87b0d0a42d8d33704c5aaae.tar.gz
bun-00a907c7de842787e87b0d0a42d8d33704c5aaae.tar.zst
bun-00a907c7de842787e87b0d0a42d8d33704c5aaae.zip
Fixes #4001 (#4034)
* Avoid a utf8 conversion in isDetached * Fixes #4001 * hit the long url codepath --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'test/js')
-rw-r--r--test/js/bun/http/bun-server.test.ts82
1 files changed, 82 insertions, 0 deletions
diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts
index 9fd97e3cb..6220b6a54 100644
--- a/test/js/bun/http/bun-server.test.ts
+++ b/test/js/bun/http/bun-server.test.ts
@@ -1,6 +1,88 @@
import { describe, expect, test } from "bun:test";
describe("Server", () => {
+ test.only("normlizes incoming request URLs", async () => {
+ const server = Bun.serve({
+ fetch(request) {
+ return new Response(request.url, {
+ headers: {
+ "Connection": "close",
+ },
+ });
+ },
+ port: 0,
+ });
+ const received: string[] = [];
+ const expected: string[] = [];
+ for (let path of [
+ "/",
+ "/../",
+ "/./",
+ "/foo",
+ "/foo/",
+ "/foo/bar",
+ "/foo/bar/",
+ "/foo/bar/..",
+ "/foo/bar/../",
+ "/foo/bar/../?123",
+ "/foo/bar/../?123=456",
+ "/foo/bar/../#123=456",
+ "/",
+ "/../",
+ "/./",
+ "/foo",
+ "/foo/",
+ "/foo/bar",
+ "/foo/bar/",
+ "/foo/bar/..",
+ "/foo/bar/../",
+ "/foo/bar/../?123",
+ "/foo/bar/../?123=456",
+ "/foo/bar/../#123=456",
+ "/../".repeat(128),
+ "/./".repeat(128),
+ "/foo".repeat(128),
+ "/foo/".repeat(128),
+ "/foo/bar".repeat(128),
+ "/foo/bar/".repeat(128),
+ "/foo/bar/..".repeat(128),
+ "/foo/bar/../".repeat(128),
+ "/../".repeat(128),
+ "/./".repeat(128),
+ "/foo".repeat(128),
+ "/foo/".repeat(128),
+ "/foo/bar".repeat(128),
+ "/foo/bar/".repeat(128),
+ "/foo/bar/..".repeat(128),
+ "/foo/bar/../".repeat(128),
+ ]) {
+ expected.push(new URL(path, "http://localhost:" + server.port).href);
+
+ const { promise, resolve } = Promise.withResolvers();
+ Bun.connect({
+ hostname: server.hostname,
+ port: server.port,
+
+ socket: {
+ async open(socket) {
+ socket.write(`GET ${path} HTTP/1.1\r\nHost: localhost:${server.port}\r\n\r\n`);
+ await socket.flush();
+ },
+ async data(socket, data) {
+ const lines = Buffer.from(data).toString("utf8");
+ received.push(lines.split("\r\n\r\n").at(-1)!);
+ await socket.end();
+ resolve();
+ },
+ },
+ });
+ await promise;
+ }
+
+ server.stop(true);
+ expect(received).toEqual(expected);
+ });
+
test("should not allow Bun.serve without first argument being a object", () => {
expect(() => {
//@ts-ignore