diff options
-rw-r--r-- | common/test_utils.h | 1 | ||||
-rw-r--r-- | common/testing_constants.h | 39 | ||||
-rw-r--r-- | download_action_android_unittest.cc | 4 | ||||
-rw-r--r-- | payload_consumer/certificate_parser_android_unittest.cc | 4 | ||||
-rw-r--r-- | payload_consumer/delta_performer.cc | 13 | ||||
-rw-r--r-- | payload_consumer/delta_performer_integration_test.cc | 8 | ||||
-rw-r--r-- | payload_consumer/delta_performer_unittest.cc | 4 | ||||
-rw-r--r-- | payload_generator/delta_diff_generator.cc | 1 | ||||
-rw-r--r-- | payload_generator/delta_diff_generator.h | 2 | ||||
-rw-r--r-- | payload_generator/payload_signer_unittest.cc | 10 |
10 files changed, 55 insertions, 31 deletions
diff --git a/common/test_utils.h b/common/test_utils.h index bb5a6789..631ded43 100644 --- a/common/test_utils.h +++ b/common/test_utils.h @@ -33,6 +33,7 @@ #include <gtest/gtest.h> #include "update_engine/common/action.h" +#include "update_engine/common/testing_constants.h" #include "update_engine/common/utils.h" #include "update_engine/update_metadata.pb.h" diff --git a/common/testing_constants.h b/common/testing_constants.h new file mode 100644 index 00000000..1367ce6d --- /dev/null +++ b/common/testing_constants.h @@ -0,0 +1,39 @@ +// +// Copyright (C) 2021 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef UPDATE_ENGINE_COMMON_TESTING_CONSTANTS_H_ +#define UPDATE_ENGINE_COMMON_TESTING_CONSTANTS_H_ + +[[maybe_unused]] +static constexpr auto&& kUnittestPrivateKeyPath = "unittest_key.pem"; +[[maybe_unused]] +static constexpr auto&& kUnittestPublicKeyPath = "unittest_key.pub.pem"; +[[maybe_unused]] +static constexpr auto&& kUnittestPrivateKey2Path = "unittest_key2.pem"; +[[maybe_unused]] +static constexpr auto&& kUnittestPublicKey2Path = "unittest_key2.pub.pem"; +[[maybe_unused]] +static constexpr auto&& kUnittestPrivateKeyRSA4096Path = + "unittest_key_RSA4096.pem"; +[[maybe_unused]] +static constexpr auto&& kUnittestPublicKeyRSA4096Path = + "unittest_key_RSA4096.pub.pem"; +[[maybe_unused]] +static constexpr auto&& kUnittestPrivateKeyECPath = "unittest_key_EC.pem"; +[[maybe_unused]] +static constexpr auto&& kUnittestPublicKeyECPath = "unittest_key_EC.pub.pem"; + +#endif // UPDATE_ENGINE_COMMON_TESTING_CONSTANTS_H_ diff --git a/download_action_android_unittest.cc b/download_action_android_unittest.cc index fef2d24d..0f7ecdcc 100644 --- a/download_action_android_unittest.cc +++ b/download_action_android_unittest.cc @@ -32,6 +32,7 @@ #include "update_engine/common/mock_action_processor.h" #include "update_engine/common/mock_http_fetcher.h" #include "update_engine/common/mock_prefs.h" +#include "update_engine/common/testing_constants.h" #include "update_engine/common/test_utils.h" #include "update_engine/common/utils.h" #include "update_engine/payload_consumer/install_plan.h" @@ -46,9 +47,6 @@ using testing::DoAll; using testing::Return; using testing::SetArgPointee; -extern const char* kUnittestPrivateKeyPath; -extern const char* kUnittestPublicKeyPath; - class DownloadActionTest : public ::testing::Test { public: static constexpr int64_t METADATA_SIZE = 1024; diff --git a/payload_consumer/certificate_parser_android_unittest.cc b/payload_consumer/certificate_parser_android_unittest.cc index e300414b..9603f962 100644 --- a/payload_consumer/certificate_parser_android_unittest.cc +++ b/payload_consumer/certificate_parser_android_unittest.cc @@ -21,15 +21,15 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> -#include "update_engine/common/hash_calculator.h" #include "update_engine/common/test_utils.h" +#include "update_engine/common/testing_constants.h" +#include "update_engine/common/hash_calculator.h" #include "update_engine/common/utils.h" #include "update_engine/payload_consumer/payload_verifier.h" #include "update_engine/payload_generator/payload_signer.h" namespace chromeos_update_engine { -extern const char* kUnittestPrivateKeyPath; const char* kUnittestOtacertsPath = "otacerts.zip"; TEST(CertificateParserAndroidTest, ParseZipArchive) { diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc index 274465cd..a383bf69 100644 --- a/payload_consumer/delta_performer.cc +++ b/payload_consumer/delta_performer.cc @@ -247,8 +247,8 @@ bool DeltaPerformer::OpenCurrentPartition() { IsDynamicPartition(install_part.name, install_plan_->target_slot)); // Open source fds if we have a delta payload, or for partitions in the // partial update. - bool source_may_exist = manifest_.partial_update() || - payload_->type == InstallPayloadType::kDelta; + const bool source_may_exist = manifest_.partial_update() || + payload_->type == InstallPayloadType::kDelta; const size_t partition_operation_num = GetPartitionOperationNum(); TEST_AND_RETURN_FALSE(partition_writer_->Init( @@ -1146,9 +1146,12 @@ ErrorCode DeltaPerformer::VerifyPayload( // Verifies the payload hash. TEST_AND_RETURN_VAL(ErrorCode::kDownloadPayloadVerificationError, !payload_hash_calculator_.raw_hash().empty()); - TEST_AND_RETURN_VAL( - ErrorCode::kPayloadHashMismatchError, - payload_hash_calculator_.raw_hash() == update_check_response_hash); + if (payload_hash_calculator_.raw_hash() != update_check_response_hash) { + LOG(ERROR) << "Actual hash: " + << HexEncode(payload_hash_calculator_.raw_hash()) + << ", expected hash: " << HexEncode(update_check_response_hash); + return ErrorCode::kPayloadHashMismatchError; + } // NOLINTNEXTLINE(whitespace/braces) auto [payload_verifier, perform_verification] = CreatePayloadVerifier(); diff --git a/payload_consumer/delta_performer_integration_test.cc b/payload_consumer/delta_performer_integration_test.cc index a72b8aea..34e4c900 100644 --- a/payload_consumer/delta_performer_integration_test.cc +++ b/payload_consumer/delta_performer_integration_test.cc @@ -41,6 +41,7 @@ #include "update_engine/common/mock_download_action.h" #include "update_engine/common/mock_prefs.h" #include "update_engine/common/test_utils.h" +#include "update_engine/common/testing_constants.h" #include "update_engine/common/utils.h" #include "update_engine/payload_consumer/install_plan.h" #include "update_engine/payload_consumer/payload_constants.h" @@ -66,13 +67,6 @@ using testing::NiceMock; using testing::Not; using testing::Return; -extern const char* kUnittestPrivateKeyPath; -extern const char* kUnittestPublicKeyPath; -extern const char* kUnittestPrivateKey2Path; -extern const char* kUnittestPublicKey2Path; -extern const char* kUnittestPrivateKeyECPath; -extern const char* kUnittestPublicKeyECPath; - static const uint32_t kDefaultKernelSize = 4096; // Something small for a test // clang-format off static const uint8_t kNewData[] = {'T', 'h', 'i', 's', ' ', 'i', 's', ' ', diff --git a/payload_consumer/delta_performer_unittest.cc b/payload_consumer/delta_performer_unittest.cc index c24c524b..bd4850a8 100644 --- a/payload_consumer/delta_performer_unittest.cc +++ b/payload_consumer/delta_performer_unittest.cc @@ -47,6 +47,7 @@ #include "update_engine/common/hash_calculator.h" #include "update_engine/common/mock_download_action.h" #include "update_engine/common/test_utils.h" +#include "update_engine/common/testing_constants.h" #include "update_engine/common/utils.h" #include "update_engine/payload_consumer/fake_file_descriptor.h" #include "update_engine/payload_consumer/mock_partition_writer.h" @@ -68,9 +69,6 @@ using testing::_; using testing::Return; using ::testing::Sequence; -extern const char* kUnittestPrivateKeyPath; -extern const char* kUnittestPublicKeyPath; - namespace { const char kBogusMetadataSignature1[] = diff --git a/payload_generator/delta_diff_generator.cc b/payload_generator/delta_diff_generator.cc index c6c70efc..46dfb0fa 100644 --- a/payload_generator/delta_diff_generator.cc +++ b/payload_generator/delta_diff_generator.cc @@ -53,7 +53,6 @@ namespace chromeos_update_engine { // bytes const size_t kRootFSPartitionSize = static_cast<size_t>(2) * 1024 * 1024 * 1024; -const size_t kBlockSize = 4096; // bytes class PartitionProcessor : public base::DelegateSimpleThread::Delegate { bool IsDynamicPartition(const std::string& partition_name) { diff --git a/payload_generator/delta_diff_generator.h b/payload_generator/delta_diff_generator.h index 8323f479..b11f30a3 100644 --- a/payload_generator/delta_diff_generator.h +++ b/payload_generator/delta_diff_generator.h @@ -23,7 +23,7 @@ namespace chromeos_update_engine { -extern const size_t kBlockSize; +constexpr size_t kBlockSize = 4096; extern const size_t kRootFSPartitionSize; // The |config| describes the payload generation request, describing both diff --git a/payload_generator/payload_signer_unittest.cc b/payload_generator/payload_signer_unittest.cc index 2a0b394c..2bfc820c 100644 --- a/payload_generator/payload_signer_unittest.cc +++ b/payload_generator/payload_signer_unittest.cc @@ -25,6 +25,7 @@ #include "update_engine/common/hash_calculator.h" #include "update_engine/common/test_utils.h" +#include "update_engine/common/testing_constants.h" #include "update_engine/common/utils.h" #include "update_engine/payload_consumer/payload_constants.h" #include "update_engine/payload_consumer/payload_verifier.h" @@ -41,15 +42,6 @@ using std::vector; namespace chromeos_update_engine { -const char* kUnittestPrivateKeyPath = "unittest_key.pem"; -const char* kUnittestPublicKeyPath = "unittest_key.pub.pem"; -const char* kUnittestPrivateKey2Path = "unittest_key2.pem"; -const char* kUnittestPublicKey2Path = "unittest_key2.pub.pem"; -const char* kUnittestPrivateKeyRSA4096Path = "unittest_key_RSA4096.pem"; -const char* kUnittestPublicKeyRSA4096Path = "unittest_key_RSA4096.pub.pem"; -const char* kUnittestPrivateKeyECPath = "unittest_key_EC.pem"; -const char* kUnittestPublicKeyECPath = "unittest_key_EC.pub.pem"; - // Some data and its corresponding hash and signature: const char kDataToSign[] = "This is some data to sign."; |