| #include "service_root.hpp" |
| |
| #include <filesystem> |
| #include <memory> |
| #include <string> |
| #include <system_error> |
| #include <vector> |
| |
| #include <gtest/gtest.h> |
| #include "http_response.hpp" |
| #include "test/redfish-core/lib/snapshot_fixture.hpp" |
| #include <nlohmann/json.hpp> |
| #include "managed_store.hpp" |
| #include "managed_store_types.hpp" |
| #include "test/g3/mock_managed_store.hpp" |
| #include "test/g3/mock_managed_store_test.hpp" |
| |
| namespace redfish { |
| namespace { |
| |
| using ::managedStore::KeyType; |
| using ::managedStore::ManagedType; |
| |
| void assertServiceRootGet(crow::Response& res) { |
| nlohmann::json json = res.jsonValue; |
| EXPECT_FALSE(json["UUID"].empty()); |
| json.erase("UUID"); |
| |
| EXPECT_EQ(json, nlohmann::json::parse(R"({ |
| "@odata.id": "/redfish/v1", |
| "@odata.type": "#ServiceRoot.v1_15_0.ServiceRoot", |
| "Cables": { |
| "@odata.id": "/redfish/v1/Cables" |
| }, |
| "CertificateService": { |
| "@odata.id": "/redfish/v1/CertificateService" |
| }, |
| "Chassis": { |
| "@odata.id": "/redfish/v1/Chassis" |
| }, |
| "ComponentIntegrity": { |
| "@odata.id": "/redfish/v1/ComponentIntegrity" |
| }, |
| "Id": "RootService", |
| "JsonSchemas": { |
| "@odata.id": "/redfish/v1/JsonSchemas" |
| }, |
| "Links": { |
| "ManagerProvidingService": { |
| "@odata.id": "/redfish/v1/Managers/bmc" |
| } |
| }, |
| "Managers": { |
| "@odata.id": "/redfish/v1/Managers" |
| }, |
| "Name": "Root Service", |
| "ProtocolFeaturesSupported": { |
| "DeepOperations": { |
| "DeepPATCH": false, |
| "DeepPOST": false |
| }, |
| "ExcerptQuery": false, |
| "ExpandQuery": { |
| "ExpandAll": true, |
| "Levels": true, |
| "Links": true, |
| "MaxLevels": 6, |
| "NoLinks": true |
| }, |
| "FilterQuery": true, |
| "OnlyMemberQuery": true, |
| "SelectQuery": true, |
| "TopSkipQuery": true |
| }, |
| "RedfishVersion": "1.9.0", |
| "Storage": { |
| "@odata.id": "/redfish/v1/Storage" |
| }, |
| "Systems": { |
| "@odata.id": "/redfish/v1/Systems" |
| }, |
| "Tasks": { |
| "@odata.id": "/redfish/v1/TaskService" |
| }, |
| "TelemetryService": { |
| "@odata.id": "/redfish/v1/TelemetryService" |
| }, |
| "UpdateService": { |
| "@odata.id": "/redfish/v1/UpdateService" |
| } |
| })")); |
| } |
| |
| class ServiceRootTest : public SnapshotFixture { |
| protected: |
| void SetUp() override { |
| SnapshotFixture::SetUp(); |
| std::error_code ec; |
| orig_path_ = std::filesystem::current_path(ec); |
| std::filesystem::current_path(std::filesystem::temp_directory_path(ec), ec); |
| } |
| |
| void TearDown() override { |
| std::error_code ec; |
| std::filesystem::current_path(orig_path_, ec); |
| SnapshotFixture::TearDown(); |
| } |
| |
| std::filesystem::path orig_path_; |
| }; |
| |
| TEST_F(ServiceRootTest, HandleServiceRootHeadSetsLinkHeader) { |
| handleServiceRootHead(app_, CreateRequest(), share_async_resp_); |
| EXPECT_FALSE( |
| share_async_resp_->res.getHeaderValue("Link").empty()); |
| } |
| |
| TEST_F(ServiceRootTest, HandleServiceRootUuidPopulatesUuid) { |
| handleServiceRootUuid(share_async_resp_); |
| EXPECT_FALSE(share_async_resp_->res.jsonValue["UUID"].empty()); |
| } |
| |
| TEST_F(ServiceRootTest, HandleServiceRootGetImplMiniBmcDetected) { |
| KeyType key(ManagedType::kManagedSubtreePaths, |
| "/xyz/openbmc_project/rde_devices", 0, {}); |
| std::vector<std::string> paths = { |
| "/xyz/openbmc_project/rde_devices/1_1_5_3_1", |
| }; |
| ASSERT_TRUE( |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( |
| managedStore::GetManagedObjectStore()) |
| ->upsertMockObjectIntoManagedStore( |
| key, managedStore::MockManagedStoreTest::CreateValueType(paths)) |
| .ok()); |
| |
| handleServiceRootGetImpl(share_async_resp_); |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"], |
| nlohmann::json::parse(R"({ |
| "ExpandAll": false, |
| "Levels": false, |
| "Links": false, |
| "MaxLevels": 1, |
| "NoLinks": false |
| })")); |
| } |
| |
| TEST_F(ServiceRootTest, HandleServiceRootGetImplEmptyRdeDevices) { |
| KeyType key(ManagedType::kManagedSubtreePaths, |
| "/xyz/openbmc_project/rde_devices", 0, {}); |
| std::vector<std::string> emptyPaths; |
| ASSERT_TRUE( |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( |
| managedStore::GetManagedObjectStore()) |
| ->upsertMockObjectIntoManagedStore( |
| key, |
| managedStore::MockManagedStoreTest::CreateValueType(emptyPaths)) |
| .ok()); |
| |
| handleServiceRootGetImpl(share_async_resp_); |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"], |
| nlohmann::json::parse(R"({ |
| "ExpandAll": true, |
| "Levels": true, |
| "Links": true, |
| "MaxLevels": 6, |
| "NoLinks": true |
| })")); |
| } |
| |
| TEST_F(ServiceRootTest, HandleServiceRootGetImplDbusErrorFallsBackToDefault) { |
| // Key not in cache simulates D-Bus / mapper error in snapshot mode |
| handleServiceRootGetImpl(share_async_resp_); |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"], |
| nlohmann::json::parse(R"({ |
| "ExpandAll": true, |
| "Levels": true, |
| "Links": true, |
| "MaxLevels": 6, |
| "NoLinks": true |
| })")); |
| } |
| |
| TEST_F(ServiceRootTest, ServiceRootStaticAttributesAreExpected) { |
| handleServiceRootGet(app_, CreateRequest(), share_async_resp_); |
| RunIoUntilDone(); |
| assertServiceRootGet(share_async_resp_->res); |
| } |
| |
| } // namespace |
| } // namespace redfish |