blob: cc9e02422d01248c57d71ec4fe0676f40bfdf0b7 [file] [log] [blame]
#include "app.hpp"
#include "async_resp.hpp"
#include "dbus_utility.hpp"
#include "component_integrity.hpp"
#include "trusted_component.hpp"
#include "http_request.hpp"
#include "http_response.hpp"
#include "snapshot_fixture.hpp"
#include "managed_store.hpp"
#include "managed_store_types.hpp"
#include <boost/beast/core/string_type.hpp>
#include <boost/beast/http/message.hpp>
#include <nlohmann/json.hpp>
#include <system_error>
#include <unordered_set>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace redfish
{
namespace
{
using ::testing::Contains;
using ::testing::NotNull;
using ::managedStore::KeyType;
using ::managedStore::ValueType;
using ::managedStore::ManagedType;
using ::dbus::utility::DBusInteracesMap;
using ::dbus::utility::MapperGetObject;
using ::dbus::utility::ManagedObjectType;
using ::dbus::utility::DBusPropertiesMap;
using ::dbus::utility::DbusVariantType;
using ::dbus::utility::MapperGetSubTreePathsResponse;
using ::dbus::utility::MapperGetSubTreeResponse;
using ::dbus::utility::MapperServiceMap;
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"}});
}
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(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(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(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(managedStore::GetManagedObjectStore()
->upsertMockObjectIntoManagedStore(keyCpuAccelMapperObject, cpuObjectMapperValue)
.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(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(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(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(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(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(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(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(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(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(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(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"]["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