1*** Settings ***
2Documentation  Connections and authentication module stability tests.
3
4Resource  ../lib/bmc_redfish_resource.robot
5Resource  ../lib/bmc_network_utils.robot
6Resource  ../lib/openbmc_ffdc.robot
7Resource  ../lib/resource.robot
8Resource  ../lib/utils.robot
9Resource  ../lib/connection_client.robot
10Resource  ../gui/lib/gui_resource.robot
11Library   ../lib/bmc_network_utils.py
12
13Library   SSHLibrary
14Library   Collections
15Library   XvfbRobot
16Library   OperatingSystem
17Library   SeleniumLibrary  120  120
18Library   Telnet  30 Seconds
19Library   Screenshot
20
21
22Suite Setup   Redfish.Logout
23
24Variables  ../gui/data/gui_variables.py
25
26*** Variables ***
27
28${iterations}         10000
29${loop_iteration}     ${1000}
30${hostname}           testhostname
31${MAX_UNAUTH_PER_IP}  ${5}
32${bmc_url}            https://${OPENBMC_HOST}
33
34
35*** Test Cases ***
36
37Test Patch Without Auth Token Fails
38    [Documentation]  Send patch method without auth token and verify it throws an error.
39    [Tags]   Test_Patch_Without_Auth_Token_Fails
40
41    ${active_channel_config}=  Get Active Channel Config
42    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
43
44    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body={'HostName': '${hostname}'}
45    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}, ${HTTP_FORBIDDEN}]
46
47
48Flood Patch Without Auth Token And Check Stability Of BMC
49    [Documentation]  Flood patch method without auth token and check BMC stability.
50    [Tags]  Flood_Patch_Without_Auth_Token_And_Check_Stability_Of_BMC
51
52    @{fail_list}=  Create List
53
54    ${active_channel_config}=  Get Active Channel Config
55    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
56
57    FOR  ${iter}  IN RANGE  ${1}  ${iterations} + 1
58        Log To Console  ${iter}th iteration Patch Request without valid session token
59        # Expected valid fail status response code.
60        Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body={'HostName': '${hostname}'}
61        ...  valid_status_codes=[${HTTP_UNAUTHORIZED}, ${HTTP_FORBIDDEN}]
62
63        # Every 100th iteration, check BMC allows patch with auth token.
64        ${status}=  Run Keyword If  ${iter} % 100 == 0  Run Keyword And Return Status
65        ...  Login And Configure Hostname  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
66        Run Keyword If  ${status} == False  Append To List  ${fail_list}  ${iter}
67    END
68    ${verify_count}=  Evaluate  ${iterations}/100
69    ${fail_count}=  Get Length  ${fail_list}
70
71    Should Be Equal As Integers  ${fail_count}  ${0}
72    ...  msg=Patch operation failed ${fail_count} times in ${verify_count} attempts; fails at iterations ${fail_list}
73
74
75Verify User Cannot Login After 5 Non-Logged In Sessions
76    [Documentation]  User should not be able to login when there
77    ...  are 5 non-logged in sessions.
78    [Tags]  Verify_User_Cannot_Login_After_5_Non-Logged_In_Sessions
79    [Setup]  Confirm Ability to Connect Then Close All Connections
80    [Teardown]  Run Keywords  Process.Terminate All Processes  AND
81    ...  SSHLibrary.Close All Connections  AND  FFDC On Test Case Fail
82
83    FOR  ${iter}  IN RANGE  ${0}  ${MAX_UNAUTH_PER_IP}
84       SSHLibrary.Open Connection  ${OPENBMC_HOST}
85       Start Process  ssh ${OPENBMC_USERNAME}@${OPENBMC_HOST}  shell=True
86    END
87
88    SSHLibrary.Open Connection  ${OPENBMC_HOST}
89    ${status}=   Run Keyword And Return Status  SSHLibrary.Login  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
90
91    Should Be Equal  ${status}  ${False}
92
93
94Test Post Without Auth Token Fails
95    [Documentation]  Send post method without auth token and verify it throws an error.
96    [Tags]   Test_Post_Without_Auth_Token_Fails
97
98    ${user_info}=  Create Dictionary
99    ...  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
100    Redfish.Post  /redfish/v1/AccountService/Accounts/  body=&{user_info}
101    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}, ${HTTP_FORBIDDEN}]
102
103
104Flood Post Without Auth Token And Check Stability Of BMC
105    [Documentation]  Flood post method without auth token and check BMC stability.
106    [Tags]  Flood_Post_Without_Auth_Token_And_Check_Stability_Of_BMC
107
108    @{fail_list}=  Create List
109
110    ${user_info}=  Create Dictionary
111    ...  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
112
113    FOR  ${iter}  IN RANGE  ${1}  ${iterations} + 1
114        Log To Console  ${iter}th iteration Post Request without valid session token
115        # Expected valid fail status response code.
116        Redfish.Post   /redfish/v1/AccountService/Accounts/  body=&{user_info}
117        ...  valid_status_codes=[${HTTP_UNAUTHORIZED}, ${HTTP_FORBIDDEN}]
118
119        # Every 100th iteration, check BMC allows post with auth token.
120        ${status}=  Run Keyword If  ${iter} % 100 == 0  Run Keyword And Return Status
121        ...  Login And Create User
122        Run Keyword If  ${status} == False  Append To List  ${fail_list}  ${iter}
123    END
124    ${verify_count}=  Evaluate  ${iterations}/100
125    ${fail_count}=  Get Length  ${fail_list}
126
127    Should Be Equal As Integers  ${fail_count}  ${0}
128    ...  msg=Post operation failed ${fail_count} times in ${verify_count} attempts; fails at iterations ${fail_list}
129
130
131Make Large Number Of Wrong SSH Login Attempts And Check Stability
132    [Documentation]  Check BMC stability with large number of SSH wrong login requests.
133    [Tags]  Make_Large_Number_Of_Wrong_SSH_Login_Attempts_And_Check_Stability
134    [Setup]  Set Account Lockout Threshold
135    [Teardown]  FFDC On Test Case Fail
136
137    SSHLibrary.Open Connection  ${OPENBMC_HOST}
138    @{ssh_status_list}=  Create List
139    FOR  ${iter}  IN RANGE  ${1}  ${loop_iteration} + 1
140      Log To Console  ${iter}th iteration
141      ${invalid_password}=   Catenate  ${OPENBMC_PASSWORD}${iter}
142      Run Keyword and Ignore Error
143      ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${invalid_password}
144
145      # Every 100th iteration Login with correct credentials
146      ${status}=   Run keyword If  ${iter} % ${100} == ${0}  Run Keyword And Return Status
147      ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
148      Run Keyword If  ${status} == ${False}  Append To List  ${ssh_status_list}  ${status}
149      SSHLibrary.Close Connection
150    END
151
152    ${valid_login_count}=  Evaluate  ${iterations}/100
153    ${fail_count}=  Get Length  ${ssh_status_list}
154    Should Be Equal  ${fail_count}  ${0}
155    ...  msg= Login Failed ${fail_count} times in ${valid_login_count} attempts.
156
157
158Test Stability On Large Number Of Wrong Login Attempts To GUI
159    [Documentation]  Test stability on large number of wrong login attempts to GUI.
160    [Tags]   Test_Stability_On_Large_Number_Of_Wrong_Login_Attempts_To_GUI
161
162    @{status_list}=  Create List
163
164    # Open headless browser.
165    Start Virtual Display
166    ${browser_ID}=  Open Browser  ${bmc_url}  alias=browser1
167    Set Window Size  1920  1080
168
169    Go To  ${bmc_url}
170
171    FOR  ${iter}  IN RANGE  ${1}  ${iterations} + 1
172        Log To Console  ${iter}th login
173        Run Keyword And Ignore Error  Login to GUI With Incorrect Credentials
174
175        # Every 100th iteration, check BMC GUI is responsive.
176        ${status}=  Run Keyword If  ${iter} % 100 == 0  Run Keyword And Return Status
177        ...  Open Browser  ${bmc_url}
178        Append To List  ${status_list}  ${status}
179        Run Keyword If  '${status}' == 'True'
180        ...  Run Keywords  Close Browser  AND  Switch Browser  browser1
181    END
182
183    ${fail_count}=  Count Values In List  ${status_list}  False
184    Run Keyword If  ${fail_count} > ${0}  FAIL  Could not open BMC GUI ${fail_count} times
185
186Test BMC GUI Stability On Continuous Refresh Of GUI Home Page
187    [Documentation]  Login to BMC GUI and keep refreshing home page and verify stability
188        ...  by login at times in another browser.
189    [Tags]  Test_BMC_GUI_Stability_On_Continuous_Refresh_Of_GUI_Home_Page
190    [Teardown]  Close All Browsers
191
192    @{failed_list}=  Create List
193
194    # Open headless browser.
195    Start Virtual Display
196    ${browser_ID}=  Open Browser  ${bmc_url}  alias=browser1
197    Set Window Size  1920  1080
198    Login GUI
199
200    FOR  ${iter}  IN RANGE  ${iterations}
201        Log To Console  ${iter}th Refresh of home page
202
203        Refresh GUI
204        Continue For Loop If   ${iter}%100 != 0
205
206        # Every 100th iteration, check BMC GUI is responsive.
207        ${status}=  Run Keyword And Return Status
208        ...  Run Keywords  Launch Browser And Login GUI  AND  Logout GUI
209        Run Keyword If  '${status}' == 'False'  Append To List  ${failed_list}  ${iter}
210        ...  ELSE IF  '${status}' == 'True'
211        ...  Run Keywords  Close Browser  AND  Switch Browser  browser1
212    END
213    Log   ${failed_list}
214    ${fail_count}=  Get Length  ${failed_list}
215    Run Keyword If  ${fail_count} > ${0}  FAIL  Could not open BMC GUI ${fail_count} times
216
217Test BMCweb Stability On Continuous Redfish Login Attempts With Invalid Credentials
218    [Documentation]  Make invalid credentials Redfish login attempts continuously and
219    ...  verify bmcweb stability by login to Redfish with valid credentials.
220    [Tags]  Test_BMCweb_Stability_On_Continuous_Redfish_Login_Attempts_With_Invalid_Credentials
221
222    Invalid Credentials Redfish Login Attempts
223
224Test User Delete Operation Without Session Token And Expect Failure
225    [Documentation]  Try to delete an object without valid session token and verifies it throws
226    ...  an unauthorised error.
227    [Tags]  Test_User_Delete_Operation_Without_Session_Token_And_Expect_Failure
228    [Setup]  Redfish.Logout
229
230    Redfish.Delete  /redfish/v1/AccountService/Accounts/test_user
231    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}]
232
233
234Test Bmcweb Stability On Continuous Redfish Delete Operation Request Without Session Token
235    [Documentation]  Send delete object request without valid session token continuously and
236    ...  verify bmcweb stability by sending delete request with valid session token.
237    [Tags]  Test_Bmcweb_Stability_On_Continuous_Redfish_Delete_Operation_Request_Without_Session_Token
238
239    @{failed_iter_list}=  Create List
240
241    FOR  ${iter}  IN RANGE  ${iterations}
242        Log To Console  ${iter}th Redfish Delete Object Request without valid session token
243
244        Run Keyword And Ignore Error
245        ...  Redfish.Delete  /redfish/v1/AccountService/Accounts/test_user
246        Continue For Loop If   ${iter}%100 != 0
247
248        # Every 100th iteration, check delete operation with valid session token.
249        ${status}=  Run Keyword And Return Status
250        ...  Login And Delete User
251        Run Keyword If  '${status}' == 'False'  Append To List  ${failed_iter_list}  ${iter}
252    END
253    Log  ${failed_iter_list}
254    ${fail_count}=  Get Length  ${failed_iter_list}
255    Run Keyword If  ${fail_count} > ${0}  FAIL  Could not do Redfish delete operation ${fail_count} times
256
257*** Keywords ***
258
259Login And Configure Hostname
260    [Documentation]  Login and configure hostname
261    [Arguments]  ${ethernet_interface_uri}
262    [Teardown]  Redfish.Logout
263
264    # Description of argument(s):
265    # ethernet_interface_uri   Network interface URI path.
266
267    Redfish.Login
268
269    Redfish.Patch  ${ethernet_interface_uri}  body={'HostName': '${hostname}'}
270    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
271
272
273Login And Create User
274    [Documentation]  Login and create user
275
276    [Teardown]  Run Keywords   Redfish.Delete  /redfish/v1/AccountService/Accounts/test_user
277    ...  AND  Redfish.Logout
278
279    Redfish.Login
280
281    ${user_info}=  Create Dictionary
282    ...  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
283    Redfish.Post  /redfish/v1/AccountService/Accounts/  body=&{user_info}
284    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_CREATED}]
285
286Login And Delete User
287    [Documentation]  Login create and delete user
288
289    [Teardown]  Redfish.Logout
290
291    Redfish.Login
292
293    ${user_info}=  Create Dictionary
294    ...  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
295    Redfish.Post  /redfish/v1/AccountService/Accounts/  body=&{user_info}
296    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_CREATED}]
297    Redfish.Delete  /redfish/v1/AccountService/Accounts/test_user
298
299Set Account Lockout Threshold
300   [Documentation]  Set user account lockout threshold.
301
302   [Teardown]  Redfish.Logout
303
304   Redfish.Login
305   Redfish.Patch  /redfish/v1/AccountService  body=[('AccountLockoutThreshold', 0)]
306
307
308Login to GUI With Incorrect Credentials
309    [Documentation]  Attempt to login to GUI as root, providing incorrect password argument.
310
311    Input Text  ${xpath_textbox_username}  root
312    Input Password  ${xpath_textbox_password}  incorrect_password
313    Click Button  ${xpath_login_button}
314
315Invalid Credentials Redfish Login Attempts
316    [Documentation]  Continuous invalid credentials login attempts to Redfish and
317    ...  login to Redfish with valid credentials at times and get failed login attempts.
318    [Arguments]  ${login_username}=${OPENBMC_USERNAME}  ${login_password}=${OPENBMC_PASSWORD}
319
320    # Description of argument(s):
321    # login_username   username for login user.
322    # login_password   password for login user.
323
324    @{failed_iter_list}=  Create List
325
326    FOR  ${iter}  IN RANGE  ${iterations}
327        Log To Console  ${iter}th Redfish login with invalid credentials
328        Run Keyword And Ignore Error  Redfish.Login   ${login_username}  incorrect_password
329        Continue For Loop If   ${iter}%100 != 0
330
331        # Every 100th iteration, check Redfish is responsive.
332        ${status}=  Run Keyword And Return Status
333        ...  Redfish.Login  ${login_username}   ${login_password}
334        Run Keyword If  '${status}' == 'False'  Append To List  ${failed_iter_list}  ${iter}
335        Redfish.Logout
336    END
337    Log  ${failed_iter_list}
338    ${fail_count}=  Get Length  ${failed_iter_list}
339    Run Keyword If  ${fail_count} > ${0}  FAIL  Could not Login to Redfish ${fail_count} times
340
341
342Confirm Ability to Connect Then Close All Connections
343    [Documentation]  Confirm that SSH login works, otherwise, skip this test.
344    ...  If login succeeds, close all SSH connections to BMC to prepare for test.
345
346    SSHLibrary.Close All Connections
347    SSHLibrary.Open Connection  ${OPENBMC_HOST}
348    ${status}=   Run Keyword And Return Status
349    ...  SSHLibrary.Login  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
350    Skip If  ${status} == ${False}  msg= SSH Login failed: test will be skipped
351    SSHLibrary.Close All Connections
352