blob: 101b07a79950768a5c63d3979da9d689df7c76bd [file]
#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"
#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"))}))}))});
}
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) {
KeyType keyMapperObject(
ManagedType::kManagedMapperObject, "xyz.openbmc_project.SPDM",
sdbusplus::message::object_path(
"/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/"
"TC_name7_1_NIC_1"),
"xyz.openbmc_project.Inventory.Item.TrustedComponent",
"TrustedComponentType");
std::shared_ptr<ValueType> objectMapperValue =
CreateValueType(CreateMapperGetObject());
EXPECT_TRUE(
dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyMapperObject, objectMapperValue)
.ok());
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());
KeyType keyObject(
ManagedType::kManagedObject, "xyz.openbmc_project.SPDM",
sdbusplus::message::object_path(
"/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/"
"TC_name7_1_NIC_1"),
"xyz.openbmc_project.Inventory.Item.TrustedComponent",
"TrustedComponentType");
std::shared_ptr<ValueType> objectValue =
CreateValueType(CreateManagedObjectType());
EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyObject, objectValue)
.ok());
KeyType keyUUID(
ManagedType::kManagedPropertyMap, "xyz.openbmc_project.SPDM",
sdbusplus::message::object_path(
"/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/"
"TC_name7_1_NIC_1"),
"xyz.openbmc_project.Common.UUID", "UUID");
std::shared_ptr<ValueType> uuid =
CreateValueType(CreateUUIDDBusPropertiesMap());
EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyUUID, uuid)
.ok());
KeyType keyAssetManufacturer(
ManagedType::kManagedPropertyMap, "xyz.openbmc_project.SPDM",
sdbusplus::message::object_path(
"/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/"
"TC_name7_1_NIC_1"),
"xyz.openbmc_project.Inventory.Decorator.Asset", "Manufacturer");
std::shared_ptr<ValueType> manufacturer =
CreateValueType(CreateAssetManufacturerDBusPropertiesMap());
EXPECT_TRUE(
dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyAssetManufacturer, manufacturer)
.ok());
KeyType keyTCType(
ManagedType::kManagedPropertyMap, "xyz.openbmc_project.SPDM",
sdbusplus::message::object_path(
"/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/"
"TC_name7_1_NIC_1"),
"xyz.openbmc_project.Inventory.Item.TrustedComponent",
"TrustedComponentType");
std::shared_ptr<ValueType> tcType =
CreateValueType(CreateTCTypeDBusPropertiesMap());
EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyTCType, tcType)
.ok());
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(CreateIntegratedAssociationsValue());
EXPECT_TRUE(
dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyIntegratedInto, integratedInto)
.ok());
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(CreateProtectingAssociationsValue());
EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyProtecting, protecting)
.ok());
KeyType keyActivelyRunning(
ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper",
sdbusplus::message::object_path(
"/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/"
"TC_name7_1_NIC_1/actively_running"),
"xyz.openbmc_project.Association", "endpoints");
std::shared_ptr<ValueType> running =
CreateValueType(CreateActivelyRunningAssociationsValue());
EXPECT_TRUE(
dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyActivelyRunning, running)
.ok());
KeyType keyRuns(
ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper",
sdbusplus::message::object_path(
"/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/"
"TC_name7_1_NIC_1/runs"),
"xyz.openbmc_project.Association", "endpoints");
std::shared_ptr<ValueType> runs =
CreateValueType(CreateRunsAssociationsValue());
EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyRuns, runs)
.ok());
KeyType keyReportedBy(
ManagedType::kManagedProperty, "xyz.openbmc_project.ObjectMapper",
sdbusplus::message::object_path(
"/xyz/openbmc_project/Chassis/name6_7_1/TrustedComponents/"
"TC_name7_1_NIC_1/reported_by"),
"xyz.openbmc_project.Association", "endpoints");
std::shared_ptr<ValueType> reportedBy =
CreateValueType(CreateReportedByAssociationsValue());
EXPECT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyReportedBy, reportedBy)
.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);
}
} // namespace
} // namespace redfish