36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
|
|
import { test } from 'node:test'
|
||
|
|
import assert from 'node:assert/strict'
|
||
|
|
|
||
|
|
import { isWildcardHost, isLoopbackHost, dashboardUrls, lanAddresses } from '../src/net.mjs'
|
||
|
|
|
||
|
|
test('host classification', () => {
|
||
|
|
assert.equal(isWildcardHost('0.0.0.0'), true)
|
||
|
|
assert.equal(isWildcardHost('::'), true)
|
||
|
|
assert.equal(isWildcardHost('127.0.0.1'), false)
|
||
|
|
assert.equal(isLoopbackHost('127.0.0.1'), true)
|
||
|
|
assert.equal(isLoopbackHost('localhost'), true)
|
||
|
|
assert.equal(isLoopbackHost('::1'), true)
|
||
|
|
assert.equal(isLoopbackHost('192.168.1.5'), false)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('dashboardUrls on loopback has no LAN URLs', () => {
|
||
|
|
const u = dashboardUrls({ host: '127.0.0.1', port: 7999 })
|
||
|
|
assert.equal(u.primary, 'http://127.0.0.1:7999')
|
||
|
|
assert.deepEqual(u.lan, [])
|
||
|
|
assert.equal(u.wildcard, false)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('dashboardUrls on a wildcard host resolves to a usable LAN address', () => {
|
||
|
|
const u = dashboardUrls({ host: '0.0.0.0', port: 7999 })
|
||
|
|
assert.equal(u.wildcard, true)
|
||
|
|
assert.ok(u.primary.startsWith('http://'))
|
||
|
|
assert.ok(!u.primary.includes('0.0.0.0'), `primary must not be the wildcard address: ${u.primary}`)
|
||
|
|
assert.deepEqual(u.lan, lanAddresses().map((ip) => `http://${ip}:7999`))
|
||
|
|
})
|
||
|
|
|
||
|
|
test('dashboardUrls on a specific non-loopback host exposes it', () => {
|
||
|
|
const u = dashboardUrls({ host: '10.0.0.5', port: 8000 })
|
||
|
|
assert.equal(u.primary, 'http://10.0.0.5:8000')
|
||
|
|
assert.deepEqual(u.lan, ['http://10.0.0.5:8000'])
|
||
|
|
})
|