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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
import pytest
from ssg_test_suite import common
def test_simple_match():
scenario_platforms = ["Red Hat Enterprise Linux 10"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_simple_no_match():
scenario_platforms = ["Red Hat Enterprise Linux 10"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:9"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is False
def test_multi_platform_all():
scenario_platforms = ["multi_platform_all"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_multi_platform_match():
scenario_platforms = ["multi_platform_rhel"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_multi_platform_no_match():
scenario_platforms = ["multi_platform_fedora"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is False
def test_list_simple_match_first():
scenario_platforms = ["Red Hat Enterprise Linux 9",
"Red Hat Enterprise Linux 10"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:9"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_list_simple_match_second():
scenario_platforms = ["Red Hat Enterprise Linux 9",
"Red Hat Enterprise Linux 10"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_list_simple_no_match():
scenario_platforms = ["Red Hat Enterprise Linux 8",
"Red Hat Enterprise Linux 9"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is False
def test_list_multi_platform_match_first():
scenario_platforms = ["multi_platform_rhel", "multi_platform_debian"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:8"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_list_multi_platform_match_second():
scenario_platforms = ["multi_platform_rhel", "multi_platform_debian"]
benchmark_cpes = {"cpe:/o:debian:debian_linux:11"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_list_multi_platform_no_match():
scenario_platforms = ["multi_platform_debian", "multi_platform_ubuntu"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:8"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is False
def test_list_combined_match():
scenario_platforms = ["multi_platform_debian", "multi_platform_ubuntu",
"Red Hat Enterprise Linux 8"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:8"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_list_combined_match_2():
scenario_platforms = ["Debian 11", "multi_platform_ubuntu", "openSUSE",
"Red Hat Enterprise Linux 8"]
benchmark_cpes = {"cpe:/o:debian:debian_linux:11"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_list_combined_no_match():
scenario_platforms = ["multi_platform_ubuntu", "multi_platform_fedora",
"Red Hat Enterprise Linux 8", "openSUSE"]
benchmark_cpes = {"cpe:/o:debian:debian_linux:11"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is False
def test_simple_multiple_unrelated_benchmark_cpes():
scenario_platforms = ["Red Hat Enterprise Linux 10"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:9",
"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_simple_multiple_bogus_benchmark_cpes():
scenario_platforms = ["Red Hat Enterprise Linux 10"]
benchmark_cpes = {"cpe:/o:abcdef:ghijklm:42"
"cpe:/o:zzzzz:xxxx:77",
"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is True
def test_simple_multiple_bogus_benchmark_cpes_no_match():
scenario_platforms = ["Fedora"]
benchmark_cpes = {"cpe:/o:abcdef:ghijklm:42"
"cpe:/o:zzzzz:xxxx:77",
"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is False
def test_multiple_multiple_bogus_benchmark_cpes_no_match():
scenario_platforms = ["Fedora", "openSUSE"]
benchmark_cpes = {"cpe:/o:abcdef:ghijklm:42"
"cpe:/o:zzzzz:xxxx:77",
"cpe:/o:redhat:enterprise_linux:10"}
assert common.matches_platform(scenario_platforms, benchmark_cpes) is False
def test_typo():
scenario_platforms = ["Rrd Hat Enterprise Linux 10"]
benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:10"}
with pytest.raises(ValueError):
common.matches_platform(scenario_platforms, benchmark_cpes)
def test_wrong_multi_platform():
scenario_platforms = ["multi_platform_fidorka"]
benchmark_cpes = {"cpe:/o:fedoraproject:fedora:30"}
with pytest.raises(ValueError):
common.matches_platform(scenario_platforms, benchmark_cpes)
|