diff options
| author | GeogeFI | 2022-12-25 22:43:21 +0100 |
|---|---|---|
| committer | GeogeFI | 2022-12-25 22:43:21 +0100 |
| commit | 40cbd0572ec5ea7454145303fc8bf1d0c71d9682 (patch) | |
| tree | 79930723e9862f13ead0d1a7c882ec0870d1b22a | |
| parent | 33cc8b4200a197603354b1142d1f4a4e964bd88b (diff) | |
| download | sec-certs-40cbd0572ec5ea7454145303fc8bf1d0c71d9682.tar.gz sec-certs-40cbd0572ec5ea7454145303fc8bf1d0c71d9682.tar.zst sec-certs-40cbd0572ec5ea7454145303fc8bf1d0c71d9682.zip | |
chore: Formating, fixed tests
| -rw-r--r-- | src/sec_certs/dataset/cve.py | 2 | ||||
| -rw-r--r-- | src/sec_certs/sample/cve.py | 8 | ||||
| -rw-r--r-- | tests/cc/test_cc_analysis.py | 8 | ||||
| -rw-r--r-- | tests/fips/test_fips_analysis.py | 8 | ||||
| -rw-r--r-- | tests/test_cpe.py | 4 | ||||
| -rw-r--r-- | tests/test_cve.py | 8 |
6 files changed, 21 insertions, 17 deletions
diff --git a/src/sec_certs/dataset/cve.py b/src/sec_certs/dataset/cve.py index 566bc2e4..9a36fa6b 100644 --- a/src/sec_certs/dataset/cve.py +++ b/src/sec_certs/dataset/cve.py @@ -84,7 +84,7 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): for cve in tqdm(self, desc="Building-up lookup dictionaries for fast CVE matching"): # See note above, we use matching_dict.get(cpe, []) instead of matching_dict[cpe] as would be expected if use_nist_mapping: - vulnerable_configurations = list( + vulnerable_configurations = set( itertools.chain.from_iterable(matching_dict.get(cpe, []) for cpe in cve.vulnerable_cpes) ) else: diff --git a/src/sec_certs/sample/cve.py b/src/sec_certs/sample/cve.py index caf2b4d7..9b2c2437 100644 --- a/src/sec_certs/sample/cve.py +++ b/src/sec_certs/sample/cve.py @@ -221,8 +221,12 @@ class CVE(PandasSerializableType, ComplexSerializableType): impact = cls.Impact.from_nist_dict(dct) cpe_and_cpe_configurations = get_vulnerable_cpes_from_nist_dict(dct) # There exist CVEs such as (CVE-2022-0177) which are rejected and do not contain any assinged CPEs - vulnerable_cpes = set(itertools.chain.from_iterable(cpe_and_cpe_configurations[0])) if cpe_and_cpe_configurations else set() - vulnerable_cpe_configurations = set(itertools.chain.from_iterable(cpe_and_cpe_configurations[1])) if cpe_and_cpe_configurations else set() + vulnerable_cpes = ( + set(itertools.chain.from_iterable(cpe_and_cpe_configurations[0])) if cpe_and_cpe_configurations else set() + ) + vulnerable_cpe_configurations = ( + set(itertools.chain.from_iterable(cpe_and_cpe_configurations[1])) if cpe_and_cpe_configurations else set() + ) published_date = dct["publishedDate"] cwe_ids = cls.parse_cwe_data(dct) diff --git a/tests/cc/test_cc_analysis.py b/tests/cc/test_cc_analysis.py index 57d36841..0c660f04 100644 --- a/tests/cc/test_cc_analysis.py +++ b/tests/cc/test_cc_analysis.py @@ -59,16 +59,16 @@ def cves(cpe_single_sign_on) -> set[CVE]: return { CVE( "CVE-2017-1732", - [cpe_single_sign_on], - [], + {cpe_single_sign_on}, + set(), CVE.Impact(5.3, "MEDIUM", 3.9, 1.4), "2021-05-26T04:15Z", {"CWE-200"}, ), CVE( "CVE-2019-4513", - [cpe_single_sign_on], - [], + {cpe_single_sign_on}, + set(), CVE.Impact(8.2, "HIGH", 3.9, 4.2), "2000-05-26T04:15Z", {"CVE-611"}, diff --git a/tests/fips/test_fips_analysis.py b/tests/fips/test_fips_analysis.py index e68ee6a5..14ec1579 100644 --- a/tests/fips/test_fips_analysis.py +++ b/tests/fips/test_fips_analysis.py @@ -33,8 +33,8 @@ def some_random_cpe() -> CPE: def cve(vulnerable_cpe: CPE) -> CVE: return CVE( "CVE-1234-123456", - [vulnerable_cpe], - [], + {vulnerable_cpe}, + set(), CVE.Impact(10, "HIGH", 10, 10), "2021-05-26T04:15Z", {"CWE-200"}, @@ -45,8 +45,8 @@ def cve(vulnerable_cpe: CPE) -> CVE: def some_other_cve(some_random_cpe: CPE) -> CVE: return CVE( "CVE-2019-4513", - [some_random_cpe], - [], + {some_random_cpe}, + set(), CVE.Impact(8.2, "HIGH", 3.9, 4.2), "2000-05-26T04:15Z", {"CVE-611"}, diff --git a/tests/test_cpe.py b/tests/test_cpe.py index e94aba78..3be2c1a6 100644 --- a/tests/test_cpe.py +++ b/tests/test_cpe.py @@ -151,7 +151,7 @@ def test_serialization_missing_path(): def test_single_platform_config_cpe(cve_dset_with_cpe_configs: CVEDataset): - tested_cpe_config = cve_dset_with_cpe_configs["CVE-2010-2325"].vulnerable_cpe_configurations[0] + tested_cpe_config = cve_dset_with_cpe_configs["CVE-2010-2325"].vulnerable_cpe_configurations cpe_set = { "cpe:2.3:a:ibm:websphere_application_server:7.0:*:*:*:*:*:*:*", "cpe:2.3:a:ibm:websphere_application_server:7.0.0.1:*:*:*:*:*:*:*", @@ -169,7 +169,7 @@ def test_single_platform_config_cpe(cve_dset_with_cpe_configs: CVEDataset): platform="cpe:2.3:o:ibm:zos:*:*:*:*:*:*:*:*", cpes=cpe_set, ) - assert cpe_config == tested_cpe_config + assert cpe_config in tested_cpe_config def test_multiple_platform_config_cpe(cve_dset_with_cpe_configs: CVEDataset): diff --git a/tests/test_cve.py b/tests/test_cve.py index a9c35d4a..441c3c34 100644 --- a/tests/test_cve.py +++ b/tests/test_cve.py @@ -69,16 +69,16 @@ def cves() -> list[CVE]: return [ CVE( "CVE-2017-1732", - [cpe_single_sign_on], - [], + {cpe_single_sign_on}, + set(), CVE.Impact(5.3, "MEDIUM", 3.9, 1.4), "2021-05-26T04:15Z", {"CWE-200"}, ), CVE( "CVE-2019-4513", - [cpe_single_sign_on], - [], + {cpe_single_sign_on}, + set(), CVE.Impact(8.2, "HIGH", 3.9, 4.2), "2000-05-26T04:15Z", {"CVE-611"}, |
