fix: ensure source property has min length of 1 (#438)

Fixes: https://github.com/cloudevents/sdk-javascript/issues/383

Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
Lance Ball 2021-09-29 09:55:37 -04:00 committed by GitHub
parent 2dc846c659
commit 2ff7852c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -79,6 +79,7 @@ export const schemaV1 = {
source: {
format: "uri-reference",
type: "string",
minLength: 1,
},
},
type: "object",

View File

@ -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");
}
});
});