Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions test/e2e/proxy-web-socket-origin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ describe.each(["target", "router"])(
});

it("should not forward a rejected upgrade after an HTTP proxy request", async () => {
await request(server.server).get("/api/hello").expect(200);
await request(`http://localhost:${devServerPort}`)
.get("/api/hello")
.expect(200);

const result = await upgrade("http://evil.example.com");

Expand All @@ -184,7 +186,9 @@ describe.each(["target", "router"])(
});

it("should allow a same-origin upgrade after an HTTP proxy request", async () => {
await request(server.server).get("/api/hello").expect(200);
await request(`http://localhost:${devServerPort}`)
.get("/api/hello")
.expect(200);

const result = await upgrade(`http://localhost:${devServerPort}`);

Expand All @@ -204,15 +208,19 @@ describe.each(["target", "router"])(
};

await startServer(() => ({ ...proxyConfig }));
await request(server.server).get("/api/hello").expect(200);
await request(`http://localhost:${devServerPort}`)
.get("/api/hello")
.expect(200);

proxyConfig = {
...proxyConfig,
ws: true,
pathRewrite: { "^/api": "/updated" },
};

await request(server.server).get("/api/hello").expect(200);
await request(`http://localhost:${devServerPort}`)
.get("/api/hello")
.expect(200);

const rejected = await upgrade("http://evil.example.com");

Expand Down
2 changes: 1 addition & 1 deletion types/lib/Server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ declare class Server<
private listeners;
/**
* @private
* @type {RequestHandler[]}
* @type {(() => RequestHandler | undefined)[]}
*/
private webSocketProxies;
/**
Expand Down
Loading