From 86ffa2fb231e8f5a8bdbf46c753865006c532518 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 20 Apr 2026 09:54:04 -0600 Subject: [PATCH] chore: remove IPv6 special-casing (YAGNI) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop the explicit IPv6 early-exit in ReadAll — ParseIPv4 already rejects non-IPv4 via Is4(). Remove IPv6-specific tests and error message wording. --- net/ipcohort/ipcohort.go | 7 +------ net/ipcohort/ipcohort_test.go | 24 ------------------------ 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/net/ipcohort/ipcohort.go b/net/ipcohort/ipcohort.go index 4cef8cb..d1e03b5 100644 --- a/net/ipcohort/ipcohort.go +++ b/net/ipcohort/ipcohort.go @@ -132,7 +132,7 @@ func ParseIPv4(raw string) (ipv4net IPv4Net, err error) { addr := ippre.Addr() if !addr.Is4() { - return ipv4net, fmt.Errorf("IPv6 not supported: %s", raw) + return ipv4net, fmt.Errorf("not an IPv4 address: %s", raw) } ip4 := addr.As4() prefix := uint8(ippre.Bits()) // 0–32 @@ -203,11 +203,6 @@ func ReadAll(r *csv.Reader) (*Cohort, error) { continue } - // skip IPv6 - if strings.Contains(raw, ":") { - continue - } - ipv4net, err := ParseIPv4(raw) if err != nil { log.Printf("skipping invalid entry: %q", raw) diff --git a/net/ipcohort/ipcohort_test.go b/net/ipcohort/ipcohort_test.go index eb37e35..c5e9d53 100644 --- a/net/ipcohort/ipcohort_test.go +++ b/net/ipcohort/ipcohort_test.go @@ -21,7 +21,6 @@ func TestParseIPv4(t *testing.T) { {"", true}, {"not-an-ip", true}, {"1.2.3.4/33", true}, - {"::1", true}, // IPv6 not supported } for _, tt := range tests { _, err := ipcohort.ParseIPv4(tt.raw) @@ -104,16 +103,6 @@ func TestContains_FailClosed(t *testing.T) { } } -func TestContains_IPv6NeverBlocked(t *testing.T) { - c, _ := ipcohort.Parse([]string{"1.2.3.4", "10.0.0.0/8"}) - // IPv6 addresses are not stored; should return false, not panic. - if c.Contains("::1") { - t.Error("IPv6 address should not be in an IPv4-only cohort") - } - if c.Contains("2001:db8::1") { - t.Error("IPv6 address should not be in an IPv4-only cohort") - } -} func TestContains_Empty(t *testing.T) { c, err := ipcohort.Parse(nil) @@ -175,16 +164,3 @@ func TestLoadFiles_Merge(t *testing.T) { } } -func TestCSVSkipsIPv6(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "mixed.txt") - os.WriteFile(path, []byte("1.2.3.4\n::1\n2001:db8::/32\n5.6.7.8\n"), 0o644) - - c, err := ipcohort.LoadFile(path) - if err != nil { - t.Fatal(err) - } - if c.Size() != 2 { - t.Errorf("Size() = %d, want 2 (IPv6 should be skipped)", c.Size()) - } -}