Skip to content
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
5 changes: 4 additions & 1 deletion actions/chocolatey-push/chocolatey_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def probe_package_state(package_id: str, http_get=None) -> PackageState:
if package_response.status != 200:
raise ProbeError(f"Chocolatey package endpoint returned HTTP {package_response.status}")

query = urlencode({"$filter": f"Id eq '{_odata_string(package_id)}'", "$orderby": "Version desc"})
query = urlencode(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium (security:security-code-auditor): Missing import for 'quote' function — the code uses 'quote_via=quote' but the import line must read 'from urllib.parse import urlencode, quote' (or equivalent). A missing import causes a NameError at runtime on the moderation probe path.

Reply to this thread when addressed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already present - quote is imported at module scope and was used before this PR.

{"$filter": f"Id eq '{_odata_string(package_id)}'", "$orderby": "Version desc"},
quote_via=quote,
)
feed_response = http_get(f"{COMMUNITY_API}/Packages()?{query}")
if feed_response.status != 200:
raise ProbeError(f"Chocolatey package listing returned HTTP {feed_response.status}")
Expand Down
25 changes: 22 additions & 3 deletions actions/chocolatey-push/test_chocolatey_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,19 @@ def test_forbidden_pending_first_submission_succeeds_with_warning(tmp_path):
work = _working_dir(tmp_path)
choco_dir = work / "packaging" / "chocolatey"
calls = []
seen_urls = []
http_get = _http_get({"/package/codereview-cli": (200, "nupkg"), "/Packages()?": (200, EMPTY_FEED)})

def recording_http_get(url):
seen_urls.append(url)
return http_get(url)

rc = chocolatey_push.pack_and_push(
package_id="codereview-cli",
working_dir=work,
api_key="key",
command_runner=_forbidden_push_runner(tmp_path, calls=calls),
http_get=_http_get({"/package/codereview-cli": (200, "nupkg"), "/Packages()?": (200, EMPTY_FEED)}),
http_get=recording_http_get,
summary_path=str(summary),
)

Expand All @@ -128,6 +134,13 @@ def test_forbidden_pending_first_submission_succeeds_with_warning(tmp_path):
choco_dir,
),
]
assert seen_urls == [
"https://community.chocolatey.org/api/v2/package/codereview-cli",
(
"https://community.chocolatey.org/api/v2/Packages()?"
"%24filter=Id%20eq%20%27codereview-cli%27&%24orderby=Version%20desc"
),
]
assert "was not accepted for this release" in summary.read_text()


Expand Down Expand Up @@ -226,7 +239,10 @@ def http_get(url):

assert state.pending_first_submission is True
assert seen[0] == "https://community.chocolatey.org/api/v2/package/codereview-cli"
assert "%24filter=Id+eq+%27codereview-cli%27" in seen[1]
assert seen[1] == (
"https://community.chocolatey.org/api/v2/Packages()?"
"%24filter=Id%20eq%20%27codereview-cli%27&%24orderby=Version%20desc"
)


def test_probe_package_state_escapes_odata_string_quotes():
Expand All @@ -241,7 +257,10 @@ def http_get(url):
state = chocolatey_push.probe_package_state("code'review-cli", http_get=http_get)

assert state.pending_first_submission is True
assert "%24filter=Id+eq+%27code%27%27review-cli%27" in seen[1]
assert seen[1] == (
"https://community.chocolatey.org/api/v2/Packages()?"
"%24filter=Id%20eq%20%27code%27%27review-cli%27&%24orderby=Version%20desc"
)


def test_request_text_transport_failure_fails_closed(monkeypatch):
Expand Down
Loading