from __future__ import annotations
import inspect
import os
import pytest
from ._async_utils import is_async_callable
dcap_qvl = pytest.importorskip("dcap_qvl")
RUN_NETWORK = os.getenv("DCAP_QVL_RUN_NETWORK_TESTS") == "1"
def test_get_collateral_exported() -> None:
assert hasattr(dcap_qvl, "get_collateral")
assert callable(dcap_qvl.get_collateral)
@pytest.mark.asyncio
async def test_get_collateral_returns_awaitable() -> None:
ret = dcap_qvl.get_collateral(
pccs_url="://invalid-url",
raw_quote=b"short",
)
assert inspect.isawaitable(ret)
with pytest.raises(ValueError):
await ret
@pytest.mark.asyncio
@pytest.mark.skipif(
not RUN_NETWORK,
reason="Network test disabled (set DCAP_QVL_RUN_NETWORK_TESTS=1 to enable)",
)
async def test_get_collateral_network_smoke() -> None:
with open("sample/sgx_quote", "rb") as f:
raw_quote = f.read()
collateral = await dcap_qvl.get_collateral(
pccs_url="https://api.trustedservices.intel.com",
raw_quote=raw_quote,
)
assert collateral is not None
assert isinstance(collateral.root_ca_crl, (bytes, bytearray))
assert isinstance(collateral.pck_crl, (bytes, bytearray))
assert isinstance(collateral.tcb_info, str)
assert isinstance(collateral.qe_identity, str)