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