loopback-hostname.client.spec.ts 716 B

123456789101112131415161718
  1. /** Shared loopback-hostname semantics for the Host fence and browser UI. */
  2. import { describe, expect, it } from 'vitest'
  3. import { isLoopbackHostname } from '../src/loopback-hostname.ts'
  4. describe('isLoopbackHostname', () => {
  5. it('accepts localhost, IPv6 loopback, and the whole IPv4 127/8 block', () => {
  6. for (const hostname of ['localhost', '[::1]', '127.0.0.1', '127.8.9.10', '127.255.255.255']) {
  7. expect(isLoopbackHostname(hostname)).toBe(true)
  8. }
  9. })
  10. it('refuses malformed and non-loopback hostnames', () => {
  11. for (const hostname of ['remote.localhost', '::1', '128.0.0.1', '127.0.0', '127.0.0.256', '127.0.0.-1']) {
  12. expect(isLoopbackHostname(hostname)).toBe(false)
  13. }
  14. })
  15. })