|
|
|
|
@ -121,47 +121,106 @@ func TestLogin_ResetsForceAttemptOAuth2_OnFailure(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestWarnIfHostHasPath verifies that warnIfHostHasPath correctly detects path components.
|
|
|
|
|
func TestWarnIfHostHasPath(t *testing.T) {
|
|
|
|
|
func TestValidateHost(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
host string
|
|
|
|
|
wantWarn bool
|
|
|
|
|
name string
|
|
|
|
|
host string
|
|
|
|
|
wantErr bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "domain only",
|
|
|
|
|
host: "ghcr.io",
|
|
|
|
|
wantWarn: false,
|
|
|
|
|
name: "domain only",
|
|
|
|
|
host: "ghcr.io",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "domain with port",
|
|
|
|
|
host: "localhost:8000",
|
|
|
|
|
wantWarn: false,
|
|
|
|
|
name: "domain with port",
|
|
|
|
|
host: "localhost:8000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "domain with repository path",
|
|
|
|
|
host: "ghcr.io/terryhowe",
|
|
|
|
|
wantWarn: true,
|
|
|
|
|
name: "domain with repository path",
|
|
|
|
|
host: "ghcr.io/terryhowe",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "domain with nested path",
|
|
|
|
|
host: "ghcr.io/terryhowe/myrepo",
|
|
|
|
|
wantWarn: true,
|
|
|
|
|
name: "domain with nested path",
|
|
|
|
|
host: "ghcr.io/terryhowe/myrepo",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "localhost with port and path",
|
|
|
|
|
host: "localhost:8000/myrepo",
|
|
|
|
|
wantWarn: true,
|
|
|
|
|
name: "localhost with port and path",
|
|
|
|
|
host: "localhost:8000/myrepo",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "domain with http protocol",
|
|
|
|
|
host: "http://ghcr.io",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "domain with https protocol",
|
|
|
|
|
host: "https://ghcr.io",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "domain with oci protocol",
|
|
|
|
|
host: "oci://ghcr.io",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "domain with uppercase scheme",
|
|
|
|
|
host: "HTTPS://ghcr.io",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "scheme with plus sign",
|
|
|
|
|
host: "coap+tcp://ghcr.io",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "scheme with dot and hyphen",
|
|
|
|
|
host: "my.custom-scheme://ghcr.io",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "IPv6 loopback with port",
|
|
|
|
|
host: "[::1]:5000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "IPv6 full address with port",
|
|
|
|
|
host: "[2001:db8::1]:443",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "IPv4 address with port",
|
|
|
|
|
host: "192.168.1.1:5000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "host with underscore",
|
|
|
|
|
host: "my_registry.local",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "scheme with path",
|
|
|
|
|
host: "https://ghcr.io/myrepo",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty string",
|
|
|
|
|
host: "",
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
got := warnIfHostHasPath(tt.host)
|
|
|
|
|
if got != tt.wantWarn {
|
|
|
|
|
t.Errorf("warnIfHostHasPath(%q) = %v, want %v", tt.host, got, tt.wantWarn)
|
|
|
|
|
err := validateHost(tt.host)
|
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
|
t.Errorf("validateHost(%q) error = %v, wantErr %v", tt.host, err, tt.wantErr)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|