镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Emit strings for CycloneDX metadata property values - #5354

Open
0Cymantek0 wants to merge 1 commit into
aboutcode-org:developfrom
0Cymantek0:issue-5349-cyclonedx-string-properties
Open

0Cymantek0 wants to merge 1 commit into
aboutcode-org:developfrom
0Cymantek0:issue-5349-cyclonedx-string-properties

Conversation

@0Cymantek0

Copy link
Copy Markdown

Fixes #5349

metadata.properties values in the CycloneDX JSON output were not strings. errors and warnings were JSON arrays, message was null and system_environment was a nested object. The CycloneDX specification types property values as strings in all versions including the declared 1.3, so schema-validating tools such as cyclonedx-cli reject the output of every scan.

Changes:

  • Convert property values to strings in from_headers() with a get_property_string_value() helper. Lists are joined with newlines, mappings are serialized to JSON. One property per list item would work too, joining keeps the property set unchanged.
  • Drop empty and null values. The to_dict() filter was meant to remove those but a property mapping is never falsy.
  • Update the from_headers test to expect strings and add tests: property values are always strings, empty values are dropped, and an end-to-end check on a scan output.

Validation:

  • pytest -vvs tests/formattedcode/test_output_cyclonedx.py : 17 passed, the four new and updated tests fail on develop without the fix
  • pytest -q tests/formattedcode/ : 42 passed, 4 skipped
  • cyclonedx-python-lib validator: BOMs rejected before the fix with "[] is not of type 'string'", no metadata violations after

Components still fail strict validation because fields such as author and copyright are emitted as null. Separate defect, will be filed separately.

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁
  • Updated documentation pages (if applicable)
  • Updated CHANGELOG.rst (if applicable)

The CycloneDX specification types property values as strings in all
versions including the 1.3 version scancode declares, but from_headers()
passed the errors and warnings lists, a null message and the extra_data
mappings of the scan header to CycloneDxProperty unchanged and to_dict()
serializes them as-is with attr.asdict. Tools that validate against the
CycloneDX JSON schema such as cyclonedx-cli fail on the resulting BOMs on
every scan.

Convert property values to strings in from_headers() with a new
get_property_string_value() helper. Lists of messages are joined with
newlines, mappings are serialized to JSON and empty or null values are
dropped. The from_headers test now expects strings and new tests check
that every emitted property value is a string.

Reference: aboutcode-org#5349
Signed-off-by: Shuvagata Dey <cymantekfnosz@gmail.com>

This branch has not been deployed

No deployments
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.

CycloneDX output: metadata.properties[].value emits JSON array instead of string

1 participant