capycli icon indicating copy to clipboard operation
capycli copied to clipboard

[capycli] Fix find_bom_item silently failing when filter has no Version key

Open prajakta128 opened this issue 5 months ago • 2 comments

Problem

find_bom_item silently returns None when a filter entry has a Name but no Version key. This is a valid and common use case — a user wants to find a component by name regardless of its version.

The bug causes add mode updates to silently fail: instead of updating the existing component, a duplicate is added with no version.

Root Cause

The method uses filterentry.get("Version", "x") as a fallback, so when Version is missing, it compares "x" against the real version string, which never matches:

if filterentry.get("Name", "x") == component.name:
    if filterentry.get("Version", "x") == component.version:  # BUG
        return component

Fix

Changed the version check to only enforce version matching when the Version key is actually present in the filter entry:

if filterentry.get("Name", "x") == component.name:
    if "Version" not in filterentry or filterentry["Version"] == component.version:
        return component

Test Added

Added test_find_bom_item_name_only in tests/test_bom_filter.py covering the case where a filter entry has only Name and no Version key.

Impact

Any user writing a filter file with name-only entries (no Version) to update components would silently get duplicate ghost components in their SBOM with no error message shown.

prajakta128 avatar Jun 06 '26 08:06 prajakta128

Thank you again, @prajakta128 for this finding!

While the root cause fix looks good and adding a focused unit test for it is great, I would be even more interested in the user-facing problem you mention with creating duplicates. Would you mind creating a 2nd test case using the sut.run() or sut.filter_bom() patter from the other TCs in the file to also verify that no such duplicates are created? I would really be interested in understanding the code flow here better.

gernot-h avatar Jun 12 '26 09:06 gernot-h

@gernot-h Thanks for the detailed explanation! I've added a second test case, test_filter_bom_add_name_only_no_duplicate, which uses the full filter_bom() flow on the existing sw360 SBOM fixture.

It creates a filter entry with only "Name": "colorama" (no Version) and "Sw360Id": "999", then runs filter_bom() and verifies:

  • the total component count stays the same (no duplicate created)
  • the existing colorama component now has the Sw360Id property set

This confirms the fix correctly updates the existing component instead of adding a duplicate when no Version is specified in the filter entry.

prajakta128 avatar Jun 12 '26 11:06 prajakta128