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
10Library   ../lib/bmc_network_utils.py
11
12Library   SSHLibrary
13Library   Collections
14Library   XvfbRobot
15Library   OperatingSystem
16Library   Selenium2Library  120  120
17Library   Telnet  30 Seconds
18Library   Screenshot
19
20
21Suite Setup   Redfish.Logout
22
23Variables  ../gui/data/gui_variables.py
24
25*** Variables ***
26
27${iterations}         10000
28${loop_iteration}     ${1000}
29${hostname}           test_hostname
30${MAX_UNAUTH_PER_IP}  ${5}
31${bmc_url}            https://${OPENBMC_HOST}
32
33
34*** Test Cases ***
35
36Test Patch Without Auth Token Fails
37    [Documentation]  Send patch method without auth token and verify it throws an error.
38    [Tags]   Test_Patch_Without_Auth_Token_Fails
39
40    ${active_channel_config}=  Get Active Channel Config
41    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
42
43    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body={'HostName': '${hostname}'}
44    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}, ${HTTP_FORBIDDEN}]
45
46
47Flood Patch Without Auth Token And Check Stability Of BMC
48    [Documentation]  Flood patch method without auth token and check BMC stability.
49    [Tags]  Flood_Patch_Without_Auth_Token_And_Check_Stability_Of_BMC
50    @{status_list}=  Create List
51
52    ${active_channel_config}=  Get Active Channel Config
53    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
54
55    FOR  ${i}  IN RANGE  ${1}  ${iterations}
56        Log To Console  ${i}th iteration
57        Run Keyword And Ignore Error
58        ...  Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body={'HostName': '${hostname}'}
59
60        # Every 100th iteration, check BMC allows patch with auth token.
61        ${status}=  Run Keyword If  ${i} % 100 == 0  Run Keyword And Return Status
62        ...  Login And Configure Hostname
63        Run Keyword If  ${status} == False  Append To List  ${status_list}  ${status}
64    END
65    ${verify_count}=  Evaluate  ${iterations}/100
66    ${fail_count}=  Get Length  ${status_list}
67
68    Should Be Equal  ${fail_count}  0
69    ...  msg=Patch operation failed ${fail_count} times in ${verify_count} attempts
70
71
72Verify User Cannot Login After 5 Non-Logged In Sessions
73    [Documentation]  User should not be able to login when there
74    ...  are 5 non-logged in sessions.
75    [Tags]  Verify_User_Cannot_Login_After_5_Non-Logged_In_Sessions
76
77    FOR  ${i}  IN RANGE  ${0}  ${MAX_UNAUTH_PER_IP}
78       SSHLibrary.Open Connection  ${OPENBMC_HOST}
79       Start Process  ssh ${OPENBMC_USERNAME}@${OPENBMC_HOST}  shell=True
80    END
81
82    SSHLibrary.Open Connection  ${OPENBMC_HOST}
83    ${status}=   Run Keyword And Return Status  SSHLibrary.Login  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
84
85    Should Be Equal  ${status}  ${False}
86
87
88Test Post Without Auth Token Fails
89    [Documentation]  Send post method without auth token and verify it throws an error.
90    [Tags]   Test_Post_Without_Auth_Token_Fails
91
92    ${user_info}=  Create Dictionary
93    ...  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
94    Redfish.Post  /redfish/v1/AccountService/Accounts/  body=&{user_info}
95    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}, ${HTTP_FORBIDDEN}]
96
97
98Flood Post Without Auth Token And Check Stability Of BMC
99    [Documentation]  Flood post method without auth token and check BMC stability.
100    [Tags]  Flood_Post_Without_Auth_Token_And_Check_Stability_Of_BMC
101
102    @{status_list}=  Create List
103    ${user_info}=  Create Dictionary
104    ...  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
105
106    FOR  ${i}  IN RANGE  ${1}  ${iterations}
107        Log To Console  ${i}th iteration
108        Run Keyword And Ignore Error
109        ...  Redfish.Post   /redfish/v1/AccountService/Accounts/  body=&{user_info}
110
111        # Every 100th iteration, check BMC allows post with auth token.
112        ${status}=  Run Keyword If  ${i} % 100 == 0  Run Keyword And Return Status
113        ...  Login And Create User
114        Run Keyword If  ${status} == False  Append To List  ${status_list}  ${status}
115    END
116    ${verify_count}=  Evaluate  ${iterations}/100
117    ${fail_count}=  Get Length  ${status_list}
118
119    Should Be Equal  ${fail_count}  0
120    ...  msg=Post operation failed ${fail_count} times in ${verify_count} attempts
121
122
123Make Large Number Of Wrong SSH Login Attempts And Check Stability
124    [Documentation]  Check BMC stability with large number of SSH wrong login requests.
125    [Tags]  Make_Large_Number_Of_Wrong_SSH_Login_Attempts_And_Check_Stability
126    [Setup]  Set Account Lockout Threshold
127    [Teardown]  FFDC On Test Case Fail
128
129    SSHLibrary.Open Connection  ${OPENBMC_HOST}
130    @{ssh_status_list}=  Create List
131    FOR  ${i}  IN RANGE  ${loop_iteration}
132      Log To Console  ${i}th iteration
133      ${invalid_password}=   Catenate  ${OPENBMC_PASSWORD}${i}
134      Run Keyword and Ignore Error
135      ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${invalid_password}
136
137      # Every 100th iteration Login with correct credentials
138      ${status}=   Run keyword If  ${i} % ${100} == ${0}  Run Keyword And Return Status
139      ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
140      Run Keyword If  ${status} == ${False}  Append To List  ${ssh_status_list}  ${status}
141      SSHLibrary.Close Connection
142    END
143
144    ${valid_login_count}=  Evaluate  ${iterations}/100
145    ${fail_count}=  Get Length  ${ssh_status_list}
146    Should Be Equal  ${fail_count}  ${0}
147    ...  msg= Login Failed ${fail_count} times in ${valid_login_count} attempts.
148
149
150Test Stability On Large Number Of Wrong Login Attempts To GUI
151    [Documentation]  Test stability on large number of wrong login attempts to GUI.
152    [Tags]   Test_Stability_On_Large_Number_Of_Wrong_Login_Attempts_To_GUI
153
154    @{status_list}=  Create List
155
156    # Open headless browser.
157    Start Virtual Display
158    ${browser_ID}=  Open Browser  ${bmc_url}  alias=browser1
159    Set Window Size  1920  1080
160
161    Go To  ${bmc_url}
162
163    FOR  ${i}  IN RANGE  ${1}  ${iterations}
164        Log To Console  ${i}th login
165        Run Keyword And Ignore Error  Login to GUI With Wrong Credentials
166
167        # Every 100th iteration, check BMC GUI is responsive.
168        ${status}=  Run Keyword If  ${i} % 100 == 0  Run Keyword And Return Status
169        ...  Open Browser  ${bmc_url}
170        Append To List  ${status_list}  ${status}
171        Run Keyword If  '${status}' == 'True'  Run Keywords  Close Browser  AND  Switch Browser  browser1
172    END
173
174    ${fail_count}=  Count Values In List  ${status_list}  False
175    Run Keyword If  ${fail_count} > ${0}  FAIL  Could not open BMC GUI ${fail_count} times
176
177
178*** Keywords ***
179
180Login And Configure Hostname
181    [Documentation]  Login and configure hostname
182
183    [Teardown]  Redfish.Logout
184
185    Redfish.Login
186
187    Redfish.patch  ${REDFISH_NW_PROTOCOL_URI}  body={'HostName': '${hostname}'}
188    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
189
190
191Login And Create User
192    [Documentation]  Login and create user
193
194    [Teardown]  Redfish.Logout
195
196    Redfish.Login
197
198    ${user_info}=  Create Dictionary
199    ...  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
200    Redfish.Post  /redfish/v1/AccountService/Accounts/  body=&{user_info}
201    ...  valid_status_codes=[${HTTP_OK}]
202
203
204Set Account Lockout Threshold
205   [Documentation]  Set user account lockout threshold.
206
207   [Teardown]  Redfish.Logout
208
209   Redfish.Login
210   Redfish.Patch  /redfish/v1/AccountService  body=[('AccountLockoutThreshold', 0)]
211
212
213Login to GUI With Incorrect Credentials
214    [Documentation]  Login to GUI With Wrong Credentials.
215
216    Input Text  ${xpath_textbox_username}  root
217    Input Password  ${xpath_textbox_password}  incorrect_password
218    Click Button  ${xpath_login_button}
219