Skip to content

Commit 35dd417

Browse files
authored
fix: include inspector links with information on if they are reachable. (#1102)
The detail info containing inspector links now contains links as keys regardless of whether they are reachable, and includes a boolean value for reachability. Signed-off-by: Carl Flottmann <[email protected]>
1 parent 06fd636 commit 35dd417

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/macaron/malware_analyzer/pypi_heuristics/metadata/wheel_absence.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes
7070
logger.debug(error_msg)
7171
raise HeuristicAnalyzerValueError(error_msg)
7272

73-
inspector_links: list[JsonType] = []
73+
# Contains a boolean field identifying if the link is reachable by this Macaron instance or not.
74+
inspector_links: dict[str, JsonType] = {}
7475
wheel_present: bool = False
7576

7677
release_distributions = json_extract(releases, [version], list)
@@ -120,10 +121,9 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes
120121
)
121122

122123
# use a head request because we don't care about the response contents
123-
if send_head_http_raw(inspector_link) is None:
124-
inspector_links.append(None)
125-
else:
126-
inspector_links.append(inspector_link)
124+
inspector_links[inspector_link] = False
125+
if send_head_http_raw(inspector_link):
126+
inspector_links[inspector_link] = True # link was reachable
127127

128128
detail_info: dict[str, JsonType] = {
129129
"inspector_links": inspector_links,

tests/malware_analyzer/pypi/test_wheel_absence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_analyze_tar_present(mock_send_head_http_raw: MagicMock, pypi_package_js
7575
mock_send_head_http_raw.return_value = MagicMock() # assume valid URL for testing purposes
7676

7777
expected_detail_info = {
78-
"inspector_links": [inspector_link_expected],
78+
"inspector_links": {inspector_link_expected: True},
7979
}
8080

8181
expected_result: tuple[HeuristicResult, dict] = (HeuristicResult.FAIL, expected_detail_info)
@@ -134,7 +134,7 @@ def test_analyze_whl_present(mock_send_head_http_raw: MagicMock, pypi_package_js
134134
mock_send_head_http_raw.return_value = MagicMock() # assume valid URL for testing purposes
135135

136136
expected_detail_info = {
137-
"inspector_links": [inspector_link_expected],
137+
"inspector_links": {inspector_link_expected: True},
138138
}
139139

140140
expected_result: tuple[HeuristicResult, dict] = (HeuristicResult.PASS, expected_detail_info)
@@ -222,7 +222,7 @@ def test_analyze_both_present(mock_send_head_http_raw: MagicMock, pypi_package_j
222222
mock_send_head_http_raw.return_value = MagicMock() # assume valid URL for testing purposes
223223

224224
expected_detail_info = {
225-
"inspector_links": [wheel_link_expected, tar_link_expected],
225+
"inspector_links": {wheel_link_expected: True, tar_link_expected: True},
226226
}
227227

228228
expected_result: tuple[HeuristicResult, dict] = (HeuristicResult.PASS, expected_detail_info)

0 commit comments

Comments
 (0)