Skip to content

Commit 4eebd93

Browse files
committed
Add test for Kafka v2 pipeline
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 8941ae3 commit 4eebd93

File tree

4 files changed

+1865
-0
lines changed

4 files changed

+1865
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
11+
from pathlib import Path
12+
from unittest.mock import patch
13+
14+
from bs4 import BeautifulSoup
15+
from django.test import TestCase
16+
17+
from vulnerabilities.models import AdvisoryV2
18+
from vulnerabilities.pipelines.v2_importers.apache_kafka_importer import ApacheKafkaImporterPipeline
19+
from vulnerabilities.tests import util_tests
20+
from vulnerabilities.tests.pipelines import TestLogger
21+
22+
TEST_DATA = Path(__file__).parent.parent.parent / "test_data" / "apache_kafka"
23+
24+
25+
class TestApacheKafkaImporterPipeline(TestCase):
26+
def setUp(self):
27+
self.logger = TestLogger()
28+
29+
@patch(
30+
"vulnerabilities.pipelines.v2_importers.apache_kafka_importer.ApacheKafkaImporterPipeline.fetch"
31+
)
32+
def test_redhat_advisories_v2(self, mock_fetch):
33+
mock_fetch.__name__ = "fetch"
34+
cve_list = TEST_DATA / "cve-list-2026_01_23.html"
35+
advisory_data = open(cve_list).read()
36+
37+
pipeline = ApacheKafkaImporterPipeline()
38+
pipeline.soup = BeautifulSoup(advisory_data, features="lxml")
39+
pipeline.log = self.logger.write
40+
pipeline.execute()
41+
42+
expected_file = TEST_DATA / "cve-list-2026_01_23-expected.json"
43+
result = [adv.to_advisory_data().to_dict() for adv in AdvisoryV2.objects.all()]
44+
util_tests.check_results_against_json(result, expected_file)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
11+
from pathlib import Path
12+
from unittest import TestCase
13+
14+
from bs4 import BeautifulSoup
15+
16+
from vulnerabilities.pipes.apache_kafka import get_original_advisory
17+
from vulnerabilities.pipes.apache_kafka import parse_range
18+
from vulnerabilities.pipes.apache_kafka import parse_summary
19+
from vulnerabilities.tests.pipelines import TestLogger
20+
21+
TEST_DATA = Path(__file__).parent.parent / "test_data" / "apache_kafka"
22+
23+
24+
class TestPipeApacheKafka(TestCase):
25+
def setUp(self):
26+
self.logger = TestLogger()
27+
cve_list = TEST_DATA / "cve-list-2026_01_23.html"
28+
advisory_data = open(cve_list).read()
29+
soup = BeautifulSoup(advisory_data, features="lxml")
30+
self.tables = soup.find(class_="td-content").find_all("table")
31+
self.tables = list(self.tables)
32+
33+
def test_vulnerability_pipes_apache_kafka_get_summary(self):
34+
table = self.tables[0]
35+
cve_h2 = table.find_previous("h2")
36+
37+
result = parse_summary(
38+
cve_h2=cve_h2,
39+
table=table,
40+
)
41+
expected = (
42+
"In CVE-2023-25194, we announced the RCE/Denial of service attack via SASL "
43+
"JAAS JndiLoginModule configuration in Kafka Connect API. But not only Kafka "
44+
"Connect API is vulnerable to this attack, the Apache Kafka brokers also have "
45+
"this vulnerability. To exploit this vulnerability, the attacker needs to be "
46+
"able to connect to the Kafka cluster and have the AlterConfigs permission on "
47+
"the cluster resource. Since Apache Kafka 3.4.0, we have added a system property "
48+
'("-Dorg.apache.kafka.disallowed.login.modules") to disable the problematic login '
49+
"modules usage in SASL JAAS configuration. Also by default "
50+
"“com.sun.security.auth.module.JndiLoginModule” is disabled in Apache Kafka 3.4.0, "
51+
"and “com.sun.security.auth.module.JndiLoginModule,com.sun.security.auth.module.LdapLoginModule” "
52+
"is disabled by default in Apache Kafka 3.9.1/4.0.0. "
53+
)
54+
self.assertEqual(result, expected)
55+
56+
def test_vulnerability_pipes_apache_kafka_get_original_advisory(self):
57+
table = self.tables[0]
58+
cve_h2 = table.find_previous("h2")
59+
60+
result = get_original_advisory(
61+
cve_h2=cve_h2,
62+
table=table,
63+
)
64+
65+
self.assertIn('id="CVE-2025-27819"', result)
66+
self.assertIn("<p>2.0.0 - 3.3.2</p>", result)
67+
68+
def test_vulnerability_pipes_apache_kafka_parse_range(self):
69+
affected = "2.8.0 - 2.8.1, 3.0.0 - 3.0.1, 3.1.0 - 3.1.1, 3.2.0 - 3.2.1"
70+
71+
result_affected = parse_range(affected)
72+
result_affected = [str(const) for const in result_affected]
73+
expected_affected = [
74+
">=2.8.0",
75+
"<=2.8.1",
76+
">=3.0.0",
77+
"<=3.0.1",
78+
">=3.1.0",
79+
"<=3.1.1",
80+
">=3.2.0",
81+
"<=3.2.1",
82+
]
83+
84+
self.assertCountEqual(result_affected, expected_affected)
85+
86+
def test_vulnerability_pipes_apache_kafka_parse_range_dirty_range(self):
87+
affected = "Apache Kafka Connect API (connect-api,connect-runtime) : 2.3.0 - 3.3.2"
88+
89+
result_affected = parse_range(affected)
90+
result_affected = [str(const) for const in result_affected]
91+
expected_affected = [">=2.3.0", "<=3.3.2"]
92+
93+
self.assertCountEqual(result_affected, expected_affected)

0 commit comments

Comments
 (0)