decomposer: generate deliverable files for Define the service contract and project architecture for the FastAPI endpoint monitoring service.; Implement the typed monitor CRUD API and concurrency-safe in-memory state according to the service design.; Implement secure on-demand endpoint checks with status updates, latency measurement, robust error handling, and redacted structured logs.; Add operational API endpoints and environment-driven runtime configuration to the monitoring service.; Create automated tests for the monitoring service.; Package the service with Docker and developer documentation.; Validate the complete project.
This commit is contained in:
@@ -1,19 +1,26 @@
|
|||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from app.logging_config import JsonFormatter, redact_url
|
import httpx
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from app.checker import EndpointChecker
|
||||||
|
from app.config import Settings
|
||||||
|
|
||||||
|
|
||||||
def test_redact_url_removes_credentials_query_and_fragment():
|
async def public_resolver(host: str, port: int) -> list[str]:
|
||||||
assert redact_url("https://user:pass@example.com:8443/a?token=secret#x") == "https://example.com:8443/a"
|
return ["93.184.216.34"]
|
||||||
|
|
||||||
|
|
||||||
def test_json_formatter_never_emits_url_secrets():
|
@pytest.mark.anyio
|
||||||
record = logging.LogRecord("test", logging.INFO, "", 0, "event", (), None)
|
async def test_logs_redact_credentials_query_and_fragment(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
record.url = "https://user:pass@example.com/a?token=secret#fragment"
|
checker = EndpointChecker(
|
||||||
record.monitor_id = "123"
|
Settings(),
|
||||||
output = JsonFormatter().format(record)
|
transport=httpx.MockTransport(lambda request: httpx.Response(200)),
|
||||||
parsed = json.loads(output)
|
resolver=public_resolver,
|
||||||
assert parsed["url"] == "https://example.com/a"
|
)
|
||||||
assert "secret" not in output
|
with caplog.at_level(logging.INFO, logger="endpoint_monitor.checker"):
|
||||||
assert "pass" not in output
|
await checker.check("monitor-1", "https://example.com/path?token=topsecret#fragment")
|
||||||
|
record = next(record for record in caplog.records if getattr(record, "event", None) == "check_completed")
|
||||||
|
assert record.url == "https://example.com/path"
|
||||||
|
assert "topsecret" not in record.getMessage()
|
||||||
|
assert "topsecret" not in record.url
|
||||||
|
|||||||
Reference in New Issue
Block a user