Skip to content

Commit 112cf43

Browse files
committed
Test Secureboot state API
See: xapi-project/xen-api#5566 Signed-off-by: Benjamin Reis <[email protected]>
1 parent 529daa8 commit 112cf43

File tree

2 files changed

+123
-1
lines changed

2 files changed

+123
-1
lines changed

jobs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@
260260
"paths": [
261261
"tests/uefi_sb/test_auth_var.py",
262262
"tests/uefi_sb/test_uefistored_sb.py",
263-
"tests/uefi_sb/test_varstored_sb.py"
263+
"tests/uefi_sb/test_varstored_sb.py",
264+
"tests/uefi_sb/test_sb_state.py"
264265
],
265266
"markers": "not windows_vm",
266267
},

tests/uefi_sb/test_sb_state.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import logging
2+
import pytest
3+
4+
from .utils import generate_keys, revert_vm_state
5+
6+
# Requirements:
7+
# On the test runner:
8+
# - See requirements documented in the project's README.md for Guest UEFI Secure Boot tests
9+
# From --hosts parameter:
10+
# - host: XCP-ng host >= 8.3
11+
# From --vm parameter
12+
# - A UEFI VM to import
13+
14+
pytestmark = pytest.mark.default_vm('mini-linux-x86_64-uefi')
15+
16+
@pytest.mark.usefixtures("host_at_least_8_3")
17+
class TestPoolGuestSecureBootReadiness:
18+
def test_pool_ready(self, host):
19+
pool_auths = generate_keys(as_dict=True)
20+
host.pool.install_custom_uefi_certs([pool_auths[key] for key in ['PK', 'KEK', 'db', 'dbx']])
21+
assert host.xe("pool-get-guest-secureboot-readiness") == "ready"
22+
23+
def test_pool_ready_no_dbx(self, host):
24+
pool_auths = generate_keys(as_dict=True)
25+
host.pool.install_custom_uefi_certs([pool_auths[key] for key in ['PK', 'KEK', 'db']])
26+
assert host.xe("pool-get-guest-secureboot-readiness") == "ready_no_dbx"
27+
28+
def test_pool_not_ready(self, host):
29+
host.pool.clear_custom_uefi_certs()
30+
assert host.xe("pool-get-guest-secureboot-readiness") == "not_ready"
31+
32+
@pytest.mark.small_vm
33+
@pytest.mark.usefixtures("host_at_least_8_3")
34+
class TestVmSecureBootReadiness:
35+
@pytest.fixture(autouse=True)
36+
def setup_and_cleanup(self, uefi_vm_and_snapshot):
37+
vm, snapshot = uefi_vm_and_snapshot
38+
self.PK, self.KEK, self.db, self.dbx = generate_keys()
39+
yield
40+
revert_vm_state(vm, snapshot)
41+
42+
def test_vm_not_supported(self, uefi_vm):
43+
vm = uefi_vm
44+
vm.param_set('HVM-boot-params', 'bios', key='firmware') # Fake BIOS VM
45+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "not_supported"
46+
47+
def test_vm_disabled(self, uefi_vm):
48+
vm = uefi_vm
49+
vm.param_set('platform', False, key='secureboot')
50+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "disabled"
51+
52+
def test_vm_first_boot(self, uefi_vm):
53+
vm = uefi_vm
54+
vm.clear_uefi_variables()
55+
vm.param_set('platform', True, key='secureboot')
56+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "first_boot"
57+
58+
def test_vm_ready(self, uefi_vm):
59+
vm = uefi_vm
60+
vm.install_uefi_certs([self.PK, self.KEK, self.db, self.dbx])
61+
vm.param_set('platform', True, key='secureboot')
62+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "ready"
63+
64+
def test_vm_ready_no_dbx(self, uefi_vm):
65+
vm = uefi_vm
66+
vm.install_uefi_certs([self.PK, self.KEK, self.db])
67+
vm.param_set('platform', True, key='secureboot')
68+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "ready_no_dbx"
69+
70+
def test_vm_setup_mode(self, uefi_vm):
71+
vm = uefi_vm
72+
vm.param_set('platform', True, key='secureboot')
73+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "setup_mode"
74+
vm.install_uefi_certs([self.KEK, self.db, self.dbx])
75+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "setup_mode"
76+
77+
def test_vm_certs_incomplete_no_kek(self, uefi_vm):
78+
vm = uefi_vm
79+
vm.install_uefi_certs([self.PK, self.db, self.dbx])
80+
vm.param_set('platform', True, key='secureboot')
81+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "certs_incomplete"
82+
83+
def test_vm_certs_incomplete_no_db(self, uefi_vm):
84+
vm = uefi_vm
85+
vm.install_uefi_certs([self.PK, self.KEK, self.dbx])
86+
vm.param_set('platform', True, key='secureboot')
87+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "certs_incomplete"
88+
89+
def test_vm_certs_incomplete_only_pk(self, uefi_vm):
90+
vm = uefi_vm
91+
vm.install_uefi_certs([self.PK])
92+
vm.param_set('platform', True, key='secureboot')
93+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "certs_incomplete"
94+
95+
@pytest.mark.small_vm
96+
@pytest.mark.usefixtures("host_at_least_8_3")
97+
class TestVmSetUefiMode:
98+
@pytest.fixture(autouse=True)
99+
def setup_and_cleanup(self, uefi_vm_and_snapshot):
100+
vm, snapshot = uefi_vm_and_snapshot
101+
self.PK, self.KEK, self.db, self.dbx = generate_keys()
102+
vm.install_uefi_certs([self.PK, self.KEK, self.db, self.dbx])
103+
vm.param_set('platform', True, key='secureboot')
104+
yield
105+
revert_vm_state(vm, snapshot)
106+
107+
def test_vm_set_uefi_mode(self, uefi_vm):
108+
vm = uefi_vm
109+
110+
# Add certs to the pool so that `xe vm-set-uefi-mode` propagates them to the VM later in the test
111+
pool_auths = {'PK': self.PK, 'KEK': self.KEK, 'db': self.db, 'dbx': self.dbx}
112+
vm.host.pool.install_custom_uefi_certs([pool_auths[key] for key in ['PK', 'KEK', 'db', 'dbx']])
113+
assert vm.host.xe("pool-get-guest-secureboot-readiness") == "ready"
114+
115+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "ready"
116+
117+
vm.host.xe("vm-set-uefi-mode", {"uuid": vm.uuid, "mode": "setup"})
118+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "setup_mode"
119+
120+
vm.host.xe("vm-set-uefi-mode", {"uuid": vm.uuid, "mode": "user"})
121+
assert vm.host.xe("vm-get-secureboot-readiness", {"uuid": vm.uuid}) == "ready"

0 commit comments

Comments
 (0)