44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { normalizeServerAddress } from "../shared/server-address";
|
|
test("Minecraft addresses compare case, trailing DNS dot and default port consistently", () => {
|
|
for (const value of [
|
|
"play.example.com",
|
|
" PLAY.EXAMPLE.COM.:25565 ",
|
|
"play.example.com:25565",
|
|
])
|
|
assert.equal(normalizeServerAddress(value), "play.example.com");
|
|
assert.equal(
|
|
normalizeServerAddress("192.168.0.120:25566"),
|
|
"192.168.0.120:25566",
|
|
);
|
|
assert.equal(normalizeServerAddress("[2001:DB8::1]:25565"), "[2001:db8::1]");
|
|
assert.equal(normalizeServerAddress("[::1]:25566"), "[::1]:25566");
|
|
assert.equal(
|
|
normalizeServerAddress("play.example.com:00080"),
|
|
"play.example.com:80",
|
|
);
|
|
});
|
|
test("clearing the server address disables its check", () => {
|
|
for (const value of [null, undefined, "", " "])
|
|
assert.equal(normalizeServerAddress(value), null);
|
|
});
|
|
test("addresses reject URLs, paths, credentials, invalid hosts and ports", () => {
|
|
for (const value of [
|
|
"https://play.example.com",
|
|
"player@host",
|
|
"host/path",
|
|
"host?query",
|
|
"host:0",
|
|
"host:65536",
|
|
"host:abcdef",
|
|
"a..b",
|
|
"-host",
|
|
"host-",
|
|
"[abc]",
|
|
"[:::]",
|
|
"a".repeat(64),
|
|
])
|
|
assert.throws(() => normalizeServerAddress(value), value);
|
|
});
|