blob: 12f12b932dd44135dd31163a84120d30ec87aeef [file] [log] [blame]
George Keishing4c394012019-02-01 06:03:02 -06001*** Settings ***
Joy Onyerikwudbfe97d2019-03-11 19:44:56 -05002Documentation Test Redfish service root login security.
3
George Keishing4c394012019-02-01 06:03:02 -06004Resource ../../lib/bmc_redfish_resource.robot
George Keishing3298d5c2019-02-12 06:59:25 -06005Resource ../../lib/openbmc_ffdc.robot
6
7Test Teardown FFDC On Test Case Fail
Michael Walshc108e422019-03-28 12:27:18 -05008Test Setup Printn
George Keishing4c394012019-02-01 06:03:02 -06009
George Keishing374e6842019-02-20 08:57:18 -060010*** Variables ***
11
12${LOGIN_SESSION_COUNT} ${50}
13
George Keishingc2837c92023-07-28 20:26:03 +053014&{header_requirements} Strict-Transport-Security=max-age=31536000; includeSubdomains
George Keishing35e0bba2019-06-04 13:10:55 -050015... X-Frame-Options=DENY
16... Pragma=no-cache
George Keishingc2837c92023-07-28 20:26:03 +053017... Cache-Control=no-store, max-age=0
18... Referrer-Policy=no-referrer
George Keishing35e0bba2019-06-04 13:10:55 -050019... X-Content-Type-Options=nosniff
George Keishingc2837c92023-07-28 20:26:03 +053020... X-Permitted-Cross-Domain-Policies=none
21... Cross-Origin-Embedder-Policy=require-corp
22... Cross-Origin-Opener-Policy=same-origin
23... Cross-Origin-Resource-Policy=same-origin
24... Content-Security-Policy=default-src 'none'; img-src 'self' data:; font-src 'self'; style-src 'self'; script-src 'self'; connect-src 'self' wss:; form-action 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'none'
George Keishing9edf5bc2019-04-09 15:07:28 -050025
George Keishing76adf442025-03-19 09:51:47 +053026${ERROR_RESPONSE_MSG} *Connection refused*
27
George Keishing4c394012019-02-01 06:03:02 -060028*** Test Cases ***
29
George Keishing5ee33d92019-02-02 12:33:25 -060030Redfish Login With Invalid Credentials
George Keishing4c394012019-02-01 06:03:02 -060031 [Documentation] Login to BMC web using invalid credential.
George Keishing5ee33d92019-02-02 12:33:25 -060032 [Tags] Redfish_Login_With_Invalid_Credentials
George Keishing4c394012019-02-01 06:03:02 -060033 [Template] Login And Verify Redfish Response
34
George Keishing32616042022-09-22 05:25:39 -050035 # Username Password Expect status
36 ${OPENBMC_USERNAME} deadpassword InvalidCredentialsError
37 groot ${OPENBMC_PASSWORD} InvalidCredentialsError
38 ${EMPTY} ${OPENBMC_PASSWORD} SessionCreationError
39 ${OPENBMC_USERNAME} ${EMPTY} SessionCreationError
40 ${EMPTY} ${EMPTY} SessionCreationError
George Keishing4c394012019-02-01 06:03:02 -060041
42
George Keishing5ee33d92019-02-02 12:33:25 -060043Redfish Login Using Unsecured HTTP
George Keishinga8116932019-02-05 11:51:47 -060044 [Documentation] Login to BMC web through http unsecured.
George Keishing5ee33d92019-02-02 12:33:25 -060045 [Tags] Redfish_Login_Using_Unsecured_HTTP
George Keishinga8116932019-02-05 11:51:47 -060046
47 Create Session openbmc http://${OPENBMC_HOST}
48 ${data}= Create Dictionary
49 ... UserName=${OPENBMC_USERNAME} Password=${OPENBMC_PASSWORD}
50
51 ${headers}= Create Dictionary Content-Type=application/json
52
53 Run Keyword And Expect Error *Connection refused*
George Keishingfbd67002022-08-01 11:24:03 -050054 ... POST On Session openbmc /redfish/v1/SessionService/Sessions
George Keishinga8116932019-02-05 11:51:47 -060055 ... data=${data} headers=${headers}
56
57
George Keishingb2f07342019-02-09 05:21:45 -060058Redfish Login Using HTTPS Wrong Port 80 Protocol
59 [Documentation] Login to BMC web through wrong protocol port 80.
60 [Tags] Redfish_Login_Using_HTTPS_Wrong_Port_80_Protocol
61
62 Create Session openbmc https://${OPENBMC_HOST}:80
63 ${data}= Create Dictionary
64 ... UserName=${OPENBMC_USERNAME} Password=${OPENBMC_PASSWORD}
65
66 ${headers}= Create Dictionary Content-Type=application/json
67
George Keishing76adf442025-03-19 09:51:47 +053068 Run Keyword And Expect Error ${ERROR_RESPONSE_MSG}
George Keishingfbd67002022-08-01 11:24:03 -050069 ... POST On Session openbmc /redfish/v1/SessionService/Sessions
George Keishingb2f07342019-02-09 05:21:45 -060070 ... data=${data} headers=${headers}
71
72
George Keishing374e6842019-02-20 08:57:18 -060073Create Multiple Login Sessions And Verify
74 [Documentation] Create 50 login instances and verify.
75 [Tags] Create_Multiple_Login_Sessions_And_Verify
Sushil Singhd1a35ac2020-08-04 11:28:56 -050076 [Teardown] Run Keyword And Ignore Error Multiple Session Cleanup
George Keishing374e6842019-02-20 08:57:18 -060077
George Keishing97c93942019-03-04 12:45:07 -060078 Redfish.Login
George Keishing374e6842019-02-20 08:57:18 -060079 # Example:
80 # {
81 # 'key': 'L0XEsZAXpNdF147jJaOD',
82 # 'location': '/redfish/v1/SessionService/Sessions/qWn2JOJSOs'
83 # }
George Keishing0b9d8ab2019-02-20 14:02:41 -060084 ${saved_session_info}= Get Redfish Session Info
George Keishing374e6842019-02-20 08:57:18 -060085
86 # Sessions book keeping for cleanup once done.
87 ${session_list}= Create List
88 Set Test Variable ${session_list}
89
90 Repeat Keyword ${LOGIN_SESSION_COUNT} times Create New Login Session
91
92 # Update the redfish session object with the first login key and location
93 # and verify if it is still working.
George Keishing97c93942019-03-04 12:45:07 -060094 Redfish.Set Session Key ${saved_session_info["key"]}
95 Redfish.Set Session Location ${saved_session_info["location"]}
96 Redfish.Get ${saved_session_info["location"]}
George Keishing374e6842019-02-20 08:57:18 -060097
98
George Keishing0b9d8ab2019-02-20 14:02:41 -060099Attempt Login With Expired Session
100 [Documentation] Authenticate to redfish, then log out and attempt to
101 ... use the session.
102 [Tags] Attempt_Login_With_Expired_Session
103
George Keishing97c93942019-03-04 12:45:07 -0600104 Redfish.Login
George Keishing0b9d8ab2019-02-20 14:02:41 -0600105 ${saved_session_info}= Get Redfish Session Info
George Keishing97c93942019-03-04 12:45:07 -0600106 Redfish.Logout
George Keishing0b9d8ab2019-02-20 14:02:41 -0600107
108 # Attempt login with expired session.
109 # By default 60 minutes of inactivity closes the session.
George Keishing97c93942019-03-04 12:45:07 -0600110 Redfish.Set Session Key ${saved_session_info["key"]}
111 Redfish.Set Session Location ${saved_session_info["location"]}
George Keishing0b9d8ab2019-02-20 14:02:41 -0600112
George Keishing97c93942019-03-04 12:45:07 -0600113 Redfish.Get ${saved_session_info["location"]} valid_status_codes=[${HTTP_UNAUTHORIZED}]
George Keishing0b9d8ab2019-02-20 14:02:41 -0600114
115
George Keishing9edf5bc2019-04-09 15:07:28 -0500116Login And Verify HTTP Response Header
117 [Documentation] Login and verify redfish HTTP response header.
118 [Tags] Login_And_Verify_HTTP_Response_Header
119
120 # Example of HTTP redfish response header.
George Keishingc2837c92023-07-28 20:26:03 +0530121 # Strict-Transport-Security: max-age=31536000; includeSubdomains
George Keishing9edf5bc2019-04-09 15:07:28 -0500122 # X-Frame-Options: DENY
123 # Pragma: no-cache
George Keishingc2837c92023-07-28 20:26:03 +0530124 # Cache-Control: no-store, max-age=0
George Keishing9edf5bc2019-04-09 15:07:28 -0500125 # X-Content-Type-Options: nosniff
George Keishingc2837c92023-07-28 20:26:03 +0530126 # Referrer-Policy: no-referrer
127 # X-Permitted-Cross-Domain-Policies: none
128 # Cross-Origin-Embedder-Policy: require-corp
129 # Cross-Origin-Opener-Policy: same-origin
130 # Cross-Origin-Resource-Policy: same-origin
131 # Content-Security-Policy: default-src 'none'; img-src 'self' data:; font-src 'self'; style-src 'self'; script-src 'self'; connect-src 'self' wss:; form-action 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'none'
132
George Keishing9edf5bc2019-04-09 15:07:28 -0500133
Michael Walsh0d5f96a2019-05-20 10:09:57 -0500134 Rprint Vars header_requirements fmt=1
George Keishing9edf5bc2019-04-09 15:07:28 -0500135
136 Redfish.Login
137 ${resp}= Redfish.Get /redfish/v1/SessionService/Sessions
138
139 # The getheaders() method returns the headers as a list of tuples:
140 # headers:
George Keishingc2837c92023-07-28 20:26:03 +0530141
142 # [Strict-Transport-Security]: max-age=31536000; includeSubdomains
143 # [X-Frame-Options]: DENY
144 # [Pragma]: no-cache
145 # [Cache-Control]: no-store, max-age=0
146 # [X-Content-Type-Options]: nosniff
147 # [Referrer-Policy]: no-referrer
148 # [X-Permitted-Cross-Domain-Policies]: none
149 # [Cross-Origin-Embedder-Policy]: require-corp
150 # [Cross-Origin-Opener-Policy]: same-origin
151 # [Cross-Origin-Resource-Policy]: same-origin
152 # [Content-Security-Policy]: default-src 'none'; img-src 'self' data:; font-src 'self'; style-src 'self'; script-src 'self'; connect-src 'self' wss:; form-action 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'none'
153 # [Content-Type]: application/json
154 # [Content-Length]: 394
George Keishing9edf5bc2019-04-09 15:07:28 -0500155
156 ${headers}= Key Value List To Dict ${resp.getheaders()}
Michael Walsh0d5f96a2019-05-20 10:09:57 -0500157 Rprint Vars headers fmt=1
George Keishing9edf5bc2019-04-09 15:07:28 -0500158
159 Dictionary Should Contain Sub Dictionary ${headers} ${header_requirements}
160
161
George Keishing4c394012019-02-01 06:03:02 -0600162*** Keywords ***
163
164Login And Verify Redfish Response
165 [Documentation] Login and verify redfish response.
George Keishing32616042022-09-22 05:25:39 -0500166 [Arguments] ${username} ${password} ${expected_response}
George Keishing4c394012019-02-01 06:03:02 -0600167
168 # Description of arguments:
George Keishing32616042022-09-22 05:25:39 -0500169 # expected_response Expected REST status.
170 # username The username to be used to connect to the server.
171 # password The password to be used to connect to the server.
George Keishing4c394012019-02-01 06:03:02 -0600172
George Keishing5e6515e2019-03-12 14:22:33 -0500173 # The redfish object may preserve a valid username or password from the
174 # last failed login attempt. If we then try to login with a null username
175 # or password value, the redfish object may prefer the preserved value.
176 # Since we're testing bad path, we wish to avoid this scenario so we will
177 # clear these values.
178
179 Redfish.Set Username ${EMPTY}
180 Redfish.Set Password ${EMPTY}
181
George Keishing32616042022-09-22 05:25:39 -0500182 ${msg}= Run Keyword And Expect Error * Redfish.Login ${username} ${password}
183
184 # redfish package version <=3.1.6 default response is InvalidCredentialsError.
185 Should Contain Any ${msg} InvalidCredentialsError ${expected_response}
George Keishing374e6842019-02-20 08:57:18 -0600186
187
188Create New Login Session
189 [Documentation] Multiple login session keys.
190
George Keishing97c93942019-03-04 12:45:07 -0600191 Redfish.Login
George Keishing374e6842019-02-20 08:57:18 -0600192 ${session_info}= Get Redfish Session Info
193
194 # Append the session location to the list.
195 # ['/redfish/v1/SessionService/Sessions/uDzihgDecs',
196 # '/redfish/v1/SessionService/Sessions/PaHF5brPPd']
197 Append To List ${session_list} ${session_info["location"]}
198
199
200Multiple Session Cleanup
201 [Documentation] Do the teardown for multiple sessions.
202
203 FFDC On Test Case Fail
204
Sushil Singh50621142020-06-16 11:12:21 -0500205 FOR ${item} IN @{session_list}
206 Redfish.Delete ${item}
207 END