CI / test (push) Successful in 2m32s
Routes Java Edition connections by the hostname in the handshake, with wildcard domains, backend failover, PROXY protocol v2, cached server-list status from health probes, hot-reloaded config, and an admin page and metrics endpoint. Includes CI, tagged releases and a container image. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package router
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.veillax.com/Veillax/spinner/internal/config"
|
|
)
|
|
|
|
func TestMatch(t *testing.T) {
|
|
cfg, err := config.Parse([]byte(`{"servers":[
|
|
{"name":"a","domains":["a.example.com","*.deep.example.com"],"addresses":["127.0.0.1:1"]},
|
|
{"name":"b","domains":["*.example.com"],"addresses":["127.0.0.1:2"]},
|
|
{"name":"c","domains":["*.x.deep.example.com"],"addresses":["127.0.0.1:3"]}
|
|
]}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := New(cfg)
|
|
cases := map[string]string{
|
|
"a.example.com": "a",
|
|
"A.Example.COM.": "a",
|
|
"a.example.com\x00FML\x00": "a",
|
|
"q.deep.example.com": "a",
|
|
"other.example.com": "b",
|
|
"s.x.deep.example.com": "c",
|
|
"example.com": "",
|
|
"evil.com": "",
|
|
"notexample.com": "",
|
|
"": "",
|
|
}
|
|
for host, want := range cases {
|
|
got := ""
|
|
if s := r.Match(host); s != nil {
|
|
got = s.Name
|
|
}
|
|
if got != want {
|
|
t.Errorf("Match(%q) = %q, want %q", host, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestConfigValidation(t *testing.T) {
|
|
bad := []string{
|
|
`{"servers":[{"name":"","domains":["a"],"addresses":["h:1"]}]}`,
|
|
`{"servers":[{"name":"a","domains":[],"addresses":["h:1"]}]}`,
|
|
`{"servers":[{"name":"a","domains":["a"],"addresses":["nope"]}]}`,
|
|
`{"servers":[{"name":"a","domains":["a"],"addresses":["h:1"]},{"name":"a","domains":["b"],"addresses":["h:1"]}]}`,
|
|
`{"unknown_field":1}`,
|
|
}
|
|
for _, b := range bad {
|
|
if _, err := config.Parse([]byte(b)); err == nil {
|
|
t.Errorf("expected error for %s", b)
|
|
}
|
|
}
|
|
}
|