mirror of
https://github.com/kairos-io/tpm-helpers.git
synced 2025-09-14 05:41:01 +00:00
Add backends and simulated TPM device
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
This commit is contained in:
13
backend/backend_suite_test.go
Normal file
13
backend/backend_suite_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package backend_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestBackend(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Backend Suite")
|
||||
}
|
17
backend/fake.go
Normal file
17
backend/fake.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
type FakeTPM struct {
|
||||
io.ReadWriteCloser
|
||||
}
|
||||
|
||||
var fixedLog = []byte{0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x21, 0x0, 0x0, 0x0, 0x53, 0x70, 0x65, 0x63, 0x20, 0x49, 0x44,
|
||||
0x20, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x33, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x2, 0x0, 0x2, 0x1, 0x0, 0x0, 0x0, 0xb, 0x0, 0x20, 0x0, 0x0}
|
||||
|
||||
func (*FakeTPM) MeasurementLog() ([]byte, error) { return fixedLog, nil }
|
13
backend/socket.go
Normal file
13
backend/socket.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package backend
|
||||
|
||||
import "net"
|
||||
|
||||
func Socket(f string) (*FakeTPM, error) {
|
||||
conn, err := net.Dial("unix", f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FakeTPM{
|
||||
ReadWriteCloser: conn,
|
||||
}, nil
|
||||
}
|
29
backend/socket_test.go
Normal file
29
backend/socket_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package backend_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
. "github.com/rancher-sandbox/go-tpm/backend"
|
||||
)
|
||||
|
||||
var _ = Describe("SWTPM", func() {
|
||||
socket := os.Getenv("SWTPM_SOCKET")
|
||||
Context("opening socket connection", func() {
|
||||
It("fails on invalid files", func() {
|
||||
|
||||
_, err := Socket("foobar")
|
||||
Expect(err).To(HaveOccurred())
|
||||
|
||||
})
|
||||
|
||||
It("dials in just fine", func() {
|
||||
if socket == "" {
|
||||
Skip("No socket file specified")
|
||||
}
|
||||
_, err := Socket(socket)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user