1*** Settings ***
2
3
4Documentation     Suite to test local user management.
5
6Library           OperatingSystem
7Library           String
8Library           Collections
9
10Resource          ../../lib/resource.robot
11Resource          ../../lib/bmc_redfish_resource.robot
12Resource          ../../lib/openbmc_ffdc.robot
13Resource          ../../lib/certificate_utils.robot
14Resource          ../../lib/dmtf_redfishtool_utils.robot
15
16Suite Setup       Suite Setup Execution
17
18
19*** Variables ***
20
21${root_cmd_args} =  SEPARATOR=
22...  redfishtool raw -r ${OPENBMC_HOST} -u ${OPENBMC_USERNAME} -p ${OPENBMC_PASSWORD} -S Always
23
24
25*** Test Cases ***
26
27
28Verify Redfishtool Create Users
29    [Documentation]  Create user via Redfishtool and verify.
30    [Tags]  Verify_Redfishtool_Create_Users
31    [Teardown]  Redfishtool Delete User  "UserT100"
32
33    Redfishtool Create User  "UserT100"  "TestPwd123"  "Operator"  true
34    Redfishtool Verify User  "UserT100"  "Operator"
35
36
37Verify Redfishtool Modify Users
38    [Documentation]  Modify user via Redfishtool and verify.
39    [Tags]  Verify_Redfishtool_Modify_Users
40    [Teardown]  Redfishtool Delete User  "UserT100"
41
42    Redfishtool Create User  "UserT100"  "TestPwd123"  "Operator"  true
43    Redfishtool Update User Role  "UserT100"  "Administrator"
44    Redfishtool Verify User  "UserT100"  "Administrator"
45
46
47Verify Redfishtool Delete Users
48    [Documentation]  Delete user via Redfishtool and verify.
49    [Tags]  Verify_Redfishtool_Delete_Users
50
51    Redfishtool Create User  "UserT100"  "TestPwd123"  "Operator"  true
52    Redfishtool Delete User  "UserT100"
53    ${status}=  Redfishtool Verify User Name Exists  "UserT100"
54    Should Be True  ${status} == False
55
56
57Verify Redfishtool Login With Deleted Redfish Users
58    [Documentation]  Verify login with deleted user via Redfishtool.
59    [Tags]  Verify_Redfishtool_Login_With_Deleted_Redfish_Users
60
61    Redfishtool Create User  "UserT100"  "TestPwd123"  "Operator"  true
62    Redfishtool Delete User  "UserT100"
63    Redfishtool Access Resource  /redfish/v1/AccountService/Accounts  "UserT100"  "TestPwd123"
64    ...  ${HTTP_UNAUTHORIZED}
65
66
67Verify Redfishtool Error Upon Creating Same Users With Different Privileges
68    [Documentation]  Verify error upon creating same users with different privileges.
69    [Tags]  Verify_Redfishtool_Error_Upon_Creating_Same_Users_With_Different_Privileges
70    [Teardown]  Redfishtool Delete User  "UserT100"
71
72    Redfishtool Create User  "UserT100"  "TestPwd123"  "Operator"  true
73    Redfishtool Create User  "UserT100"  "TestPwd123"  "Administrator"  true
74    ...  expected_error=${HTTP_BAD_REQUEST}
75
76
77Verify Redfishtool Admin User Privilege
78    [Documentation]  Verify privilege of admin user.
79    [Tags]  Verify_Redfishtool_Admin_User_Privilege
80    [Teardown]  Run Keywords  Redfishtool Delete User  "UserT100"  AND
81    ...  Redfishtool Delete User  "UserT101"
82
83    Redfishtool Create User  "UserT100"  "TestPwd123"  "Administrator"  true
84
85    # Verify if an user can be added by admin
86    Redfishtool Create User  "UserT101"  "TestPwd123"  "Operator"  true  "UserT100"  "TestPwd123"
87
88
89Verify Redfishtool ReadOnly User Privilege
90    [Documentation]  Verify Redfishtool ReadOnly user privilege works.
91    [Tags]  Verify_Redfishtool_ReadOnly_User_Privilege
92    [Teardown]  Redfishtool Delete User  "UserT100"
93
94    Redfishtool Create User  "UserT100"  "TestPwd123"  "ReadOnly"  true
95    Redfishtool Access Resource  /redfish/v1/Systems/  "UserT100"  "TestPwd123"
96
97    Redfishtool Create User
98    ...  "UserT101"  "TestPwd123"  "Operator"  true  "UserT100"  "TestPwd123"  ${HTTP_FORBIDDEN}
99
100
101*** Keywords ***
102
103
104Redfishtool Access Resource
105    [Documentation]  Access resource.
106    [Arguments]  ${uri}   ${login_user}  ${login_pasword}  ${expected_error}=200
107
108    # Description of argument(s):
109    # uri            URI for resource access.
110    # login_user     The login user name used other than default root user.
111    # login_pasword  The login password.
112    # expected_error Expected error optionally provided in testcase (e.g. 401 /
113    #                authentication error, etc. )
114
115    ${user_cmd_args}=  Set Variable
116    ...  redfishtool raw -r ${OPENBMC_HOST} -u ${login_user} -p ${login_pasword} -S Always
117    Redfishtool Get  ${uri}  ${user_cmd_args}  ${expected_error}
118
119
120Redfishtool Create User
121    [Documentation]  Create new user.
122    [Arguments]  ${user_name}  ${password}  ${roleID}  ${enable}  ${login_user}=""  ${login_pasword}=""
123    ...  ${expected_error}=200
124
125    # Description of argument(s):
126    # user_name      The user name (e.g. "test", "robert", etc.).
127    # password       The user password (e.g. "0penBmc", "0penBmc1", etc.).
128    # roleID         The role of user (e.g. "Administrator", "Operator", etc.).
129    # enable         Enabled attribute of (e.g. true or false).
130    # expected_error Expected error optionally provided in testcase (e.g. 401 /
131    #                authentication error, etc. )
132
133    ${user_cmd_args}=  Set Variable
134    ...  redfishtool raw -r ${OPENBMC_HOST} -u ${login_user} -p ${login_pasword} -S Always
135    ${data}=  Set Variable
136    ...  '{"UserName":${user_name},"Password":${password},"RoleId":${roleId},"Enabled":${enable}}'
137    Run Keyword If  ${login_user} == ""
138    ...   Redfishtool Post  ${data}  /redfish/v1/AccountService/Accounts  ${root_cmd_args}  ${expected_error}
139    ...   ELSE
140    ...   Redfishtool Post  ${data}  /redfish/v1/AccountService/Accounts  ${user_cmd_args}  ${expected_error}
141
142
143Redfishtool Update User Role
144    [Documentation]  Update user role.
145    [Arguments]  ${user_name}  ${newRole}  ${login_user}=""  ${login_pasword}=""
146    ...  ${expected_error}=200
147
148    # Description of argument(s):
149    # user_name      The user name (e.g. "test", "robert", etc.).
150    # newRole        The new role of user (e.g. "Administrator", "Operator", etc.).
151    # login_user     The login user name used other than default root user.
152    # login_pasword  The login password.
153    # expected_error Expected error optionally provided in testcase (e.g. 401 /
154    #                authentication error, etc. )
155
156    ${user_cmd_args}=  Set Variable
157    ...  redfishtool raw -r ${OPENBMC_HOST} -u ${login_user} -p ${login_pasword} -S Always
158    Run Keyword If  ${login_user} == ""
159    ...   Redfishtool Patch  '{"RoleId":${newRole}}'
160          ...  /redfish/v1/AccountService/Accounts/${user_name}  ${root_cmd_args}  ${expected_error}
161    ...   ELSE
162    ...   Redfishtool Patch  '{"RoleId":${newRole}}'
163          ...  /redfish/v1/AccountService/Accounts/${user_name}  ${user_cmd_args}  ${expected_error}
164
165
166Redfishtool Delete User
167    [Documentation]  Delete an user.
168    [Arguments]  ${user_name}  ${expected_error}=200
169
170    # Description of argument(s):
171    # user_name       The user name (e.g. "test", "robert", etc.).
172    # expected_error  Expected error optionally provided in testcase (e.g. 401 /
173    #                 authentication error, etc. ).
174
175    Redfishtool Delete  /redfish/v1/AccountService/Accounts/${user_name}
176    ...  ${root_cmd_args}  ${expected_error}
177
178
179Redfishtool Verify User
180    [Documentation]  Verify role of the user.
181    [Arguments]  ${user_name}  ${role}
182
183    # Description of argument(s):
184    # user_name  The user name (e.g. "test", "robert", etc.).
185    # role       The new role of user (e.g. "Administrator", "Operator", etc.).
186
187    ${user_account}=  Redfishtool Get  /redfish/v1/AccountService/Accounts/${user_name}
188    ${json_obj}=   Evaluate  json.loads('''${user_account}''')  json
189    Should Be equal  "${json_obj["RoleId"]}"  ${role}
190
191
192Redfishtool Verify User Name Exists
193    [Documentation]  Verify user name exists.
194    [Arguments]  ${user_name}
195
196    # Description of argument(s):
197    # user_name  The user name (e.g. "test", "robert", etc.).
198
199    ${status}=  Run Keyword And Return Status  redfishtool Get
200    ...  /redfish/v1/AccountService/Accounts/${user_name}
201
202    [return]  ${status}
203
204
205Suite Setup Execution
206    [Documentation]  Do suite setup execution.
207
208    ${tool_exist}=  Run  which redfishtool
209    Should Not Be Empty  ${tool_exist}
210