mirror of
https://github.com/Pacerino/CaddyProxyManager.git
synced 2026-07-22 13:33:36 -04:00
Route host changes through the selected Caddy provider, add auth routes and the frontend-dir serving toggle, seed a default admin user on first run, and validate space/comma separated domain lists via a custom validator. Includes validator tests.
40 lines
1010 B
Go
40 lines
1010 B
Go
package handler
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Pacerino/CaddyProxyManager/internal/database"
|
|
)
|
|
|
|
func TestDomainsValidator(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
domains string
|
|
wantErr bool
|
|
}{
|
|
{"single fqdn", "example.com", false},
|
|
{"multiple space separated", "example.com www.example.com", false},
|
|
{"comma separated", "example.com,www.example.com", false},
|
|
{"host:port", "example.com:8080", false},
|
|
{"empty", "", true},
|
|
{"invalid domain", "not a domain!", true},
|
|
{"one invalid among valid", "example.com bad domain", true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
h := database.Host{
|
|
Domains: tt.domains,
|
|
Upstreams: []database.Upstream{{Backend: "127.0.0.1:8080"}},
|
|
}
|
|
err := validate.Struct(h)
|
|
if tt.wantErr && err == nil {
|
|
t.Errorf("domains %q: expected validation error, got none", tt.domains)
|
|
}
|
|
if !tt.wantErr && err != nil {
|
|
t.Errorf("domains %q: unexpected error %v", tt.domains, err)
|
|
}
|
|
})
|
|
}
|
|
}
|