mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 04:26:45 +00:00
fix(webhook): fix hostname validation logic (#2015)
Signed-off-by: Lukas Boettcher <lukas.boettcher@sick.de>
This commit is contained in:
@@ -80,7 +80,7 @@ func TestErrorConstructors(t *testing.T) {
|
||||
{name: "ingress forbidden", err: apierrors.NewIngressClassForbidden("nginx", allowed), want: "Ingress Class nginx is forbidden"},
|
||||
{name: "ingress collision", err: apierrors.NewIngressHostnameCollision("example.com"), want: "example.com is already used"},
|
||||
{name: "empty ingress hostname", err: apierrors.NewEmptyIngressHostname(api.AllowedListSpec{Exact: []string{"example.com"}, Regex: ".*\\.example\\.com"}), want: "empty hostname is not allowed"},
|
||||
{name: "ingress hostnames invalid", err: apierrors.NewIngressHostnamesNotValid([]string{"bad_host"}, []string{"other.com"}, api.AllowedListSpec{Exact: []string{"example.com"}}), want: "Hostnames [bad_host] are not valid"},
|
||||
{name: "ingress hostnames invalid", err: apierrors.NewIngressHostnamesNotValid([]string{"bad_host"}, api.AllowedListSpec{Exact: []string{"example.com"}}), want: "Hostnames [bad_host] are not valid"},
|
||||
{name: "ingress undefined", err: apierrors.NewIngressClassUndefined(allowed), want: "No Ingress Class is forbidden"},
|
||||
{name: "ingress not valid", err: apierrors.NewIngressClassNotValid("nginx", allowed), want: "Ingress Class nginx is forbidden"},
|
||||
{name: "namespace quota", err: apierrors.NewNamespaceQuotaExceededError(), want: "Cannot exceed Namespace quota"},
|
||||
|
||||
@@ -45,9 +45,8 @@ func (i IngressClassForbiddenError) Error() string {
|
||||
}
|
||||
|
||||
type IngressHostnameNotValidError struct {
|
||||
invalidHostnames []string
|
||||
notMatchingHostnames []string
|
||||
spec api.AllowedListSpec
|
||||
invalidHostnames []string
|
||||
spec api.AllowedListSpec
|
||||
}
|
||||
|
||||
type IngressHostnameCollisionError struct {
|
||||
@@ -76,13 +75,13 @@ func (e EmptyIngressHostnameError) Error() string {
|
||||
return fmt.Sprintf("empty hostname is not allowed for the current Tenant%s", appendHostnameError(e.spec))
|
||||
}
|
||||
|
||||
func NewIngressHostnamesNotValid(invalidHostnames []string, notMatchingHostnames []string, spec api.AllowedListSpec) error {
|
||||
return &IngressHostnameNotValidError{invalidHostnames: invalidHostnames, notMatchingHostnames: notMatchingHostnames, spec: spec}
|
||||
func NewIngressHostnamesNotValid(hostnames []string, spec api.AllowedListSpec) error {
|
||||
return &IngressHostnameNotValidError{invalidHostnames: hostnames, spec: spec}
|
||||
}
|
||||
|
||||
func (i IngressHostnameNotValidError) Error() string {
|
||||
return fmt.Sprintf("Hostnames %s are not valid for the current Tenant. Hostnames %s not matching for the current Tenant%s",
|
||||
i.invalidHostnames, i.notMatchingHostnames, appendHostnameError(i.spec))
|
||||
return fmt.Sprintf("Hostnames %v are not valid for the current Tenant%s",
|
||||
i.invalidHostnames, appendHostnameError(i.spec))
|
||||
}
|
||||
|
||||
type IngressClassUndefinedError struct {
|
||||
|
||||
Reference in New Issue
Block a user