|
| 1 | +# Copyright (c) 2017 nexB Inc. and others. All rights reserved. |
| 2 | +# http://nexb.com and https://github.com/nexB/vulnerablecode/ |
| 3 | +# The VulnerableCode software is licensed under the Apache License version 2.0. |
| 4 | +# Data generated with VulnerableCode require an acknowledgment. |
| 5 | +# |
| 6 | +# You may not use this software except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 8 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 9 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 10 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | +# specific language governing permissions and limitations under the License. |
| 12 | +# |
| 13 | +# When you publish or redistribute any data created with VulnerableCode or any VulnerableCode |
| 14 | +# derivative work, you must accompany this data with the following acknowledgment: |
| 15 | +# |
| 16 | +# Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 17 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 18 | +# VulnerableCode should be considered or used as legal advice. Consult an Attorney |
| 19 | +# for any legal advice. |
| 20 | +# VulnerableCode is a free software code scanning tool from nexB Inc. and others. |
| 21 | +# Visit https://github.com/nexB/vulnerablecode/ for support and download. |
| 22 | + |
| 23 | +from collections import OrderedDict |
| 24 | +import os |
| 25 | +from unittest import TestCase |
| 26 | +import yaml |
| 27 | + |
| 28 | +from packageurl import PackageURL |
| 29 | + |
| 30 | +from vulnerabilities.importers.suse_backports import SUSEBackportsDataSource |
| 31 | +from vulnerabilities.data_source import Advisory |
| 32 | + |
| 33 | +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 34 | + |
| 35 | + |
| 36 | +def yaml_loader(): |
| 37 | + path = os.path.join(BASE_DIR, "test_data/suse_backports/") |
| 38 | + yaml_files = {} |
| 39 | + for file in os.listdir(path): |
| 40 | + with open(os.path.join(path, file)) as f: |
| 41 | + yaml_files[file] = yaml.safe_load(f) |
| 42 | + return yaml_files |
| 43 | + |
| 44 | + |
| 45 | +class TestSUSEBackportsDataSource(TestCase): |
| 46 | + |
| 47 | + @classmethod |
| 48 | + def setUpClass(cls): |
| 49 | + data_source_cfg = { |
| 50 | + 'url': 'https://endpoint.com', |
| 51 | + 'etags': {}} |
| 52 | + cls.data_src = SUSEBackportsDataSource(1, config=data_source_cfg) |
| 53 | + |
| 54 | + def test_process_file(self): |
| 55 | + parsed_yamls = yaml_loader() |
| 56 | + expected_data = [ |
| 57 | + Advisory( |
| 58 | + summary='', |
| 59 | + impacted_package_urls=[], |
| 60 | + resolved_package_urls=[ |
| 61 | + PackageURL( |
| 62 | + type='rpm', |
| 63 | + namespace='opensuse', |
| 64 | + name='MozillaFirefox', |
| 65 | + version='3.0.10-1.1.1', |
| 66 | + qualifiers=OrderedDict(), |
| 67 | + subpath=None)], |
| 68 | + reference_urls=[], |
| 69 | + reference_ids=[], |
| 70 | + cve_id='CVE-2009-1313'), |
| 71 | + Advisory( |
| 72 | + summary='', |
| 73 | + impacted_package_urls=[], |
| 74 | + resolved_package_urls=[ |
| 75 | + PackageURL( |
| 76 | + type='rpm', |
| 77 | + namespace='opensuse', |
| 78 | + name='MozillaFirefox-branding-SLED', |
| 79 | + version='3.5-1.1.5', |
| 80 | + qualifiers=OrderedDict(), |
| 81 | + subpath=None)], |
| 82 | + reference_urls=[], |
| 83 | + reference_ids=[], |
| 84 | + cve_id='CVE-2009-1313'), |
| 85 | + Advisory( |
| 86 | + summary='', |
| 87 | + impacted_package_urls=[], |
| 88 | + resolved_package_urls=[ |
| 89 | + PackageURL( |
| 90 | + type='rpm', |
| 91 | + namespace='opensuse', |
| 92 | + name='MozillaFirefox-translations', |
| 93 | + version='3.0.10-1.1.1', |
| 94 | + qualifiers=OrderedDict(), |
| 95 | + subpath=None)], |
| 96 | + reference_urls=[], |
| 97 | + reference_ids=[], |
| 98 | + cve_id='CVE-2009-1313'), |
| 99 | + Advisory( |
| 100 | + summary='', |
| 101 | + impacted_package_urls=[], |
| 102 | + resolved_package_urls=[ |
| 103 | + PackageURL( |
| 104 | + type='rpm', |
| 105 | + namespace='opensuse', |
| 106 | + name='NetworkManager', |
| 107 | + version='0.7.0.r4359-15.9.2', |
| 108 | + qualifiers=OrderedDict(), |
| 109 | + subpath=None)], |
| 110 | + reference_urls=[], |
| 111 | + reference_ids=[], |
| 112 | + cve_id='CVE-2009-0365'), |
| 113 | + Advisory( |
| 114 | + summary='', |
| 115 | + impacted_package_urls=[], |
| 116 | + resolved_package_urls=[ |
| 117 | + PackageURL( |
| 118 | + type='rpm', |
| 119 | + namespace='opensuse', |
| 120 | + name='NetworkManager', |
| 121 | + version='0.7.0.r4359-15.9.2', |
| 122 | + qualifiers=OrderedDict(), |
| 123 | + subpath=None)], |
| 124 | + reference_urls=[], |
| 125 | + reference_ids=[], |
| 126 | + cve_id='CVE-2009-0578'), |
| 127 | + ] |
| 128 | + |
| 129 | + found_data = self.data_src.process_file( |
| 130 | + parsed_yamls['backports-sle11-sp0.yaml']) |
| 131 | + assert expected_data == found_data |
0 commit comments