Files
echolot/server/internal/config/addrs_test.go
T
mrambossekandClaude Opus 5 c4f2a10790 app: show what the server reports as facts, not as inputs
The settings card offered three editable boxes and said nothing about the
server itself — which addresses a test will actually use, on which ports,
what it can measure. That is the part a person checks before trusting a
result, and "which address did this come from" is precisely the question
a report leaves open.

The server now publishes it. The profile's targets carried one IPv4 and a
TODO; it reports both families and both alternates, derived from the UDP
listen spec rather than configured separately, so the list cannot drift
from what is actually bound. No reservation means no alternate is
claimed: announcing a second address as the RFC 5780 alternate when none
was set aside would promise a redirect the server will not send.

The app renders them read-only, in a panel visibly distinct from the
fields above. An editable box that changes nothing is worse than no box,
and these are facts to read rather than settings to apply.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-02 08:14:42 +02:00

57 lines
2.1 KiB
Go

// 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)
}
}