-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathenclave_keys_test.go
84 lines (73 loc) · 2.01 KB
/
enclave_keys_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"bytes"
"testing"
)
// newTestKeys returns arbitrary keys that we use for testing.
func newTestKeys(t *testing.T) *enclaveKeys {
t.Helper()
var testKeys = &enclaveKeys{
AppKeys: []byte("AppTestKeys"),
}
cert, key, err := createCertificate("example.com")
if err != nil {
t.Fatal(err)
}
testKeys.setNitridingKeys(key, cert)
return testKeys
}
func TestSetKeys(t *testing.T) {
var (
keys enclaveKeys
appKeys = []byte("AppKeys")
testKeys = newTestKeys(t)
)
// Ensure that the application keys are set correctly.
keys = enclaveKeys{}
keys.setAppKeys(appKeys)
if !bytes.Equal(keys.AppKeys, appKeys) {
t.Fatal("Application keys not set correctly.")
}
// Ensure that the nitriding keys are set correctly.
keys = enclaveKeys{}
keys.setNitridingKeys(testKeys.NitridingKey, testKeys.NitridingCert)
if !bytes.Equal(keys.NitridingKey, testKeys.NitridingKey) {
t.Fatal("Nitriding key not set correctly.")
}
if !bytes.Equal(keys.NitridingCert, testKeys.NitridingCert) {
t.Fatal("Nitriding cert not set correctly.")
}
// Ensure that a new set of keys is set correctly.
keys = enclaveKeys{}
keys.set(testKeys)
if !keys.equal(testKeys) {
t.Fatal("Enclave keys not set correctly.")
}
}
func TestGetKeys(t *testing.T) {
var (
testKeys = newTestKeys(t)
appKeys = testKeys.getAppKeys()
keys = testKeys.copy()
)
// Ensure that the application key is retrieved correctly.
if !bytes.Equal(appKeys, testKeys.AppKeys) {
t.Fatal("Application keys not retrieved correctly.")
}
// Ensure that a new set of keys is retrieved correctly.
if !keys.equal(testKeys) {
t.Fatal("Enclave keys not retrieved correctly.")
}
}
func TestModifyCloneObject(t *testing.T) {
var (
keys = newTestKeys(t)
clonedKeys = keys.copy()
)
// Make sure that setting the clone's application keys does not affect the
// original object.
keys.setAppKeys([]byte("foobar"))
if bytes.Equal(keys.getAppKeys(), clonedKeys.getAppKeys()) {
t.Fatal("Cloned object must not affect original object.")
}
}