forked from google/go-tpm-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy_constants_test.go
56 lines (48 loc) · 1.78 KB
/
policy_constants_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package server
import (
"testing"
pb "github.com/google/go-tpm-tools/proto/attest"
)
func getGceMemoryEncryptionNonhostEvent(memoryEncrypted bool) []byte {
event := make([]byte, 32)
copy(event[:], []byte(GCENonHostInfoSignature))
// event[15] is a null byte.
if memoryEncrypted {
event[16] = 0x01
}
// Last 15 bytes are reserved.
return event
}
func TestParseGCENonHostInfo(t *testing.T) {
nonconfidentialEvent := getGceMemoryEncryptionNonhostEvent( /*memoryEncrypted=*/ false)
// Empty events should return NONCONFIDENTIAL.
confTech, err := ParseGCENonHostInfo([]byte{})
if err == nil {
t.Error("expected error on incorrect size!")
}
if confTech != pb.GCEConfidentialTechnology_NONE {
t.Errorf("expected ConfidentialTechnology %v, received %v", pb.GCEConfidentialTechnology_NONE, confTech)
}
confTech, err = ParseGCENonHostInfo(nonconfidentialEvent)
if err != nil {
t.Errorf("failed to parse GCE confidential tech: %v", err)
}
if confTech != pb.GCEConfidentialTechnology_NONE {
t.Errorf("expected ConfidentialTechnology %v, received %v", pb.GCEConfidentialTechnology_NONE, confTech)
}
sevEvent := getGceMemoryEncryptionNonhostEvent( /*memoryEncrypted=*/ true)
confTech, err = ParseGCENonHostInfo(sevEvent)
if err != nil {
t.Errorf("failed to parse GCE confidential tech: %v", err)
}
if confTech != pb.GCEConfidentialTechnology_AMD_SEV {
t.Errorf("expected ConfidentialTechnology %v, received %v", pb.GCEConfidentialTechnology_AMD_SEV, confTech)
}
}
func TestParseGCENonHostInfoUnknownType(t *testing.T) {
nonconfidentialEvent := getGceMemoryEncryptionNonhostEvent( /*memoryEncrypted=*/ false)
nonconfidentialEvent[16] = 0x99
if _, err := ParseGCENonHostInfo(nonconfidentialEvent); err == nil {
t.Errorf("expected error parsing GCE confidential nonhost event")
}
}