Close certificate auth before revoking worker tokens and rotating its secret

This commit is contained in:
2026-11-16 12:03:49 +03:00
parent d8455d9417
commit 040fa8d4da
6 changed files with 156 additions and 5 deletions
+5 -3
View File
@@ -16,12 +16,14 @@ def honor_login_retry_after():
self, method, path, expected=200, body=None, actor=None, headers=None, raw=None, schema=None
):
global _paced_logins
if method != "POST" or path != "/api/v1/auth/sessions" or expected != 201:
if method != "POST" or path != "/api/v1/auth/sessions" or expected not in (201, 401):
return original(self, method, path, expected, body, actor, headers, raw, schema)
deadline = time.monotonic() + 90
while True:
response = original(self, method, path, [201, 429], body, actor, headers, raw, schema)
if response["status"] == 201:
response = original(
self, method, path, [expected, 429], body, actor, headers, raw, schema
)
if response["status"] == expected:
return response
if time.monotonic() >= deadline:
pytest.fail("Shared login budget did not recover within test deadline")
+45
View File
@@ -0,0 +1,45 @@
"""Real exporter failure must remain bounded and account for lost sampled spans."""
import json
import os
import subprocess
import sys
from pathlib import Path
def test_span_queue_loss_conservation_when_collector_absent():
code = """
import json, time
from messenger.telemetry import setup
class Pool:
def get_stats(self): return {}
class Store:
pool=Pool()
t=setup("messenger-api")
t.start_background(Store())
for index in range(1200):
with t.tracer.start_as_current_span("synthetic-safe-span"):
pass
time.sleep(7)
counts=t.export_stats.snapshot()
pending=len(t.batch_spans._batch_processor._queue)
loss=counts["spans_recorded"]-counts["spans_exported"]-counts["spans_export_failed"]-counts["spans_in_flight"]-pending
assert counts["spans_recorded"]==1200
assert 0<=pending<=256
assert loss>0
assert counts["spans_export_failed"]>0
print(json.dumps({"recorded":1200,"pending":pending,"queue_lost":loss,"export_failed":counts["spans_export_failed"]}))
t.close()
"""
env = {
**os.environ,
"PYTHONPATH": str(Path(__file__).resolve().parents[1] / "src"),
"OTEL_ENABLED": "1",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://127.0.0.1:1",
}
result = subprocess.run(
[sys.executable, "-c", code], env=env, capture_output=True, text=True, timeout=15
)
assert result.returncode == 0, result.stderr[-1000:]
payload = json.loads(next(line for line in result.stdout.splitlines() if line.startswith("{")))
assert payload["queue_lost"] > 0
+22
View File
@@ -0,0 +1,22 @@
import pytest
from pydantic import ValidationError
from messenger.models import CreateChat, CreateMessage, CreateUser
@pytest.mark.parametrize("scalar", ["\ud800", "\udfff"])
def test_unpaired_surrogates_rejected(scalar):
for factory in (
lambda: CreateUser(username="valid_user", display_name=scalar, password="valid-pass-123"),
lambda: CreateUser(
username="valid_user", display_name="Valid", password="valid-pass-" + scalar
),
lambda: CreateChat(title=scalar, member_ids=["00000000-0000-4000-8000-000000000001"]),
lambda: CreateMessage(text=scalar),
):
with pytest.raises(ValidationError):
factory()
def test_valid_unicode_and_nul():
assert CreateMessage(text="😀\x00").text == "😀\x00"