Skip to content

fix: include inspector links with information on if they are reachable. #1102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes
logger.debug(error_msg)
raise HeuristicAnalyzerValueError(error_msg)

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

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

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

detail_info: dict[str, JsonType] = {
"inspector_links": inspector_links,
Expand Down
6 changes: 3 additions & 3 deletions tests/malware_analyzer/pypi/test_wheel_absence.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_analyze_tar_present(mock_send_head_http_raw: MagicMock, pypi_package_js
mock_send_head_http_raw.return_value = MagicMock() # assume valid URL for testing purposes

expected_detail_info = {
"inspector_links": [inspector_link_expected],
"inspector_links": {inspector_link_expected: True},
}

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

expected_detail_info = {
"inspector_links": [inspector_link_expected],
"inspector_links": {inspector_link_expected: True},
}

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

expected_detail_info = {
"inspector_links": [wheel_link_expected, tar_link_expected],
"inspector_links": {wheel_link_expected: True, tar_link_expected: True},
}

expected_result: tuple[HeuristicResult, dict] = (HeuristicResult.PASS, expected_detail_info)
Expand Down
Loading