Skip to content
Closed
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
4 changes: 3 additions & 1 deletion src/newsdom_api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class ArticleNode(BaseModel):
body_blocks: List[str] = Field(
default_factory=list,
description="Ordered text blocks that make up the article body.",
json_schema_extra={"example": ["First paragraph of the article.", "Second paragraph."]},
json_schema_extra={
"example": ["First paragraph of the article.", "Second paragraph."]
},
)
images: List[ImageNode] = Field(
default_factory=list,
Expand Down
27 changes: 16 additions & 11 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
security_boundary_middleware,
)

_PDF_FILES = {
"file": ("fixture.pdf", b"%PDF-1.4\n%synthetic\n", "application/pdf")
}
_PDF_FILES = {"file": ("fixture.pdf", b"%PDF-1.4\n%synthetic\n", "application/pdf")}


def _settings(
Expand Down Expand Up @@ -147,9 +145,12 @@ def test_development_disabled_mode_allows_parse_and_warns_once(
assert client.post("/parse", files=_PDF_FILES).status_code == 200
assert parser_spy["count"] == 2
messages = [record.getMessage() for record in caplog.records]
assert messages.count(
"Parser authentication is disabled for the explicit development profile"
) == 1
assert (
messages.count(
"Parser authentication is disabled for the explicit development profile"
)
== 1
)


def test_direct_runtime_settings_reject_invalid_security_invariants() -> None:
Expand Down Expand Up @@ -350,11 +351,15 @@ def test_concurrent_requests_cannot_switch_authentication_state(
)

def request(token: str) -> int:
return TestClient(application).post(
"/parse",
files=_PDF_FILES,
headers={"Authorization": f"Bearer {token}"},
).status_code
return (
TestClient(application)
.post(
"/parse",
files=_PDF_FILES,
headers={"Authorization": f"Bearer {token}"},
)
.status_code
)

tokens = ["fixed" if index % 2 == 0 else "changed" for index in range(20)]
with ThreadPoolExecutor(max_workers=8) as executor:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth_deployment_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _project_version(pyproject_text: str) -> str:
)
match = (
re.search(
r'''^version\s*=\s*(["'])([^"']+)\1\s*(?:#.*)?$''',
r"""^version\s*=\s*(["'])([^"']+)\1\s*(?:#.*)?$""",
project_table.group("body"),
re.MULTILINE,
)
Expand Down
28 changes: 8 additions & 20 deletions tests/test_auth_fail_closed_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
)
from newsdom_api.main import create_app

_PDF_FILES = {
"file": ("fixture.pdf", b"%PDF-1.4\n%synthetic\n", "application/pdf")
}
_PDF_FILES = {"file": ("fixture.pdf", b"%PDF-1.4\n%synthetic\n", "application/pdf")}


def test_default_configuration_without_token_blocks_parser_before_work(
Expand All @@ -36,12 +34,10 @@ def fake_parse_pdf(*_args, **_kwargs):
monkeypatch.setattr("newsdom_api.main._validate_pdf_structure", lambda _: None)
monkeypatch.setattr("newsdom_api.main.parse_pdf", fake_parse_pdf)

application = create_app(
settings, runtime_readiness_probe=lambda: True
application = create_app(settings, runtime_readiness_probe=lambda: True)
response = TestClient(application, raise_server_exceptions=False).post(
"/parse", files=_PDF_FILES
)
response = TestClient(
application, raise_server_exceptions=False
).post("/parse", files=_PDF_FILES)

assert response.status_code == 503
assert response.json() == {"detail": "Service Unavailable"}
Expand All @@ -58,13 +54,9 @@ def test_ready_fails_closed_when_required_authentication_is_unconfigured(
runtime_profile=RuntimeProfile.PRODUCTION,
api_token=None,
)
application = create_app(
settings, runtime_readiness_probe=lambda: True
)
application = create_app(settings, runtime_readiness_probe=lambda: True)

response = TestClient(
application, raise_server_exceptions=False
).get("/ready")
response = TestClient(application, raise_server_exceptions=False).get("/ready")

assert response.status_code == 503
assert response.json() == {"detail": "Service Unavailable"}
Expand All @@ -82,13 +74,9 @@ def test_health_remains_liveness_only_when_authentication_is_unconfigured(
runtime_profile=RuntimeProfile.PRODUCTION,
api_token=None,
)
application = create_app(
settings, runtime_readiness_probe=lambda: False
)
application = create_app(settings, runtime_readiness_probe=lambda: False)

response = TestClient(
application, raise_server_exceptions=False
).get("/health")
response = TestClient(application, raise_server_exceptions=False).get("/health")

assert response.status_code == 200
assert response.json() == {"status": "ok"}
4 changes: 1 addition & 3 deletions tests/test_auth_protocol_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
)
from newsdom_api.main import create_app

_PDF_FILES = {
"file": ("fixture.pdf", b"%PDF-1.4\n%synthetic\n", "application/pdf")
}
_PDF_FILES = {"file": ("fixture.pdf", b"%PDF-1.4\n%synthetic\n", "application/pdf")}
_BEARER_PREFIX = "Bearer "


Expand Down
6 changes: 2 additions & 4 deletions tests/test_project_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,10 @@ def test_project_declares_python_compatible_locked_fuzz_extra():

assert "fuzz = [" in text
assert (
'"atheris==3.0.0 ; platform_system == \'Linux\' and '
'python_version == \'3.11\'"'
"\"atheris==3.0.0 ; platform_system == 'Linux' and python_version == '3.11'\""
) in text
assert (
'"atheris==3.1.0 ; platform_system == \'Linux\' and '
'python_version >= \'3.12\'"'
"\"atheris==3.1.0 ; platform_system == 'Linux' and python_version >= '3.12'\""
) in text
assert _locked_package_versions("atheris") == {(3, 0, 0), (3, 1, 0)}
assert '"pyinstaller==6.21.0"' in text
Expand Down
4 changes: 1 addition & 3 deletions tests/test_pypdf_security_floor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def test_trivy_registry_exception_is_scoped_to_the_example_manifest() -> None:
ignore_document = yaml.safe_load(
Path(".trivyignore.yaml").read_text(encoding="utf-8")
)
exceptions = {
entry["id"]: entry for entry in ignore_document["misconfigurations"]
}
exceptions = {entry["id"]: entry for entry in ignore_document["misconfigurations"]}

assert trivy_config["ignorefile"] == ".trivyignore.yaml"
assert exceptions["KSV-0125"]["paths"] == [
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading