1*** Settings ***
2Documentation    Test Redfish to verify responses for SessionService and Hypermedia.
3
4Resource         ../../lib/resource.robot
5Resource         ../../lib/bmc_redfish_resource.robot
6Resource         ../../lib/openbmc_ffdc.robot
7
8
9Test Teardown    FFDC On Test Case Fail
10Test Setup       Printn
11
12*** Test Cases ***
13
14Redfish Login And Logout
15    [Documentation]  Login to BMCweb and then logout.
16    [Tags]  Redfish_Login_And_Logout
17
18    Redfish.Login
19    Redfish.Logout
20
21
22GET Redfish Hypermedia Without Login
23    [Documentation]  GET hypermedia URL without login.
24    [Tags]  GET_Redfish_Hypermedia_Without_Login
25    [Template]  GET And Verify Redfish Response
26
27    # Expect status      Resource URL Path
28    ${HTTP_OK}           /
29    ${HTTP_OK}           /redfish
30    ${HTTP_OK}           /redfish/v1
31
32
33GET Redfish SessionService Resource With Login
34    [Documentation]  Login to BMCweb and get /redfish/v1/SessionService.
35    [Tags]  GET_Redfish_SessionService_Resource_With_Login
36
37    Redfish.Login
38    ${resp}=  Redfish.Get  /redfish/v1/SessionService
39    Redfish.Logout
40
41
42GET Redfish SessionService Without Login
43    [Documentation]  Get /redfish/v1/SessionService without login
44    [Tags]  GET_Redfish_SessionService_Without_Login
45
46    ${resp}=  Redfish.Get  /redfish/v1/SessionService
47    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}]
48
49
50Redfish Login Using Invalid Token
51    [Documentation]  Login to BMCweb with invalid token.
52    [Tags]  Redfish_Login_Using_Invalid_Token
53
54    Create Session  openbmc  ${AUTH_URI}
55
56    # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
57    ${headers}=  Create Dictionary  Content-Type=application/json
58    ...  X-Auth-Token=deadbeef
59
60    ${resp}=  Get Request
61    ...  openbmc  /redfish/v1/SessionService/Sessions  headers=${headers}
62
63    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_UNAUTHORIZED}
64
65
66Delete Redfish Session Using Valid login
67    [Documentation]  Delete a session using valid login.
68    [Tags]  Delete_Redfish_Session_Using_Valid_Login
69
70    Redfish.Login
71    ${session_info}=  Get Redfish Session Info
72
73    Redfish.Login
74
75    # Example o/p:
76    # [{'@odata.id': '/redfish/v1/SessionService/Sessions/bOol3WlCI8'},
77    #  {'@odata.id': '/redfish/v1/SessionService/Sessions/Yu3xFqjZr1'}]
78    ${resp_list}=  Redfish_Utils.List Request
79    ...  /redfish/v1/SessionService/Sessions
80
81    Redfish.Delete  ${session_info["location"]}
82
83    ${resp}=  Redfish_Utils.List Request  /redfish/v1/SessionService/Sessions
84    List Should Not Contain Value  ${resp}  ${session_info["location"]}
85
86
87*** Keywords ***
88
89GET And Verify Redfish Response
90    [Documentation]  GET given resource and verfiy response.
91    [Arguments]  ${valid_status_codes}  ${resource_path}
92
93    # Description of argument(s):
94    # valid_status_codes            A comma-separated list of acceptable
95    #                               status codes (e.g. 200).
96    # resource_path                 Redfish resource URL path.
97
98    ${resp}=  Redfish.Get  ${resource_path}
99    ...  valid_status_codes=[${valid_status_codes}]
100