Skip to content

Commit 2ff7852

Browse files
authored
fix: ensure source property has min length of 1 (#438)
Fixes: #383 Signed-off-by: Lance Ball <lball@redhat.com>
1 parent 2dc846c commit 2ff7852

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/event/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const schemaV1 = {
7979
source: {
8080
format: "uri-reference",
8181
type: "string",
82+
minLength: 1,
8283
},
8384
},
8485
type: "object",

test/integration/cloud_event_test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,20 @@ describe("A 1.0 CloudEvent", () => {
209209
expect(obj.source).to.equal(source);
210210
expect(obj.specversion).to.equal(Version.V1);
211211
});
212+
213+
it("throws if the provded source is empty string", () => {
214+
try {
215+
new CloudEvent({
216+
id: "0815",
217+
specversion: "1.0",
218+
type: "my.event.type",
219+
source: "",
220+
});
221+
} catch (err) {
222+
expect(err).to.be.instanceOf(TypeError);
223+
expect(err.message).to.include("invalid payload");
224+
expect(err.errors[0].dataPath).to.equal(".source");
225+
expect(err.errors[0].keyword).to.equal("minLength");
226+
}
227+
});
212228
});

0 commit comments

Comments
 (0)