Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 1 | /** |
| 2 | * The goal of these tests is to verify the behavior of all blob commands given |
| 3 | * the current state is verificationCompleted. This state is achieved as a out |
| 4 | * of verificationStarted. |
| 5 | */ |
| 6 | #include "firmware_handler.hpp" |
| 7 | #include "firmware_unittest.hpp" |
| 8 | #include "status.hpp" |
| 9 | #include "util.hpp" |
| 10 | |
| 11 | #include <cstdint> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
| 15 | #include <gtest/gtest.h> |
| 16 | |
| 17 | namespace ipmi_flash |
| 18 | { |
| 19 | namespace |
| 20 | { |
| 21 | |
| 22 | using ::testing::Return; |
| 23 | |
| 24 | /* |
| 25 | * There are the following calls (parameters may vary): |
| 26 | * canHandleBlob(blob) |
| 27 | * getBlobIds |
| 28 | * deleteBlob(blob) |
| 29 | * stat(blob) |
| 30 | * stat(session) |
| 31 | * open(blob) |
| 32 | * close(session) |
| 33 | * writemeta(session) |
| 34 | * write(session) |
| 35 | * read(session) |
| 36 | * commit(session) |
| 37 | * |
| 38 | * Like the state verificationStarted, there is a file open in |
| 39 | * verificationCompleted. This state is transitioned to after a stat() command |
| 40 | * indicates a successful verification. |
| 41 | */ |
| 42 | |
| 43 | class FirmwareHandlerVerificationCompletedTest |
| 44 | : public IpmiOnlyFirmwareStaticTest |
| 45 | { |
| 46 | protected: |
Patrick Venture | 0c642fd | 2019-05-24 16:09:29 -0700 | [diff] [blame] | 47 | void getToVerificationCompleted(VerifyCheckResponses checkResponse) |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 48 | { |
Patrick Venture | 0c642fd | 2019-05-24 16:09:29 -0700 | [diff] [blame] | 49 | /* The hash was not sent up, as it's technically optional. Therefore, |
| 50 | * there is no active hash file. |
| 51 | */ |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 52 | EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true)); |
| 53 | EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId)); |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 54 | expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); |
| 55 | |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 56 | EXPECT_CALL(imageMock, close()).WillRepeatedly(Return()); |
| 57 | handler->close(session); |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 58 | expectedState(FirmwareBlobHandler::UpdateState::verificationPending); |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 59 | |
| 60 | EXPECT_TRUE(handler->open(session, flags, verifyBlobId)); |
| 61 | EXPECT_CALL(*verifyMockPtr, triggerVerification()) |
| 62 | .WillOnce(Return(true)); |
| 63 | |
| 64 | EXPECT_TRUE(handler->commit(session, {})); |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 65 | expectedState(FirmwareBlobHandler::UpdateState::verificationStarted); |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 66 | |
| 67 | EXPECT_CALL(*verifyMockPtr, checkVerificationState()) |
Patrick Venture | 0c642fd | 2019-05-24 16:09:29 -0700 | [diff] [blame] | 68 | .WillOnce(Return(checkResponse)); |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 69 | blobs::BlobMeta meta; |
| 70 | EXPECT_TRUE(handler->stat(session, &meta)); |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 71 | expectedState(FirmwareBlobHandler::UpdateState::verificationCompleted); |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | std::uint16_t session = 1; |
| 75 | std::uint16_t flags = |
| 76 | blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi; |
| 77 | }; |
| 78 | |
Patrick Venture | 0c642fd | 2019-05-24 16:09:29 -0700 | [diff] [blame] | 79 | /* TODO: |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 80 | * canHandleBlob(blob) |
| 81 | * getBlobIds |
| 82 | * deleteBlob(blob) |
| 83 | * |
| 84 | */ |
| 85 | |
| 86 | /* |
| 87 | * stat(blob) |
| 88 | */ |
Patrick Venture | 0c642fd | 2019-05-24 16:09:29 -0700 | [diff] [blame] | 89 | TEST_F(FirmwareHandlerVerificationCompletedTest, |
| 90 | StatOnActiveImageReturnsFailure) |
| 91 | { |
| 92 | getToVerificationCompleted(VerifyCheckResponses::success); |
| 93 | ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId)); |
| 94 | |
| 95 | blobs::BlobMeta meta; |
| 96 | EXPECT_FALSE(handler->stat(activeImageBlobId, &meta)); |
| 97 | } |
| 98 | |
Patrick Venture | fbf07ff | 2019-05-29 08:58:45 -0700 | [diff] [blame^] | 99 | TEST_F(FirmwareHandlerVerificationCompletedTest, |
| 100 | VerifyActiveHashIdMissingInThisCase) |
| 101 | { |
| 102 | /* The path taken to get to this state never opened the hash blob Id, which |
| 103 | * is fine. But let's verify it behaved as intended. |
| 104 | */ |
| 105 | getToVerificationCompleted(VerifyCheckResponses::success); |
| 106 | EXPECT_FALSE(handler->canHandleBlob(activeHashBlobId)); |
| 107 | } |
| 108 | |
| 109 | /* TODO: Add sufficient warning that you can get to verificationCompleted |
| 110 | * without ever opening the image blob id (or the tarball one). |
| 111 | * |
| 112 | * Although in this case, it's expected that any verification triggered would |
| 113 | * certainly fail. So, although it's possible, it's uninteresting. |
| 114 | */ |
| 115 | |
Patrick Venture | 0c642fd | 2019-05-24 16:09:29 -0700 | [diff] [blame] | 116 | TEST_F(FirmwareHandlerVerificationCompletedTest, StatOnVerifyBlobReturnsFailure) |
| 117 | { |
| 118 | getToVerificationCompleted(VerifyCheckResponses::success); |
| 119 | ASSERT_TRUE(handler->canHandleBlob(verifyBlobId)); |
| 120 | |
| 121 | blobs::BlobMeta meta; |
| 122 | EXPECT_FALSE(handler->stat(verifyBlobId, &meta)); |
| 123 | } |
| 124 | |
| 125 | TEST_F(FirmwareHandlerVerificationCompletedTest, |
| 126 | StatOnNormalBlobsReturnsSuccess) |
| 127 | { |
| 128 | getToVerificationCompleted(VerifyCheckResponses::success); |
| 129 | |
| 130 | blobs::BlobMeta expected; |
| 131 | expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi; |
| 132 | expected.size = 0; |
| 133 | |
| 134 | std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId}; |
| 135 | for (const auto& blob : testBlobs) |
| 136 | { |
| 137 | ASSERT_TRUE(handler->canHandleBlob(blob)); |
| 138 | |
| 139 | blobs::BlobMeta meta = {}; |
| 140 | EXPECT_TRUE(handler->stat(blob, &meta)); |
| 141 | EXPECT_EQ(expected, meta); |
| 142 | } |
| 143 | } |
Patrick Venture | a82f99e | 2019-05-24 15:44:35 -0700 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * stat(session) - the verify blobid is open in this state, so stat on that once |
| 147 | * completed should have no effect. |
| 148 | * |
| 149 | * open(blob) - all open should fail |
| 150 | * |
| 151 | * close(session) - close on the verify blobid: |
| 152 | * 1. if successful adds update blob id, changes state to UpdatePending |
| 153 | * 2. if unsuccessful doesn't add update blob id, changes state to? |
| 154 | */ |
| 155 | |
| 156 | /* |
| 157 | * writemeta(session) - write meta should fail. |
| 158 | * write(session) - write should fail. |
| 159 | * read(session) - read returns empty. |
| 160 | * commit(session) - ? |
| 161 | */ |
| 162 | |
| 163 | } // namespace |
| 164 | } // namespace ipmi_flash |