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+ import os
24+ from unittest import TestCase
25+ from collections import OrderedDict
26+
27+ from vulnerabilities .data_source import Reference
28+ from packageurl import PackageURL
29+
30+ from vulnerabilities .importers .elixir_security import ElixirSecurityDataSource
31+ from vulnerabilities .data_source import Advisory
32+
33+ BASE_DIR = os .path .dirname (os .path .abspath (__file__ ))
34+
35+
36+ class TestElixirSecurityDataSource (TestCase ):
37+
38+ @classmethod
39+ def setUpClass (cls ):
40+ data_source_cfg = {
41+ 'repository_url' : 'https://test.net' , }
42+ cls .data_src = ElixirSecurityDataSource (1 , config = data_source_cfg )
43+
44+ def test_generate_all_versions_list (self ):
45+ package = 'coherence'
46+ actual_list = self .data_src .generate_all_versions_list (package )
47+ expected_list = ['0.5.2' , '0.5.1' , '0.5.0' , '0.4.0' , '0.3.1' , '0.3.0' , '0.2.0' , '0.1.3' , '0.1.2' , '0.1.1' , '0.1.0' ]
48+ assert actual_list == expected_list
49+
50+ def test_process_file (self ):
51+
52+ path = os .path .join (BASE_DIR , "test_data/elixir_security/test_file.yml" )
53+ expected_data = Advisory (
54+ summary = ('The Coherence library has "Mass Assignment"-like vulnerabilities.\n ' ),
55+
56+ impacted_package_urls = [],
57+
58+ resolved_package_urls = {
59+ PackageURL (
60+ type = 'hex' ,
61+ name = 'coherence' ,
62+ version = '0.5.2' ,
63+ ),
64+ },
65+ vuln_references = [
66+ Reference (
67+ url = "https://github.com/smpallen99/coherence/issues/270"
68+ )
69+ ],
70+ cve_id = '2018-20301' )
71+
72+ found_data = self .data_src .process_file (path )
73+
74+ assert expected_data == found_data
0 commit comments