Skip to content

Commit 2926d37

Browse files
authored
Change: adding wildcard support to CPE Part; unrequire product, vendor (#1099)
* Change: adding wildcard support to CPE Part; unrequire product * Change: unrequire vendor
1 parent 9b5f3e4 commit 2926d37

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

pontos/cpe/_cpe.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Part(StrEnum):
3636
APPLICATION = "a"
3737
OPERATING_SYSTEM = "o"
3838
HARDWARE_DEVICE = "h"
39+
WILDCARD = "*" # wildcard for requesting "all" possible cpe parts
3940

4041

4142
def is_uri_binding(cpe: str) -> bool:
@@ -427,8 +428,8 @@ class CPEWellFormed:
427428
"""
428429

429430
part: Part
430-
vendor: str
431-
product: str
431+
vendor: Optional[str] = None
432+
product: Optional[str] = None
432433
version: Optional[str] = None
433434
update: Optional[str] = None
434435
edition: Optional[str] = None
@@ -495,8 +496,8 @@ def __init__(
495496
*,
496497
cpe_string: Optional[str] = None,
497498
part: Part,
498-
vendor: str,
499-
product: str,
499+
vendor: Optional[str] = None,
500+
product: Optional[str] = None,
500501
version: Optional[str] = None,
501502
update: Optional[str] = None,
502503
edition: Optional[str] = None,

tests/cpe/test_cpe.py

+16
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,22 @@ def test_uri_unbind_examples(self):
456456
self.assertIsNone(cpe.target_hw)
457457
self.assertIsNone(cpe.other)
458458

459+
# example 7a
460+
cpe = CPE.from_string("cpe:2.3:*:Microsoft")
461+
self.assertFalse(cpe.is_uri_binding())
462+
self.assertTrue(cpe.is_formatted_string_binding())
463+
self.assertEqual(cpe.part, Part.WILDCARD)
464+
self.assertEqual(cpe.vendor, "microsoft")
465+
self.assertIsNone(cpe.product)
466+
self.assertIsNone(cpe.version)
467+
self.assertIsNone(cpe.update)
468+
self.assertIsNone(cpe.language)
469+
self.assertIsNone(cpe.edition)
470+
self.assertIsNone(cpe.sw_edition)
471+
self.assertIsNone(cpe.target_sw)
472+
self.assertIsNone(cpe.target_hw)
473+
self.assertIsNone(cpe.other)
474+
459475
# example 8
460476
with self.assertRaisesRegex(
461477
CPEParsingError,

0 commit comments

Comments
 (0)