Refuse IPv4-mapped prefixes with an error that says so
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
715cb772e7
commit
83b97ad538
3 files changed
+36
-1
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseAddress(t *testing.T) {
|
||||
for _, c := range []struct{ in, want, err string }{
|
||||
{in: "10.0.0.0/8", want: "10.0.0.0/8"},
|
||||
{in: "2001:db8::/32", want: "2001:db8::/32"},
|
||||
{in: "::ffff:10.0.0.1", want: "10.0.0.1"},
|
||||
{in: "10.0.0.1/8", err: "host bits"},
|
||||
{in: "::ffff:0:0/96", err: "IPv4-mapped"},
|
||||
{in: "::ffff:10.0.0.0/104", err: "IPv4-mapped"},
|
||||
} {
|
||||
a, err := ParseAddress(c.in)
|
||||
if c.err != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), c.err) {
|
||||
t.Errorf("%s: error %v, want one saying %q", c.in, err, c.err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil || a.String() != c.want {
|
||||
t.Errorf("%s: %q, %v; want %q", c.in, a.String(), err, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user