blob: 805ce20395cd6d79dca87f5d65635ca54a58131c [file] [log] [blame]
#include "data_interface_mock.hpp"
#include "updater.hpp"
#include <blobs-ipmid/blobs.hpp>
#include <ipmiblob/test/blob_interface_mock.hpp>
#include <string>
#include <gtest/gtest.h>
namespace host_tool
{
using ::testing::_;
using ::testing::Eq;
using ::testing::Return;
using ::testing::StrEq;
using ::testing::TypedEq;
TEST(UpdaterTest, NormalWalkthroughAllHappy)
{
/* Call updaterMain and have everything respond happily. */
DataInterfaceMock handlerMock;
ipmiblob::BlobInterfaceMock blobMock;
std::string firmwareImage = "image.bin";
std::string signatureFile = "image.sig";
std::string expectedBlob = "/flash/image";
std::string expectedHash = "/flash/hash";
std::string expectedVerify = "/flash/verify";
std::vector<std::string> blobList = {expectedBlob};
ipmiblob::StatResponse statObj;
statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
blobs::FirmwareBlobHandler::UpdateFlags::lpc;
statObj.size = 0;
std::uint16_t supported =
static_cast<std::uint16_t>(
blobs::FirmwareBlobHandler::UpdateFlags::lpc) |
static_cast<std::uint16_t>(blobs::OpenFlags::write);
std::uint16_t session = 0xbeef;
EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
EXPECT_CALL(blobMock, getStat(TypedEq<const std::string&>(expectedBlob)))
.WillOnce(Return(statObj));
EXPECT_CALL(handlerMock, supportedType())
.WillOnce(Return(blobs::FirmwareBlobHandler::UpdateFlags::lpc));
EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported)))
.WillOnce(Return(session));
EXPECT_CALL(handlerMock,
sendContents(StrEq(firmwareImage.c_str()), Eq(session)))
.WillOnce(Return(true));
EXPECT_CALL(blobMock, openBlob(StrEq(expectedHash.c_str()), Eq(supported)))
.WillOnce(Return(session));
EXPECT_CALL(handlerMock,
sendContents(StrEq(signatureFile.c_str()), Eq(session)))
.WillOnce(Return(true));
EXPECT_CALL(blobMock,
openBlob(StrEq(expectedVerify.c_str()), Eq(supported)))
.WillOnce(Return(session));
EXPECT_CALL(blobMock, commit(Eq(session), _)).WillOnce(Return());
ipmiblob::StatResponse verificationResponse;
verificationResponse.blob_state = supported | blobs::StateFlags::committing;
verificationResponse.size = 0;
verificationResponse.metadata.push_back(static_cast<std::uint8_t>(
blobs::FirmwareBlobHandler::VerifyCheckResponses::success));
EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session)))
.WillOnce(Return(verificationResponse));
updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile);
}
} // namespace host_tool