diff --git a/cloudevents/sdk/converters/util.py b/cloudevents/sdk/converters/util.py index b31c39c8..b0a8adc3 100644 --- a/cloudevents/sdk/converters/util.py +++ b/cloudevents/sdk/converters/util.py @@ -4,7 +4,7 @@ def has_binary_headers(headers: typing.Dict[str, str]) -> bool: return ( "ce-specversion" in headers - and "ce-source" in headers - and "ce-type" in headers - and "ce-id" in headers + or "ce-source" in headers + or "ce-type" in headers + or "ce-id" in headers ) diff --git a/cloudevents/tests/test_http_events.py b/cloudevents/tests/test_http_events.py index a6023a9c..57e8b67e 100644 --- a/cloudevents/tests/test_http_events.py +++ b/cloudevents/tests/test_http_events.py @@ -30,6 +30,8 @@ ) from cloudevents.sdk import converters +required_headers = {"ce-id", "ce-source", "ce-type", "ce-specversion"} + invalid_test_headers = [ { "ce-source": "", @@ -96,9 +98,17 @@ def test_missing_required_fields_structured(body): @pytest.mark.parametrize("headers", invalid_test_headers) def test_missing_required_fields_binary(headers): - with pytest.raises(cloud_exceptions.MissingRequiredFields): + with pytest.raises(cloud_exceptions.MissingRequiredFields) as e: _ = from_http(headers, json.dumps(test_data)) + if "ce-specversion" not in headers: + assert "Failed to find specversion in HTTP request" == str(e.value) + else: + assert ( + f"Missing required attributes: {set(required_headers) - set(headers)}" + == str(e.value) + ) + @pytest.mark.parametrize("headers", invalid_test_headers) def test_missing_required_fields_empty_data_binary(headers):