|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# |
| 4 | +# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 5 | +# |
| 6 | +import pytest |
| 7 | +import subprocess |
| 8 | + |
| 9 | +DEFAULT_NRAS_GPU_URL = "https://nras.attestation.nvidia.com/v3/attest/gpu" |
| 10 | +DEFAULT_NRAS_SWITCH_URL = "https://nras.attestation.nvidia.com/v3/attest/switch" |
| 11 | +DEFAULT_RIM_SERVICE_URL = "https://rim.attestation.nvidia.com/v1/rim/" |
| 12 | +DEFAULT_OCSP_URL = "https://ocsp.ndis.nvidia.com/" |
| 13 | +DEFAULT_TRUST_OUTPOST_RIM_SERVICE_URL = "https://rim.attestation.nvidia.com/v1/rim/" |
| 14 | +DEFAULT_TRUST_OUTPOST_OCSP_URL = "https://ocsp.ndis.nvidia.com" |
| 15 | + |
| 16 | +def pytest_addoption(parser): |
| 17 | + parser.addoption("--nras-gpu-url", action="store", default=DEFAULT_NRAS_GPU_URL, |
| 18 | + help="NRAS URL for GPU attestation (default: %(default)s)") |
| 19 | + parser.addoption("--nras-switch-url", action="store", default=DEFAULT_NRAS_GPU_URL, |
| 20 | + help="NRAS URL for Switch attestation (default: %(default)s)") |
| 21 | + parser.addoption("--rim-url", action="store", default=DEFAULT_RIM_SERVICE_URL, |
| 22 | + help="RIM URL for attestation (default: %(default)s)") |
| 23 | + parser.addoption("--ocsp-url", action="store", default=DEFAULT_OCSP_URL, |
| 24 | + help="OCSP URL for attestation (default: %(default)s)") |
| 25 | + parser.addoption("--trust-outpost-rim-url", action="store", default=DEFAULT_TRUST_OUTPOST_RIM_SERVICE_URL, |
| 26 | + help="RIM URL for Trust Outpost attestation (default: %(default)s)") |
| 27 | + parser.addoption("--trust-outpost-ocsp-url", action="store", default=DEFAULT_TRUST_OUTPOST_OCSP_URL, |
| 28 | + help="OCSP URL for Trust Outpost attestation (default: %(default)s)") |
| 29 | + parser.addoption("--service-key", action="store", default=None, |
| 30 | + help="Service key for calling attestation services (default: %(default)s)") |
| 31 | + |
| 32 | +@pytest.fixture(autouse=True) |
| 33 | +def nras_gpu_url(request, monkeypatch): |
| 34 | + """Fixture to get the NRAS GPU URL from command line or use default. This also sets the environment variable NV_NRAS_GPU_URL""" |
| 35 | + nras_gpu_url = request.config.getoption("--nras-gpu-url") |
| 36 | + if nras_gpu_url is not None: |
| 37 | + monkeypatch.setenv("NV_NRAS_GPU_URL", nras_gpu_url) |
| 38 | + return nras_gpu_url |
| 39 | + |
| 40 | +@pytest.fixture(autouse=True) |
| 41 | +def nras_switch_url(request, monkeypatch): |
| 42 | + """Fixture to get the NRAS Switch URL from command line or use default. This also sets the environment variable NV_NRAS_NVSWITCH_URL""" |
| 43 | + nras_switch_url = request.config.getoption("--nras-switch-url") |
| 44 | + if nras_switch_url is not None: |
| 45 | + monkeypatch.setenv("NV_NRAS_NVSWITCH_URL", nras_switch_url) |
| 46 | + return nras_switch_url |
| 47 | + |
| 48 | +@pytest.fixture(autouse=True) |
| 49 | +def rim_url(request, monkeypatch): |
| 50 | + """Fixture to get the RIM URL from command line or use default. This also sets the environment variable NV_RIM_URL""" |
| 51 | + rim_url = request.config.getoption("--rim-url") |
| 52 | + if rim_url is not None: |
| 53 | + monkeypatch.setenv("NV_RIM_URL", rim_url) |
| 54 | + return rim_url |
| 55 | + |
| 56 | +@pytest.fixture(autouse=True) |
| 57 | +def trust_outpost_rim_url(request, monkeypatch): |
| 58 | + """Fixture to get the Trust Outpost RIM URL from command line or use default. This also sets the environment variable NV_RIM_URL""" |
| 59 | + trust_outpost_rim_url = request.config.getoption("--trust-outpost-rim-url") |
| 60 | + if trust_outpost_rim_url is not None: |
| 61 | + monkeypatch.setenv("NV_RIM_URL", trust_outpost_rim_url) |
| 62 | + return trust_outpost_rim_url |
| 63 | + |
| 64 | +@pytest.fixture |
| 65 | +def ocsp_url(request, monkeypatch): |
| 66 | + """Fixture to get the OCSP URL from command line or use default. This also sets the environment variable NV_OCSP_URL""" |
| 67 | + ocsp_url = request.config.getoption("--ocsp-url") |
| 68 | + if ocsp_url is not None: |
| 69 | + monkeypatch.setenv("NV_OCSP_URL", ocsp_url) |
| 70 | + return ocsp_url |
| 71 | + |
| 72 | +@pytest.fixture |
| 73 | +def trust_outpost_ocsp_url(request, monkeypatch): |
| 74 | + """Fixture to get the Trust Outpost OCSP URL from command line or use default. This also sets the environment variable NV_OCSP_URL""" |
| 75 | + trust_outpost_ocsp_url = request.config.getoption("--trust-outpost-ocsp-url") |
| 76 | + if trust_outpost_ocsp_url is not None: |
| 77 | + monkeypatch.setenv("NV_OCSP_URL", trust_outpost_ocsp_url) |
| 78 | + return trust_outpost_ocsp_url |
| 79 | + |
| 80 | +@pytest.fixture |
| 81 | +def service_key(request): |
| 82 | + """Fixture to get the service key from command line or use default""" |
| 83 | + return request.config.getoption("--service-key") |
0 commit comments