Skip to content

Commit

Permalink
Change: adding wildcard support to CPE Part; unrequire product, vendor (
Browse files Browse the repository at this point in the history
#1099)

* Change: adding wildcard support to CPE Part; unrequire product

* Change: unrequire vendor
  • Loading branch information
y0urself authored Mar 7, 2025
1 parent 9b5f3e4 commit 2926d37
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pontos/cpe/_cpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Part(StrEnum):
APPLICATION = "a"
OPERATING_SYSTEM = "o"
HARDWARE_DEVICE = "h"
WILDCARD = "*" # wildcard for requesting "all" possible cpe parts


def is_uri_binding(cpe: str) -> bool:
Expand Down Expand Up @@ -427,8 +428,8 @@ class CPEWellFormed:
"""

part: Part
vendor: str
product: str
vendor: Optional[str] = None
product: Optional[str] = None
version: Optional[str] = None
update: Optional[str] = None
edition: Optional[str] = None
Expand Down Expand Up @@ -495,8 +496,8 @@ def __init__(
*,
cpe_string: Optional[str] = None,
part: Part,
vendor: str,
product: str,
vendor: Optional[str] = None,
product: Optional[str] = None,
version: Optional[str] = None,
update: Optional[str] = None,
edition: Optional[str] = None,
Expand Down
16 changes: 16 additions & 0 deletions tests/cpe/test_cpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,22 @@ def test_uri_unbind_examples(self):
self.assertIsNone(cpe.target_hw)
self.assertIsNone(cpe.other)

# example 7a
cpe = CPE.from_string("cpe:2.3:*:Microsoft")
self.assertFalse(cpe.is_uri_binding())
self.assertTrue(cpe.is_formatted_string_binding())
self.assertEqual(cpe.part, Part.WILDCARD)
self.assertEqual(cpe.vendor, "microsoft")
self.assertIsNone(cpe.product)
self.assertIsNone(cpe.version)
self.assertIsNone(cpe.update)
self.assertIsNone(cpe.language)
self.assertIsNone(cpe.edition)
self.assertIsNone(cpe.sw_edition)
self.assertIsNone(cpe.target_sw)
self.assertIsNone(cpe.target_hw)
self.assertIsNone(cpe.other)

# example 8
with self.assertRaisesRegex(
CPEParsingError,
Expand Down

0 comments on commit 2926d37

Please sign in to comment.