Integration tests: use simulated TPM in debug coordinator

Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
Malte Poll 2022-04-11 11:46:11 +02:00 committed by Malte Poll
parent bcd8c36777
commit 4c73c5076e
2 changed files with 29 additions and 0 deletions

View File

@ -43,3 +43,31 @@ func (t nopTPM) Write(p []byte) (int, error) {
func (t nopTPM) Close() error {
return nil
}
type simulatedTPM struct {
openSimulatedTPM io.ReadWriteCloser
}
// NewSimulatedTPMOpenFunc returns a TPMOpenFunc that opens a simulated TPM.
func NewSimulatedTPMOpenFunc() (TPMOpenFunc, io.Closer) {
tpm, err := OpenSimulatedTPM()
if err != nil {
panic(err)
}
return func() (io.ReadWriteCloser, error) {
return &simulatedTPM{tpm}, nil
}, tpm
}
func (t *simulatedTPM) Read(p []byte) (int, error) {
return t.openSimulatedTPM.Read(p)
}
func (t *simulatedTPM) Write(p []byte) (int, error) {
return t.openSimulatedTPM.Write(p)
}
func (t *simulatedTPM) Close() error {
// never close the underlying simulated TPM to allow calling the TPMOpenFunc again
return nil
}

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"flag"
"io"
"log"
"net"
"os"