From 6c78ddbe2ad502e5b7a7565c59927d5cb6ba6f86 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Tue, 28 Sep 2021 17:34:28 -0400 Subject: [PATCH 1/2] fix: ensure source property has min length of 1 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 27cfd118..9444a98f 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 1c7ee422..edaefe0a 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"); + } + }); }); From b004a62daa31153cb7cbf4a7112d4780ebb0089d Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Wed, 29 Sep 2021 09:52:31 -0400 Subject: [PATCH 2/2] fixup: whitespace Signed-off-by: Lance Ball --- test/integration/cloud_event_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/cloud_event_test.ts b/test/integration/cloud_event_test.ts index edaefe0a..6b624f0e 100644 --- a/test/integration/cloud_event_test.ts +++ b/test/integration/cloud_event_test.ts @@ -210,7 +210,7 @@ describe("A 1.0 CloudEvent", () => { expect(obj.specversion).to.equal(Version.V1); }); - it(" throws if the provded source is empty string", () => { + it("throws if the provded source is empty string", () => { try { new CloudEvent({ id: "0815",