Skip to content

Commit f5afd13

Browse files
authored
Add URI validation for EventType Source and Schema fields (#8837)
1 parent 30cd193 commit f5afd13

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

pkg/apis/eventing/v1beta1/eventtype_validation.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ func (ets *EventTypeSpec) Validate(ctx context.Context) *apis.FieldError {
3333
fe := apis.ErrMissingField("type")
3434
errs = errs.Also(fe)
3535
}
36-
// TODO validate Source is a valid URI.
37-
// TODO validate Schema is a valid URI.
36+
// Validate Source is a non-empty URI when provided
37+
if ets.Source != nil && ets.Source.IsEmpty() {
38+
errs = errs.Also(apis.ErrInvalidValue("", "source", "source URI cannot be empty"))
39+
}
40+
// Validate Schema is a non-empty URI when provided
41+
if ets.Schema != nil && ets.Schema.IsEmpty() {
42+
errs = errs.Also(apis.ErrInvalidValue("", "schema", "schema URI cannot be empty"))
43+
}
3844
// There is no validation of the SchemaData, it is application specific data.
3945
return errs
4046
}

pkg/apis/eventing/v1beta1/eventtype_validation_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ func TestEventTypeSpecValidation(t *testing.T) {
6161
Source: testSource,
6262
Broker: "test-broker",
6363
},
64+
}, {
65+
name: "invalid empty source",
66+
ets: &EventTypeSpec{
67+
Type: "test-type",
68+
Source: &apis.URL{},
69+
Broker: "test-broker",
70+
},
71+
want: apis.ErrInvalidValue("", "source", "source URI cannot be empty"),
72+
}, {
73+
name: "invalid empty schema",
74+
ets: &EventTypeSpec{
75+
Type: "test-type",
76+
Source: testSource,
77+
Schema: &apis.URL{},
78+
Broker: "test-broker",
79+
},
80+
want: apis.ErrInvalidValue("", "schema", "schema URI cannot be empty"),
6481
},
6582
}
6683

0 commit comments

Comments
 (0)