ACLs, views' match lists, options with address match lists and blocking client groups take ranges such as 10.0.10.101-10.0.10.199 or 2001:db8::100-2001:db8::1ff (negated, or with spaces around the dash, too). Jarl stores the range as written and writes the fewest prefixes that cover exactly that range to named.conf, with the range as a comment. New package internal/iprange; namedconf gets an AMRange element (a range used to parse as an ACL name), ExpandRanges and statement comments. Mistakes are refused when entered, validation sees what ranges cover, and IPv6 ranges in the IPv4-mapped space get a warning. The web UI shows what a range becomes while typing (GET /catalog/ranges). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
872 B
Go
32 lines
872 B
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestCatalogRanges(t *testing.T) {
|
|
e := newAPIEnv(t)
|
|
b, status := e.req("GET", "/catalog/ranges?r=10.0.10.101-10.0.10.199,!2001:db8::100-2001:db8::1ff,branch-office,10.0.0.9-10.0.0.1", e.token, nil)
|
|
if status != 200 {
|
|
t.Fatalf("status %d: %s", status, b)
|
|
}
|
|
var out []struct {
|
|
Input, Range, Size, Error string
|
|
Prefixes []string
|
|
}
|
|
json.Unmarshal(b, &out)
|
|
if len(out) != 3 {
|
|
t.Fatalf("got %s", b)
|
|
}
|
|
if out[0].Range != "10.0.10.101-10.0.10.199" || len(out[0].Prefixes) != 6 || out[0].Size != "99 addresses" {
|
|
t.Errorf("IPv4 = %+v", out[0])
|
|
}
|
|
if out[1].Input != "!2001:db8::100-2001:db8::1ff" || len(out[1].Prefixes) != 1 || out[1].Prefixes[0] != "2001:db8::100/120" {
|
|
t.Errorf("IPv6 = %+v", out[1])
|
|
}
|
|
if out[2].Error == "" {
|
|
t.Errorf("reversed range = %+v", out[2])
|
|
}
|
|
}
|