summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-09-21 02:03:59 +0200
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-09-21 02:03:59 +0200
commitff29eb7f12ffce5cfd63fb73c17d8ed170eed29e (patch)
tree953295f16c621146f623963000f345f9307814af /tests
parentMerge "Move the parse of last_install to recovery-persist" (diff)
parentRefactor update_verifier into a class (diff)
downloadandroid_bootable_recovery-ff29eb7f12ffce5cfd63fb73c17d8ed170eed29e.tar
android_bootable_recovery-ff29eb7f12ffce5cfd63fb73c17d8ed170eed29e.tar.gz
android_bootable_recovery-ff29eb7f12ffce5cfd63fb73c17d8ed170eed29e.tar.bz2
android_bootable_recovery-ff29eb7f12ffce5cfd63fb73c17d8ed170eed29e.tar.lz
android_bootable_recovery-ff29eb7f12ffce5cfd63fb73c17d8ed170eed29e.tar.xz
android_bootable_recovery-ff29eb7f12ffce5cfd63fb73c17d8ed170eed29e.tar.zst
android_bootable_recovery-ff29eb7f12ffce5cfd63fb73c17d8ed170eed29e.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/component/update_verifier_test.cpp63
1 files changed, 40 insertions, 23 deletions
diff --git a/tests/component/update_verifier_test.cpp b/tests/component/update_verifier_test.cpp
index a97071635..543e4278e 100644
--- a/tests/component/update_verifier_test.cpp
+++ b/tests/component/update_verifier_test.cpp
@@ -29,19 +29,29 @@
#include "care_map.pb.h"
+using namespace std::string_literals;
+
class UpdateVerifierTest : public ::testing::Test {
protected:
void SetUp() override {
std::string verity_mode = android::base::GetProperty("ro.boot.veritymode", "");
verity_supported = android::base::EqualsIgnoreCase(verity_mode, "enforcing");
+
+ care_map_pb_ = care_map_dir_.path + "/care_map.pb"s;
+ care_map_txt_ = care_map_dir_.path + "/care_map.txt"s;
+ }
+
+ void TearDown() override {
+ unlink(care_map_pb_.c_str());
+ unlink(care_map_txt_.c_str());
}
// Returns a serialized string of the proto3 message according to the given partition info.
std::string ConstructProto(
std::vector<std::unordered_map<std::string, std::string>>& partitions) {
- UpdateVerifier::CareMap result;
+ recovery_update_verifier::CareMap result;
for (const auto& partition : partitions) {
- UpdateVerifier::CareMap::PartitionInfo info;
+ recovery_update_verifier::CareMap::PartitionInfo info;
if (partition.find("name") != partition.end()) {
info.set_name(partition.at("name"));
}
@@ -59,12 +69,16 @@ class UpdateVerifierTest : public ::testing::Test {
}
bool verity_supported;
- TemporaryFile care_map_file;
+ UpdateVerifier verifier_;
+
+ TemporaryDir care_map_dir_;
+ std::string care_map_pb_;
+ std::string care_map_txt_;
};
TEST_F(UpdateVerifierTest, verify_image_no_care_map) {
// Non-existing care_map is allowed.
- ASSERT_TRUE(verify_image("/doesntexist"));
+ ASSERT_FALSE(verifier_.ParseCareMap("/doesntexist"));
}
TEST_F(UpdateVerifierTest, verify_image_smoke) {
@@ -75,25 +89,27 @@ TEST_F(UpdateVerifierTest, verify_image_smoke) {
}
std::string content = "system\n2,0,1";
- ASSERT_TRUE(android::base::WriteStringToFile(content, care_map_file.path));
- ASSERT_TRUE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile(content, care_map_txt_));
+ ASSERT_TRUE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_TRUE(verifier_.VerifyPartitions());
// Leading and trailing newlines should be accepted.
- ASSERT_TRUE(android::base::WriteStringToFile("\n" + content + "\n\n", care_map_file.path));
- ASSERT_TRUE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile("\n" + content + "\n\n", care_map_txt_));
+ ASSERT_TRUE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_TRUE(verifier_.VerifyPartitions());
}
TEST_F(UpdateVerifierTest, verify_image_empty_care_map) {
- ASSERT_FALSE(verify_image(care_map_file.path));
+ ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
}
TEST_F(UpdateVerifierTest, verify_image_wrong_lines) {
// The care map file can have only 2 / 4 / 6 lines.
- ASSERT_TRUE(android::base::WriteStringToFile("line1", care_map_file.path));
- ASSERT_FALSE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile("line1", care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
- ASSERT_TRUE(android::base::WriteStringToFile("line1\nline2\nline3", care_map_file.path));
- ASSERT_FALSE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile("line1\nline2\nline3", care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
}
TEST_F(UpdateVerifierTest, verify_image_malformed_care_map) {
@@ -104,8 +120,8 @@ TEST_F(UpdateVerifierTest, verify_image_malformed_care_map) {
}
std::string content = "system\n2,1,0";
- ASSERT_TRUE(android::base::WriteStringToFile(content, care_map_file.path));
- ASSERT_FALSE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile(content, care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
}
TEST_F(UpdateVerifierTest, verify_image_legacy_care_map) {
@@ -116,8 +132,8 @@ TEST_F(UpdateVerifierTest, verify_image_legacy_care_map) {
}
std::string content = "/dev/block/bootdevice/by-name/system\n2,1,0";
- ASSERT_TRUE(android::base::WriteStringToFile(content, care_map_file.path));
- ASSERT_TRUE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile(content, care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
}
TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_smoke) {
@@ -132,8 +148,9 @@ TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_smoke) {
};
std::string proto = ConstructProto(partitions);
- ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_file.path));
- ASSERT_TRUE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_pb_));
+ ASSERT_TRUE(verifier_.ParseCareMap(care_map_pb_));
+ ASSERT_TRUE(verifier_.VerifyPartitions());
}
TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_missing_name) {
@@ -148,8 +165,8 @@ TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_missing_name) {
};
std::string proto = ConstructProto(partitions);
- ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_file.path));
- ASSERT_FALSE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_pb_));
+ ASSERT_FALSE(verifier_.ParseCareMap(care_map_pb_));
}
TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_bad_ranges) {
@@ -164,6 +181,6 @@ TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_bad_ranges) {
};
std::string proto = ConstructProto(partitions);
- ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_file.path));
- ASSERT_FALSE(verify_image(care_map_file.path));
+ ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_pb_));
+ ASSERT_FALSE(verifier_.ParseCareMap(care_map_pb_));
}