1*** Settings ***
2Documentation     Test root user expire password.
3
4Resource          ../lib/resource.robot
5Resource          ../gui/lib/resource.robot
6Resource          ../lib/ipmi_client.robot
7Library           ../lib/bmc_ssh_utils.py
8Library           SSHLibrary
9
10*** Variables ***
11
12# If user re-tries more than 5 time incorrectly, the user gets locked for 5 minutes.
13${default_lockout_duration}   ${300}
14
15
16*** Test Cases ***
17
18Expire Root Password And Check IPMI Access Fails
19    [Documentation]   Expire root user password and expect an error while access via IPMI.
20    [Tags]  Expire_Root_Password_And_Check_IPMI_Access_Fails
21    [Teardown]  Test Teardown Execution
22
23    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
24
25    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
26    Should Contain  ${output}  password expiry information changed
27
28    ${status}=  Run Keyword And Return Status   Run External IPMI Standard Command  lan print -v
29    Should Be Equal  ${status}  ${False}
30
31
32Expire Root Password And Check SSH Access Fails
33    [Documentation]   Expire root user password and expect an error while access via SSH.
34    [Tags]  Expire_Root_Password_And_Check_SSH_Access_Fails
35    [Teardown]  Test Teardown Execution
36
37    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
38    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
39    Should Contain  ${output}  password expiry information changed
40
41    ${status}=  Run Keyword And Return Status
42    ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
43    Should Be Equal  ${status}  ${False}
44
45
46Expire And Change Root User Password And Access Via SSH
47    [Documentation]   Expire and change root user password and access via SSH.
48    [Tags]  Expire_Root_User_Password_And_Access_Via_SSH
49    [Teardown]  Run Keywords  Wait Until Keyword Succeeds  1 min  10 sec
50    ...  Restore Default Password For Root User  AND  FFDC On Test Case Fail
51
52    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
53
54    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
55    Should Contain  ${output}  password expiry information changed
56
57    Redfish.Login
58    # Change to a valid password.
59    ${resp}=  Redfish.Patch  /redfish/v1/AccountService/Accounts/${OPENBMC_USERNAME}
60    ...  body={'Password': '0penBmc123'}  valid_status_codes=[${HTTP_OK}]
61
62    # Verify login with the new password through SSH.
63    Open Connection And Log In  ${OPENBMC_USERNAME}  0penBmc123
64
65
66Expire Root Password And Update Bad Password Length Via Redfish
67   [Documentation]  Expire root password and update bad password via Redfish and expect an error.
68   [Tags]  Expire_Root_Password_And_Update_Bad_Password_Length_Via_Redfish
69   [Teardown]  Run Keywords  Wait Until Keyword Succeeds  1 min  10 sec
70   ...  Restore Default Password For Root User  AND  FFDC On Test Case Fail
71
72   Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
73   ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
74   Should Contain  ${output}  password expiry information changed
75
76   Redfish.Login
77   ${status}=  Run Keyword And Return Status
78   ...  Redfish.Patch  /redfish/v1/AccountService/Accounts/${OPENBMC_USERNAME}
79   ...  body={'Password': '0penBmc0penBmc0penBmc'}
80   Should Be Equal  ${status}  ${False}
81
82
83Expire And Change Root User Password Via Redfish And Verify
84   [Documentation]   Expire and change root user password via Redfish and verify.
85   [Tags]  Expire_And_Change_Root_User_Password_Via_Redfish_And_Verify
86   [Teardown]  Run Keywords  FFDC On Test Case Fail  AND
87   ...  Wait Until Keyword Succeeds  1 min  10 sec
88   ...  Restore Default Password For Root User
89
90   Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
91
92   ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
93   Should Contain  ${output}  password expiry information changed
94
95   Redfish.Login
96   Verify Root Password Expired
97   # Change to a valid password.
98   Redfish.Patch  /redfish/v1/AccountService/Accounts/${OPENBMC_USERNAME}
99   ...  body={'Password': '0penBmc123'}
100   Redfish.Logout
101
102   # Verify login with the new password.
103   Redfish.Login  ${OPENBMC_USERNAME}  0penBmc123
104
105
106Verify Error While Creating User With Expired Password
107    [Documentation]  Expire root password and expect an error while creating new user.
108    [Tags]  Verify_Error_While_Creating_User_With_Expired_Password
109    [Teardown]  Run Keywords  Wait Until Keyword Succeeds  1 min  10 sec
110    ...  Restore Default Password For Root User  AND  FFDC On Test Case Fail
111
112    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
113    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
114    Should Contain  ${output}  password expiry information changed
115
116    Verify Root Password Expired
117    Redfish.Login
118    ${payload}=  Create Dictionary
119    ...  UserName=admin_user  Password=TestPwd123  RoleId=Administrator  Enabled=${True}
120    Redfish.Post  /redfish/v1/AccountService/Accounts/  body=&{payload}
121    ...  valid_status_codes=[${HTTP_FORBIDDEN}]
122
123
124Expire And Change Root Password Via GUI
125    [Documentation]  Expire and change root password via GUI.
126    [Tags]  Expire_And_Change_Root_Password_Via_GUI
127    [Setup]  Run Keywords  Launch Browser And Login OpenBMC GUI
128    [Teardown]  Run Keywords  Logout And Close Browser
129    ...  AND  Restore Default Password For Root User  AND  FFDC On Test Case Fail
130
131    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
132    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
133    Should Contain  ${output}  password expiry information changed
134
135    Click Button  ${xpath_button_user_action}
136    Click Element  ${xpath_button_profile_settings}
137    Page Should Contain  Change password
138    Sleep  2s
139    # Change valid password.
140    Input Text  ${xpath_input_password}  0penBmc123
141    Input Text  ${xpath_input_confirm_password}  0penBmc123
142    Click Button  ${xpath_submit_button}
143
144    # Verify valid password.
145    Open Browser With URL  ${obmc_gui_url}
146    Login OpenBMC GUI  ${OPENBMC_USERNAME}  0penBmc123
147    Redfish.Login  ${OPENBMC_USERNAME}  0penBmc123
148
149
150Verify Maximum Failed Attempts And Check Root User Account Locked
151    [Documentation]  Verify maximum failed attempts and locks out root user account.
152    [Tags]  Verify_Maximum_Failed_Attempts_And_Check_Root_User_Account_Locked
153
154    # Make maximum failed login attempts.
155    Repeat Keyword  ${5} times
156    ...  Run Keyword And Expect Error  InvalidCredentialsError*  Redfish.Login  root  0penBmc123
157
158    # Verify that legitimate login fails due to lockout.
159    Run Keyword And Expect Error  InvalidCredentialsError*
160    ...  Redfish.Login  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
161
162    # Wait for lockout duration to expire and then verify that login works.
163    Sleep  ${default_lockout_duration}s
164    Redfish.Login
165    Redfish.Logout
166
167Verify New Password Persistency After BMC Reboot
168    [Documentation]  Verify new password persistency after BMC reboot.
169    [Tags]  Verify_New_Password_Persistency_After_BMC_Reboot
170    [Teardown]  Run Keywords  Restore Default Password For Root User
171    ...  AND  FFDC On Test Case Fail
172
173    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
174    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${OPENBMC_USERNAME}
175    Should Contain  ${output}  password expiry information changed
176
177    Redfish.Login
178    # Change to a valid password.
179    Redfish.Patch  /redfish/v1/AccountService/Accounts/${OPENBMC_USERNAME}
180    ...  body={'Password': '0penBmc123'}
181
182    # Reboot BMC and verify persistency.
183    OBMC Reboot (off)
184
185    # verify new password
186    Redfish.Login  ${OPENBMC_USERNAME}  0penBmc123
187
188
189*** Keywords ***
190
191Test Setup Execution
192   [Documentation]  Suite setup  execution.
193
194   Redfish.login
195   Redfish.Patch  /redfish/v1/AccountService/  body={"AccountLockoutThreshold": 0}
196   Valid Length  OPENBMC_PASSWORD  min_length=8
197   Redfish.Logout
198
199Restore Default Password For Root User
200    [Documentation]  Restore default password for root user (i.e. 0penBmc).
201
202    # Set default password for root user.
203    Redfish.Patch  /redfish/v1/AccountService/Accounts/${OPENBMC_USERNAME}
204    ...   body={'Password': '${OPENBMC_PASSWORD}'}  valid_status_codes=[${HTTP_OK}]
205    # Verify that root user is able to run Redfish command using default password.
206    Redfish.Logout
207
208
209Test Teardown Execution
210    [Documentation]  Do test teardown task.
211
212    Redfish.Login
213    Wait Until Keyword Succeeds  1 min  10 sec  Restore Default Password For Root User
214    Redfish.Patch  /redfish/v1/AccountService/  body={"AccountLockoutThreshold": 5}
215    Redfish.Logout
216    FFDC On Test Case Fail
217
218
219Verify Root Password Expired
220    [Documentation]  Checking whether root password expired or not.
221
222    Create Session  openbmc  ${AUTH_URI}
223    ${headers}=  Create Dictionary  Content-Type=application/json
224    @{credentials}=  Create List  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
225    ${data}=  Create Dictionary  data=@{credentials}
226    ${resp}=  Post Request  openbmc  /login  data=${data}  headers=${headers}
227    ${json}=  To JSON  ${resp.content}
228    Should Contain  ${json["extendedMessage"]}  POST the new password
229