web.ts re-sampled interfaces after boot, so an address change during entry.run() could advertise a LAN URL absent from the trustedHosts snapshot composePatches captured, answering 403 on arrival. resolveLanTrust now returns the single sample and AppCLIEntry exposes it for display.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
/** Single-sample LAN-trust resolution for the /api browser-trust fence (`resolveLanTrust`). */
|
|
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import { resolveLanTrust } from '../src/app-cli-entry.ts'
|
|
|
|
vi.mock('node:os', () => ({
|
|
networkInterfaces: () => ({
|
|
lo0: [
|
|
{ family: 'IPv4', internal: true, address: '127.0.0.1' },
|
|
],
|
|
en0: [
|
|
{ family: 'IPv6', internal: false, address: 'fe80::1' },
|
|
{ family: 'IPv4', internal: false, address: '192.168.1.5' },
|
|
],
|
|
en1: [
|
|
{ family: 'IPv4', internal: false, address: '10.0.0.7' },
|
|
],
|
|
utun0: undefined,
|
|
}),
|
|
}))
|
|
|
|
describe('resolveLanTrust', () => {
|
|
it('samples non-internal IPv4 addresses once for an all-interfaces bind: trust and display share them', () => {
|
|
const { lanAddresses, trustedHosts } = resolveLanTrust('0.0.0.0', ['harness.internal:3080'])
|
|
expect(lanAddresses).toEqual(['192.168.1.5', '10.0.0.7'])
|
|
expect(trustedHosts).toEqual(['192.168.1.5', '10.0.0.7', 'harness.internal:3080'])
|
|
})
|
|
|
|
it('derives nothing for a loopback or unresolved bind — extras alone stand, no LAN URL to print', () => {
|
|
expect(resolveLanTrust('127.0.0.1', [])).toEqual({ lanAddresses: [], trustedHosts: [] })
|
|
expect(resolveLanTrust(undefined, ['lab.internal'])).toEqual({ lanAddresses: [], trustedHosts: ['lab.internal'] })
|
|
})
|
|
})
|