Skip to content

[codex] validate v1 compat attribute names#301

Draft
MickeyWzt wants to merge 1 commit into
cloudevents:mainfrom
MickeyWzt:codex/validate-v1-attribute-names
Draft

[codex] validate v1 compat attribute names#301
MickeyWzt wants to merge 1 commit into
cloudevents:mainfrom
MickeyWzt:codex/validate-v1-attribute-names

Conversation

@MickeyWzt

Copy link
Copy Markdown

Summary

  • reject invalid attribute names in the deprecated cloudevents.v1.http.CloudEvent compatibility class
  • add a dedicated InvalidAttributeName exception for the legacy v1 API
  • cover invalid extension names both during construction and later item assignment

Why

CloudEvents attribute names must only contain lowercase ASCII letters and digits. The core v1 event model already rejects invalid extension names such as example-extension, but the deprecated cloudevents.v1.http.CloudEvent compatibility class accepted them and could serialize an invalid structured CloudEvent.

Fixes #300.

Tests

  • uv run --with-editable . pytest tests/test_v1_compat/test_event_extensions.py -q
  • uv run --with-editable . pytest tests/test_core/test_v1/test_event.py tests/test_core/test_v03/test_event.py -q
  • uv run --with-editable . pytest tests/test_v1_compat -q
  • uv run ruff check src/cloudevents/v1/http/event.py src/cloudevents/v1/exceptions.py tests/test_v1_compat/test_event_extensions.py
  • uv run ruff format --check src/cloudevents/v1/http/event.py src/cloudevents/v1/exceptions.py tests/test_v1_compat/test_event_extensions.py
  • uv run --with-editable . pytest -q

Signed-off-by: MickeyWzt <289528356+MickeyWzt@users.noreply.github.com>

@xSAVIKx xSAVIKx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MickeyWzt thank you for the PR!

Your change only covers the v1 compatibility layer. Do you mind tackling the the cloudevents.core implementation as well? cloudevents.core is the v2 SDK rollout that we will keep moving forward while dropping the cloudevents.v1 package soon.

_attribute_name_pattern = re.compile(r"^[a-z0-9]+$")


def _validate_attribute_name(name: str) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a link to the spec reference here to support this validation

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CloudEvent serializes invalid extension attribute names without validation

2 participants