Files
rose-ash/federation/tests/test_identity.py
giles 3809affcab
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m11s
Test dashboard: full menu system, all-service tests, filtering
- Run tests for all 10 services via per-service pytest subprocesses
- Group results by service with section headers
- Clickable summary cards filter by outcome (passed/failed/errors/skipped)
- Service filter nav using ~nav-link buttons in menu bar
- Full menu integration: ~header-row + ~header-child + ~menu-row
- Show logo image via cart-mini rendering
- Mount full service directories in docker-compose for test access
- Add 24 unit test files across 9 services

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 22:54:25 +00:00

71 lines
1.8 KiB
Python

"""Unit tests for federation identity validation."""
from __future__ import annotations
import pytest
from federation.bp.identity.routes import USERNAME_RE, RESERVED
class TestUsernameRegex:
def test_valid_simple(self):
assert USERNAME_RE.match("alice")
def test_valid_with_numbers(self):
assert USERNAME_RE.match("user42")
def test_valid_with_underscore(self):
assert USERNAME_RE.match("alice_bob")
def test_min_length(self):
assert USERNAME_RE.match("abc")
def test_too_short(self):
assert not USERNAME_RE.match("ab")
def test_single_char(self):
assert not USERNAME_RE.match("a")
def test_max_length(self):
assert USERNAME_RE.match("a" * 32)
def test_too_long(self):
assert not USERNAME_RE.match("a" * 33)
def test_starts_with_digit(self):
assert not USERNAME_RE.match("1abc")
def test_starts_with_underscore(self):
assert not USERNAME_RE.match("_abc")
def test_uppercase_rejected(self):
assert not USERNAME_RE.match("Alice")
def test_hyphen_rejected(self):
assert not USERNAME_RE.match("alice-bob")
def test_spaces_rejected(self):
assert not USERNAME_RE.match("alice bob")
def test_empty_rejected(self):
assert not USERNAME_RE.match("")
class TestReservedUsernames:
def test_admin_reserved(self):
assert "admin" in RESERVED
def test_root_reserved(self):
assert "root" in RESERVED
def test_api_reserved(self):
assert "api" in RESERVED
def test_inbox_reserved(self):
assert "inbox" in RESERVED
def test_normal_name_not_reserved(self):
assert "alice" not in RESERVED
def test_at_least_20_reserved(self):
assert len(RESERVED) >= 20