-
Notifications
You must be signed in to change notification settings - Fork 2
/
trustvector_test.go
137 lines (118 loc) · 4.39 KB
/
trustvector_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2022 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package ear
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTrustVector_Report_bw_default(t *testing.T) {
tv := TrustVector{
// default is all 0 == none
}
color := false
expectedShort := `Instance Identity [none]: no claim being made
Configuration [none]: no claim being made
Executables [none]: no claim being made
File System [none]: no claim being made
Hardware [none]: no claim being made
Runtime Opaque [none]: no claim being made
Storage Opaque [none]: no claim being made
Sourced Data [none]: no claim being made
`
short := true
assert.Equal(t, expectedShort, tv.Report(short, color))
expectedLong := `Instance Identity [none]: The Evidence received is insufficient to make a conclusion.
Configuration [none]: The Evidence received is insufficient to make a conclusion.
Executables [none]: The Evidence received is insufficient to make a conclusion.
File System [none]: The Evidence received is insufficient to make a conclusion.
Hardware [none]: The Evidence received is insufficient to make a conclusion.
Runtime Opaque [none]: The Evidence received is insufficient to make a conclusion.
Storage Opaque [none]: The Evidence received is insufficient to make a conclusion.
Sourced Data [none]: The Evidence received is insufficient to make a conclusion.
`
short = false
assert.Equal(t, expectedLong, tv.Report(short, color))
}
func TestTrustVector_Report_bw_unknown_affirming(t *testing.T) {
tv := TrustVector{
InstanceIdentity: -2,
Configuration: -2,
Executables: -2,
FileSystem: -2,
Hardware: -2,
RuntimeOpaque: -2,
StorageOpaque: -2,
SourcedData: -2,
}
color := false
expectedShort := `Instance Identity [affirming]: unknown code-point -2
Configuration [affirming]: unknown code-point -2
Executables [affirming]: unknown code-point -2
File System [affirming]: unknown code-point -2
Hardware [affirming]: unknown code-point -2
Runtime Opaque [affirming]: unknown code-point -2
Storage Opaque [affirming]: unknown code-point -2
Sourced Data [affirming]: unknown code-point -2
`
short := true
assert.Equal(t, expectedShort, tv.Report(short, color))
expectedLong := expectedShort
short = false
assert.Equal(t, expectedLong, tv.Report(short, color))
}
func TestToTrustVector(t *testing.T) {
tv, err := ToTrustVector(map[string]interface{}{
"instance-identity": TrustworthyInstanceClaim,
"configuration": 2,
"executables": 2,
"file-system": "approved_fs",
"hardware": 32,
"runtime-opaque": -7,
"storage-opaque": 32,
"sourced-data": NoClaim,
})
assert.NoError(t, err)
assert.Equal(t, TrustworthyInstanceClaim, tv.InstanceIdentity)
assert.Equal(t, UnsafeHardwareClaim, tv.Hardware)
assert.Equal(t, ApprovedFilesClaim, tv.FileSystem)
assert.Equal(t, TrustClaim(-7), tv.RuntimeOpaque)
assert.Equal(t, NoClaim, tv.SourcedData)
tv, err = ToTrustVector(map[string]string{
"runtime-opaque": "encrypted_rt",
"hardware": "unsafe_hw",
"file-system": "approved_fs",
})
assert.NoError(t, err)
assert.Equal(t, EncryptedMemoryRuntimeClaim, tv.RuntimeOpaque)
assert.Equal(t, UnsafeHardwareClaim, tv.Hardware)
assert.Equal(t, ApprovedFilesClaim, tv.FileSystem)
assert.Equal(t, NoClaim, tv.Configuration)
tv2 := TrustVector{
InstanceIdentity: 2,
Configuration: 2,
Executables: 2,
}
tv, err = ToTrustVector(tv2)
assert.NoError(t, err)
assert.Equal(t, TrustworthyInstanceClaim, tv.InstanceIdentity)
assert.Equal(t, ApprovedConfigClaim, tv.Configuration)
assert.Equal(t, ApprovedRuntimeClaim, tv.Executables)
tv, err = ToTrustVector(&tv2)
assert.NoError(t, err)
assert.Equal(t, TrustworthyInstanceClaim, tv.InstanceIdentity)
assert.Equal(t, ApprovedConfigClaim, tv.Configuration)
assert.Equal(t, ApprovedRuntimeClaim, tv.Executables)
_, err = ToTrustVector(42)
assert.ErrorContains(t, err, "invalid value '42': expected a TrustVector, but found int")
_, err = ToTrustVector(map[string]interface{}{
"instance-identity": TrustworthyInstanceClaim,
"hardware": "bad claim",
"file-system": "approved_fs",
})
assert.ErrorContains(t, err, `invalid value(s) for 'hardware' (not a valid TrustClaim value: "bad claim")`)
}
func TestTrustVector_SetAll(t *testing.T) {
var tv TrustVector
tv.SetAll(VerifierMalfunctionClaim)
assert.Equal(t, VerifierMalfunctionClaim, tv.Configuration)
}