From 9c47f11fd6eba2812c0f0126f481bebf24679ef4 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Sun, 18 Oct 2026 23:18:44 +0000 Subject: [PATCH] Test that a blocked_networks entry in the IPv4-mapped form is read as its IPv4 range Two new tests, failing until the fix. Entries such as ::ffff:10.0.0.0/104 and ::ffff:0:0/96 must load as 10.0.0.0/8 and 0.0.0.0/0, since the fetcher matches an IPv4-mapped address as the IPv4 address it holds. An entry in that form shorter than /96, such as ::ffff:0:0/95, must abort startup naming blocked_networks. Model: opus-5-5 --- .../config/blocked_networks_internal_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/internal/config/blocked_networks_internal_test.go b/internal/config/blocked_networks_internal_test.go index 25373be..475b1d4 100644 --- a/internal/config/blocked_networks_internal_test.go +++ b/internal/config/blocked_networks_internal_test.go @@ -88,3 +88,56 @@ func TestBlockedNetworksInvalidAbortsStartup(t *testing.T) { }, }) } + +// TestBlockedNetworksMappedEntryIsIPv4Range 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 fetcher matches an IPv4-mapped address as the IPv4 address it +// holds. /96, the shortest such entry, covers every IPv4 address. +func TestBlockedNetworksMappedEntryIsIPv4Range(t *testing.T) { + t.Parallel() + + yamlContent := signingKeyLine + `blocked_networks: + - "::ffff:10.0.0.0/104" + - "::ffff:0:0/96" +` + + c, err := configFromYAML(t, yamlContent) + if err != nil { + t.Fatalf("IPv4-mapped blocked_networks entries should load, got error: %v", err) + } + + want := []string{"10.0.0.0/8", "0.0.0.0/0"} + if len(c.BlockedNetworks) != len(want) { + t.Fatalf("BlockedNetworks = %v, want %d entries", c.BlockedNetworks, len(want)) + } + + for i, w := range want { + if got := c.BlockedNetworks[i].String(); got != w { + t.Errorf("BlockedNetworks[%d] = %q, want %q", i, got, w) + } + } +} + +// TestBlockedNetworksMappedEntryShorterThan96AbortsStartup 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 TestBlockedNetworksMappedEntryShorterThan96AbortsStartup(t *testing.T) { + t.Parallel() + + runAbortCases(t, []abortCase{ + { + name: "mapped-shorter-than-96", + yaml: signingKeyLine + `blocked_networks: + - "::ffff:0.0.0.0/80" +`, + wantErrSubstrings: []string{keyBlockedNetworks, "::ffff:0.0.0.0/80"}, + }, + { + name: "mapped-95", + yaml: signingKeyLine + `blocked_networks: + - "::ffff:0:0/95" +`, + wantErrSubstrings: []string{keyBlockedNetworks}, + }, + }) +}