blob: 3e6a1aeca2e3e26d39a548564fe33082e910bf7a [file] [log] [blame]
#include "app.hpp"
#include "async_resp.hpp"
#include "component_integrity.hpp"
#include "trusted_component.hpp"
#include "http_request.hpp"
#include "http_response.hpp"
#include "snapshot_fixture.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;
constexpr const char* fakeComponentIntegrity = "fakeComponentIntegrity";
TEST_F(SnapshotFixture_Platform22, GetComponentIntegritySPDMGetSignedMeasurementsActionInfoReturnsCorrectResponse){
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_Platform22, 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_Platform22, 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