list_unused_certificates: naive NPM-Zeitstempel als UTC behandeln
Tests / test (push) Canceled after 0s
Build and Push Docker Image / build (push) Canceled after 0s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mikei386andClaude Opus 5.5 committed 2026-11-23 14:57:30 +01:00
1 parent bfcf5c2e25
commit 29beba9597
3 files changed
+20 -10

No files matched your search

+8 -1
View File
@@ -740,6 +740,13 @@ async def create_certificate(
# =============================================================================
def _aware(value):
"""NPM returns naive UTC timestamps; make them comparable with aware datetimes."""
from datetime import UTC
return value.replace(tzinfo=UTC) if value.tzinfo is None else value
def _preview(text: str) -> str:
return (
f"Preview only - nothing changed.\n\n{text}\n"
@@ -806,7 +813,7 @@ async def list_unused_certificates(
line = f"[{cert.id}] {', '.join(cert.domain_names)} (expires {expires})"
if cert.id not in usage:
unused.append(line)
elif cert.expires_on and cert.expires_on < soon:
elif cert.expires_on and _aware(cert.expires_on) < soon:
expiring.append(f"{line} - used by {'; '.join(usage[cert.id])}")
parts = [f"Unused certificates ({len(unused)}):"] + (unused or [" none"])
parts += [
+3 -9
View File
@@ -401,9 +401,7 @@ class TestProxyHostLocations:
assert "locations" not in _api_request_body(httpx_mock, "POST")
@pytest.mark.asyncio
async def test_update_preserves_locations_when_omitted(
self, httpx_mock, mock_token_response
):
async def test_update_preserves_locations_when_omitted(self, httpx_mock, mock_token_response):
"""Update without locations must re-send the existing list (no drop)."""
httpx_mock.add_response(
method="POST",
@@ -436,9 +434,7 @@ class TestProxyHostLocations:
assert "access_list_id" not in loc
@pytest.mark.asyncio
async def test_update_replaces_locations_when_provided(
self, httpx_mock, mock_token_response
):
async def test_update_replaces_locations_when_provided(self, httpx_mock, mock_token_response):
"""An explicit locations list replaces the existing one entirely."""
httpx_mock.add_response(
method="POST",
@@ -482,9 +478,7 @@ class TestProxyHostLocations:
"""Preserved locations keep an explicitly set access_list_id."""
host_with_acl = {
**MOCK_HOST_WITH_LOCATIONS,
"locations": [
{**MOCK_HOST_WITH_LOCATIONS["locations"][0], "access_list_id": 5}
],
"locations": [{**MOCK_HOST_WITH_LOCATIONS["locations"][0], "access_list_id": 5}],
}
httpx_mock.add_response(
method="POST",
+9
View File
@@ -274,3 +274,12 @@ async def test_client_certificate_endpoints(httpx_mock):
assert await client.delete_certificate(12) is True
renewed = await client.renew_certificate(10)
assert renewed.id == 10
async def test_unused_certificates_with_naive_npm_timestamps(fake):
naive = (datetime.now(UTC) + timedelta(days=3)).replace(tzinfo=None)
fake.certs[1] = Certificate(
id=11, provider="letsencrypt", domain_names=["xn--hrbuch-wxa.example.de"], expires_on=naive
)
out = await server.list_unused_certificates(expiring_within_days=30)
assert "[11]" in out.partition("Used certificates")[2]