|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +# |
| 4 | +# Unit tests for upgrading Shim and GRUB bootloaders on Debian 10 |
| 5 | +# |
| 6 | + |
| 7 | +function setup_file() { |
| 8 | + REAR_SHARE_DIR="$(realpath "$BATS_TEST_DIRNAME/../../usr/share/rear")" |
| 9 | + export REAR_SHARE_DIR |
| 10 | +} |
| 11 | + |
| 12 | +function setup() { |
| 13 | + # shellcheck disable=SC1091 |
| 14 | + source "$REAR_SHARE_DIR/lib/global-functions.sh" |
| 15 | + |
| 16 | + function LogPrint() { |
| 17 | + echo "$@" |
| 18 | + } |
| 19 | + |
| 20 | + OS_VERSION=10 |
| 21 | + USING_UEFI_BOOTLOADER=yes |
| 22 | + function is_cove_in_azure() { |
| 23 | + false |
| 24 | + } |
| 25 | + EFI_STUB=no |
| 26 | + UEFI_BOOTLOADER=/boot/efi/EFI/debian/shimx64.efi |
| 27 | +} |
| 28 | + |
| 29 | +@test "Shim and GRUB are upgraded successfully" { |
| 30 | + function upgrade_bootloaders() { |
| 31 | + return 0 |
| 32 | + } |
| 33 | + |
| 34 | + run source "$REAR_SHARE_DIR/finalize/COVE/Debian/620_upgrade_bootloaders.sh" |
| 35 | + [ "$status" -eq 0 ] |
| 36 | + |
| 37 | + local expected_output="Upgraded signed Shim and GRUB bootloaders for this system." |
| 38 | + [ "$output" = "$expected_output" ] |
| 39 | +} |
| 40 | + |
| 41 | +@test "Failed to upgrade Shim and GRUB" { |
| 42 | + function upgrade_bootloaders() { |
| 43 | + return 1 |
| 44 | + } |
| 45 | + |
| 46 | + run source "$REAR_SHARE_DIR/finalize/COVE/Debian/620_upgrade_bootloaders.sh" |
| 47 | + [ "$status" -eq 0 ] |
| 48 | + |
| 49 | + local expected_output="Failed to upgrade signed Shim and GRUB bootloaders for this system. UEFI Secure Boot might not be available." |
| 50 | + [ "$output" = "$expected_output" ] |
| 51 | +} |
| 52 | + |
| 53 | +@test "Skip upgrading Shim and GRUB if the system is not Debian 10" { |
| 54 | + # shellcheck disable=SC2034 |
| 55 | + OS_VERSION=11 |
| 56 | + |
| 57 | + run source "$REAR_SHARE_DIR/finalize/COVE/Debian/620_upgrade_bootloaders.sh" |
| 58 | + [ "$status" -eq 0 ] |
| 59 | + |
| 60 | + local expected_output="" |
| 61 | + [ "$output" = "$expected_output" ] |
| 62 | +} |
| 63 | + |
| 64 | +@test "Skip upgrading Shim and GRUB if the system is not EFI" { |
| 65 | + # shellcheck disable=SC2034 |
| 66 | + USING_UEFI_BOOTLOADER=no |
| 67 | + |
| 68 | + run source "$REAR_SHARE_DIR/finalize/COVE/Debian/620_upgrade_bootloaders.sh" |
| 69 | + [ "$status" -eq 0 ] |
| 70 | + |
| 71 | + local expected_output="" |
| 72 | + [ "$output" = "$expected_output" ] |
| 73 | +} |
| 74 | + |
| 75 | +@test "Skip upgrading Shim and GRUB on Azure" { |
| 76 | + function is_cove_in_azure() { |
| 77 | + true |
| 78 | + } |
| 79 | + |
| 80 | + run source "$REAR_SHARE_DIR/finalize/COVE/Debian/620_upgrade_bootloaders.sh" |
| 81 | + [ "$status" -eq 0 ] |
| 82 | + |
| 83 | + local expected_output="" |
| 84 | + [ "$output" = "$expected_output" ] |
| 85 | +} |
| 86 | + |
| 87 | +@test "Skip upgrading Shim and GRUB if the system is EFI stub" { |
| 88 | + # shellcheck disable=SC2034 |
| 89 | + EFI_STUB=yes |
| 90 | + |
| 91 | + run source "$REAR_SHARE_DIR/finalize/COVE/Debian/620_upgrade_bootloaders.sh" |
| 92 | + [ "$status" -eq 0 ] |
| 93 | + |
| 94 | + local expected_output="" |
| 95 | + [ "$output" = "$expected_output" ] |
| 96 | +} |
| 97 | + |
| 98 | +@test "Skip upgrading Shim and GRUB if the bootloader is not shim" { |
| 99 | + # shellcheck disable=SC2034 |
| 100 | + UEFI_BOOTLOADER=/boot/efi/EFI/debian/grubx64.efi |
| 101 | + |
| 102 | + run source "$REAR_SHARE_DIR/finalize/COVE/Debian/620_upgrade_bootloaders.sh" |
| 103 | + [ "$status" -eq 0 ] |
| 104 | + |
| 105 | + local expected_output="" |
| 106 | + [ "$output" = "$expected_output" ] |
| 107 | +} |
0 commit comments