blob: c495847c7a3dbd706e82d128abf9a0e69fbcee25 [file]
#include "component_integrity.hpp"
#include <memory>
#include <string>
#include <system_error> // NOLINT
#include <unordered_set>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "boost/beast/http/message.hpp" // NOLINT
#include "test/redfish-core/lib/snapshot_fixture.hpp"
#include <nlohmann/json.hpp>
#include "managed_store.hpp"
#include "test/g3/mock_managed_store_test.hpp"
#ifdef SNAPSHOT_FIXTURE_G3
#include "devtools/build/runtime/get_runfiles_dir.h"
#endif
namespace redfish {
namespace {
using ::testing::Contains;
using ::testing::NotNull;
constexpr const char* fakeComponentIntegrity = "fakeComponentIntegrity";
class SnapshotFixture_ComponentIntegrity : public redfish::SnapshotFixture {
protected:
static void SetUpTestSuite() {
::managedStore::MockManagedStoreTest::SetUpTestSuite();
#ifdef SNAPSHOT_FIXTURE_G3
std::string snapshotFilepath_platform22Local =
::devtools_build::GetDataDependencyFilepath(
"google3/third_party/openbmc_build_scripts/additional/"
"scrubbed_gBMCwebManagedStore_platform22_0_2024_08_13.json");
EXPECT_TRUE(managedStore::GetManagedObjectStore()->deserialize(
snapshotFilepath_platform22Local));
#else
EXPECT_TRUE(managedStore::GetManagedObjectStore()->deserialize(
snapshotFilepath_platform22));
#endif
}
};
TEST_F(
SnapshotFixture_ComponentIntegrity,
GetComponentIntegritySPDMGetSignedMeasurementsActionInfoReturnsCorrectResponse) { // NOLINT
handleSPDMGetSignedMeasurementsActionInfoGet(
app_, CreateRequest(), share_async_resp_, fakeComponentIntegrity);
RunIoUntilDone();
nlohmann::json& json = share_async_resp_->res.jsonValue;
EXPECT_EQ(json["@odata.id"],
"/redfish/v1/ComponentIntegrity/fakeComponentIntegrity/"
"SPDMGetSignedMeasurementsActionInfo");
EXPECT_EQ(json["@odata.type"], "#ActionInfo.v1_3_0.ActionInfo");
EXPECT_EQ(json["Name"], "SPDMGetSignedMeasurements Action Info");
EXPECT_EQ(json["Id"], "SPDMGetSignedMeasurementsActionInfo");
EXPECT_EQ(json["Parameters"][0]["Name"], "MeasurementIndices");
EXPECT_EQ(json["Parameters"][0]["Required"], false);
EXPECT_EQ(json["Parameters"][0]["DataType"], "NumberArray");
EXPECT_EQ(json["Parameters"][1]["Name"], "Nonce");
EXPECT_EQ(json["Parameters"][1]["Required"], false);
EXPECT_EQ(json["Parameters"][1]["DataType"], "String");
EXPECT_EQ(json["Parameters"][2]["Name"], "SlotId");
EXPECT_EQ(json["Parameters"][2]["Required"], false);
EXPECT_EQ(json["Parameters"][2]["DataType"], "Number");
EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok);
}
TEST_F(SnapshotFixture_ComponentIntegrity,
GetComponentIntegrityCollectionTestReturnsCorrectResponse) {
handleComponentIntegrityCollectionGet(app_, CreateRequest(),
share_async_resp_);
RunIoUntilDone();
nlohmann::json& json = share_async_resp_->res.jsonValue;
EXPECT_EQ(json["@odata.id"], "/redfish/v1/ComponentIntegrity");
EXPECT_EQ(json["@odata.type"],
"#ComponentIntegrityCollection.ComponentIntegrityCollection");
EXPECT_EQ(json["Name"], "Component Integrity Collection");
EXPECT_EQ(json["Members@odata.count"], json["Members"].size());
std::unordered_set<std::string> component_integrity_set{{
"/redfish/v1/ComponentIntegrity/CI_name6_7_1_name7_1_NIC_1",
"/redfish/v1/ComponentIntegrity/CI_name6_7_2_name7_1_NIC_1",
"/redfish/v1/ComponentIntegrity/CI_name6_7_3_name7_1_NIC_1",
"/redfish/v1/ComponentIntegrity/CI_name6_7_4_name7_1_NIC_1",
"/redfish/v1/ComponentIntegrity/CI_name6_7_5_name7_1_NIC_1",
"/redfish/v1/ComponentIntegrity/CI_name6_7_6_name7_1_NIC_1",
"/redfish/v1/ComponentIntegrity/CI_name6_7_7_name7_1_NIC_1",
"/redfish/v1/ComponentIntegrity/CI_name6_7_8_name7_1_NIC_1",
}};
for (const auto& member : json["Members"]) {
ASSERT_TRUE(member.contains("@odata.id"));
const std::string* ci = member["@odata.id"].get_ptr<const std::string*>();
ASSERT_THAT(ci, NotNull());
EXPECT_THAT(component_integrity_set, Contains(*ci));
}
EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok);
}
TEST_F(SnapshotFixture_ComponentIntegrity,
GetComponentIntegrityTestReturnsCorrectResponse) {
handleComponentIntegrityGet(app_, CreateRequest(), share_async_resp_,
"CI_name6_7_1_name7_1_NIC_1");
RunIoUntilDone();
nlohmann::json& json = share_async_resp_->res.jsonValue;
EXPECT_EQ(json["@odata.id"],
"/redfish/v1/ComponentIntegrity/CI_name6_7_1_name7_1_NIC_1");
EXPECT_EQ(json["@odata.type"],
"#ComponentIntegrity.v1_2_0.ComponentIntegrity");
EXPECT_EQ(json["Actions"]["#ComponentIntegrity.SPDMGetSignedMeasurements"]
["@Redfish.ActionInfo"],
"/redfish/v1/ComponentIntegrity/CI_name6_7_1_name7_1_NIC_1/"
"SPDMGetSignedMeasurementsActionInfo");
EXPECT_EQ(json["Actions"]["#ComponentIntegrity.SPDMGetSignedMeasurements"]
["target"],
"/redfish/v1/ComponentIntegrity/CI_name6_7_1_name7_1_NIC_1/Actions/"
"ComponentIntegrity.SPDMGetSignedMeasurements");
EXPECT_EQ(json["Name"], "Component Integrity");
EXPECT_EQ(json["Id"], "CI_name6_7_1_name7_1_NIC_1");
EXPECT_EQ(json["LastUpdated"], "20230308T201000Z");
EXPECT_EQ(json["ComponentIntegrityType"], "SPDM");
EXPECT_EQ(json["SPDM"]["Requester"]["@odata.id"], "/redfish/v1/Managers/bmc");
EXPECT_EQ(
json["SPDM"]["IdentityAuthentication"]["ResponderAuthentication"]
["ComponentCertificate"]["@odata.id"],
"/redfish/v1/Chassis/name6_7_1/Certificates/name7_1_NIC_1_PemCertChain");
EXPECT_EQ(json["SPDM"]["IdentityAuthentication"]["ResponderAuthentication"]
["VerificationStatus"],
"Success");
EXPECT_EQ(json["TargetComponentURI"],
"/redfish/v1/Chassis/name6_7_1/TrustedComponents/TC_name7_1_NIC_1");
EXPECT_EQ(json["ComponentIntegrityTypeVersion"], "1.1");
EXPECT_EQ(json["Description"],
"SPDM-capable RoT physically attached to a device.");
EXPECT_EQ(json["Links"]["ComponentsProtected"][0]["@odata.id"],
"/redfish/v1/Chassis/name6_7_1/NetworkAdapters/name7_1_NIC_1");
EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok);
}
} // namespace
} // namespace redfish