Files
statuspage/server/config_fuzz_test.go
T
aziis98 41a01244c4 server: expand {a,b}/{1..10} host patterns in config; fuzz + tests
Hosts accept brace groups expanded at load time: enumeration {1,2,3},
inclusive ranges {2..5,8..10} with '..' syntax, and labels {a3,a4};
several groups multiply in cartesian fashion. Leading zeros are
preserved, each expanded machine gets its host as unique ID/name.

Malformed patterns (unmatched/nested braces, non-integer or descending
ranges, extra dots) and patterns expanding past 10000 machines fail at
startup. Adds table tests plus a FuzzExpandHostPattern target; the
safety cap keeps fuzzing and real configs from blowing up memory.
2026-08-01 11:27:59 +02:00

52 lines
1.0 KiB
Go

package main
import (
"reflect"
"strings"
"testing"
)
func FuzzExpandHostPattern(f *testing.F) {
seeds := []string{
"server{1..3}.example.org",
"server{1,2,3}.example.org",
"server-{a3,a4}-{1..2}.example.org",
"host{01..03}",
"router.example.net",
"host-{5..2}.example.org",
"host-{1,2.example.org",
"{1..10}",
"{2..5,8..10}.example.org",
"",
"host-{}",
"{1..}",
"{..5}",
"x}{y}",
"{a,b}{c,d}",
"{0..10001}",
}
for _, s := range seeds {
f.Add(s)
}
f.Fuzz(func(t *testing.T, pattern string) {
hosts, err := expandHostPattern(pattern)
if err != nil {
return
}
if !strings.Contains(pattern, "{") {
if !reflect.DeepEqual(hosts, []string{pattern}) {
t.Fatalf("pattern without braces %q expanded to %v", pattern, hosts)
}
return
}
if len(hosts) == 0 {
t.Fatalf("pattern %q produced no hosts", pattern)
}
for _, h := range hosts {
if strings.Contains(h, "{") {
t.Fatalf("expanded host %q still contains '{' (pattern %q)", h, pattern)
}
}
})
}