tests/conftest.py
| 1 | """Shared pytest fixtures.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | |
| 7 | import pytest |
| 8 | from quantumshield.identity.agent import AgentIdentity |
| 9 | |
| 10 | from pqc_gpu_driver import DriverAttester, DriverModule |
| 11 | |
| 12 | |
| 13 | @pytest.fixture |
| 14 | def signer_identity() -> AgentIdentity: |
| 15 | """A generic signer identity used as the default driver attester.""" |
| 16 | return AgentIdentity.create("test-driver-signer", capabilities=["attest"]) |
| 17 | |
| 18 | |
| 19 | @pytest.fixture |
| 20 | def trusted_identity() -> AgentIdentity: |
| 21 | """An identity that is on the verifier's trusted allow-list.""" |
| 22 | return AgentIdentity.create("trusted-gpu-vendor", capabilities=["attest"]) |
| 23 | |
| 24 | |
| 25 | @pytest.fixture |
| 26 | def untrusted_identity() -> AgentIdentity: |
| 27 | """An identity NOT on the verifier's trusted allow-list.""" |
| 28 | return AgentIdentity.create("rogue-driver-author", capabilities=["attest"]) |
| 29 | |
| 30 | |
| 31 | @pytest.fixture |
| 32 | def attester(signer_identity: AgentIdentity) -> DriverAttester: |
| 33 | return DriverAttester(signer_identity) |
| 34 | |
| 35 | |
| 36 | @pytest.fixture |
| 37 | def sample_module_bytes() -> bytes: |
| 38 | """Deterministic 4KB blob that stands in for a .ko driver module.""" |
| 39 | return b"\x00NVIDIA-GPU-DRV\x00" + b"\xaa" * (4096 - 16) |
| 40 | |
| 41 | |
| 42 | @pytest.fixture |
| 43 | def sample_module(sample_module_bytes: bytes) -> DriverModule: |
| 44 | return DriverModule( |
| 45 | name="nvidia.ko", |
| 46 | version="550.54.14", |
| 47 | module_hash=DriverModule.hash_module_bytes(sample_module_bytes), |
| 48 | module_size=len(sample_module_bytes), |
| 49 | target="linux", |
| 50 | ) |
| 51 | |
| 52 | |
| 53 | @pytest.fixture |
| 54 | def random_tensor_bytes() -> bytes: |
| 55 | """1 KiB of random bytes to use as a fake tensor payload.""" |
| 56 | return os.urandom(1024) |
| 57 | |