1*** Settings ***
2Resource         ../../lib/resource.txt
3Resource         ../../lib/bmc_redfish_resource.robot
4
5*** Test Cases ***
6
7Login And Logout BMCweb
8    [Documentation]  Login to BMCweb and then logout.
9    [Tags]  Login_And_Logout_BMCweb
10
11    redfish.Login
12    redfish.Logout
13
14
15GET BMCweb Hypermedia Without Login
16    [Documentation]  GET hypermedia URL without login.
17    [Tags]  GET_BMCweb_Hypermedia_Without_Login
18    [Template]  GET And Verify Redfish Response
19
20    # Expect status      Resource URL Path
21    ${HTTP_OK}           /
22    ${HTTP_OK}           /redfish
23    ${HTTP_OK}           /redfish/v1
24
25
26GET SessionService Resource With Login
27    [Documentation]  Login to BMCweb and get /redfish/v1/SessionService.
28    [Tags]  GET_SessionService_Resource_With_Login
29
30    redfish.Login
31    ${resp}=  redfish.Get  /redfish/v1/SessionService
32    Should Be Equal As Strings  ${resp.status}  ${HTTP_OK}
33    redfish.Logout
34
35
36GET SessionService Without Login
37    [Documentation]  Get /redfish/v1/SessionService without login
38    [Tags]  GET_SessionService_Without_Login
39
40    ${resp}=  redfish.Get  /redfish/v1/SessionService
41    Should Be Equal As Strings  ${resp.status}  ${HTTP_UNAUTHORIZED}
42
43
44Login Using Invalid Token
45    [Documentation]  Login to BMCweb with invalid token.
46    [Tags]  Login_Using_Invalid_Token
47
48    Create Session  openbmc  ${AUTH_URI}
49
50    # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
51    ${headers}=  Create Dictionary  Content-Type=application/json
52    ...  X-Auth-Token=deadbeef
53
54    ${resp}=  Get Request
55    ...  openbmc  /redfish/v1/SessionService/Sessions  headers=${headers}
56
57    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_UNAUTHORIZED}
58
59
60Delete Session Using Valid login
61    [Documentation]  Delete a session using valid login.
62    [Tags]  Delete_Session_Using_Valid_Login
63
64    redfish.Login
65
66    # Example o/p:
67    # [{'@odata.id': '/redfish/v1/SessionService/Sessions/bOol3WlCI8'},
68    #  {'@odata.id': '/redfish/v1/SessionService/Sessions/Yu3xFqjZr1'}]
69    ${resp_list}=  redfish.List Request  SessionService/Sessions
70    redfish.Delete  ${resp_list[1]}
71
72    ${resp}=  redfish.List Request  SessionService/Sessions
73    List Should Not Contain Value  ${resp}  ${resp_list[1]}
74
75    # BadRequestError: Invalid session resource:
76    # /redfish/v1/SessionService/Sessions/gAEabN5Q0t, return code: 401
77
78    ${error_message}=  Catenate  SEPARATOR=  BadRequestError: Invalid session resource:
79    ...  ${SPACE}${resp_list[1]}, return code: 401
80    Run Keyword And Expect Error  ${error_message}  redfish.Logout
81
82
83*** Keywords ***
84
85GET And Verify Redfish Response
86    [Documentation]  GET given resource and verfiy response.
87    [Arguments]  ${expected_response_code}  ${resource_path}
88
89    # Description of arguments:
90    # expected_response_code   Expected REST status codes.
91    # resource_path            Redfish resource URL path.
92
93    ${resp}=  redfish.Get  ${resource_path}
94    Should Be Equal As Strings  ${resp.status}  ${expected_response_code}
95