forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounts_test.go
160 lines (134 loc) · 3.98 KB
/
accounts_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
)
var accountBody = strings.NewReader(
`{
"@odata.context": "/redfish/v1/$metadata#AccountService/Links/Members/Accounts/Links/Members/$entity",
"@odata.id": "/redfish/v1/AccountService/Accounts/1",
"@odata.type": "#AccountService.0.94.0.ManagerAccount",
"Id": "1",
"Name": "User Account",
"Modified": "2013-09-11T17:03:55+00:00",
"Description": "User Account",
"Password": "Password",
"UserName": "Administrator",
"Locked": false,
"Enabled": true,
"RoleId": "Admin",
"Links": {
"Role": {
"@odata.id": "/redfish/v1/AccountService/Roles/Admin"
}
}
}`)
var accountServiceBody = strings.NewReader(
`{
"@odata.context": "/redfish/v1/$metadata#AccountService",
"@odata.id": "/redfish/v1/AccountService",
"@odata.type": "#AccountService.0.94.0.AccountService",
"Id": "AccountService",
"Name": "Account Service",
"Description": "BMC User Accounts",
"Modified": "2036-09-11T14:17:21+00:00",
"AuthFailureLoggingThreshold": 3,
"MinPasswordLength": 8,
"Links": {
"Accounts": {
"@odata.id": "/redfish/v1/AccountService/Accounts"
},
"Roles": {
"@odata.id": "/redfish/v1/AccountService/Roles"
}
}
}`)
var roleBody = strings.NewReader(
`{
"@odata.context": "/redfish/v1/$metadata#AccountService/Links/Members/Roles/Links/Members/$entity",
"@odata.id": "/redfish/v1/AccountService/Roles/ReadOnlyUser",
"@odata.type": "#Role.1.0.0.Role",
"Id": "ReadOnlyUser",
"Name": "User Role",
"Modified": "2013-09-11T17:03:55+00:00",
"Description": "ReadOnlyUser User Role",
"IsPredefined": true,
"AssignedPrivileges": [
"Login"
],
"OEMPrivileges": []
}`)
// TestAccount tests the parsing of Account objects.
func TestAccount(t *testing.T) {
var result Account
err := json.NewDecoder(accountBody).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "User Account" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.RoleID != "Admin" {
t.Errorf("Received invalid Role ID: %s", result.RoleID)
}
if result.role != "/redfish/v1/AccountService/Roles/Admin" {
t.Errorf("Received invalid Role: %s", result.role)
}
}
// TestAccountService tests the parsing of AccountService objects.
func TestAccountService(t *testing.T) {
var result AccountService
err := json.NewDecoder(accountServiceBody).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "AccountService" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "Account Service" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.AuthFailureLoggingThreshold != 3 {
t.Errorf("Received invalid authentication failure logging threshold: %d",
result.AuthFailureLoggingThreshold)
}
if result.MinPasswordLength != 8 {
t.Errorf("Received invalid minimum password length: %d", result.MinPasswordLength)
}
if result.accounts != "/redfish/v1/AccountService/Accounts" {
t.Errorf("Received invalid Accounts: %s", result.accounts)
}
if result.roles != "/redfish/v1/AccountService/Roles" {
t.Errorf("Received invalid Roles: %s", result.roles)
}
}
// TestRole tests the parsing of Role objects.
func TestRole(t *testing.T) {
var result Role
err := json.NewDecoder(roleBody).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "ReadOnlyUser" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "User Role" {
t.Errorf("Received invalid name: %s", result.Name)
}
if !result.IsPredefined {
t.Errorf("IsPredefined incorrect for role.")
}
if len(result.AssignedPrivileges) != 1 {
t.Errorf("Expected 1 assigned privilege, found: %d", len(result.AssignedPrivileges))
}
if result.AssignedPrivileges[0] != "Login" {
t.Errorf("Expected 'Login' assigned privilege, got: %s", result.AssignedPrivileges[0])
}
}