forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurebootdatabase_test.go
77 lines (63 loc) · 2.09 KB
/
securebootdatabase_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var secureBootDatabaseBody = `{
"@odata.type": "#SecureBootDatabase.v1_0_2.SecureBootDatabase",
"Id": "PK",
"Name": "PK - Platform Key",
"Description": "UEFI PK Secure Boot Database",
"DatabaseId": "PK",
"Certificates": {
"@odata.id": "/redfish/v1/Systems/1/SecureBoot/SecureBootDatabases/PK/Certificates/"
},
"Actions": {
"#SecureBootDatabase.ResetKeys": {
"target": "/redfish/v1/Systems/1/SecureBoot/SecureBootDatabases/PK/Actions/SecureBootDatabase.ResetKeys",
"[email protected]": [
"ResetAllKeysToDefault",
"DeleteAllKeys"
]
}
},
"@odata.id": "/redfish/v1/Systems/1/SecureBoot/SecureBootDatabases/PK"
}`
// TestSecureBootDatabase tests the parsing of SecureBootDatabase objects.
func TestSecureBootDatabase(t *testing.T) {
var result SecureBootDatabase
err := json.NewDecoder(strings.NewReader(secureBootDatabaseBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "PK", result.ID)
assertEquals(t, "PK - Platform Key", result.Name)
assertEquals(t, "PK", result.DatabaseID)
assertEquals(t, "/redfish/v1/Systems/1/SecureBoot/SecureBootDatabases/PK/Certificates/", result.certificates)
}
// TestSecureBootDatabaseResetKeys tests the SecureBootDatabase ResetKeys call.
func TestSecureBootDatabaseResetKeys(t *testing.T) {
var result SecureBootDatabase
err := json.NewDecoder(strings.NewReader(applicationBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
err = result.ResetKeys(DeleteAllKeysResetKeysType)
if err != nil {
t.Errorf("Error making Reset call: %s", err)
}
calls := testClient.CapturedCalls()
if len(calls) != 1 {
t.Errorf("Expected one call to be made, captured: %#v", calls)
}
if !strings.Contains(calls[0].Payload, "ResetKeysType:DeleteAllKeys") {
t.Errorf("Expected reset type not found in payload: %s", calls[0].Payload)
}
}