Add URI validation for EventType Source and Schema fields#8837
Add URI validation for EventType Source and Schema fields#8837Kunal1522 wants to merge 1 commit intoknative:mainfrom
Conversation
|
Hi @Kunal1522. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Kunal1522 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| // TODO validate Schema is a valid URI. | ||
| // Validate Source is a non-empty URI when provided | ||
| if ets.Source != nil && ets.Source.IsEmpty() { | ||
| errs = errs.Also(apis.ErrInvalidValue("", "source", "source URI cannot be empty")) |
There was a problem hiding this comment.
ets.Source could be nil, while this error would not be set. As IsEmpty() seems also to be nil safe, you could also use ets.Source.IsEmpty() directly.
There was a problem hiding this comment.
Hey thanks @creydr ! I tried removing the nil check but the existing tests started failing. IsEmpty() returns true for nil, so it was treating "not provided" the same as "provided but empty". I think we only want to error on the second case since the fields are optional. Let me know if I'm missing something though!
| } | ||
| // Validate Schema is a non-empty URI when provided | ||
| if ets.Schema != nil && ets.Schema.IsEmpty() { | ||
| errs = errs.Also(apis.ErrInvalidValue("", "schema", "schema URI cannot be empty")) |
Changes
Fixes #8836
This PR addresses the TODO comments in eventtype_validation.go by adding validation for the
SourceandSchemaURI fields in EventTypeSpec.Before: An EventType could be created with empty Source/Schema URIs (e.g.,
"source": ""), which would parse successfully but result in a meaningless empty URI.After: If
SourceorSchemais provided (non-nil) but empty, validation will reject it with a clear error message.What type of PR is this?
/kind cleanup
What this PR does
EventTypeSpec.Validate()to check thatSourceandSchemafields are not empty when providedWhich issue(s) this PR fixes
Fixes the following TODOs in the codebase:
// TODO validate Source is a valid URI.// TODO validate Schema is a valid URI.How was this tested?
go test -v ./pkg/apis/eventing/v1beta1/... -run TestEventType