Skip to content

Commit

Permalink
fix: rename trustedDomains into trustedURLs
Browse files Browse the repository at this point in the history
  • Loading branch information
jspdown committed Apr 30, 2024
1 parent e6cfb0e commit a45ef79
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
7 changes: 4 additions & 3 deletions pkg/apis/hub/v1alpha1/api_portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ type APIPortalSpec struct {
// +optional
Description string `json:"description,omitempty"`

// TrustedDomains are the domains that are trusted by the OAuth 2.0 authorization server.
// TrustedURLs are the urls that are trusted by the OAuth 2.0 authorization server.
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=20
TrustedDomains []string `json:"trustedDomains"`
// +kubebuilder:validation:MaxItems=1
// +kubebuilder:validation:XValidation:message="must be a valid URLs",rule="self.all(x, isURL(x))"
TrustedURLs []string `json:"trustedUrls"`

// UI holds the UI customization options.
// +optional
Expand Down
13 changes: 8 additions & 5 deletions pkg/apis/hub/v1alpha1/crd/hub.traefik.io_apiportals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ spec:
title:
description: Title is the public facing name of the APIPortal.
type: string
trustedDomains:
description: TrustedDomains are the domains that are trusted by the
OAuth 2.0 authorization server.
trustedUrls:
description: TrustedURLs are the urls that are trusted by the OAuth
2.0 authorization server.
items:
type: string
maxItems: 20
maxItems: 1
minItems: 1
type: array
x-kubernetes-validations:
- message: must be a valid URLs
rule: self.all(x, isURL(x))
ui:
description: UI holds the UI customization options.
properties:
Expand All @@ -61,7 +64,7 @@ spec:
type: string
type: object
required:
- trustedDomains
- trustedUrls
type: object
status:
description: The current status of this APIPortal.
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/hub/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 23 additions & 11 deletions pkg/validation/v1alpha1/portal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ metadata:
name: my-portal
namespace: default
spec:
trustedDomains: ["example.com"]`),
trustedUrls: ["https://example.com"]`),
},
{
desc: "valid: full",
Expand All @@ -49,7 +49,7 @@ metadata:
spec:
title: title
description: description
trustedDomains: ["example.com"]
trustedUrls: ["https://example.com"]
ui:
logoUrl: https://example.com/logo.png
`),
Expand All @@ -62,7 +62,7 @@ kind: APIPortal
metadata:
name: my-portal
spec:
trustedDomains: ["example.com"]`),
trustedUrls: ["https://example.com"]`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeRequired, Field: "metadata.namespace", BadValue: ""}},
},
{
Expand All @@ -74,7 +74,7 @@ metadata:
name: .non-dns-compliant-portal
namespace: default
spec:
trustedDomains: ["example.com"]`),
trustedUrls: ["https://example.com"]`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "metadata.name", BadValue: ".non-dns-compliant-portal", Detail: "a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')"}},
},
{
Expand All @@ -86,7 +86,7 @@ metadata:
name: ""
namespace: default
spec:
trustedDomains: ["example.com"]`),
trustedUrls: ["https://example.com"]`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeRequired, Field: "metadata.name", BadValue: "", Detail: "name or generateName is required"}},
},
{
Expand All @@ -98,31 +98,43 @@ metadata:
name: portal-with-a-way-toooooooooooooooooooooooooooooooooooooo-long-name
namespace: default
spec:
trustedDomains: ["example.com"]`),
trustedUrls: ["https://example.com"]`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "metadata.name", BadValue: "portal-with-a-way-toooooooooooooooooooooooooooooooooooooo-long-name", Detail: "must be no more than 63 characters"}},
},
{
desc: "missing trustedDomains",
desc: "missing trustedUrls",
manifest: []byte(`
apiVersion: hub.traefik.io/v1alpha1
kind: APIPortal
metadata:
name: my-portal
namespace: default
spec: {}`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeRequired, Field: "spec.trustedDomains", BadValue: ""}},
wantErrs: field.ErrorList{{Type: field.ErrorTypeRequired, Field: "spec.trustedUrls", BadValue: ""}},
},
{
desc: "empty trustedDomains",
desc: "empty trustedUrls",
manifest: []byte(`
apiVersion: hub.traefik.io/v1alpha1
kind: APIPortal
metadata:
name: my-portal
namespace: default
spec:
trustedDomains: []`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "spec.trustedDomains", BadValue: int64(0), Detail: "spec.trustedDomains in body should have at least 1 items"}},
trustedUrls: []`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "spec.trustedUrls", BadValue: int64(0), Detail: "spec.trustedUrls in body should have at least 1 items"}},
},
{
desc: "too many trustedUrls",
manifest: []byte(`
apiVersion: hub.traefik.io/v1alpha1
kind: APIPortal
metadata:
name: my-portal
namespace: default
spec:
trustedUrls: ["https://example.com", https://another.example.com]`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeTooMany, Field: "spec.trustedUrls", BadValue: 2, Detail: "must have at most 1 items"}},
},
}

Expand Down

0 comments on commit a45ef79

Please sign in to comment.