Skip to content
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

Re-enable ruff in proxy/ folder #2234

Merged
merged 1 commit into from
Sep 30, 2024
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
11 changes: 6 additions & 5 deletions proxy/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import os
import subprocess
from typing import Optional, Union

import pytest

Expand All @@ -20,15 +19,17 @@ def proxy_bin() -> str:

@pytest.fixture
def proxy_request(httpbin, proxy_bin):
def proxy_(
input: Union[bytes, dict], origin: Optional[str] = None
) -> subprocess.CompletedProcess:
def proxy_(input: bytes | dict, origin: str | None = None) -> subprocess.CompletedProcess:
if isinstance(input, dict):
input = json.dumps(input).encode()
if origin is None:
origin = httpbin.url
return subprocess.run(
[proxy_bin], env={"SD_PROXY_ORIGIN": origin}, input=input, capture_output=True
[proxy_bin],
env={"SD_PROXY_ORIGIN": origin},
input=input,
capture_output=True,
check=False,
)

return proxy_
7 changes: 5 additions & 2 deletions proxy/tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Test `securedrop-proxy`'s handling of errors from generic HTTP endpoints, not tied to the SecureDrop SDK."""
"""
Test `securedrop-proxy`'s handling of errors from generic HTTP endpoints,
not tied to the SecureDrop SDK.
"""

import os
import subprocess
Expand All @@ -8,7 +11,7 @@ def test_missing_config(proxy_bin):
env = os.environ.copy()
if "SD_PROXY_ORIGIN" in env:
del env["SD_PROXY_ORIGIN"]
result = subprocess.run([proxy_bin], env=env, capture_output=True)
result = subprocess.run([proxy_bin], env=env, capture_output=True, check=False)
assert result.returncode == 1
assert result.stderr.decode().strip() == '{"error":"environment variable not found"}'

Expand Down
8 changes: 4 additions & 4 deletions proxy/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_json_response(proxy_request):
assert response["headers"]["content-type"] == "application/json"


@pytest.mark.parametrize("status_code", (200, 404, 503))
@pytest.mark.parametrize("status_code", [200, 404, 503])
def test_status_codes(proxy_request, status_code):
"""HTTP errors are passed through cleanly"""
test_input = {
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_timeout(proxy_request, httpbin):
assert result.returncode == 1
assert (
result.stderr.decode().strip()
== '{"error":"error sending request for url (http://127.0.0.1:%s/delay/10): ' % httpbin.port
== f'{{"error":"error sending request for url (http://127.0.0.1:{httpbin.port}/delay/10): '
+ 'operation timed out"}'
)
end = time.time()
Expand All @@ -72,7 +72,7 @@ def test_streaming(proxy_request):
result = proxy_request(input=test_input)
assert result.returncode == 0
stderr = json.loads(result.stderr.decode())
assert "headers" in stderr.keys()
assert "headers" in stderr
assert result.stdout.decode() == "*" * count


Expand All @@ -81,7 +81,7 @@ def test_non_json_response(proxy_request):
result = proxy_request(input=test_input)
assert result.returncode == 0
stderr = json.loads(result.stderr.decode())
assert "headers" in stderr.keys()
assert "headers" in stderr
assert result.stdout.decode().splitlines()[0] == "<!DOCTYPE html>"


Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ shellcheck-py = "*"
[tool.ruff]
line-length = 100
extend-include = ["log/securedrop-{log,log-saver,redis-log}"]
# temporarily ignore until proxy v2
extend-exclude = ["proxy/"]

[tool.ruff.lint]
select = [
Expand Down