Skip to content

Commit cb0d5f4

Browse files
committed
Add tests for nginx importers
Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
1 parent efe93f6 commit cb0d5f4

3 files changed

Lines changed: 216 additions & 1 deletion

File tree

vulnerabilities/importers/nginx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def set_api(self):
5151
self.version_api = GitHubTagsAPI()
5252
asyncio.run(self.version_api.load_api(["nginx/nginx"]))
5353

54-
# For some reason nginx tags it's releases in the form of `release-1.2.3`
54+
# For some reason nginx tags it's releases are in the form of `release-1.2.3`
5555
# Chop off the `release-` part here.
5656
for index, version in enumerate(self.version_api.cache["nginx/nginx"]):
5757
self.version_api.cache["nginx/nginx"][index] = version.replace("release-", "")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html><head></head>
3+
</p><p>
4+
Patches are signed using one of the
5+
<a href="pgp_keys.html">PGP public keys</a>.
6+
</p><ul>
7+
8+
9+
<li><p>Stack-based buffer overflow with specially crafted request<br>Severity: <b>major</b><br><a href="http://mailman.nginx.org/pipermail/nginx-announce/2013/000112.html">Advisory</a><br><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-2028">CVE-2013-2028</a><br>Not vulnerable: 1.5.0+, 1.4.1+<br>Vulnerable: 1.3.9-1.4.0<br><a href="/download/patch.2013.chunked.txt">The patch</a>  <a href="/download/patch.2013.chunked.txt.asc">pgp</a></p></li>
10+
11+
<!-- Use this -->
12+
<li><p>Vulnerabilities with Windows directory aliases<br>Severity: medium<br><a href="http://mailman.nginx.org/pipermail/nginx-announce/2012/000086.html">Advisory</a><br><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-4963">CVE-2011-4963</a><br>Not vulnerable: 1.3.1+, 1.2.1+<br>Vulnerable: nginx/Windows 0.7.52-1.3.0</p></li>
13+
14+
15+
<!-- Use this -->
16+
<li><p>Vulnerabilities with invalid UTF-8 sequence on Windows<br>Severity: <b>major</b><br><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-2266">CVE-2010-2266</a><br>Not vulnerable: 0.8.41+, 0.7.67+<br>Vulnerable: nginx/Windows 0.7.52-0.8.40</p></li>
17+
18+
19+
<!-- Use this -->
20+
<li><p>An error log data are not sanitized<br>Severity: none<br><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-4487">CVE-2009-4487</a><br>Not vulnerable: none<br>Vulnerable: all</p></li>
21+
22+
23+
<li><p>The renegotiation vulnerability in SSL protocol<br>Severity: <b>major</b><br><a href="http://www.kb.cert.org/vuls/id/120541">VU#120541</a>  <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3555">CVE-2009-3555</a><br>Not vulnerable: 0.8.23+, 0.7.64+<br>Vulnerable: 0.1.0-0.8.22<br><a href="/download/patch.cve-2009-3555.txt">The patch</a>  <a href="/download/patch.cve-2009-3555.txt.asc">pgp</a></p></li>
24+
25+
<li><p>Directory traversal vulnerability<br>Severity: minor<br><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3898">CVE-2009-3898</a><br>Not vulnerable: 0.8.17+, 0.7.63+<br>Vulnerable: 0.1.0-0.8.16</p></li>
26+
/patch.null.pointer.txt">The patch</a>  <a href="/download/patch.null.pointer.txt.asc">pgp</a></p></li>
27+
28+
</ul></div></div></body></html>
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Copyright (c) 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 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 unittest.mock import patch
26+
27+
from packageurl import PackageURL
28+
29+
from vulnerabilities.data_source import Advisory
30+
from vulnerabilities.data_source import Reference
31+
from vulnerabilities.importers.nginx import NginxDataSource
32+
from vulnerabilities.package_managers import GitHubTagsAPI
33+
34+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
35+
TEST_DATA = os.path.join(BASE_DIR, "test_data/nginx", "security_advisories.html")
36+
37+
38+
class TestNginxDataSource(TestCase):
39+
@classmethod
40+
def setUpClass(cls):
41+
with open(TEST_DATA) as f:
42+
cls.data = f.read()
43+
data_source_cfg = {"etags": {}}
44+
cls.data_src = NginxDataSource(1, config=data_source_cfg)
45+
cls.data_src.version_api = GitHubTagsAPI(
46+
cache={"nginx/nginx": {"1.2.3", "1.7.0", "1.3.9", "0.7.52"}}
47+
)
48+
49+
def test_to_advisories(self):
50+
expected_data = sorted(
51+
[
52+
Advisory(
53+
summary="Stack-based buffer overflow with specially crafted request",
54+
impacted_package_urls={
55+
PackageURL(
56+
type="generic",
57+
namespace=None,
58+
name="nginx",
59+
version="1.3.9",
60+
qualifiers={},
61+
subpath=None,
62+
)
63+
},
64+
resolved_package_urls={
65+
PackageURL(
66+
type="generic",
67+
namespace=None,
68+
name="nginx",
69+
version="1.7.0",
70+
qualifiers={},
71+
subpath=None,
72+
)
73+
},
74+
vuln_references=[],
75+
cve_id="CVE-2013-2028",
76+
),
77+
Advisory(
78+
summary="Vulnerabilities with Windows directory aliases",
79+
impacted_package_urls={
80+
PackageURL(
81+
type="generic",
82+
namespace=None,
83+
name="nginx",
84+
version="0.7.52",
85+
qualifiers={"os": "windows"},
86+
subpath=None,
87+
),
88+
PackageURL(
89+
type="generic",
90+
namespace=None,
91+
name="nginx",
92+
version="1.2.3",
93+
qualifiers={"os": "windows"},
94+
subpath=None,
95+
),
96+
},
97+
resolved_package_urls={
98+
PackageURL(
99+
type="generic",
100+
namespace=None,
101+
name="nginx",
102+
version="1.2.3",
103+
qualifiers={},
104+
subpath=None,
105+
),
106+
PackageURL(
107+
type="generic",
108+
namespace=None,
109+
name="nginx",
110+
version="1.3.9",
111+
qualifiers={},
112+
subpath=None,
113+
),
114+
PackageURL(
115+
type="generic",
116+
namespace=None,
117+
name="nginx",
118+
version="1.7.0",
119+
qualifiers={},
120+
subpath=None,
121+
),
122+
},
123+
vuln_references=[],
124+
cve_id="CVE-2011-4963",
125+
),
126+
Advisory(
127+
summary="Vulnerabilities with invalid UTF-8 sequence on Windows",
128+
impacted_package_urls={
129+
PackageURL(
130+
type="generic",
131+
namespace=None,
132+
name="nginx",
133+
version="0.7.52",
134+
qualifiers={"os": "windows"},
135+
subpath=None,
136+
)
137+
},
138+
resolved_package_urls=set(),
139+
vuln_references=[],
140+
cve_id="CVE-2010-2266",
141+
),
142+
Advisory(
143+
summary="An error log data are not sanitized",
144+
impacted_package_urls=set(),
145+
resolved_package_urls={},
146+
vuln_references=[],
147+
cve_id="CVE-2009-4487",
148+
),
149+
Advisory(
150+
summary="The renegotiation vulnerability in SSL protocol",
151+
impacted_package_urls={
152+
PackageURL(
153+
type="generic",
154+
namespace=None,
155+
name="nginx",
156+
version="0.7.52",
157+
qualifiers={},
158+
subpath=None,
159+
)
160+
},
161+
resolved_package_urls=set(),
162+
vuln_references=[],
163+
cve_id="CVE-2009-3555",
164+
),
165+
Advisory(
166+
summary="Directory traversal vulnerability",
167+
impacted_package_urls={
168+
PackageURL(
169+
type="generic",
170+
namespace=None,
171+
name="nginx",
172+
version="0.7.52",
173+
qualifiers={},
174+
subpath=None,
175+
)
176+
},
177+
resolved_package_urls=set(),
178+
vuln_references=[],
179+
cve_id="CVE-2009-3898",
180+
),
181+
],
182+
key=lambda adv: adv.cve_id,
183+
)
184+
185+
found_data = sorted(self.data_src.to_advisories(self.data), key=lambda adv: adv.cve_id)
186+
187+
assert expected_data == found_data

0 commit comments

Comments
 (0)