/** * The gate for the original bug, one layer up. * * A `public_dns` check that quietly resolved through the fleet's own resolver * would pass forever whatever the internet sees — exactly like caddy's `dig` * check does today, and exactly the blindness that let celilo#626 run for nine * days. So "the resolver is off-fleet" is asserted rather than left to a * comment, and the assertion lives where the probe is built. */ import { describe, expect, test } from 'bun:test'; import { DEFAULT_PUBLIC_RESOLVER, FleetResolverAsPublicVantageError, assertOffFleetResolver, parseFleetResolvers, } from './public-dns-probe'; const FLEET = [ { role: 'dns.primary', ip: '10.0.20.5' }, { role: 'dns.fallback', ip: '8.8.8.8' }, ]; describe('assertOffFleetResolver', () => { test("refuses the fleet's own resolver", () => { expect(() => assertOffFleetResolver('10.0.20.5', FLEET)).toThrow( FleetResolverAsPublicVantageError, ); }); test('refuses it even when the fleet resolver is a public address', () => { // The failure is "the fleet asks this resolver too", not "the address is // private": a fleet configured to forward to 8.8.8.8 gets the same // split-horizon answers back through it. expect(() => assertOffFleetResolver('8.8.8.8', FLEET)).toThrow( FleetResolverAsPublicVantageError, ); }); test('accepts a resolver the fleet does not use', () => { expect(() => assertOffFleetResolver(DEFAULT_PUBLIC_RESOLVER, FLEET)).not.toThrow(); }); test('the refusal says how to fix it', () => { try { assertOffFleetResolver('10.0.20.5', FLEET); throw new Error('expected a refusal'); } catch (error) { expect((error as Error).message).toContain('celilo system config set public_dns.resolver'); } }); }); describe('parseFleetResolvers', () => { test('a comma-separated dns.fallback yields one entry per address', () => { // `system init` writes `dns.fallback=1.0.0.1,8.8.8.8`. Compared whole, the // guard matched neither address and would have accepted 8.8.8.8 as the // "off-fleet" vantage point of a fleet that forwards to 8.8.8.8. expect( parseFleetResolvers([ { role: 'dns.primary', value: '10.0.20.5' }, { role: 'dns.fallback', value: '1.0.0.1, 8.8.8.8' }, ]), ).toEqual([ { role: 'dns.primary', ip: '10.0.20.5' }, { role: 'dns.fallback', ip: '1.0.0.1' }, { role: 'dns.fallback', ip: '8.8.8.8' }, ]); }); test('an unset key contributes nothing', () => { expect(parseFleetResolvers([{ role: 'dns.primary', value: undefined }])).toEqual([]); }); test('a multi-entry fallback is caught by the guard', () => { const fleet = parseFleetResolvers([{ role: 'dns.fallback', value: '1.0.0.1,8.8.8.8' }]); expect(() => assertOffFleetResolver('8.8.8.8', fleet)).toThrow( FleetResolverAsPublicVantageError, ); }); });