From c025959fb359403314c776b27a47578a9a4da066 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Mon, 19 Oct 2026 02:34:35 +0000 Subject: [PATCH] Test that a trusted_proxies entry in the IPv4-mapped form is read as its IPv4 range These tests fail on next: ::ffff:10.0.0.0/104 is kept as written and so never matches, and ::ffff:0:0/95 loads without an error. The fix follows in the next commit. Model: opus-5-5 --- .../config/trusted_proxies_internal_test.go | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/config/trusted_proxies_internal_test.go b/internal/config/trusted_proxies_internal_test.go index ae61bfd..41a184d 100644 --- a/internal/config/trusted_proxies_internal_test.go +++ b/internal/config/trusted_proxies_internal_test.go @@ -83,3 +83,41 @@ func TestTrustedProxiesInvalidAbortsStartup(t *testing.T) { }, }) } + +// TestTrustedProxiesMappedEntryIsIPv4Range checks that an entry written in +// the IPv4-mapped form (::ffff:a.b.c.d) is kept as the IPv4 range it covers, +// since the client address is matched as the IPv4 address it holds. /96, the +// shortest such entry, covers every IPv4 address. +func TestTrustedProxiesMappedEntryIsIPv4Range(t *testing.T) { + t.Parallel() + + c, err := configFromYAML(t, signingKeyLine+ + `trusted_proxies: ["::ffff:10.0.0.0/104", "::ffff:0:0/96"]`+"\n") + if err != nil { + t.Fatalf("IPv4-mapped trusted_proxies entries should load: %v", err) + } + + got := make([]string, len(c.TrustedProxies)) + for i, p := range c.TrustedProxies { + got[i] = p.String() + } + + if joined := strings.Join(got, ","); joined != "10.0.0.0/8,0.0.0.0/0" { + t.Errorf("TrustedProxies = %v, want 10.0.0.0/8 and 0.0.0.0/0", got) + } +} + +// TestTrustedProxiesMappedEntryShorterThan96AbortsStartup checks that an +// entry in the IPv4-mapped form shorter than /96, which covers more than the +// IPv4 addresses, aborts startup with an error naming the key and the value. +func TestTrustedProxiesMappedEntryShorterThan96AbortsStartup(t *testing.T) { + t.Parallel() + + runAbortCases(t, []abortCase{ + { + name: "mapped-95", + yaml: signingKeyLine + `trusted_proxies: ["::ffff:0:0/95"]` + "\n", + wantErrSubstrings: []string{keyTrustedProxies, "::ffff:0:0/95"}, + }, + }) +}