Skip to content

Commit

Permalink
tests: fix instantiation of the BootContent model missing hmac
Browse files Browse the repository at this point in the history
  • Loading branch information
mhecko committed Apr 23, 2023
1 parent c092cb2 commit f5ede13
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def get_boot_file_paths():
raise StopActorExecutionError('Could not create a GRUB boot entry for the upgrade initramfs',
details={'details': 'Did not receive a message about the leapp-provided'
'kernel and initramfs'})
# Returning information about kernel hmac file path is needless as it is not used when adding boot entry
return boot_content.kernel_path, boot_content.initram_path


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_boot_file_paths_mocked():
def test_get_boot_file_paths(monkeypatch):
# BootContent message available
def consume_message_mocked(*models):
yield BootContent(kernel_path='/ghi', initram_path='/jkl')
yield BootContent(kernel_path='/ghi', initram_path='/jkl', kernel_hmac_path='/path')

monkeypatch.setattr('leapp.libraries.stdlib.api.consume', consume_message_mocked)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,24 @@ def error(self, *args, **dummy):


@pytest.mark.parametrize('arch', architecture.ARCH_SUPPORTED)
@pytest.mark.parametrize('is_fips_enabled', (True, False))
def test_copy_boot_files(monkeypatch, arch, is_fips_enabled):
def test_copy_boot_files(monkeypatch, arch):
kernel = 'vmlinuz-upgrade.{}'.format(arch)
kernel_hmac = '.vmlinuz-upgrade.{}.hmac'.format(arch)
initram = 'initramfs-upgrade.{}.img'.format(arch)
bootc = BootContent(
kernel_path=os.path.join('/boot', kernel),
kernel_hmac_path=os.path.join('/boot', kernel_hmac),
initram_path=os.path.join('/boot', initram)
)

kernel_hmac = '.vmlinuz-upgrade.{0}.hmac'.format(arch)
if is_fips_enabled:
bootc.kernel_hmac_path = os.path.join('/boot', kernel_hmac)

context = MockedContext()

fips_info = FIPSInfo(is_enabled=is_fips_enabled)
monkeypatch.setattr(upgradeinitramfsgenerator.api, 'current_actor', CurrentActorMocked(arch=arch,
msgs=[fips_info]))
monkeypatch.setattr(upgradeinitramfsgenerator.api, 'current_actor', CurrentActorMocked(arch=arch))
monkeypatch.setattr(upgradeinitramfsgenerator.api, 'produce', produce_mocked())

def create_upgrade_hmac_from_target_hmac_mock(original_hmac_path, upgrade_hmac_path, upgrade_kernel):
assert is_fips_enabled, 'The hmac for upgrade kernel should be created only when fips is enabled.'
hmac_file = '.{}.hmac'.format(upgrade_kernel)
assert original_hmac_path == os.path.join(context.full_path('/artifacts'), hmac_file)
assert upgrade_hmac_path == os.path.join('/boot/', hmac_file)
assert upgrade_hmac_path == bootc.kernel_hmac_path

monkeypatch.setattr(upgradeinitramfsgenerator,
'create_upgrade_hmac_from_target_hmac',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def __call__(self, filename):
def test_remove_boot_files(monkeypatch):
# BootContent message available
def consume_message_mocked(*models):
yield BootContent(kernel_path='/abc', initram_path='/def')
yield BootContent(kernel_path='/abc', initram_path='/def', kernel_hmac_path='/ghi')

monkeypatch.setattr('leapp.libraries.stdlib.api.consume', consume_message_mocked)
monkeypatch.setattr(removebootfiles, 'remove_file', remove_file_mocked())

removebootfiles.remove_boot_files()

assert removebootfiles.remove_file.files_to_remove == ['/abc', '/def']
assert removebootfiles.remove_file.files_to_remove == ['/abc', '/def', '/ghi']

# No BootContent message available
def consume_no_message_mocked(*models):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def consume_systemfacts_mocked(*models):
def test_get_upgrade_kernel_filepath(monkeypatch):
# BootContent message available
def consume_message_mocked(*models):
yield BootContent(kernel_path='/abc', initram_path='/def')
yield BootContent(kernel_path='/abc', initram_path='/def', kernel_hmac_path='/ghi')

monkeypatch.setattr(api, 'consume', consume_message_mocked)

Expand Down

0 comments on commit f5ede13

Please sign in to comment.