fix: validate maintenance profiles and canonical local auth origins

This commit is contained in:
Codex
2026-10-06 16:09:39 +02:00
parent d79e261e09
commit 2aac228cdc
10 changed files with 106 additions and 11 deletions
@@ -0,0 +1,29 @@
package authconfig
import "testing"
func TestLocalHTTPOriginMatchesBackendLiteralLoopbackPolicy(t *testing.T) {
for _, origin := range []string{"http://127.0.0.1:8080", "http://127.0.0.2", "http://[::1]:8080"} {
if !isLoopbackURL(origin) {
t.Errorf("canonical origin refused: %s", origin)
}
}
for _, origin := range []string{"http://localhost:8080", "http://127.1:8080", "http://[::ffff:127.0.0.1]:8080", "http://127.0.0.1:08080", "http://127.0.0.1:", "http://127.0.0.1:99999"} {
if isLoopbackURL(origin) {
t.Errorf("backend-incompatible origin accepted: %s", origin)
}
}
}
func TestPublicOriginMatchesBackendURLContract(t *testing.T) {
for _, origin := range []string{"http://127.0.0.1:8080/", "https://example.com/", "https://example.com:443", "http://[::1]:8080/"} {
if !ValidPublicURL(origin) {
t.Errorf("runtime-valid origin refused: %s", origin)
}
}
for _, origin := range []string{"https://example.com:99999", "http://localhost:8080", "HTTP://127.0.0.1:8080", "https://example.com/path", "http://example.com", "https://user:password@example.com"} {
if ValidPublicURL(origin) {
t.Errorf("runtime-invalid origin accepted: %s", origin)
}
}
}