Skip to content

Should throw if specversion attribute is missing #332

Closed

Description

@satazor

Describe the Bug

Does not throw if event doesn't have a specversion attribute, and fallbacks to 1.0. The spec says that the specversion attribute is mandatory, so I think this library should fail when it's missing, instead of "magically" falling back.

Steps to Reproduce

  1. Receiver.accept({ 'Content-Type': 'application/cloudevents+json' }, { id: 'foo', source: 'foo', type: 'foo' });
  2. Prints console.error saying it will fallback to 1.0
  3. Validation passes

Expected Behavior
It should throw, since the specversion attribute is missing

Activity

  1. satazor commented on Sep 2, 2020

    @satazor
    Author
  2. added
    module/libRelated to the main source code
    module/transport/httpIssues related to the HTTP transport protocol implementation
    on Sep 2, 2020
  3. lance commented on Sep 2, 2020

    @lance
    Member

    @satazor thanks for pointing this out. I will look into dealing with this in #328

  4. self-assigned this
    on Sep 2, 2020
  5. lance commented on Sep 3, 2020

    @lance
    Member

    @satazor in this PR, there was discussion around loose validation on receipt of a CloudEvent. Based on input from the community, noted in that comment, receipt of a CloudEvent should have loose validation, since it should be possible to receive and recover from poorly formed/invalid events. The example you provide is when receiving events on the wire - just such a scenario. If you would like to check whether the received event is valid, you can call CloudEvent#validate().

    That method returns a boolean. I think it might be nice to see what the validation errors actually were, and we don't really have a convenience function for that. In any case, this is expected behavior.

  6. lance commented on Sep 3, 2020

    @lance
    Member

    Oh - but I see the problem here. Since it's defaulting the specversion, property, by the time it's unmarshalled as a CloudEvent, it is valid, so calling ce.validate() won't help.

  7. lance commented on Sep 3, 2020

    @lance
    Member

    The other required attribute that we supply a default for if it's not provided is id. The same would happen for this.

  8. github-actions commented on Oct 4, 2020

    @github-actions
    Contributor

    This issue is stale because it has been open 30 days with no activity.

  9. lholmquist commented on Oct 7, 2020

    @lholmquist
    Contributor

    I know this has been open for a while, but the idea is that we shouldn't be defaulting the specversion and id fields?

    This would be a good one to get into the 4.0 release. i can assign myself to take of it

  10. lance commented on Oct 7, 2020

    @lance
    Member

    I know this has been open for a while, but the idea is that we shouldn't be defaulting the specversion and id fields?

    I think defaulting them on creation with new CloudEvent() is fine. But when receiving events, we should not just assume that they are v1.0. That's what we are doing here.

    if (version !== Version.V03 && version !== Version.V1) {
    console.error(`Unknown spec version ${version}. Default to ${Version.V1}`);
    version = Version.V1;

    Throwing here would also remove that console.error() and resolve #333

  11. lholmquist commented on Oct 7, 2020

    @lholmquist
    Contributor

    @lance that sounds good. i'll take of it

  12. 1 remaining item

  13. added a commit that references this issue on Oct 7, 2020
    eef8cec
  14. c-pius commented on Feb 4, 2021

    @c-pius

    I think defaulting them on creation with new CloudEvent() is fine. But when receiving events, we should not just assume that they are v1.0. That's what we are doing here.

    I think this should also be the same for the id attribute, right?

    As of now, HTTP.toEvent() will also assign a new uuidv4 to an event if passed in structured mode with no id present. This time even implicitly without a log message that it was defaulted.


    parseStructured will call the CloudEvent constructor with eventObj missing the id attribute and generate it.

    return new CloudEvent(eventObj as CloudEventV1 | CloudEventV03, false);

    this.id = (properties.id as string) || uuidv4();


    PS: the same would also happen with the time attribute. Maybe less important though because not a required attribute.

  15. c-pius commented on Feb 11, 2021

    @c-pius

    FYI, there is another effect that when calling HTTP.toEvent with a structured mode event and a specversion value different from 1.0 or 0.3 (e.g. 2), than the defaulting here is applied:

    if (version !== Version.V03 && version !== Version.V1) {

    but the parsed event is actually getting the original value (e.g. 2) assigned by this block:

    for (const key in parserMap) {


    in binary mode this is prevented by this block:

    no sure if therefore this block for structured should use the body attributes instead (I think sending ce-header even though structured mode is used is valid as long as the context attributes are present in the body)?

  16. github-actions commented on Mar 14, 2021

    @github-actions
    Contributor

    This issue is stale because it has been open 30 days with no activity.

  17. lance commented on May 17, 2021

    @lance
    Member

    @lholmquist ping - were you still thinking you'd take this? If not, I'll pick it up. Running into this as an issue now with function runtime.

  18. lholmquist commented on May 18, 2021

    @lholmquist
    Contributor

    @lance it isn't on my radar atm, so feel free to pick it up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

module/libRelated to the main source codemodule/transport/httpIssues related to the HTTP transport protocol implementation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions