diff options
| author | Adam Janovsky | 2023-04-20 15:30:33 +0200 |
|---|---|---|
| committer | Adam Janovsky | 2023-04-20 15:30:33 +0200 |
| commit | 9545cae8288e7e58e3b1df409fc27b7f164087d9 (patch) | |
| tree | a90d590846bffdcfea3653f0f423fd89e2033a73 | |
| parent | b0ca54fdd4fc3db8b52fe4d875af7190a9e20329 (diff) | |
| download | sec-certs-9545cae8288e7e58e3b1df409fc27b7f164087d9.tar.gz sec-certs-9545cae8288e7e58e3b1df409fc27b7f164087d9.tar.zst sec-certs-9545cae8288e7e58e3b1df409fc27b7f164087d9.zip | |
share some fixtures
| -rw-r--r-- | src/sec_certs/dataset/cve.py | 2 | ||||
| -rw-r--r-- | tests/cc/test_cc_analysis.py | 20 | ||||
| -rw-r--r-- | tests/fips/test_fips_analysis.py | 19 | ||||
| -rw-r--r-- | tests/test_cpe.py | 21 | ||||
| -rw-r--r-- | tests/test_cve.py | 37 |
5 files changed, 23 insertions, 76 deletions
diff --git a/src/sec_certs/dataset/cve.py b/src/sec_certs/dataset/cve.py index 8bf3b40e..79016991 100644 --- a/src/sec_certs/dataset/cve.py +++ b/src/sec_certs/dataset/cve.py @@ -111,7 +111,7 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): def build_lookup_dict( self, cpe_match_feed: dict, - limit_to_cpes: set[CPE] | None = None, + limit_to_cpes: set[CPE] = set(), ): self._cpe_uri_to_cve_ids_lookup = {} cpe_uris_of_interest = {x.uri for x in limit_to_cpes} if limit_to_cpes else None diff --git a/tests/cc/test_cc_analysis.py b/tests/cc/test_cc_analysis.py index cb15e195..fb2633d9 100644 --- a/tests/cc/test_cc_analysis.py +++ b/tests/cc/test_cc_analysis.py @@ -1,6 +1,5 @@ from __future__ import annotations -import json import shutil from importlib import resources from pathlib import Path @@ -25,25 +24,6 @@ def analysis_data_dir() -> Path: @pytest.fixture(scope="module") -def cpe_dataset() -> CPEDataset: - with resources.path(tests.data.common, "cpe_dataset.json") as path: - return CPEDataset.from_json(path) - - -@pytest.fixture(scope="module") -def cve_dataset() -> CVEDataset: - with resources.open_text(tests.data.common, "cpe_match_feed.json") as handle: - cpe_match_feed = json.load(handle) - - with resources.path(tests.data.common, "cve_dataset.json") as path: - cve_dataset = CVEDataset.from_json(path) - - cve_dataset.build_lookup_dict(cpe_match_feed) - - return cve_dataset - - -@pytest.fixture(scope="module") def processed_cc_dset( analysis_data_dir: Path, cve_dataset: CVEDataset, cpe_dataset: CPEDataset, tmp_path_factory ) -> CCDataset: diff --git a/tests/fips/test_fips_analysis.py b/tests/fips/test_fips_analysis.py index b95e8409..4827f43e 100644 --- a/tests/fips/test_fips_analysis.py +++ b/tests/fips/test_fips_analysis.py @@ -1,6 +1,5 @@ from __future__ import annotations -import json from importlib import resources import pytest @@ -12,24 +11,6 @@ from sec_certs.dataset.fips import FIPSDataset @pytest.fixture(scope="module") -def cpe_dataset() -> CPEDataset: - with resources.path(tests.data.common, "cpe_dataset.json") as cpe_dataset_path: - return CPEDataset.from_json(cpe_dataset_path) - - -@pytest.fixture(scope="module") -def cve_dataset() -> CVEDataset: - with resources.open_text(tests.data.common, "cpe_match_feed.json") as handle: - cpe_match_feed = json.load(handle) - - with resources.path(tests.data.common, "cve_dataset.json") as cve_dataset_path: - cve_dataset = CVEDataset.from_json(cve_dataset_path) - - cve_dataset.build_lookup_dict(cpe_match_feed) - return cve_dataset - - -@pytest.fixture(scope="module") def toy_static_dataset() -> FIPSDataset: with resources.path(tests.data.fips.dataset, "toy_dataset.json") as dataset_path: return FIPSDataset.from_json(dataset_path) diff --git a/tests/test_cpe.py b/tests/test_cpe.py index bd355576..22cf69ea 100644 --- a/tests/test_cpe.py +++ b/tests/test_cpe.py @@ -1,28 +1,15 @@ from __future__ import annotations -from importlib import resources from pathlib import Path import pytest -import tests.data.common from sec_certs import constants from sec_certs.dataset import CPEDataset from sec_certs.sample import CPE from sec_certs.serialization.json import SerializationError -@pytest.fixture(scope="module") -def cpe_dataset_path() -> Path: - with resources.path(tests.data.common, "cpe_dataset.json") as path: - return path - - -@pytest.fixture(scope="module") -def cpe_dataset(cpe_dataset_path: Path) -> CPEDataset: - return CPEDataset.from_json(cpe_dataset_path) - - def test_cpe_dset_from_json(cpe_dataset_path: Path, cpe_dataset: CPEDataset, tmp_path: Path): assert CPEDataset.from_json(cpe_dataset_path) == cpe_dataset @@ -82,3 +69,11 @@ def test_serialization_missing_path(): dummy_dset = CPEDataset() with pytest.raises(SerializationError): dummy_dset.to_json() + + +def test_enhance_with_nvd_data(): + pass + + +def test_criteria_configuration_expansion(): + pass diff --git a/tests/test_cve.py b/tests/test_cve.py index 6f5cd7ff..35636b82 100644 --- a/tests/test_cve.py +++ b/tests/test_cve.py @@ -1,38 +1,15 @@ from __future__ import annotations import itertools -import json -from importlib import resources from pathlib import Path import pytest -import tests.data.common from sec_certs.dataset import CVEDataset from sec_certs.sample import CVE from sec_certs.serialization.json import SerializationError -@pytest.fixture(scope="module") -def cve_dataset_path() -> Path: - with resources.path(tests.data.common, "cve_dataset.json") as cve_dataset_path: - return cve_dataset_path - - -@pytest.fixture(scope="module") -def cpe_match_feed() -> dict: - with resources.open_text(tests.data.common, "cpe_match_feed.json") as handle: - data = json.load(handle) - return data - - -@pytest.fixture(scope="module") -def cve_dataset(cve_dataset_path: Path, cpe_match_feed: dict) -> CVEDataset: - cve_dataset = CVEDataset.from_json(cve_dataset_path) - cve_dataset.build_lookup_dict(cpe_match_feed) - return cve_dataset - - def test_cve_dset_lookup_dicts(cve_dataset: CVEDataset): assert cve_dataset._cpe_uri_to_cve_ids_lookup["cpe:2.3:o:linux:linux_kernel:2.4.18:*:*:*:*:*:*:*"] == { "CVE-2003-0001" @@ -85,3 +62,17 @@ def test_serialization_missing_path(): dummy_dset = CVEDataset({}) with pytest.raises(SerializationError): dummy_dset.to_json() + + +# def test_enhance_with_nvd_data(): +# pass + + +# def test_dataset_prunning(cve_dataset_path: Path, cpe_match_feed: dict): +# cve_dataset = CVEDataset.from_json(cve_dataset_path) +# cpes_to_consider = set() +# cve_dataset.build_lookup_dict( +# cpe_match_feed, +# ) +# # TODO: Note that also CVEs with configurations are being prunned, their prunning must also be tested. +# pass |
