tests: Fixup secureboot enrollment test

Also split out Exec, we need it in more tests

Signed-off-by: Morten Linderud <morten@linderud.pw>
This commit is contained in:
Morten Linderud 2021-06-01 01:02:46 +02:00
parent 9587644626
commit 95170e5117
No known key found for this signature in database
GPG Key ID: E742683BA08CB2FF
2 changed files with 22 additions and 20 deletions

View File

@ -3,39 +3,29 @@
package main
import (
"os"
"os/exec"
"strings"
"testing"
"github.com/foxboron/go-uefi/efi"
"github.com/foxboron/sbctl/tests/utils"
)
func Exec(c string) error {
args := strings.Split(c, " ")
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func TestEnrollKeys(t *testing.T) {
if !efi.GetSetupMode() {
t.Fatal("not in setup mode")
}
if efi.GetSecureBoot() {
t.Fatal("in secure boot mode")
}
Exec("/mnt/sbctl status")
if !efi.GetSetupMode() {
t.Fatal("not in setup mode")
}
utils.Exec("rm -rf /usr/share/secureboot")
utils.Exec("/mnt/sbctl status")
utils.Exec("/mnt/sbctl create-keys")
utils.Exec("/mnt/sbctl enroll-keys")
if efi.GetSetupMode() {
t.Fatal("in setup mode")
}
}

View File

@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
@ -141,3 +142,14 @@ func (tvm *TestVM) RunTest(path string) func(t *testing.T) {
}
}
}
func Exec(c string) error {
args := strings.Split(c, " ")
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
return nil
}