blob: 3d20ce74e17ccd8ea89d3a304b3e7bfdaba30d66 [file] [log] [blame]
Patrick Venturea82f99e2019-05-24 15:44:35 -07001/**
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
17namespace ipmi_flash
18{
19namespace
20{
21
22using ::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
43class FirmwareHandlerVerificationCompletedTest
44 : public IpmiOnlyFirmwareStaticTest
45{
46 protected:
Patrick Venture0c642fd2019-05-24 16:09:29 -070047 void getToVerificationCompleted(VerifyCheckResponses checkResponse)
Patrick Venturea82f99e2019-05-24 15:44:35 -070048 {
Patrick Venture0c642fd2019-05-24 16:09:29 -070049 /* The hash was not sent up, as it's technically optional. Therefore,
50 * there is no active hash file.
51 */
Patrick Venturea82f99e2019-05-24 15:44:35 -070052 EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
53 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070054 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
55
Patrick Venturea82f99e2019-05-24 15:44:35 -070056 EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
57 handler->close(session);
Patrick Venture6fdd02e2019-05-28 13:02:04 -070058 expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
Patrick Venturea82f99e2019-05-24 15:44:35 -070059
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 Venture6fdd02e2019-05-28 13:02:04 -070065 expectedState(FirmwareBlobHandler::UpdateState::verificationStarted);
Patrick Venturea82f99e2019-05-24 15:44:35 -070066
67 EXPECT_CALL(*verifyMockPtr, checkVerificationState())
Patrick Venture0c642fd2019-05-24 16:09:29 -070068 .WillOnce(Return(checkResponse));
Patrick Venturea82f99e2019-05-24 15:44:35 -070069 blobs::BlobMeta meta;
70 EXPECT_TRUE(handler->stat(session, &meta));
Patrick Venture6fdd02e2019-05-28 13:02:04 -070071 expectedState(FirmwareBlobHandler::UpdateState::verificationCompleted);
Patrick Venturea82f99e2019-05-24 15:44:35 -070072 }
73
74 std::uint16_t session = 1;
75 std::uint16_t flags =
76 blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
77};
78
Patrick Venture0c642fd2019-05-24 16:09:29 -070079/* TODO:
Patrick Venturea82f99e2019-05-24 15:44:35 -070080 * canHandleBlob(blob)
81 * getBlobIds
82 * deleteBlob(blob)
83 *
84 */
85
86/*
87 * stat(blob)
88 */
Patrick Venture0c642fd2019-05-24 16:09:29 -070089TEST_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 Venturefbf07ff2019-05-29 08:58:45 -070099TEST_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 Venture0c642fd2019-05-24 16:09:29 -0700116TEST_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
125TEST_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 Venturea82f99e2019-05-24 15:44:35 -0700144
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