| #include "trusted_component.hpp" | |
| #include <memory> | |
| #include <string> | |
| #include <unordered_set> | |
| #include <utility> | |
| #include <vector> | |
| #include <gmock/gmock.h> | |
| #include <gtest/gtest.h> | |
| #include "boost/beast/http/message.hpp" // NOLINT | |
| #include "boost/beast/http/status.hpp" // NOLINT | |
| #include "dbus_utility.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 "sdbusplus/message/native_types.hpp" | |
| namespace redfish { | |
| namespace { | |
| using ::dbus::utility::DBusInteracesMap; | |
| using ::dbus::utility::DBusPropertiesMap; | |
| using ::dbus::utility::DbusVariantType; | |
| using ::dbus::utility::ManagedObjectType; | |
| using ::dbus::utility::MapperGetObject; | |
| using ::dbus::utility::MapperGetSubTreePathsResponse; | |
| using ::dbus::utility::MapperGetSubTreeResponse; | |
| using ::dbus::utility::MapperServiceMap; | |
| using ::managedStore::KeyType; | |
| using ::managedStore::ManagedType; | |
| using ::managedStore::ValueType; | |
| using ::testing::Contains; | |
| using ::testing::NotNull; | |
| MapperGetSubTreePathsResponse CreateMapperGetSubTreePathsResponse() { | |
| return MapperGetSubTreePathsResponse({ | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1", | |
| }); | |
| } | |
| MapperGetSubTreeResponse CreateMapperGetSubTreeResponse() { | |
| return MapperGetSubTreeResponse({std::make_pair( | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1", | |
| MapperServiceMap({{ | |
| "xyz.openbmc_project.SPDM", | |
| { | |
| "xyz.openbmc_project.Inventory.Item.TrustedComponent", | |
| "xyz.openbmc_project.Inventory.Decorator.Asset", | |
| "xyz.openbmc_project.Common.UUID", | |
| }, | |
| }}))}); | |
| } | |
| DBusPropertiesMap CreateUUIDDBusPropertiesMap() { | |
| return DBusPropertiesMap( | |
| {std::make_pair("UUID", DbusVariantType("UUID-abcd12345678"))}); | |
| } | |
| DBusPropertiesMap CreateTCTypeDBusPropertiesMap() { | |
| return DBusPropertiesMap({std::make_pair( | |
| "TrustedComponentType", | |
| DbusVariantType("xyz.openbmc_project.Inventory.Item.TrustedComponent." | |
| "ComponentAttachType.Integrated"))}); | |
| } | |
| DbusVariantType CreateIntegratedAssociationsValue() { | |
| return DbusVariantType(std::vector<std::string>{ | |
| {"/xyz/openbmc_project/inventory/system/board/BoardName/system1/" | |
| "chassis/motherboard/cpu0"}}); | |
| } | |
| DbusVariantType CreateProtectingAssociationsValue() { | |
| return DbusVariantType(std::vector<std::string>{ | |
| {"/xyz/openbmc_project/inventory/system/board/BoardName/system1/" | |
| "chassis/motherboard/cpu0"}, | |
| {"/xyz/openbmc_project/inventory/system/board/BoardName/cpu0"}}); | |
| } | |
| DbusVariantType CreateActivelyRunningAssociationsValue() { | |
| return DbusVariantType( | |
| std::vector<std::string>{{"/xyz/openbmc_project/software/b4187ab8"}}); | |
| } | |
| DbusVariantType CreateRunsAssociationsValue() { | |
| return DbusVariantType( | |
| std::vector<std::string>{{"/xyz/openbmc_project/software/b4187ab8"}}); | |
| } | |
| DbusVariantType CreateReportedByAssociationsValue() { | |
| return DbusVariantType(std::vector<std::string>{ | |
| {"/xyz/openbmc_project/ComponentIntegrity/CI_name6_7_1_name7_1_NIC_1"}}); | |
| } | |
| DBusPropertiesMap CreateAssetManufacturerDBusPropertiesMap() { | |
| return DBusPropertiesMap( | |
| {std::make_pair("Manufacturer", DbusVariantType("Manu-Google LLC")), | |
| std::make_pair("PartNumber", DbusVariantType("PartNumber")), | |
| std::make_pair("SerialNumber", DbusVariantType("SN-12345678")), | |
| std::make_pair("SKU", DbusVariantType("SKU"))}); | |
| } | |
| MapperGetObject CreateMapperGetObject() { | |
| return MapperGetObject({{ | |
| "xyz.openbmc_project.SPDM", | |
| { | |
| "xyz.openbmc_project.Inventory.Item.TrustedComponent", | |
| "xyz.openbmc_project.Inventory.Decorator.Asset", | |
| "xyz.openbmc_project.Common.UUID", | |
| }, | |
| }}); | |
| } | |
| MapperGetObject CreateCpuAccelMapperGetObject() { | |
| return MapperGetObject({{ | |
| "xyz.openbmc_project.SPDM", | |
| { | |
| "xyz.openbmc_project.Inventory.Item.Cpu", | |
| "xyz.openbmc_project.Inventory.Item.Accelerator", | |
| }, | |
| }}); | |
| } | |
| MapperGetObject CreateSystemMapperGetObject() { | |
| return MapperGetObject({{ | |
| "xyz.openbmc_project.SPDM", | |
| { | |
| "xyz.openbmc_project.Inventory.Item.System", | |
| "xyz.openbmc_project.Inventory.Item", | |
| }, | |
| }}); | |
| } | |
| MapperGetObject CreateChassisMapperGetObject() { | |
| return MapperGetObject({{ | |
| "xyz.openbmc_project.SPDM", | |
| { | |
| "xyz.openbmc_project.Inventory.Item.Chassis", | |
| "xyz.openbmc_project.Inventory.Item.Board", | |
| }, | |
| }}); | |
| } | |
| ManagedObjectType CreateManagedObjectType() { | |
| return ManagedObjectType({std::make_pair( | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1"), | |
| DBusInteracesMap({std::make_pair( | |
| "xyz.openbmc_project.Inventory.Item.TrustedComponent", | |
| DBusPropertiesMap({std::make_pair( | |
| "TrustedComponentType", | |
| DbusVariantType("xyz.openbmc_project.Inventory.Item." | |
| "TrustedComponent.ComponentAttachType." | |
| "Integrated"))}))}))}); | |
| } | |
| // Upserts every store entry handleTrustedComponentGet reads for | |
| // name6_7_1/TC_name7_1_NIC_1 that the platform22 snapshot does not carry. The | |
| // mock managed store is a process-wide static that is never reset between | |
| // tests, so a test that relies on another test having populated these keys | |
| // only passes for some orderings. | |
| void UpsertTrustedComponentMocks() { | |
| auto* store = dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()); | |
| ASSERT_THAT(store, NotNull()); | |
| constexpr char const* trustedComponentPath = | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1"; | |
| KeyType keySubtree(ManagedType::kManagedSubtree, | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents", | |
| 0, | |
| {"xyz.openbmc_project.Inventory.Item.TrustedComponent"}); | |
| EXPECT_TRUE(store | |
| ->upsertMockObjectIntoManagedStore( | |
| keySubtree, SnapshotFixture::CreateValueType( | |
| CreateMapperGetSubTreeResponse())) | |
| .ok()); | |
| KeyType keyMapperObject( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path(trustedComponentPath), | |
| "xyz.openbmc_project.Inventory.Item.TrustedComponent", | |
| "TrustedComponentType"); | |
| EXPECT_TRUE( | |
| store | |
| ->upsertMockObjectIntoManagedStore( | |
| keyMapperObject, | |
| SnapshotFixture::CreateValueType(CreateMapperGetObject())) | |
| .ok()); | |
| KeyType keyObject(ManagedType::kManagedObject, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path(trustedComponentPath), | |
| "xyz.openbmc_project.Inventory.Item.TrustedComponent", | |
| "TrustedComponentType"); | |
| EXPECT_TRUE( | |
| store | |
| ->upsertMockObjectIntoManagedStore( | |
| keyObject, | |
| SnapshotFixture::CreateValueType(CreateManagedObjectType())) | |
| .ok()); | |
| KeyType keyTCType(ManagedType::kManagedPropertyMap, | |
| "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path(trustedComponentPath), | |
| "xyz.openbmc_project.Inventory.Item.TrustedComponent", | |
| "TrustedComponentType"); | |
| EXPECT_TRUE( | |
| store | |
| ->upsertMockObjectIntoManagedStore( | |
| keyTCType, | |
| SnapshotFixture::CreateValueType(CreateTCTypeDBusPropertiesMap())) | |
| .ok()); | |
| KeyType keyUUID(ManagedType::kManagedPropertyMap, | |
| "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path(trustedComponentPath), | |
| "xyz.openbmc_project.Common.UUID", "UUID"); | |
| EXPECT_TRUE( | |
| store | |
| ->upsertMockObjectIntoManagedStore( | |
| keyUUID, | |
| SnapshotFixture::CreateValueType(CreateUUIDDBusPropertiesMap())) | |
| .ok()); | |
| KeyType keyAssetManufacturer( | |
| ManagedType::kManagedPropertyMap, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path(trustedComponentPath), | |
| "xyz.openbmc_project.Inventory.Decorator.Asset", "Manufacturer"); | |
| EXPECT_TRUE(store | |
| ->upsertMockObjectIntoManagedStore( | |
| keyAssetManufacturer, | |
| SnapshotFixture::CreateValueType( | |
| CreateAssetManufacturerDBusPropertiesMap())) | |
| .ok()); | |
| // The association lookups below all report a plain error rather than EBADR | |
| // when they are absent from the snapshot, which handleTrustedComponentGet | |
| // turns into an InternalError, so every one of them has to be mocked. | |
| const std::pair<const char*, DbusVariantType> associations[] = { | |
| {"integrated_into", CreateIntegratedAssociationsValue()}, | |
| {"protecting", CreateProtectingAssociationsValue()}, | |
| {"actively_running", CreateActivelyRunningAssociationsValue()}, | |
| {"runs", CreateRunsAssociationsValue()}, | |
| {"reported_by", CreateReportedByAssociationsValue()}, | |
| }; | |
| for (const auto& [association, value] : associations) { | |
| KeyType key(ManagedType::kManagedProperty, | |
| "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| std::string(trustedComponentPath) + "/" + association), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| EXPECT_TRUE( | |
| store | |
| ->upsertMockObjectIntoManagedStore( | |
| key, SnapshotFixture::CreateValueType(DbusVariantType(value))) | |
| .ok()); | |
| } | |
| } | |
| // Replaces the protecting association with an empty endpoint list. The | |
| // IntegratedInto tests do not assert on ComponentsProtected, and resolving it | |
| // would otherwise require mocking the inventory objects it points at. | |
| void ClearProtectingAssociation() { | |
| KeyType keyProtecting( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1/protecting"), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore( | |
| keyProtecting, SnapshotFixture::CreateValueType( | |
| DbusVariantType( | |
| std::vector<std::string>{}))) | |
| .ok()); | |
| } | |
| TEST_F(SnapshotFixture_Platform22, | |
| GetTrustedComponentCollectionTestReturnsCorrectResponse) { | |
| // Looking for Key: | |
| // kManagedSubtreePaths|/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents | |
| KeyType keySubtreePaths( | |
| ManagedType::kManagedSubtreePaths, | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents", 0, | |
| {"xyz.openbmc_project.Inventory.Item.TrustedComponent"}); | |
| std::shared_ptr<ValueType> mockedPaths = | |
| CreateValueType(CreateMapperGetSubTreePathsResponse()); | |
| EXPECT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keySubtreePaths, mockedPaths) | |
| .ok()); | |
| KeyType keySubtree(ManagedType::kManagedSubtree, | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents", | |
| 0, | |
| {"xyz.openbmc_project.Inventory.Item.TrustedComponent"}); | |
| std::shared_ptr<ValueType> mockedSubtree = | |
| CreateValueType(CreateMapperGetSubTreeResponse()); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keySubtree, mockedSubtree) | |
| .ok()); | |
| handleTrustedComponentCollectionGet(app_, CreateRequest(), share_async_resp_, | |
| "name6_7_1"); | |
| RunIoUntilDone(); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json["@odata.id"], | |
| "/redfish/v1/Chassis/name6_7_1/TrustedComponents"); | |
| EXPECT_EQ(json["@odata.type"], | |
| "#TrustedComponentCollection.TrustedComponentCollection"); | |
| EXPECT_EQ(json["Name"], "Trusted Component Collection"); | |
| EXPECT_EQ(json["Members@odata.count"], json["Members"].size()); | |
| std::unordered_set<std::string> trusted_component_set{{ | |
| "/redfish/v1/Chassis/name6_7_1/TrustedComponents/TC_name7_1_NIC_1", | |
| }}; | |
| for (const auto& member : json["Members"]) { | |
| ASSERT_TRUE(member.contains("@odata.id")); | |
| const std::string* tc = member["@odata.id"].get_ptr<const std::string*>(); | |
| ASSERT_THAT(tc, NotNull()); | |
| EXPECT_THAT(trusted_component_set, Contains(*tc)); | |
| } | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| } | |
| TEST_F(SnapshotFixture_Platform22, | |
| GetTrustedComponentTestReturnsCorrectResponse) { | |
| UpsertTrustedComponentMocks(); | |
| KeyType keyCpuAccelMapperObject( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/BoardName/system1/" | |
| "chassis/motherboard/cpu0"), | |
| "xyz.openbmc_project.Inventory.Item.Cpu", "Socket"); | |
| std::shared_ptr<ValueType> cpuObjectMapperValue = | |
| CreateValueType(CreateCpuAccelMapperGetObject()); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyCpuAccelMapperObject, | |
| cpuObjectMapperValue) | |
| .ok()); | |
| KeyType keyCpuAccelMapperObject2( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/BoardName/cpu0"), | |
| "xyz.openbmc_project.Inventory.Item.Cpu", "Socket"); | |
| std::shared_ptr<ValueType> cpuObjectMapperValue2 = | |
| CreateValueType(CreateCpuAccelMapperGetObject()); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyCpuAccelMapperObject2, | |
| cpuObjectMapperValue2) | |
| .ok()); | |
| KeyType keySystemMapperObject( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/BoardName/system1"), | |
| "xyz.openbmc_project.Inventory.Item.System", "PrettyName"); | |
| std::shared_ptr<ValueType> systemObjectMapperValue = | |
| CreateValueType(CreateSystemMapperGetObject()); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keySystemMapperObject, | |
| systemObjectMapperValue) | |
| .ok()); | |
| KeyType keyChassisMapperObject( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/BoardName"), | |
| "xyz.openbmc_project.Inventory.Item.Chassis", "ChassisName"); | |
| std::shared_ptr<ValueType> chassisObjectMapperValue = | |
| CreateValueType(CreateChassisMapperGetObject()); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyChassisMapperObject, | |
| chassisObjectMapperValue) | |
| .ok()); | |
| handleTrustedComponentGet(app_, CreateRequest(), share_async_resp_, | |
| "name6_7_1", "TC_name7_1_NIC_1"); | |
| RunIoUntilDone(); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json["@odata.id"], | |
| "/redfish/v1/Chassis/name6_7_1/TrustedComponents/TC_name7_1_NIC_1"); | |
| EXPECT_EQ(json["@odata.type"], "#TrustedComponent.v1_0_0.TrustedComponent"); | |
| EXPECT_EQ(json["Name"], "TC_name7_1_NIC_1"); | |
| EXPECT_EQ(json["Id"], "TC_name7_1_NIC_1"); | |
| EXPECT_EQ(json["TrustedComponentType"], "Integrated"); | |
| EXPECT_EQ(json["UUID"], "UUID-abcd12345678"); | |
| EXPECT_EQ(json["Location"]["PartLocation"]["LocationType"], "Embedded"); | |
| EXPECT_EQ(json["Manufacturer"], "Manu-Google LLC"); | |
| EXPECT_EQ(json["SerialNumber"], "SN-12345678"); | |
| EXPECT_EQ(json["PartNumber"], "PartNumber"); | |
| EXPECT_EQ(json["SKU"], "SKU"); | |
| // TODO(b/355068455): add support for properties below in D-Bus interface | |
| // EXPECT_EQ(json["FirmwareVersion"], "FirmwareVersion"); | |
| EXPECT_EQ(json["Links"]["ActiveSoftwareImage"]["@odata.id"], | |
| "/redfish/v1/UpdateService/FirmwareInventory/b4187ab8"); | |
| EXPECT_EQ(json["Links"]["SoftwareImages"][0]["@odata.id"], | |
| "/redfish/v1/UpdateService/FirmwareInventory/b4187ab8"); | |
| EXPECT_EQ(json["Links"]["ComponentsProtected"][0]["@odata.id"], | |
| "/redfish/v1/Systems/system1/Processors/cpu0"); | |
| EXPECT_EQ(json["Links"]["ComponentsProtected"][1]["@odata.id"], | |
| "/redfish/v1/Systems/system/Processors/cpu0"); | |
| EXPECT_EQ(json["Links"]["IntegratedInto"]["@odata.id"], | |
| "/redfish/v1/Systems/system1/Processors/cpu0"); | |
| EXPECT_EQ(json["Links"]["ComponentIntegrity"][0]["@odata.id"], | |
| "/redfish/v1/ComponentIntegrity/CI_name6_7_1_name7_1_NIC_1"); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| } | |
| TEST_F(SnapshotFixture_Platform22, | |
| GetTrustedComponentComponentItemReturnsCorrectResponse) { | |
| MapperGetObject componentMapperObj{ | |
| {{"xyz.openbmc_project.SPDM", | |
| {"xyz.openbmc_project.Inventory.Item.Component"}}}}; | |
| UpsertTrustedComponentMocks(); | |
| ClearProtectingAssociation(); | |
| KeyType keyGetObject( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/BoardName/system1/" | |
| "chassis/motherboard/cpu0"), | |
| "xyz.openbmc_project.Inventory.Item.Component", "Component"); | |
| std::shared_ptr<ValueType> mockedObj = CreateValueType(componentMapperObj); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyGetObject, mockedObj) | |
| .ok()); | |
| KeyType keyContainedBy( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/BoardName/system1/" | |
| "chassis/motherboard/cpu0/contained_by"), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| // keyContainedBy is a kManagedProperty key, so the value has to be built | |
| // from a DbusVariantType. Passing a bare std::vector<std::string> selects | |
| // the MapperGetSubTreePathsResponse overload of ValueType instead, and the | |
| // upsert is then rejected with "Key and Value type are not compatible". | |
| std::shared_ptr<ValueType> mockedContainedBy = | |
| CreateValueType(DbusVariantType(dbus::utility::MapperEndPoints{ | |
| "/xyz/openbmc_project/inventory/system/board/chassis_name"})); | |
| EXPECT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyContainedBy, mockedContainedBy) | |
| .ok()); | |
| handleTrustedComponentGet(app_, CreateRequest(), share_async_resp_, | |
| "name6_7_1", "TC_name7_1_NIC_1"); | |
| RunIoUntilDone(); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| EXPECT_EQ(json["Links"]["IntegratedInto"]["@odata.id"], | |
| "/redfish/v1/Chassis/chassis_name"); | |
| } | |
| TEST_F(SnapshotFixture_Platform22, | |
| GetTrustedComponentComponentItemWithoutContainedByUsesParentPath) { | |
| UpsertTrustedComponentMocks(); | |
| ClearProtectingAssociation(); | |
| // Repoint integrated_into at a board-level device, whose lexical parent is | |
| // the chassis. name6_7_4 is not touched by any other test in this binary, | |
| // which matters because the mock store is never reset between tests. | |
| KeyType keyIntegratedInto( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1/integrated_into"), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| std::shared_ptr<ValueType> integratedInto = | |
| CreateValueType(DbusVariantType(std::vector<std::string>{ | |
| {"/xyz/openbmc_project/inventory/system/board/name6_7_4/" | |
| "name7_1_NIC_1"}})); | |
| EXPECT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyIntegratedInto, integratedInto) | |
| .ok()); | |
| MapperGetObject componentMapperObj{ | |
| {{"xyz.openbmc_project.SPDM", | |
| {"xyz.openbmc_project.Inventory.Item.Component"}}}}; | |
| KeyType keyGetObject( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.SPDM", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/name6_7_4/" | |
| "name7_1_NIC_1"), | |
| "xyz.openbmc_project.Inventory.Item.Component", "Component"); | |
| std::shared_ptr<ValueType> mockedObj = CreateValueType(componentMapperObj); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyGetObject, mockedObj) | |
| .ok()); | |
| // No contained_by association is upserted for this object, and the snapshot | |
| // does not carry one either. The store runs in snapshot mode, so the lookup | |
| // fails with an error instead of reading through to D-Bus, which is the | |
| // inventory-without-association case the fallback exists for. The chassis id | |
| // must then come from the parent of the component's own inventory path. | |
| handleTrustedComponentGet(app_, CreateRequest(), share_async_resp_, | |
| "name6_7_1", "TC_name7_1_NIC_1"); | |
| RunIoUntilDone(); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| EXPECT_EQ(json["Links"]["IntegratedInto"]["@odata.id"], | |
| "/redfish/v1/Chassis/name6_7_4"); | |
| } | |
| // Verifies that when a TrustedComponent is associated with an inventory item | |
| // implementing xyz.openbmc_project.Inventory.Item.Drive via integrated_into and | |
| // protecting associations, Links.IntegratedInto and Links.ComponentsProtected | |
| // resolve to the corresponding Redfish Drive URI | |
| // (/redfish/v1/Chassis/{chassisId}/Drives/{driveId}). | |
| TEST_F(SnapshotFixture_Platform22, | |
| GetTrustedComponentDriveIntegratedIntoTestReturnsCorrectResponse) { | |
| UpsertTrustedComponentMocks(); | |
| // Mock ObjectMapper GetObject response for Drive_1 exposing the Drive | |
| // interface. | |
| KeyType keyDriveMapperObject( | |
| ManagedType::kManagedMapperObject, | |
| "/xyz/openbmc_project/inventory/system/board/name6_7_1/Drive_1", | |
| std::vector<std::string>{}); | |
| std::shared_ptr<ValueType> driveMapperValue = | |
| CreateValueType(MapperGetObject({{ | |
| "xyz.openbmc_project.SPDM", | |
| {"xyz.openbmc_project.Inventory.Item.Drive"}, | |
| }})); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyDriveMapperObject, | |
| driveMapperValue) | |
| .ok()); | |
| // Mock integrated_into association pointing to Drive_1. | |
| KeyType keyIntegratedInto( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1/integrated_into"), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| std::shared_ptr<ValueType> integratedInto = | |
| CreateValueType(DbusVariantType(std::vector<std::string>{ | |
| {"/xyz/openbmc_project/inventory/system/board/name6_7_1/Drive_1"}})); | |
| EXPECT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyIntegratedInto, integratedInto) | |
| .ok()); | |
| // Mock protecting association pointing to Drive_1. | |
| KeyType keyProtecting( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1/protecting"), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| std::shared_ptr<ValueType> protecting = | |
| CreateValueType(DbusVariantType(std::vector<std::string>{ | |
| {"/xyz/openbmc_project/inventory/system/board/name6_7_1/Drive_1"}})); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyProtecting, protecting) | |
| .ok()); | |
| handleTrustedComponentGet(app_, CreateRequest(), share_async_resp_, | |
| "name6_7_1", "TC_name7_1_NIC_1"); | |
| RunIoUntilDone(); | |
| // Verify that both IntegratedInto and ComponentsProtected link to the Redfish | |
| // Drive resource. | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json["@odata.id"], | |
| "/redfish/v1/Chassis/name6_7_1/TrustedComponents/TC_name7_1_NIC_1"); | |
| EXPECT_EQ(json["Links"]["IntegratedInto"]["@odata.id"], | |
| "/redfish/v1/Chassis/name6_7_1/Drives/Drive_1"); | |
| ASSERT_TRUE(json["Links"].contains("ComponentsProtected")); | |
| ASSERT_EQ(json["Links"]["ComponentsProtected"].size(), 1); | |
| EXPECT_EQ(json["Links"]["ComponentsProtected"][0]["@odata.id"], | |
| "/redfish/v1/Chassis/name6_7_1/Drives/Drive_1"); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| } | |
| TEST_F(SnapshotFixture_Platform22, | |
| GetTrustedComponentMctpUsbDeviceReturnsCorrectResponse) { | |
| MapperGetObject mctpMapperObj{ | |
| {{"xyz.openbmc_project.EntityManager", | |
| {"xyz.openbmc_project.Configuration.MCTPUSBDevice"}}}}; | |
| UpsertTrustedComponentMocks(); | |
| ClearProtectingAssociation(); | |
| KeyType keyIntegratedInto( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1/integrated_into"), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| std::shared_ptr<ValueType> integratedInto = | |
| CreateValueType(DbusVariantType(std::vector<std::string>{ | |
| {"/xyz/openbmc_project/inventory/system/board/name6_7_5/" | |
| "name7_1_NIC_1"}})); | |
| EXPECT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyIntegratedInto, integratedInto) | |
| .ok()); | |
| KeyType keyGetObject( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.EntityManager", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/name6_7_5/" | |
| "name7_1_NIC_1"), | |
| "xyz.openbmc_project.Configuration.MCTPUSBDevice", "MCTPUSBDevice"); | |
| std::shared_ptr<ValueType> mockedObj = CreateValueType(mctpMapperObj); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyGetObject, mockedObj) | |
| .ok()); | |
| KeyType keyContainedBy( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/name6_7_5/" | |
| "name7_1_NIC_1/contained_by"), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| std::shared_ptr<ValueType> mockedContainedBy = | |
| CreateValueType(DbusVariantType(dbus::utility::MapperEndPoints{ | |
| "/xyz/openbmc_project/inventory/system/board/chassis_name"})); | |
| EXPECT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyContainedBy, mockedContainedBy) | |
| .ok()); | |
| handleTrustedComponentGet(app_, CreateRequest(), share_async_resp_, | |
| "name6_7_1", "TC_name7_1_NIC_1"); | |
| RunIoUntilDone(); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| EXPECT_EQ(json["Links"]["IntegratedInto"]["@odata.id"], | |
| "/redfish/v1/Chassis/chassis_name"); | |
| } | |
| TEST_F(SnapshotFixture_Platform22, | |
| GetTrustedComponentMctpUsbDeviceWithoutContainedByUsesParentPath) { | |
| UpsertTrustedComponentMocks(); | |
| ClearProtectingAssociation(); | |
| KeyType keyIntegratedInto( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/" | |
| "TC_name7_1_NIC_1/integrated_into"), | |
| "xyz.openbmc_project.Association", "endpoints"); | |
| std::shared_ptr<ValueType> integratedInto = | |
| CreateValueType(DbusVariantType(std::vector<std::string>{ | |
| {"/xyz/openbmc_project/inventory/system/board/name6_7_6/" | |
| "name7_1_NIC_1"}})); | |
| EXPECT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyIntegratedInto, integratedInto) | |
| .ok()); | |
| MapperGetObject mctpMapperObj{ | |
| {{"xyz.openbmc_project.EntityManager", | |
| {"xyz.openbmc_project.Configuration.MCTPUSBDevice"}}}}; | |
| KeyType keyGetObject( | |
| ManagedType::kManagedMapperObject, "xyz.openbmc_project.EntityManager", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/name6_7_6/" | |
| "name7_1_NIC_1"), | |
| "xyz.openbmc_project.Configuration.MCTPUSBDevice", "MCTPUSBDevice"); | |
| std::shared_ptr<ValueType> mockedObj = CreateValueType(mctpMapperObj); | |
| EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(keyGetObject, mockedObj) | |
| .ok()); | |
| handleTrustedComponentGet(app_, CreateRequest(), share_async_resp_, | |
| "name6_7_1", "TC_name7_1_NIC_1"); | |
| RunIoUntilDone(); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| EXPECT_EQ(json["Links"]["IntegratedInto"]["@odata.id"], | |
| "/redfish/v1/Chassis/name6_7_6"); | |
| } | |
| } // namespace | |
| } // namespace redfish |