Some checks failed
Docker Build and Publish / build-and-push (pull_request) Has been skipped
Contributor Attribution Check / check-attribution (pull_request) Failing after 26s
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Successful in 27s
Tests / e2e (pull_request) Successful in 2m31s
Tests / test (pull_request) Failing after 41m50s
Part of #806
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""Tests for A2A mutual TLS (#806)."""
|
|
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
|
|
def test_import():
|
|
"""Module imports cleanly."""
|
|
from agent.a2a_mtls import get_server_ssl_context, get_client_ssl_context, verify_agent_cert
|
|
assert callable(get_server_ssl_context)
|
|
assert callable(get_client_ssl_context)
|
|
assert callable(verify_agent_cert)
|
|
|
|
|
|
def test_default_paths():
|
|
"""Default cert paths resolve correctly."""
|
|
from agent.a2a_mtls import DEFAULT_CERTS_DIR
|
|
assert DEFAULT_CERTS_DIR is not None
|
|
assert "fleet-certs" in str(DEFAULT_CERTS_DIR)
|
|
|
|
|
|
def test_server_context_creation():
|
|
"""Server SSL context can be created with agent name."""
|
|
# This will fail if certs don't exist, which is expected
|
|
from agent.a2a_mtls import get_server_ssl_context
|
|
try:
|
|
ctx = get_server_ssl_context(agent_name="timmy")
|
|
assert ctx is not None
|
|
except FileNotFoundError:
|
|
pass # Expected when certs don't exist
|
|
|
|
|
|
def test_client_context_creation():
|
|
"""Client SSL context can be created with agent name."""
|
|
from agent.a2a_mtls import get_client_ssl_context
|
|
try:
|
|
ctx = get_client_ssl_context(agent_name="timmy")
|
|
assert ctx is not None
|
|
except FileNotFoundError:
|
|
pass # Expected when certs don't exist
|
|
|
|
|
|
def test_verify_agent_cert_invalid():
|
|
"""Invalid cert returns False."""
|
|
from agent.a2a_mtls import verify_agent_cert
|
|
valid, msg = verify_agent_cert("not a cert")
|
|
assert not valid
|
|
|
|
|
|
if __name__ == "__main__":
|
|
tests = [test_import, test_default_paths, test_server_context_creation,
|
|
test_client_context_creation, test_verify_agent_cert_invalid]
|
|
for t in tests:
|
|
print(f"Running {t.__name__}...")
|
|
t()
|
|
print(" PASS")
|
|
print("\nAll tests passed.")
|