|
| 1 | +# |
| 2 | +# Copyright (c) nexB Inc. and others. All rights reserved. |
| 3 | +# VulnerableCode is a trademark of nexB Inc. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. |
| 6 | +# See https://github.com/nexB/vulnerablecode for support or download. |
| 7 | +# See https://aboutcode.org for more information about nexB OSS projects. |
| 8 | +# |
| 9 | +import os |
| 10 | +from unittest import TestCase |
| 11 | + |
| 12 | +import saneyaml |
| 13 | + |
| 14 | +from vulnerabilities.importers.osv import parse_advisory_data |
| 15 | +from vulnerabilities.tests import util_tests |
| 16 | + |
| 17 | +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 18 | +TEST_DATA = os.path.join(BASE_DIR, "test_data/oss_fuzz") |
| 19 | + |
| 20 | + |
| 21 | +class TestOSSFuzzImporter(TestCase): |
| 22 | + def test_to_advisories1(self): |
| 23 | + with open(os.path.join(TEST_DATA, "oss-fuzz-data1.yaml")) as f: |
| 24 | + mock_response = saneyaml.load(f) |
| 25 | + expected_file = os.path.join(TEST_DATA, "oss-fuzz-data1.yaml-expected.json") |
| 26 | + imported_data = parse_advisory_data(mock_response, "oss-fuzz") |
| 27 | + result = imported_data.to_dict() |
| 28 | + util_tests.check_results_against_json(result, expected_file) |
| 29 | + |
| 30 | + def test_to_advisorie2(self): |
| 31 | + with open(os.path.join(TEST_DATA, "oss-fuzz-data2.yaml")) as f: |
| 32 | + mock_response = saneyaml.load(f) |
| 33 | + expected_file = os.path.join(TEST_DATA, "oss-fuzz-data2.yaml-expected.json") |
| 34 | + imported_data = parse_advisory_data(mock_response, "oss-fuzz") |
| 35 | + result = imported_data.to_dict() |
| 36 | + util_tests.check_results_against_json(result, expected_file) |
0 commit comments