Home | History | Annotate | Line # | Download | only in isctest
      1      1.1  christos #!/usr/bin/python3
      2      1.1  christos 
      3      1.1  christos # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      4      1.1  christos #
      5      1.1  christos # SPDX-License-Identifier: MPL-2.0
      6      1.1  christos #
      7      1.1  christos # This Source Code Form is subject to the terms of the Mozilla Public
      8      1.1  christos # License, v. 2.0.  If a copy of the MPL was not distributed with this
      9      1.1  christos # file, you can obtain one at https://mozilla.org/MPL/2.0/.
     10      1.1  christos #
     11      1.1  christos # See the COPYRIGHT file distributed with this work for additional
     12      1.1  christos # information regarding copyright ownership.
     13      1.1  christos 
     14      1.1  christos import os
     15      1.1  christos from pathlib import Path
     16  1.1.1.5  christos import platform
     17  1.1.1.5  christos import socket
     18  1.1.1.3  christos import shutil
     19      1.1  christos import subprocess
     20      1.1  christos 
     21      1.1  christos import pytest
     22      1.1  christos 
     23      1.1  christos long_test = pytest.mark.skipif(
     24  1.1.1.4  christos     not os.environ.get("CI_ENABLE_LONG_TESTS"), reason="CI_ENABLE_LONG_TESTS not set"
     25  1.1.1.4  christos )
     26  1.1.1.4  christos 
     27  1.1.1.4  christos live_internet_test = pytest.mark.skipif(
     28  1.1.1.4  christos     not os.environ.get("CI_ENABLE_LIVE_INTERNET_TESTS"),
     29  1.1.1.4  christos     reason="CI_ENABLE_LIVE_INTERNET_TESTS not set",
     30      1.1  christos )
     31      1.1  christos 
     32      1.1  christos 
     33      1.1  christos DNSRPS_BIN = Path(os.environ["TOP_BUILDDIR"]) / "bin/tests/system/rpz/dnsrps"
     34      1.1  christos 
     35      1.1  christos 
     36      1.1  christos def is_dnsrps_available():
     37  1.1.1.5  christos     if os.getenv("FEATURE_DNSRPS") != "1":
     38      1.1  christos         return False
     39      1.1  christos     try:
     40      1.1  christos         subprocess.run([DNSRPS_BIN, "-a"], check=True)
     41      1.1  christos     except subprocess.CalledProcessError:
     42      1.1  christos         return False
     43      1.1  christos     return True
     44      1.1  christos 
     45      1.1  christos 
     46  1.1.1.5  christos def is_host_freebsd_13(*_):
     47  1.1.1.5  christos     return platform.system() == "FreeBSD" and platform.release().startswith("13")
     48      1.1  christos 
     49      1.1  christos 
     50  1.1.1.3  christos def with_algorithm(name: str):
     51  1.1.1.3  christos     key = f"{name}_SUPPORTED"
     52  1.1.1.3  christos     assert key in os.environ, f"{key} env variable undefined"
     53  1.1.1.3  christos     return pytest.mark.skipif(os.getenv(key) != "1", reason=f"{name} is not supported")
     54  1.1.1.3  christos 
     55  1.1.1.3  christos 
     56  1.1.1.4  christos with_dnstap = pytest.mark.skipif(
     57  1.1.1.5  christos     os.getenv("FEATURE_DNSTAP") != "1", reason="DNSTAP support disabled in the build"
     58  1.1.1.4  christos )
     59  1.1.1.4  christos 
     60  1.1.1.4  christos 
     61  1.1.1.3  christos without_fips = pytest.mark.skipif(
     62  1.1.1.5  christos     os.getenv("FEATURE_FIPS_MODE") == "1", reason="FIPS support enabled in the build"
     63  1.1.1.3  christos )
     64  1.1.1.3  christos 
     65  1.1.1.3  christos with_libxml2 = pytest.mark.skipif(
     66  1.1.1.5  christos     os.getenv("FEATURE_LIBXML2") != "1", reason="libxml2 support disabled in the build"
     67      1.1  christos )
     68      1.1  christos 
     69  1.1.1.3  christos with_lmdb = pytest.mark.skipif(
     70  1.1.1.5  christos     os.getenv("FEATURE_LMDB") != "1", reason="LMDB support disabled in the build"
     71  1.1.1.3  christos )
     72  1.1.1.3  christos 
     73  1.1.1.3  christos with_json_c = pytest.mark.skipif(
     74  1.1.1.5  christos     os.getenv("FEATURE_JSON_C") != "1", reason="json-c support disabled in the build"
     75      1.1  christos )
     76      1.1  christos 
     77      1.1  christos dnsrps_enabled = pytest.mark.skipif(
     78      1.1  christos     not is_dnsrps_available(), reason="dnsrps disabled in the build"
     79      1.1  christos )
     80      1.1  christos 
     81      1.1  christos 
     82  1.1.1.3  christos softhsm2_environment = pytest.mark.skipif(
     83  1.1.1.3  christos     not (
     84  1.1.1.3  christos         os.getenv("SOFTHSM2_CONF")
     85  1.1.1.3  christos         and os.getenv("SOFTHSM2_MODULE")
     86  1.1.1.3  christos         and shutil.which("pkcs11-tool")
     87  1.1.1.3  christos         and shutil.which("softhsm2-util")
     88  1.1.1.3  christos     ),
     89  1.1.1.3  christos     reason="SOFTHSM2_CONF and SOFTHSM2_MODULE environmental variables must be set and pkcs11-tool and softhsm2-util tools present",
     90  1.1.1.3  christos )
     91  1.1.1.3  christos 
     92      1.1  christos 
     93  1.1.1.5  christos def have_ipv6():
     94  1.1.1.5  christos     sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
     95  1.1.1.5  christos     try:
     96  1.1.1.5  christos         sock.bind(("fd92:7065:b8e:ffff::1", 0))
     97  1.1.1.5  christos     except OSError:
     98  1.1.1.5  christos         return False
     99  1.1.1.5  christos     return True
    100      1.1  christos 
    101      1.1  christos 
    102  1.1.1.5  christos with_ipv6 = pytest.mark.skipif(not have_ipv6(), reason="IPv6 not available")
    103