|
| 1 | +"""Tests for foundational authority spec primitives.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from pydantic import ValidationError |
| 5 | + |
| 6 | +from netengine.spec import Authority, AuthorityKind, AuthorityScope, AuthoritySource |
| 7 | + |
| 8 | + |
| 9 | +def test_authority_defaults_to_local_source() -> None: |
| 10 | + authority = Authority( |
| 11 | + id="world-root", |
| 12 | + kind=AuthorityKind.WORLD_ROOT, |
| 13 | + scope=AuthorityScope.WORLD, |
| 14 | + operator="root-operator", |
| 15 | + controls=["dns.root", "pki.root_ca"], |
| 16 | + ) |
| 17 | + |
| 18 | + assert authority.source == AuthoritySource.LOCAL |
| 19 | + assert authority.description is None |
| 20 | + |
| 21 | + |
| 22 | +def test_authority_accepts_enum_values() -> None: |
| 23 | + authority = Authority( |
| 24 | + id="mail-authority", |
| 25 | + kind="mail", |
| 26 | + scope="org", |
| 27 | + operator="mail-ops", |
| 28 | + controls=["mx.example.internal"], |
| 29 | + source="mirrored", |
| 30 | + ) |
| 31 | + |
| 32 | + assert authority.kind == AuthorityKind.MAIL |
| 33 | + assert authority.scope == AuthorityScope.ORG |
| 34 | + assert authority.source == AuthoritySource.MIRRORED |
| 35 | + |
| 36 | + |
| 37 | +def test_authority_model_is_frozen() -> None: |
| 38 | + authority = Authority( |
| 39 | + id="registry-authority", |
| 40 | + kind=AuthorityKind.DOMAIN_REGISTRY, |
| 41 | + scope=AuthorityScope.INWORLD, |
| 42 | + operator="registry-ops", |
| 43 | + controls=["domains"], |
| 44 | + ) |
| 45 | + |
| 46 | + with pytest.raises(ValidationError): |
| 47 | + authority.operator = "other-operator" |
0 commit comments