blob: 37e619e574557a51485277f1b1a40bb4542a776a [file] [log] [blame]
Patrick Venture27ac5822019-05-20 17:39:31 -07001#include "bmc_update_mock.hpp"
Patrick Ventureffcc5502018-11-16 12:32:38 -08002#include "data_mock.hpp"
3#include "firmware_handler.hpp"
4#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07005#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07006#include "verification_mock.hpp"
Patrick Ventureffcc5502018-11-16 12:32:38 -08007
Patrick Venture481cd4a2019-05-17 17:53:11 -07008#include <memory>
Patrick Ventureffcc5502018-11-16 12:32:38 -08009#include <vector>
10
11#include <gtest/gtest.h>
12
Patrick Venture1d5a31c2019-05-20 11:38:22 -070013namespace ipmi_flash
Patrick Ventureffcc5502018-11-16 12:32:38 -080014{
Patrick Venturecabc1172018-11-16 16:14:26 -080015using ::testing::_;
16using ::testing::IsNull;
17using ::testing::NotNull;
Patrick Ventureffcc5502018-11-16 12:32:38 -080018using ::testing::Return;
Patrick Venturecabc1172018-11-16 16:14:26 -080019using ::testing::StrEq;
20using ::testing::StrictMock;
Patrick Ventureffcc5502018-11-16 12:32:38 -080021
Patrick Venture481cd4a2019-05-17 17:53:11 -070022class FirmwareHandlerCommitTest : public ::testing::Test
23{
24 protected:
25 ImageHandlerMock imageMock1, imageMock2;
26 std::vector<HandlerPack> blobs;
27 std::vector<DataHandlerPack> data;
28
29 void SetUp() override
30 {
31 blobs = {
32 {hashBlobId, &imageMock1},
33 {"asdf", &imageMock2},
34 };
35
36 data = {
37 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
38 };
39 }
40};
41
42TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
Patrick Ventureffcc5502018-11-16 12:32:38 -080043{
44 /* Verify the flash image returns failure on this command. It's a fairly
45 * artificial test.
46 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080047
Patrick Venture3ecb3502019-05-17 11:03:51 -070048 /* Verify it doesn't get called by using StrictMock. */
49 std::unique_ptr<VerificationInterface> verifyMock =
50 std::make_unique<StrictMock<VerificationMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080051
52 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture27ac5822019-05-20 17:39:31 -070053 blobs, data, std::move(verifyMock), CreateUpdateMock());
Patrick Ventureffcc5502018-11-16 12:32:38 -080054
55 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
56
57 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070058 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
59 "asdf"));
Patrick Ventureffcc5502018-11-16 12:32:38 -080060
61 EXPECT_FALSE(handler->commit(0, {}));
62}
63
Patrick Venture481cd4a2019-05-17 17:53:11 -070064TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
Patrick Ventureffcc5502018-11-16 12:32:38 -080065{
66 /* Verify the hash file returns failure on this command. It's a fairly
67 * artificial test.
68 */
Patrick Ventureffcc5502018-11-16 12:32:38 -080069
Patrick Venture3ecb3502019-05-17 11:03:51 -070070 /* Verify it doesn't get called by using StrictMock. */
71 std::unique_ptr<VerificationInterface> verifyMock =
72 std::make_unique<StrictMock<VerificationMock>>();
Patrick Venture4eb55952018-11-16 15:36:24 -080073
74 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture27ac5822019-05-20 17:39:31 -070075 blobs, data, std::move(verifyMock), CreateUpdateMock());
Patrick Ventureffcc5502018-11-16 12:32:38 -080076
Patrick Venture7dad86f2019-05-17 08:52:20 -070077 EXPECT_CALL(imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Ventureffcc5502018-11-16 12:32:38 -080078
79 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070080 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070081 hashBlobId));
Patrick Ventureffcc5502018-11-16 12:32:38 -080082
83 EXPECT_FALSE(handler->commit(0, {}));
84}
85
Patrick Venture1d5a31c2019-05-20 11:38:22 -070086} // namespace ipmi_flash