summaryrefslogtreecommitdiff
path: root/test/redfish-core/lib/service_root_test.cpp
blob: 78c068d760719cb35bd941f0d1ce1c3788b0b58f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "bmcweb_config.h"

#include "async_resp.hpp"
#include "http_response.hpp"
#include "service_root.hpp"

#include <nlohmann/json.hpp>

#include <memory>
#include <vector>

#include <gmock/gmock.h> // IWYU pragma: keep
#include <gtest/gtest.h> // IWYU pragma: keep

// IWYU pragma: no_include <gtest/gtest-message.h>
// IWYU pragma: no_include <gtest/gtest-test-part.h>
// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
// IWYU pragma: no_include <gmock/gmock-matchers.h>
// IWYU pragma: no_include <gtest/gtest-matchers.h>

namespace redfish
{
namespace
{

void assertServiceRootGet(crow::Response& res)
{
    nlohmann::json& json = res.jsonValue;
    EXPECT_EQ(json["@odata.id"], "/redfish/v1");
    EXPECT_EQ(json["@odata.type"], "#ServiceRoot.v1_15_0.ServiceRoot");

    EXPECT_EQ(json["AccountService"]["@odata.id"],
              "/redfish/v1/AccountService");
    EXPECT_EQ(json["AccountService"].size(), 1);

    EXPECT_EQ(json["CertificateService"]["@odata.id"],
              "/redfish/v1/CertificateService");
    EXPECT_EQ(json["CertificateService"].size(), 1);

    EXPECT_EQ(json["Chassis"]["@odata.id"], "/redfish/v1/Chassis");
    EXPECT_EQ(json["Chassis"].size(), 1);

    EXPECT_EQ(json["EventService"]["@odata.id"], "/redfish/v1/EventService");
    EXPECT_EQ(json["EventService"].size(), 1);

    EXPECT_EQ(json["Id"], "RootService");
    EXPECT_EQ(json["Links"]["Sessions"]["@odata.id"],
              "/redfish/v1/SessionService/Sessions");
    EXPECT_EQ(json["Links"].size(), 2);
    EXPECT_EQ(json["Links"]["Sessions"].size(), 1);
    EXPECT_EQ(json["Links"]["ManagerProvidingService"].size(), 1);
    EXPECT_EQ(json["Links"]["ManagerProvidingService"]["@odata.id"],
              "/redfish/v1/Managers/bmc");

    EXPECT_EQ(json["Managers"]["@odata.id"], "/redfish/v1/Managers");
    EXPECT_EQ(json["Managers"].size(), 1);

    EXPECT_EQ(json["Name"], "Root Service");
    EXPECT_EQ(json["RedfishVersion"], "1.17.0");

    EXPECT_EQ(json["Registries"]["@odata.id"], "/redfish/v1/Registries");
    EXPECT_EQ(json["Registries"].size(), 1);

    EXPECT_EQ(json["SessionService"]["@odata.id"],
              "/redfish/v1/SessionService");
    EXPECT_EQ(json["SessionService"].size(), 1);

    EXPECT_EQ(json["Systems"]["@odata.id"], "/redfish/v1/Systems");
    EXPECT_EQ(json["Systems"].size(), 1);

    EXPECT_EQ(json["Tasks"]["@odata.id"], "/redfish/v1/TaskService");
    EXPECT_EQ(json["Tasks"].size(), 1);

    EXPECT_EQ(json["TelemetryService"]["@odata.id"],
              "/redfish/v1/TelemetryService");
    EXPECT_EQ(json["TelemetryService"].size(), 1);

    EXPECT_THAT(
        json["UUID"],
        testing::MatchesRegex("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-"
                              "9a-fA-F]{4}-[0-9a-fA-F]{12}"));

    EXPECT_EQ(json["UpdateService"]["@odata.id"], "/redfish/v1/UpdateService");

    EXPECT_EQ(json["ProtocolFeaturesSupported"].size(), 6);
    EXPECT_FALSE(json["ProtocolFeaturesSupported"]["ExcerptQuery"]);
    EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["ExpandAll"],
              bmcwebInsecureEnableQueryParams);
    EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Levels"],
              bmcwebInsecureEnableQueryParams);
    EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Links"],
              bmcwebInsecureEnableQueryParams);
    EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["NoLinks"],
              bmcwebInsecureEnableQueryParams);
    if (bmcwebInsecureEnableQueryParams)
    {
        EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"].size(), 5);
        EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["MaxLevels"],
                  6);
    }
    else
    {
        EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"].size(), 4);
    }
    EXPECT_FALSE(json["ProtocolFeaturesSupported"]["FilterQuery"]);
    EXPECT_TRUE(json["ProtocolFeaturesSupported"]["OnlyMemberQuery"]);
    EXPECT_TRUE(json["ProtocolFeaturesSupported"]["SelectQuery"]);
    EXPECT_FALSE(
        json["ProtocolFeaturesSupported"]["DeepOperations"]["DeepPOST"]);
    EXPECT_FALSE(
        json["ProtocolFeaturesSupported"]["DeepOperations"]["DeepPATCH"]);
    EXPECT_EQ(json["ProtocolFeaturesSupported"]["DeepOperations"].size(), 2);
    EXPECT_EQ(json.size(), 21);
}

TEST(HandleServiceRootGet, ServiceRootStaticAttributesAreExpected)
{
    auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();

    shareAsyncResp->res.setCompleteRequestHandler(assertServiceRootGet);

    redfish::handleServiceRootGetImpl(shareAsyncResp);
}

} // namespace
} // namespace redfish