Skip to content

Commit a6ae5bf

Browse files
authored
Fix/skip tests would fail on real TPM (google#624)
1 parent e211718 commit a6ae5bf

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

cel/canonical_eventlog_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ func TestCELMeasureAndReplay(t *testing.T) {
7878
if err != nil {
7979
t.Fatal(err)
8080
}
81+
defer tpm2.PCRReset(tpm, tpmutil.Handle(test.DebugPCR))
82+
8183
err = tpm2.PCRReset(tpm, tpmutil.Handle(test.ApplicationPCR))
8284
if err != nil {
8385
t.Fatal(err)
8486
}
87+
defer tpm2.PCRReset(tpm, tpmutil.Handle(test.ApplicationPCR))
8588

8689
cel := &CEL{}
8790
celRTMR := &CEL{}
@@ -120,6 +123,18 @@ func TestCELReplayFailTamperedDigest(t *testing.T) {
120123
tpm := test.GetTPM(t)
121124
defer client.CheckedClose(t, tpm)
122125

126+
err := tpm2.PCRReset(tpm, tpmutil.Handle(test.DebugPCR))
127+
if err != nil {
128+
t.Fatal(err)
129+
}
130+
defer tpm2.PCRReset(tpm, tpmutil.Handle(test.DebugPCR))
131+
132+
err = tpm2.PCRReset(tpm, tpmutil.Handle(test.ApplicationPCR))
133+
if err != nil {
134+
t.Fatal(err)
135+
}
136+
defer tpm2.PCRReset(tpm, tpmutil.Handle(test.ApplicationPCR))
137+
123138
cel := &CEL{}
124139

125140
cosEvent := CosTlv{ImageRefType, []byte("docker.io/bazel/experimental/test:latest")}
@@ -147,6 +162,18 @@ func TestCELReplayEmpty(t *testing.T) {
147162
tpm := test.GetTPM(t)
148163
defer client.CheckedClose(t, tpm)
149164

165+
err := tpm2.PCRReset(tpm, tpmutil.Handle(test.DebugPCR))
166+
if err != nil {
167+
t.Fatal(err)
168+
}
169+
170+
err = tpm2.PCRReset(tpm, tpmutil.Handle(test.ApplicationPCR))
171+
if err != nil {
172+
t.Fatal(err)
173+
}
174+
175+
tpm2.PCRExtend(tpm, tpmutil.Handle(test.DebugPCR), tpm2.AlgSHA256, []byte("333"), "")
176+
150177
cel := &CEL{}
151178
replay(t, cel, tpm, []crypto.Hash{crypto.SHA1, crypto.SHA256},
152179
[]int{test.DebugPCR, test.ApplicationPCR}, true /*shouldSucceed*/)
@@ -156,6 +183,18 @@ func TestCELReplayFailMissingPCRsInBank(t *testing.T) {
156183
tpm := test.GetTPM(t)
157184
defer client.CheckedClose(t, tpm)
158185

186+
err := tpm2.PCRReset(tpm, tpmutil.Handle(test.DebugPCR))
187+
if err != nil {
188+
t.Fatal(err)
189+
}
190+
defer tpm2.PCRReset(tpm, tpmutil.Handle(test.DebugPCR))
191+
192+
err = tpm2.PCRReset(tpm, tpmutil.Handle(test.ApplicationPCR))
193+
if err != nil {
194+
t.Fatal(err)
195+
}
196+
defer tpm2.PCRReset(tpm, tpmutil.Handle(test.ApplicationPCR))
197+
159198
cel := &CEL{}
160199

161200
someEvent := make([]byte, 10)
@@ -175,6 +214,12 @@ func TestCELMeasureToAllPCRBanks(t *testing.T) {
175214
tpm := test.GetTPM(t)
176215
defer client.CheckedClose(t, tpm)
177216

217+
err := tpm2.PCRReset(tpm, tpmutil.Handle(test.DebugPCR))
218+
if err != nil {
219+
t.Fatal(err)
220+
}
221+
defer tpm2.PCRReset(tpm, tpmutil.Handle(test.DebugPCR))
222+
178223
pcrs, err := client.ReadAllPCRs(tpm)
179224
if err != nil {
180225
t.Fatal(err)

cmd/token_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525
func TestTokenWithGCEAK(t *testing.T) {
2626
rwc := test.GetTPM(t)
2727
defer client.CheckedClose(t, rwc)
28+
29+
test.SkipForRealTPM(t)
30+
2831
ExternalTPM = rwc
2932
secretFile1 := makeOutputFile(t, "token")
3033
defer os.RemoveAll(secretFile1)

0 commit comments

Comments
 (0)