From 198a0f02486927e6ef3e0ed13115ff7aa55c3749 Mon Sep 17 00:00:00 2001 From: chaitanyamogal <49728920+chaitanyamogal@users.noreply.github.com> Date: Thu, 21 Jan 2021 16:42:44 +0530 Subject: [PATCH 1/6] Test fails if any VENDOR_PRODUCT in checker is not lowercase The test fails when the `VENDOR_PRODUCT` pair provided is not lowercase. ( #987 ) --- cve_bin_tool/checkers/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cve_bin_tool/checkers/__init__.py b/cve_bin_tool/checkers/__init__.py index 3b78d4e2a1..1423560ad9 100644 --- a/cve_bin_tool/checkers/__init__.py +++ b/cve_bin_tool/checkers/__init__.py @@ -96,6 +96,14 @@ def __new__(cls, name, bases, props): cls.VENDOR_PRODUCT = list( map(lambda vpkg: VendorProductPair(*vpkg), cls.VENDOR_PRODUCT) ) + # Validate that vendor product pair is in lowercase + for items in cls.VENDOR_PRODUCT: + for vp in items: + if vp.islower() != True: + raise AssertionError( + "Checker %s has a VENDOR_PRODUCT string that is not lowercase" + % (name) + ) # Compile regex cls.CONTAINS_PATTERNS = list(map(re.compile, cls.CONTAINS_PATTERNS)) cls.VERSION_PATTERNS = list(map(re.compile, cls.VERSION_PATTERNS)) From 28bb82d5a51b8310bfd7382ba39b791b4c0c6e97 Mon Sep 17 00:00:00 2001 From: chaitanyamogal <49728920+chaitanyamogal@users.noreply.github.com> Date: Fri, 22 Jan 2021 13:20:08 +0530 Subject: [PATCH 2/6] Update __init__.py --- cve_bin_tool/checkers/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cve_bin_tool/checkers/__init__.py b/cve_bin_tool/checkers/__init__.py index 1423560ad9..cbe6ff8f08 100644 --- a/cve_bin_tool/checkers/__init__.py +++ b/cve_bin_tool/checkers/__init__.py @@ -2,6 +2,7 @@ import collections import re +from ..error_handler import InvalidCheckerError from ..util import regex_find __all__ = [ @@ -100,9 +101,8 @@ def __new__(cls, name, bases, props): for items in cls.VENDOR_PRODUCT: for vp in items: if vp.islower() != True: - raise AssertionError( - "Checker %s has a VENDOR_PRODUCT string that is not lowercase" - % (name) + raise InvalidCheckerError( + f"Checker {name} has a VENDOR_PRODUCT string that is not lowercase" ) # Compile regex cls.CONTAINS_PATTERNS = list(map(re.compile, cls.CONTAINS_PATTERNS)) From fb36449f01de84ce1f59f45294dd2e4a06512715 Mon Sep 17 00:00:00 2001 From: chaitanyamogal <49728920+chaitanyamogal@users.noreply.github.com> Date: Fri, 22 Jan 2021 13:21:53 +0530 Subject: [PATCH 3/6] Update error_handler.py --- cve_bin_tool/error_handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cve_bin_tool/error_handler.py b/cve_bin_tool/error_handler.py index 8b53caa751..4527c5f6b9 100644 --- a/cve_bin_tool/error_handler.py +++ b/cve_bin_tool/error_handler.py @@ -17,6 +17,10 @@ class InvalidCsvError(Exception): """ Given File is an Invalid CSV """ +class InvalidCheckerError(Exception): + """ Raised when data provided to Checker is not correct """ + + class MissingFieldsError(Exception): """ Missing needed fields """ From 5e87fa5db4d3328211f8d2e76b585cd981cb6067 Mon Sep 17 00:00:00 2001 From: chaitanyamogal <49728920+chaitanyamogal@users.noreply.github.com> Date: Fri, 22 Jan 2021 15:26:03 +0530 Subject: [PATCH 4/6] Update error_handler.py --- cve_bin_tool/error_handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cve_bin_tool/error_handler.py b/cve_bin_tool/error_handler.py index 4527c5f6b9..32881aa4da 100644 --- a/cve_bin_tool/error_handler.py +++ b/cve_bin_tool/error_handler.py @@ -144,6 +144,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): SystemExit: -2, FileNotFoundError: -3, InvalidCsvError: -4, + InvalidCheckerError: -4, InvalidJsonError: -4, MissingFieldsError: -5, InsufficientArgs: -6, From ae6e0cce98dd45abc3ffc0e33cb16a8fb8c35a30 Mon Sep 17 00:00:00 2001 From: chaitanyamogal <49728920+chaitanyamogal@users.noreply.github.com> Date: Tue, 26 Jan 2021 15:00:35 +0530 Subject: [PATCH 5/6] Update error_handler.py --- cve_bin_tool/error_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cve_bin_tool/error_handler.py b/cve_bin_tool/error_handler.py index 32881aa4da..a7ecaf83d3 100644 --- a/cve_bin_tool/error_handler.py +++ b/cve_bin_tool/error_handler.py @@ -144,7 +144,6 @@ def __exit__(self, exc_type, exc_val, exc_tb): SystemExit: -2, FileNotFoundError: -3, InvalidCsvError: -4, - InvalidCheckerError: -4, InvalidJsonError: -4, MissingFieldsError: -5, InsufficientArgs: -6, @@ -157,4 +156,5 @@ def __exit__(self, exc_type, exc_val, exc_tb): UnknownArchiveType: -13, UnknownConfigType: -14, CVEDataMissing: -15, + InvalidCheckerError: -16, } From c4d86c05f8b2dee3f21e42cd380e94b61c7a955a Mon Sep 17 00:00:00 2001 From: chaitanyamogal <49728920+chaitanyamogal@users.noreply.github.com> Date: Tue, 26 Jan 2021 15:01:41 +0530 Subject: [PATCH 6/6] Update __init__.py --- cve_bin_tool/checkers/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cve_bin_tool/checkers/__init__.py b/cve_bin_tool/checkers/__init__.py index cbe6ff8f08..1ea7fbed3a 100644 --- a/cve_bin_tool/checkers/__init__.py +++ b/cve_bin_tool/checkers/__init__.py @@ -2,8 +2,8 @@ import collections import re -from ..error_handler import InvalidCheckerError -from ..util import regex_find +from cve_bin_tool.error_handler import InvalidCheckerError +from cve_bin_tool.util import regex_find __all__ = [ "Checker",