1- #
21# Copyright (c) nexB Inc. and others. All rights reserved.
32# VulnerableCode is a trademark of nexB Inc.
43# SPDX-License-Identifier: Apache-2.0
87#
98
109from pathlib import Path
10+ from unittest import mock
1111
1212from commoncode import testcase
1313from packageurl import PackageURL
1414
1515from vulnerabilities .tests import util_tests
1616from vulntotal .datasources import gitlab
1717
18-
1918class TestGitlab (testcase .FileBasedTesting ):
2019 test_data_dir = str (Path (__file__ ).resolve ().parent / "test_data" / "gitlab" )
2120
@@ -32,17 +31,34 @@ def test_generate_package_advisory_url(self):
3231 expected_file = self .get_test_loc ("package_advisory_url-expected.json" , must_exist = False )
3332 util_tests .check_results_against_json (results , expected_file )
3433
35- def test_parse_html_advisory (self ):
36- advisory_folder = (
37- Path (__file__ )
38- .resolve ()
39- .parent .joinpath ("test_data/gitlab/temp_vulntotal_gitlab_datasource" )
40- )
34+ @mock .patch ('vulntotal.datasources.gitlab.fetch_yaml' )
35+ def test_parse_interesting_advisories (self , mock_fetch_yaml ):
36+ # Mock the yaml file responses
37+ advisory_folder = Path (__file__ ).resolve ().parent .joinpath ("test_data/gitlab/temp_vulntotal_gitlab_datasource/gemnasium-db-master-pypi-Jinja2/pypi/Jinja2" )
38+ yaml_files = []
39+ for file in advisory_folder .iterdir ():
40+ if file .suffix == '.yml' :
41+ with open (file , 'r' ) as f :
42+ yaml_files .append (f .read ())
43+
44+ mock_fetch_yaml .side_effect = yaml_files
45+
46+ purl = PackageURL ("generic" , "namespace" , "test" , "0.1.1" )
47+
48+ yml_files = [
49+ {"name" : "CVE-2014-1402.yml" , "path" : "path/to/CVE-2014-1402.yml" },
50+ {"name" : "CVE-2016-10745.yml" , "path" : "path/to/CVE-2016-10745.yml" },
51+ {"name" : "CVE-2019-8341.yml" , "path" : "path/to/CVE-2019-8341.yml" },
52+ {"name" : "CVE-2019-10906.yml" , "path" : "path/to/CVE-2019-10906.yml" },
53+ {"name" : "CVE-2020-28493.yml" , "path" : "path/to/CVE-2020-28493.yml" }
54+ ]
55+
4156 results = [
4257 adv .to_dict ()
4358 for adv in gitlab .parse_interesting_advisories (
44- advisory_folder , PackageURL ( "generic" , "namespace" , "test" , "0.1.1" ), False
59+ yml_files , purl
4560 )
4661 ]
62+
4763 expected_file = self .get_test_loc ("parsed_advisory-expected.json" , must_exist = False )
4864 util_tests .check_results_against_json (results , expected_file )
0 commit comments