forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponentintegrity_test.go
103 lines (95 loc) · 2.86 KB
/
componentintegrity_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
)
var componentIntegrityBody = `{
"@odata.type": "#ComponentIntegrity.v1_2_2.ComponentIntegrity",
"Id": "TPM-0",
"Description": "TPM physically attached to a GPU.",
"Status": {
"Health": "OK",
"State": "Enabled"
},
"ComponentIntegrityType": "TPM",
"ComponentIntegrityTypeVersion": "1.2.0",
"ComponentIntegrityEnabled": true,
"LastUpdated": "2021-11-02T14:09:54-07:00",
"TargetComponentURI": "/redfish/v1/Systems/437XR1138R2#/TrustedModules/0",
"Links": {
"ComponentsProtected": [
{
"@odata.id": "/redfish/v1/Systems/437XR1138R2/GraphicsControllers/GPU1"
}
]
},
"TPM": {
"MeasurementSet": {
"Measurements": [
{
"PCR": 1,
"Measurement": "h6spEuxbyOtGhP35UoGhTcVX3iRaZQGDw4Yk5oQcabw=",
"LastUpdated": "2021-10-31T20:14:27-07:00",
"MeasurementHashAlgorithm": "TPM_ALG_SHA256"
},
{
"PCR": 3,
"Measurement": "GnbzS4ToNQb+Y7SxXw4AvRDTf4SzO5eeAlAlDca28AA=",
"LastUpdated": "2021-10-31T20:14:27-07:00",
"MeasurementHashAlgorithm": "TPM_ALG_SHA256"
},
{
"PCR": 1,
"Measurement": "pLJa5Dyh8CDYFZ1WNOrsiSG1eyCPBlre42CD7CTywg7VkcC4afw4ZG3gQxi2XEFCt5jxz6tN1/cbx/DNx2/tOg==",
"LastUpdated": "2021-10-31T20:14:27-07:00",
"MeasurementHashAlgorithm": "TPM_ALG_SHA512"
},
{
"PCR": 3,
"Measurement": "GBgEucATV8omirTmYqY+vvbbisHR1jBKfVAEK1XSifBHnnIYXopsc0NExURDSSyPjO21NrPqnwiq5LhI1p6rzQ==",
"LastUpdated": "2021-10-31T20:14:27-07:00",
"MeasurementHashAlgorithm": "TPM_ALG_SHA512"
}
]
},
"IdentityAuthentication": {
"VerificationStatus": "Success",
"ComponentCertificate": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Certificates/TPMcert"
}
},
"ComponentCommunication": {
"Sessions": [
{
"SessionId": 4556,
"SessionType": "Plain"
}
]
}
},
"@odata.id": "/redfish/v1/ComponentIntegrity/TPM-0"
}`
// TestComponentIntegrity tests the parsing of ComponentIntegrity objects.
func TestComponentIntegrity(t *testing.T) {
var result ComponentIntegrity
err := json.NewDecoder(strings.NewReader(componentIntegrityBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "TPM-0", result.ID)
assertEquals(t, "TPM physically attached to a GPU.", result.Description)
assertEquals(t, "TPM", string(result.ComponentIntegrityType))
assertEquals(t, "1.2.0", result.ComponentIntegrityTypeVersion)
assertEquals(t, "/redfish/v1/Systems/437XR1138R2#/TrustedModules/0", result.TargetComponentURI)
assertEquals(t, "Success", string(result.TPM.IdentityAuthentication.VerificationStatus))
if len(result.TPM.MeasurementSet.Measurements) != 4 {
t.Errorf("Expected 4 measurements, got %#v", result.TPM.MeasurementSet.Measurements)
}
if !result.ComponentIntegrityEnabled {
t.Error("Expected component integrity to be enabled")
}
}