mirror of
https://github.com/coder/code-server.git
synced 2026-05-05 12:05:18 +02:00
Add origin checks to web sockets (#6048)
* Move splitOnFirstEquals to util I will be making use of this to parse the forwarded header. * Type splitOnFirstEquals with two items Also add some test cases. * Check origin header on web sockets * Update changelog with origin check * Fix web sockets not closing with error code
This commit is contained in:
@@ -601,3 +601,41 @@ describe("constructOpenOptions", () => {
|
||||
expect(urlSearch).toBe("?q=^&test")
|
||||
})
|
||||
})
|
||||
|
||||
describe("splitOnFirstEquals", () => {
|
||||
const tests = [
|
||||
{
|
||||
name: "empty",
|
||||
key: "",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "split on first equals",
|
||||
key: "foo",
|
||||
value: "bar",
|
||||
},
|
||||
{
|
||||
name: "split on first equals even with multiple equals",
|
||||
key: "foo",
|
||||
value: "bar=baz",
|
||||
},
|
||||
{
|
||||
name: "split with empty value",
|
||||
key: "foo",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "split with no value",
|
||||
key: "foo",
|
||||
value: undefined,
|
||||
},
|
||||
]
|
||||
tests.forEach((test) => {
|
||||
it("should ${test.name}", () => {
|
||||
const input = test.key && typeof test.value !== "undefined" ? `${test.key}=${test.value}` : test.key
|
||||
const [key, value] = util.splitOnFirstEquals(input)
|
||||
expect(key).toStrictEqual(test.key)
|
||||
expect(value).toStrictEqual(test.value || undefined)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user