-
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathtest_pysec_importer_pipeline.py
More file actions
59 lines (48 loc) · 2.21 KB
/
Copy pathtest_pysec_importer_pipeline.py
File metadata and controls
59 lines (48 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# VulnerableCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import json
from pathlib import Path
from unittest import TestCase
from vulnerabilities.importers.osv import parse_advisory_data
from vulnerabilities.tests.util_tests import VULNERABLECODE_REGEN_TEST_FIXTURES as REGEN
from vulnerabilities.tests.util_tests import check_results_against_json
TEST_DATA = Path(__file__).parent.parent / "test_data" / "pysec"
class TestPyPIImporter(TestCase):
def test_to_advisories_with_summary(self):
with open(TEST_DATA / "pysec-advisories_with_summary.json") as f:
mock_response = json.load(f)
results = parse_advisory_data(mock_response, ["pypi"], "https://test.com").to_dict()
expected_file = TEST_DATA / "pysec-advisories_with_summary-expected.json"
check_results_against_json(
results=results,
expected_file=expected_file,
regen=REGEN,
)
def test_to_advisories_without_summary(self):
with open(TEST_DATA / "pysec-advisories_without_summary.json") as f:
mock_response = json.load(f)
results = parse_advisory_data(mock_response, ["pypi"], "https://test.com").to_dict()
expected_file = TEST_DATA / "pysec-advisories_without_summary-expected.json"
check_results_against_json(
results=results,
expected_file=expected_file,
regen=REGEN,
)
def test_to_advisories_with_cwe(self):
with open(TEST_DATA / "pysec-advisory_with_cwe.json") as f:
mock_response = json.load(f)
results = parse_advisory_data(
raw_data=mock_response, supported_ecosystems=["pypi"], advisory_url="https://tes.com"
).to_dict()
expected_file = TEST_DATA / "pysec-advisories_with_cwe-expected.json"
check_results_against_json(
results=results,
expected_file=expected_file,
regen=REGEN,
)