41 行
1.3 KiB
JavaScript
41 行
1.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { validateLoopbackHttpUrl, validateTcpPort } from "../validate-loopback-url.mjs";
|
|
|
|
for (const [input, expected] of [
|
|
["http://127.0.0.1:5178", "http://127.0.0.1:5178"],
|
|
["http://localhost:3000/", "http://localhost:3000"],
|
|
["http://[::1]:4173", "http://[::1]:4173"],
|
|
]) {
|
|
test(`accepts loopback origin ${input}`, () => {
|
|
assert.equal(validateLoopbackHttpUrl(input), expected);
|
|
});
|
|
}
|
|
|
|
for (const input of ["1", "80", "5178", "65535"]) {
|
|
test(`accepts canonical TCP port ${input}`, () => {
|
|
assert.equal(validateTcpPort(input), input);
|
|
});
|
|
}
|
|
|
|
for (const input of ["", "0", "065", "65536", "5178/path", "[email protected]", "1.5", "-1"]) {
|
|
test(`rejects ambiguous or invalid TCP port ${input || "<empty>"}`, () => {
|
|
assert.throws(() => validateTcpPort(input));
|
|
});
|
|
}
|
|
|
|
for (const input of [
|
|
"https://127.0.0.1:5178",
|
|
"http://example.invalid:5178",
|
|
"http://localhost.example.invalid:5178",
|
|
"http://[email protected]:5178",
|
|
"http://remote.invalid@localhost:5178",
|
|
"http://user:[email protected]:5178",
|
|
"http://127.0.0.1:5178/path",
|
|
"not-a-url",
|
|
]) {
|
|
test(`rejects non-loopback or ambiguous target ${input}`, () => {
|
|
assert.throws(() => validateLoopbackHttpUrl(input));
|
|
});
|
|
}
|