Skip to content

Commit 136d868

Browse files
committed
Add tests for apache httpd improver
Signed-off-by: Tushar Goel <[email protected]>
1 parent 522ab6a commit 136d868

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

vulnerabilities/tests/test_apache_httpd.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99

1010
import json
1111
import os
12+
from unittest import mock
1213

1314
import pytest
1415
from univers.version_constraint import VersionConstraint
1516
from univers.version_range import ApacheVersionRange
1617
from univers.versions import SemverVersion
1718

19+
from vulnerabilities.importer import AdvisoryData
1820
from vulnerabilities.importers.apache_httpd import ApacheHTTPDImporter
21+
from vulnerabilities.importers.apache_httpd import ApacheHTTPDImprover
22+
from vulnerabilities.improvers.default import DefaultImprover
1923
from vulnerabilities.tests import util_tests
2024

2125
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -116,3 +120,24 @@ def test_to_advisory_CVE_2022_28614():
116120
result = advisories.to_dict()
117121
expected_file = os.path.join(TEST_DATA, f"CVE-2022-28614-apache-httpd-expected.json")
118122
util_tests.check_results_against_json(result, expected_file)
123+
124+
125+
@mock.patch("vulnerabilities.importers.apache_httpd.ApacheHTTPDImprover.get_package_versions")
126+
def test_apache_httpd_improver(mock_response):
127+
advisory_file = os.path.join(TEST_DATA, f"CVE-2021-44224-apache-httpd-expected.json")
128+
expected_file = os.path.join(TEST_DATA, f"apache-httpd-improver-expected.json")
129+
with open(advisory_file) as exp:
130+
advisory = AdvisoryData.from_dict(json.load(exp))
131+
mock_response.return_value = [
132+
"2.4.8",
133+
"2.4.9",
134+
"2.4.10",
135+
"2.4.53",
136+
"2.4.54",
137+
]
138+
improvers = [ApacheHTTPDImprover(), DefaultImprover()]
139+
result = []
140+
for improver in improvers:
141+
inference = [data.to_dict() for data in improver.get_inferences(advisory)]
142+
result.extend(inference)
143+
util_tests.check_results_against_json(result, expected_file)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
[
2+
{
3+
"vulnerability_id": null,
4+
"aliases": [
5+
"CVE-2021-44224"
6+
],
7+
"confidence": 100,
8+
"summary": "A crafted URI sent to httpd configured as a forward proxy (ProxyRequests on) can cause a crash (NULL pointer dereference) or, for configurations mixing forward and reverse proxy declarations, can allow for requests to be directed to a declared Unix Domain Socket endpoint (Server Side Request Forgery).\n\nThis issue affects Apache HTTP Server 2.4.7 up to 2.4.51 (included).",
9+
"affected_purls": [
10+
{
11+
"type": "apache",
12+
"namespace": null,
13+
"name": "httpd",
14+
"version": "2.4.8",
15+
"qualifiers": null,
16+
"subpath": null
17+
},
18+
{
19+
"type": "apache",
20+
"namespace": null,
21+
"name": "httpd",
22+
"version": "2.4.9",
23+
"qualifiers": null,
24+
"subpath": null
25+
},
26+
{
27+
"type": "apache",
28+
"namespace": null,
29+
"name": "httpd",
30+
"version": "2.4.10",
31+
"qualifiers": null,
32+
"subpath": null
33+
}
34+
],
35+
"fixed_purl": {
36+
"type": "apache",
37+
"namespace": null,
38+
"name": "httpd",
39+
"version": "2.4.53",
40+
"qualifiers": null,
41+
"subpath": null
42+
},
43+
"references": [
44+
{
45+
"reference_id": "CVE-2021-44224",
46+
"url": "https://httpd.apache.org/security/json/CVE-2021-44224.json",
47+
"severities": [
48+
{
49+
"system": "apache_httpd",
50+
"value": "moderate",
51+
"scoring_elements": ""
52+
}
53+
]
54+
}
55+
],
56+
"weaknesses": []
57+
},
58+
{
59+
"vulnerability_id": null,
60+
"aliases": [
61+
"CVE-2021-44224"
62+
],
63+
"confidence": 100,
64+
"summary": "A crafted URI sent to httpd configured as a forward proxy (ProxyRequests on) can cause a crash (NULL pointer dereference) or, for configurations mixing forward and reverse proxy declarations, can allow for requests to be directed to a declared Unix Domain Socket endpoint (Server Side Request Forgery).\n\nThis issue affects Apache HTTP Server 2.4.7 up to 2.4.51 (included).",
65+
"affected_purls": [
66+
{
67+
"type": "apache",
68+
"namespace": null,
69+
"name": "httpd",
70+
"version": "2.4.7",
71+
"qualifiers": null,
72+
"subpath": null
73+
},
74+
{
75+
"type": "apache",
76+
"namespace": null,
77+
"name": "httpd",
78+
"version": "2.4.51",
79+
"qualifiers": null,
80+
"subpath": null
81+
}
82+
],
83+
"fixed_purl": {
84+
"type": "apache",
85+
"namespace": null,
86+
"name": "httpd",
87+
"version": "2.4.52",
88+
"qualifiers": null,
89+
"subpath": null
90+
},
91+
"references": [
92+
{
93+
"reference_id": "CVE-2021-44224",
94+
"url": "https://httpd.apache.org/security/json/CVE-2021-44224.json",
95+
"severities": [
96+
{
97+
"system": "apache_httpd",
98+
"value": "moderate",
99+
"scoring_elements": ""
100+
}
101+
]
102+
}
103+
],
104+
"weaknesses": []
105+
}
106+
]

0 commit comments

Comments
 (0)