From 43e3de80080ceffa1585765d19e1fac078a2f6aa Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Wed, 18 Oct 2023 14:54:58 -0400 Subject: [PATCH] add sles snapshot tests Signed-off-by: Alex Goodman --- .../snapshots/sles:15.1/cve-2021-29154.json | 1 + .../snapshots/sles:15/cve-2021-29154.json | 1 + tests/unit/providers/sles/test_sles.py | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/unit/providers/sles/test-fixtures/snapshots/sles:15.1/cve-2021-29154.json create mode 100644 tests/unit/providers/sles/test-fixtures/snapshots/sles:15/cve-2021-29154.json diff --git a/tests/unit/providers/sles/test-fixtures/snapshots/sles:15.1/cve-2021-29154.json b/tests/unit/providers/sles/test-fixtures/snapshots/sles:15.1/cve-2021-29154.json new file mode 100644 index 00000000..b125e93f --- /dev/null +++ b/tests/unit/providers/sles/test-fixtures/snapshots/sles:15.1/cve-2021-29154.json @@ -0,0 +1 @@ +{"schema":"https://raw.githubusercontent.com/anchore/vunnel/main/schema/vulnerability/os/schema-1.0.0.json","identifier":"sles:15.1/cve-2021-29154","item":{"Vulnerability":{"Name":"CVE-2021-29154","NamespaceName":"sles:15.1","Description":"BPF JIT compilers in the Linux kernel through 5.11.12 have incorrect computation of branch displacements, allowing them to execute arbitrary code within the kernel context. This affects arch/x86/net/bpf_jit_comp.c and arch/x86/net/bpf_jit_comp32.c.","Severity":"High","Link":"https://www.suse.com/security/cve/CVE-2021-29154","CVSS":[{"version":"3.1","vector_string":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","base_metrics":{"base_score":7.0,"exploitability_score":1.0,"impact_score":5.9,"base_severity":"High"},"status":"N/A"}],"FixedIn":[{"Name":"kernel-default","NamespaceName":"sles:15.1","VersionFormat":"rpm","Version":"0:4.12.14-197.89.2","Module":"","VendorAdvisory":{"NoAdvisory":false,"AdvisorySummary":[]}}],"Metadata":{}}}} diff --git a/tests/unit/providers/sles/test-fixtures/snapshots/sles:15/cve-2021-29154.json b/tests/unit/providers/sles/test-fixtures/snapshots/sles:15/cve-2021-29154.json new file mode 100644 index 00000000..74103153 --- /dev/null +++ b/tests/unit/providers/sles/test-fixtures/snapshots/sles:15/cve-2021-29154.json @@ -0,0 +1 @@ +{"schema":"https://raw.githubusercontent.com/anchore/vunnel/main/schema/vulnerability/os/schema-1.0.0.json","identifier":"sles:15/cve-2021-29154","item":{"Vulnerability":{"Name":"CVE-2021-29154","NamespaceName":"sles:15","Description":"BPF JIT compilers in the Linux kernel through 5.11.12 have incorrect computation of branch displacements, allowing them to execute arbitrary code within the kernel context. This affects arch/x86/net/bpf_jit_comp.c and arch/x86/net/bpf_jit_comp32.c.","Severity":"High","Link":"https://www.suse.com/security/cve/CVE-2021-29154","CVSS":[{"version":"3.1","vector_string":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","base_metrics":{"base_score":7.0,"exploitability_score":1.0,"impact_score":5.9,"base_severity":"High"},"status":"N/A"}],"FixedIn":[{"Name":"kernel-default","NamespaceName":"sles:15","VersionFormat":"rpm","Version":"0:4.12.14-150.72.1","Module":"","VendorAdvisory":{"NoAdvisory":false,"AdvisorySummary":[]}}],"Metadata":{}}}} diff --git a/tests/unit/providers/sles/test_sles.py b/tests/unit/providers/sles/test_sles.py index 2cc7a26b..a2e6f885 100644 --- a/tests/unit/providers/sles/test_sles.py +++ b/tests/unit/providers/sles/test_sles.py @@ -308,3 +308,26 @@ def mock_download(self, *args, **kwargs): assert 2 == workspace.num_result_entries() assert workspace.result_schemas_valid(require_entries=True) + + +def test_provider_via_snapshot(helpers, disable_get_requests, monkeypatch): + workspace = helpers.provider_workspace_helper(name=Provider.name()) + + c = Config() + # keep all of the default values for the result store, but override the strategy + c.runtime.result_store = result.StoreStrategy.FLAT_FILE + p = Provider( + root=workspace.root, + config=c, + ) + + mock_data_path = helpers.local_dir("test-fixtures/suse_truncated.xml") + shutil.copy(mock_data_path, workspace.input_dir / "suse-linux-enterprise-server-15.xml") + + def mock_download(self, *args, **kwargs): + return mock_data_path + + monkeypatch.setattr(p.parser, "_download", mock_download) + p.update(None) + + workspace.assert_result_snapshots()