Files
sbctl/backend/backend_test.go
Morten Linderud 73a077051b sbctl: ensure we are passing state to KeyHierarchy
Signed-off-by: Morten Linderud <morten@linderud.pw>
2024-07-31 00:11:22 +02:00

44 lines
747 B
Go

package backend
import (
"fmt"
"log"
"testing"
"github.com/foxboron/sbctl/config"
"github.com/foxboron/sbctl/hierarchy"
"github.com/spf13/afero"
)
func TestCreateKeys(t *testing.T) {
c := &config.Config{
Keydir: t.TempDir(),
Keys: &config.Keys{
PK: &config.KeyConfig{
Type: "file",
},
KEK: &config.KeyConfig{},
Db: &config.KeyConfig{},
},
}
state := &config.State{
Fs: afero.NewOsFs(),
Config: c,
}
hier, err := CreateKeys(state)
if err != nil {
t.Fatalf("%v", err)
}
err = hier.SaveKeys(afero.NewOsFs(), c.Keydir)
if err != nil {
t.Fatalf("%v", err)
}
key, err := GetKeyBackend(state, hierarchy.PK)
if err != nil {
log.Fatal(err)
}
fmt.Println(key.Certificate().Subject.CommonName)
}