33 lines
707 B
Go
33 lines
707 B
Go
package allowlist
|
|
|
|
import (
|
|
"net/netip"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseCommaList(t *testing.T) {
|
|
list, err := ParseCommaList(" ")
|
|
if err != nil || list != nil {
|
|
t.Fatalf("empty: list=%v err=%v", list, err)
|
|
}
|
|
list, err = ParseCommaList("192.168.1.1, 10.0.0.0/8")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(list) != 2 {
|
|
t.Fatalf("want 2 prefixes, got %d", len(list))
|
|
}
|
|
a := netip.MustParseAddr("10.5.5.5")
|
|
if !Contains(list, a) {
|
|
t.Fatal("10.5.5.5 should match 10.0.0.0/8")
|
|
}
|
|
b := netip.MustParseAddr("192.168.1.1")
|
|
if !Contains(list, b) {
|
|
t.Fatal("192.168.1.1 should match host /32")
|
|
}
|
|
c := netip.MustParseAddr("8.8.8.8")
|
|
if Contains(list, c) {
|
|
t.Fatal("8.8.8.8 should not match")
|
|
}
|
|
}
|