1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
import subprocess
import logging
import pytest
import os
from enum import Enum
pkgs = ['389-ds-base', 'nss', 'nspr', 'openldap', 'cyrus-sasl']
class FIPSState(Enum):
ENABLED = 'enabled'
DISABLED = 'disabled'
NOT_AVAILABLE = 'not_available'
def __unicode__(self):
return self.value
def __str__(self):
return self.value
def get_rpm_version(pkg):
try:
result = subprocess.check_output(['rpm', '-q', '--queryformat',
'%{VERSION}-%{RELEASE}', pkg])
except:
result = b"not installed"
return result.decode('utf-8')
def is_fips():
# Are we running in FIPS mode?
if not os.path.exists('/proc/sys/crypto/fips_enabled'):
return FIPSState.NOT_AVAILABLE
state = None
with open('/proc/sys/crypto/fips_enabled', 'r') as f:
state = f.readline()
if state == '1':
return FIPSState.ENABLED
else:
return FIPSState.DISABLED
@pytest.fixture(autouse=True)
def _environment(request):
if "_metadata" in dir(request.config):
for pkg in pkgs:
request.config._metadata[pkg] = get_rpm_version(pkg)
request.config._metadata['FIPS'] = is_fips()
def pytest_cmdline_main(config):
logging.basicConfig(level=logging.DEBUG)
def pytest_report_header(config):
header = ""
for pkg in pkgs:
header += "%s: %s\n" % (pkg, get_rpm_version(pkg))
header += "FIPS: %s" % is_fips()
return header
@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
cells.pop()
@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
cells.pop()
|