list_unused_certificates: naive NPM-Zeitstempel als UTC behandeln
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bfcf5c2e25
commit
29beba9597
3 files changed
+20
-10
No files matched your search
@@ -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:
|
def _preview(text: str) -> str:
|
||||||
return (
|
return (
|
||||||
f"Preview only - nothing changed.\n\n{text}\n"
|
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})"
|
line = f"[{cert.id}] {', '.join(cert.domain_names)} (expires {expires})"
|
||||||
if cert.id not in usage:
|
if cert.id not in usage:
|
||||||
unused.append(line)
|
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])}")
|
expiring.append(f"{line} - used by {'; '.join(usage[cert.id])}")
|
||||||
parts = [f"Unused certificates ({len(unused)}):"] + (unused or [" none"])
|
parts = [f"Unused certificates ({len(unused)}):"] + (unused or [" none"])
|
||||||
parts += [
|
parts += [
|
||||||
|
|||||||
@@ -401,9 +401,7 @@ class TestProxyHostLocations:
|
|||||||
assert "locations" not in _api_request_body(httpx_mock, "POST")
|
assert "locations" not in _api_request_body(httpx_mock, "POST")
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_update_preserves_locations_when_omitted(
|
async def test_update_preserves_locations_when_omitted(self, httpx_mock, mock_token_response):
|
||||||
self, httpx_mock, mock_token_response
|
|
||||||
):
|
|
||||||
"""Update without locations must re-send the existing list (no drop)."""
|
"""Update without locations must re-send the existing list (no drop)."""
|
||||||
httpx_mock.add_response(
|
httpx_mock.add_response(
|
||||||
method="POST",
|
method="POST",
|
||||||
@@ -436,9 +434,7 @@ class TestProxyHostLocations:
|
|||||||
assert "access_list_id" not in loc
|
assert "access_list_id" not in loc
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_update_replaces_locations_when_provided(
|
async def test_update_replaces_locations_when_provided(self, httpx_mock, mock_token_response):
|
||||||
self, httpx_mock, mock_token_response
|
|
||||||
):
|
|
||||||
"""An explicit locations list replaces the existing one entirely."""
|
"""An explicit locations list replaces the existing one entirely."""
|
||||||
httpx_mock.add_response(
|
httpx_mock.add_response(
|
||||||
method="POST",
|
method="POST",
|
||||||
@@ -482,9 +478,7 @@ class TestProxyHostLocations:
|
|||||||
"""Preserved locations keep an explicitly set access_list_id."""
|
"""Preserved locations keep an explicitly set access_list_id."""
|
||||||
host_with_acl = {
|
host_with_acl = {
|
||||||
**MOCK_HOST_WITH_LOCATIONS,
|
**MOCK_HOST_WITH_LOCATIONS,
|
||||||
"locations": [
|
"locations": [{**MOCK_HOST_WITH_LOCATIONS["locations"][0], "access_list_id": 5}],
|
||||||
{**MOCK_HOST_WITH_LOCATIONS["locations"][0], "access_list_id": 5}
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
httpx_mock.add_response(
|
httpx_mock.add_response(
|
||||||
method="POST",
|
method="POST",
|
||||||
|
|||||||
@@ -274,3 +274,12 @@ async def test_client_certificate_endpoints(httpx_mock):
|
|||||||
assert await client.delete_certificate(12) is True
|
assert await client.delete_certificate(12) is True
|
||||||
renewed = await client.renew_certificate(10)
|
renewed = await client.renew_certificate(10)
|
||||||
assert renewed.id == 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]
|
||||||
Reference in new issue
Block a user