Skip to content

Commit 79da6b8

Browse files
committed
Add tests for apache kafka advisory importer
Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
1 parent bcdee7d commit 79da6b8

3 files changed

Lines changed: 145 additions & 4 deletions

File tree

vulnerabilities/importers/apache_kafka.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ def to_advisory(self, advisory_page):
5959
cve_description_paragraph = cve_section_beginning.find_next_sibling("p")
6060
cve_data_table = cve_section_beginning.find_next_sibling("table")
6161
cve_data_table_rows = cve_data_table.find_all("tr")
62-
affected_versions_row, fixed_versions_row = (
63-
cve_data_table_rows[0],
64-
cve_data_table_rows[1],
65-
)
62+
affected_versions_row = cve_data_table_rows[0]
63+
fixed_versions_row = cve_data_table_rows[1]
6664
affected_version_ranges = to_version_ranges(
6765
affected_versions_row.find_all("td")[1].text
6866
)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
26+
from dephell_specifier import RangeSpecifier
27+
from packageurl import PackageURL
28+
29+
from vulnerabilities.data_source import Advisory, Reference
30+
from vulnerabilities.package_managers import GitHubTagsAPI
31+
from vulnerabilities.importers.apache_kafka import ApacheKafkaDataSource, to_version_ranges
32+
33+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
34+
TEST_DATA = os.path.join(BASE_DIR, "test_data", "apache_kafka", "cve-list.html")
35+
36+
37+
class TestApacheKafkaDataSource(TestCase):
38+
@classmethod
39+
def setUpClass(cls):
40+
cls.data_source = ApacheKafkaDataSource(batch_size=1)
41+
cls.data_source.version_api = GitHubTagsAPI(
42+
cache={"apache/kafka": ["2.1.2", "0.10.2.2"]}
43+
)
44+
45+
def test_to_version_ranges(self):
46+
# Check single version
47+
assert [RangeSpecifier("==3.2.2")] == to_version_ranges("3.2.2")
48+
49+
# Check range with lower and upper bounds
50+
assert [RangeSpecifier(">=3.2.2, <=3.2.3")] == to_version_ranges("3.2.2 to 3.2.3")
51+
52+
# Check range with "and later"
53+
assert [RangeSpecifier(">=3.2.2")] == to_version_ranges("3.2.2 and later")
54+
55+
# Check combination of above cases
56+
assert [
57+
RangeSpecifier(">=3.2.2"),
58+
RangeSpecifier(">=3.2.2, <=3.2.3"),
59+
RangeSpecifier("==3.2.2"),
60+
] == to_version_ranges("3.2.2 and later, 3.2.2 to 3.2.3, 3.2.2")
61+
62+
def test_to_advisory(self):
63+
expected_data = [
64+
Advisory(
65+
summary="In Apache Kafka versions between 0.11.0.0 and 2.1.0, it is possible to "
66+
"manually\n craft a Produce request which bypasses transaction/idempotent ACL "
67+
"validation.\n Only authenticated clients with Write permission on the "
68+
"respective topics are\n able to exploit this vulnerability. Users should "
69+
"upgrade to 2.1.1 or later\n where this vulnerability has been fixed.",
70+
impacted_package_urls=[
71+
PackageURL(
72+
type="apache",
73+
namespace=None,
74+
name="kafka",
75+
version="0.10.2.2",
76+
qualifiers={},
77+
subpath=None,
78+
)
79+
],
80+
resolved_package_urls=[
81+
PackageURL(
82+
type="apache",
83+
namespace=None,
84+
name="kafka",
85+
version="2.1.2",
86+
qualifiers={},
87+
subpath=None,
88+
)
89+
],
90+
vuln_references=[
91+
Reference(url="https://kafka.apache.org/cve-list", reference_id=""),
92+
Reference(
93+
url="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-17196",
94+
reference_id="CVE-2018-17196",
95+
),
96+
],
97+
cve_id="CVE-2018-17196",
98+
)
99+
]
100+
with open(TEST_DATA) as f:
101+
found_data = self.data_source.to_advisory(f)
102+
103+
assert found_data == expected_data
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!--#include virtual="includes/_header.htm" -->
2+
<body class="page-cve-list ">
3+
<!--#include virtual="includes/_top.htm" -->
4+
<div class="content">
5+
<!--#include virtual="includes/_nav.htm" -->
6+
<div class="right">
7+
8+
<h1>Apache Kafka Security Vulnerabilities</h1>
9+
10+
This page lists all security vulnerabilities fixed in released versions of Apache Kafka
11+
12+
<h2><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-17196">CVE-2018-17196</a>
13+
Authenticated clients with Write permission may bypass transaction/idempotent ACL validation</h2>
14+
<p>In Apache Kafka versions between 0.11.0.0 and 2.1.0, it is possible to manually
15+
craft a Produce request which bypasses transaction/idempotent ACL validation.
16+
Only authenticated clients with Write permission on the respective topics are
17+
able to exploit this vulnerability. Users should upgrade to 2.1.1 or later
18+
where this vulnerability has been fixed.</p>
19+
20+
<table class="data-table">
21+
<tbody>
22+
<tr>
23+
<td>Versions affected</td>
24+
<td>0.11.0.0 to 2.1.0, 0.10.2.2</td>
25+
</tr>
26+
<tr>
27+
<td>Fixed versions</td>
28+
<td>2.1.1 and later</td>
29+
</tr>
30+
<tr>
31+
<td>Impact</td>
32+
<td>This issue could result in privilege escalation.</td>
33+
</tr>
34+
<tr>
35+
<td>Issue announced</td>
36+
<td>10 July 2019</td>
37+
</tr>
38+
</tbody>
39+
</table>
40+
<!--#include virtual="includes/_footer.htm" -->

0 commit comments

Comments
 (0)