Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests : fix intel trust authority quote generation tests #290

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions tests/tests/test_guest_ita.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import Qemu
import util

ubuntu_codename = None

def test_guest_measurement_trust_authority_success():
"""
Trust Authority CLI quote generation success
"""
change_qgsd_state('start')
quote_str = run_trust_authority()
quote = json.loads(quote_str.replace(' ', ','))
assert len(quote) > 0, "Quote not valid: %s" % (quote_str)

check_ita_output(quote_str, for_success = True)

def test_guest_measurement_trust_authority_failure():
"""
Expand All @@ -40,18 +40,44 @@ def test_guest_measurement_trust_authority_failure():
change_qgsd_state('stop')
quote_str = run_trust_authority()
change_qgsd_state('start')
quote = json.loads(quote_str.replace(' ', ','))
assert len(quote) == 0, "Quote not valid: %s" % (quote_str)

check_ita_output(quote_str, for_success = False)

def change_qgsd_state(state):
cmd = ['systemctl', state, 'qgsd']
subprocess.run(cmd)
rc = subprocess.run(cmd, stderr=subprocess.STDOUT, timeout=30)
assert 0 == rc.returncode, 'Failed change state of qgsd'

def check_ita_output(quote_str : str, for_success : bool = True):
"""
Check the validity of ITA quote output
Depending on the version of the ITA client, the output
may vary:
- Ubuntu 24.04 (ITA 1.5.0)
On success: [4 0 2 0 129 0 0 ... 0 0 0 0 0 ]
On failure: []
- Ubuntu 24.10 (ITA 1.6.1)
On success:
Quote: <base64_encoded_quote>
runtime_data: base64_encoded_runtime_data <- Optional
user_data: base64_encoded_user_data <- Optional
On failure:
Quote:
"""
# regex to check the output of ITA quote command, the regex depends on ITA version
# for the moment, we extract the ITA version from the ubuntu release
# {10,0}: check for at least 10 characters to declare the quote valid
ita_output_regexp = {
'noble' : '\\[[0-9 ]{10,}\\]',
'oracular' : 'Quote: [-A-Za-z0-9+/]{10,}'
}
import re
pattern = re.compile(ita_output_regexp[ubuntu_codename])
assert (bool(pattern.match(quote_str)) == for_success), f'Error for code name : {codename}'

def run_trust_authority():
global ubuntu_codename

quote_str = ""
with Qemu.QemuMachine() as qm:
machine = qm.qcmd.plugins['machine']
Expand All @@ -61,6 +87,9 @@ def run_trust_authority():

ssh = Qemu.QemuSSH(qm)

stdout, _ = ssh.check_exec('lsb_release -cs')
ubuntu_codename = stdout.read().decode().strip()

stdout, stderr = ssh.check_exec('trustauthority-cli quote')
quote_str = stdout.read().decode()
return quote_str