| 1 |
package client_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/google/go-tpm-tools/client" |
| 8 |
"github.com/google/go-tpm-tools/internal/test" |
| 9 |
"github.com/google/go-tpm/legacy/tpm2" |
| 10 |
"github.com/google/go-tpm/tpmutil" |
| 11 |
) |
| 12 |
|
| 13 |
const ( |
| 14 |
// Maximum number of handles to keys tests can create within a simulator. |
| 15 |
maxHandles = 3 |
| 16 |
) |
| 17 |
|
| 18 |
func TestHandles(t *testing.T) { |
| 19 |
rwc := test.GetTPM(t) |
| 20 |
defer client.CheckedClose(t, rwc) |
| 21 |
|
| 22 |
expected := make([]tpmutil.Handle, 0) |
| 23 |
for i := 0; i < maxHandles; i++ { |
| 24 |
expected = append(expected, test.LoadRandomExternalKey(t, rwc)) |
| 25 |
|
| 26 |
handles, err := client.Handles(rwc, tpm2.HandleTypeTransient) |
| 27 |
if err != nil { |
| 28 |
t.Fatal(err) |
| 29 |
} |
| 30 |
if !reflect.DeepEqual(handles, expected) { |
| 31 |
t.Errorf("Handles mismatch got: %v; want: %v", handles, expected) |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
// Don't leak our handles |
| 36 |
for _, handle := range expected { |
| 37 |
if err := tpm2.FlushContext(rwc, handle); err != nil { |
| 38 |
t.Error(err) |
| 39 |
} |
| 40 |
} |
| 41 |
} |