import assert from 'node:assert/strict' import { test } from 'node:test' import { normalizeAddress } from '../www/server.js' test('a bare host gets https', () => { assert.equal(normalizeAddress('music.example.org'), 'https://music.example.org') }) test('a scheme that was typed is kept, and so is the port', () => { assert.equal(normalizeAddress('http://192.168.1.5:8080'), 'http://192.168.1.5:8080') assert.equal(normalizeAddress('https://music.example.org:8443'), 'https://music.example.org:8443') }) test('spaces, a trailing slash, a path and a query are dropped', () => { assert.equal(normalizeAddress(' https://music.example.org/ '), 'https://music.example.org') assert.equal(normalizeAddress('https://music.example.org/albums/3?x=1#top'), 'https://music.example.org') }) test('nothing, or something that is not an address, is refused', () => { for (const bad of ['', ' ', null, undefined, 'ftp://music.example.org', 'http://', 'not an address']) { assert.equal(normalizeAddress(bad), null, String(bad)) } })