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
66Verify Redfish Invalid URL Response Code
67    [Documentation]  Login to BMCweb and verify error response code.
68    [Tags]  Verify_Redfish_Invalid_URL_Response_Code
69
70    Redfish.Login
71    Redfish.Get  /redfish/v1/idontexist  valid_status_codes=[${HTTP_NOT_FOUND}]
72    Redfish.Logout
73
74
75Delete Redfish Session Using Valid login
76    [Documentation]  Delete a session using valid login.
77    [Tags]  Delete_Redfish_Session_Using_Valid_Login
78
79    Redfish.Login
80    ${session_info}=  Get Redfish Session Info
81
82    Redfish.Login
83
84    # Example o/p:
85    # [{'@odata.id': '/redfish/v1/SessionService/Sessions/bOol3WlCI8'},
86    #  {'@odata.id': '/redfish/v1/SessionService/Sessions/Yu3xFqjZr1'}]
87    ${resp_list}=  Redfish_Utils.List Request
88    ...  /redfish/v1/SessionService/Sessions
89
90    Redfish.Delete  ${session_info["location"]}
91
92    ${resp}=  Redfish_Utils.List Request  /redfish/v1/SessionService/Sessions
93    List Should Not Contain Value  ${resp}  ${session_info["location"]}
94
95
96*** Keywords ***
97
98GET And Verify Redfish Response
99    [Documentation]  GET given resource and verfiy response.
100    [Arguments]  ${valid_status_codes}  ${resource_path}
101
102    # Description of argument(s):
103    # valid_status_codes            A comma-separated list of acceptable
104    #                               status codes (e.g. 200).
105    # resource_path                 Redfish resource URL path.
106
107    ${resp}=  Redfish.Get  ${resource_path}
108    ...  valid_status_codes=[${valid_status_codes}]
109