Archived
1
0

Add debug log for origin check (#6096)

Extracted host detection into a separate function to avoid multiple log
lines on each return and went with a thrown error to consolidate the
common log text.
This commit is contained in:
Asher
2023-03-30 09:24:33 -08:00
committed by GitHub
parent c32a31d802
commit 19bcd043d7
2 changed files with 48 additions and 27 deletions

View File

@ -24,32 +24,35 @@ describe("http", () => {
{
origin: "",
host: "",
expected: true,
},
{
origin: "http://localhost:8080",
host: "",
expected: false,
expected: "no host headers",
},
{
origin: "http://localhost:8080",
host: " ",
expected: "does not match",
},
{
origin: "http://localhost:8080",
host: "localhost:8080",
expected: true,
},
{
origin: "http://localhost:8080",
host: "localhost:8081",
expected: false,
expected: "does not match",
},
{
origin: "localhost:8080",
host: "localhost:8080",
expected: false, // Gets parsed as host: localhost and path: 8080.
expected: "does not match", // Gets parsed as host: localhost and path: 8080.
},
{
origin: "test.org",
host: "localhost:8080",
expected: false, // Parsing fails completely.
expected: "malformed", // Parsing fails completely.
},
].forEach((test) => {
;[
@ -67,7 +70,11 @@ describe("http", () => {
[key]: value,
},
})
expect(http.authenticateOrigin(req)).toBe(test.expected)
if (typeof test.expected === "string") {
expect(() => http.authenticateOrigin(req)).toThrow(test.expected)
} else {
expect(() => http.authenticateOrigin(req)).not.toThrow()
}
})
})
})