// SPDX-FileCopyrightText: 2026 Echolot contributors // SPDX-License-Identifier: GPL-3.0-or-later package config import "testing" // The fixture is fmr's real UDP listen spec, because the point of deriving these from the bound // listeners is that they cannot disagree with what the server actually answers on. const fmrUDP = "89.185.109.150:8442,89.185.109.151:8442," + "[2001:1ad0:c4fe:6767::150]:8442,[2001:1ad0:c4fe:6767::151]:8442" func TestMeasurementAddrsSplitsPrimaryFromReserved(t *testing.T) { c := &Config{ UDPListen: fmrUDP, ReservedAddrs: "89.185.109.151,2001:1ad0:c4fe:6767::151", } ip4, ip6, ip4Alt, ip6Alt := c.MeasurementAddrs() for _, tc := range []struct{ got, want, name string }{ {ip4, "89.185.109.150", "ip4"}, {ip6, "2001:1ad0:c4fe:6767::150", "ip6"}, {ip4Alt, "89.185.109.151", "ip4_alt"}, {ip6Alt, "2001:1ad0:c4fe:6767::151", "ip6_alt"}, } { if tc.got != tc.want { t.Errorf("%s = %q, want %q", tc.name, tc.got, tc.want) } } } func TestMeasurementAddrsWithNothingReserved(t *testing.T) { // No reservation means no alternate: reporting a second address as the RFC 5780 alternate // when it was never set aside for that would tell a client to expect a redirect that the // server has no intention of sending. c := &Config{UDPListen: fmrUDP} ip4, ip6, ip4Alt, ip6Alt := c.MeasurementAddrs() if ip4 == "" || ip6 == "" { t.Fatalf("primaries should still be found: ip4=%q ip6=%q", ip4, ip6) } if ip4Alt != "" || ip6Alt != "" { t.Errorf("no address is reserved, so there is no alternate; got %q / %q", ip4Alt, ip6Alt) } } func TestMeasurementAddrsIgnoresWhatItCannotRead(t *testing.T) { // A wildcard bind names no address, and a hostname is not resolved here. Either would be a // guess presented to clients as fact. c := &Config{UDPListen: ":8442,probe.example.net:8442,89.185.109.150:8442"} ip4, ip6, _, _ := c.MeasurementAddrs() if ip4 != "89.185.109.150" { t.Errorf("ip4 = %q, want the one address that was actually spelled out", ip4) } if ip6 != "" { t.Errorf("ip6 = %q, want empty — none was configured", ip6) } }