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       Rprintn
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    Redfish.Login
72
73    # Example o/p:
74    # [{'@odata.id': '/redfish/v1/SessionService/Sessions/bOol3WlCI8'},
75    #  {'@odata.id': '/redfish/v1/SessionService/Sessions/Yu3xFqjZr1'}]
76    ${resp_list}=  Redfish_Utils.List Request
77    ...  /redfish/v1/SessionService/Sessions
78    Redfish.Delete  ${resp_list[1]}
79
80    ${resp}=  Redfish_Utils.List Request  /redfish/v1/SessionService/Sessions
81    List Should Not Contain Value  ${resp}  ${resp_list[1]}
82
83
84*** Keywords ***
85
86GET And Verify Redfish Response
87    [Documentation]  GET given resource and verfiy response.
88    [Arguments]  ${valid_status_codes}  ${resource_path}
89
90    # Description of argument(s):
91    # valid_status_codes            A comma-separated list of acceptable
92    #                               status codes (e.g. 200).
93    # resource_path                 Redfish resource URL path.
94
95    ${resp}=  Redfish.Get  ${resource_path}
96    ...  valid_status_codes=[${valid_status_codes}]
97