From 2ff7852c3689c486261ec4cd45a18315750b0f2e Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Wed, 29 Sep 2021 09:55:37 -0400 Subject: [PATCH] fix: ensure source property has min length of 1 (#438) Fixes: https://github.com/cloudevents/sdk-javascript/issues/383 Signed-off-by: Lance Ball --- src/event/schemas.ts | 1 + test/integration/cloud_event_test.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/event/schemas.ts b/src/event/schemas.ts index 27cfd11..9444a98 100644 --- a/src/event/schemas.ts +++ b/src/event/schemas.ts @@ -79,6 +79,7 @@ export const schemaV1 = { source: { format: "uri-reference", type: "string", + minLength: 1, }, }, type: "object", diff --git a/test/integration/cloud_event_test.ts b/test/integration/cloud_event_test.ts index 1c7ee42..6b624f0 100644 --- a/test/integration/cloud_event_test.ts +++ b/test/integration/cloud_event_test.ts @@ -209,4 +209,20 @@ describe("A 1.0 CloudEvent", () => { expect(obj.source).to.equal(source); expect(obj.specversion).to.equal(Version.V1); }); + + it("throws if the provded source is empty string", () => { + try { + new CloudEvent({ + id: "0815", + specversion: "1.0", + type: "my.event.type", + source: "", + }); + } catch (err) { + expect(err).to.be.instanceOf(TypeError); + expect(err.message).to.include("invalid payload"); + expect(err.errors[0].dataPath).to.equal(".source"); + expect(err.errors[0].keyword).to.equal("minLength"); + } + }); });