summaryrefslogtreecommitdiffstats
path: root/tests/component
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-09-14 21:52:02 +0200
committerTianjie Xu <xunchang@google.com>2018-10-05 01:42:57 +0200
commit9eed65e1db49abe44daedc2f569acff6ce861035 (patch)
tree6003da94d6b463b32981b0d74b02658ac8e24268 /tests/component
parentMerge "Reland: "recovery_test_component: Add libbinderthreadstate as static dependency."" (diff)
downloadandroid_bootable_recovery-9eed65e1db49abe44daedc2f569acff6ce861035.tar
android_bootable_recovery-9eed65e1db49abe44daedc2f569acff6ce861035.tar.gz
android_bootable_recovery-9eed65e1db49abe44daedc2f569acff6ce861035.tar.bz2
android_bootable_recovery-9eed65e1db49abe44daedc2f569acff6ce861035.tar.lz
android_bootable_recovery-9eed65e1db49abe44daedc2f569acff6ce861035.tar.xz
android_bootable_recovery-9eed65e1db49abe44daedc2f569acff6ce861035.tar.zst
android_bootable_recovery-9eed65e1db49abe44daedc2f569acff6ce861035.zip
Diffstat (limited to 'tests/component')
-rw-r--r--tests/component/update_verifier_test.cpp102
1 files changed, 87 insertions, 15 deletions
diff --git a/tests/component/update_verifier_test.cpp b/tests/component/update_verifier_test.cpp
index 543e4278e..2420c27fe 100644
--- a/tests/component/update_verifier_test.cpp
+++ b/tests/component/update_verifier_test.cpp
@@ -16,6 +16,7 @@
#include <update_verifier/update_verifier.h>
+#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
@@ -37,8 +38,19 @@ class UpdateVerifierTest : public ::testing::Test {
std::string verity_mode = android::base::GetProperty("ro.boot.veritymode", "");
verity_supported = android::base::EqualsIgnoreCase(verity_mode, "enforcing");
+ care_map_prefix_ = care_map_dir_.path + "/care_map"s;
care_map_pb_ = care_map_dir_.path + "/care_map.pb"s;
care_map_txt_ = care_map_dir_.path + "/care_map.txt"s;
+ // Overrides the the care_map_prefix.
+ verifier_.set_care_map_prefix(care_map_prefix_);
+
+ property_id_ = "ro.build.fingerprint";
+ fingerprint_ = android::base::GetProperty(property_id_, "");
+ // Overrides the property_reader if we cannot read the given property on the device.
+ if (fingerprint_.empty()) {
+ fingerprint_ = "mock_fingerprint";
+ verifier_.set_property_reader([](const std::string& /* id */) { return "mock_fingerprint"; });
+ }
}
void TearDown() override {
@@ -58,6 +70,9 @@ class UpdateVerifierTest : public ::testing::Test {
if (partition.find("ranges") != partition.end()) {
info.set_ranges(partition.at("ranges"));
}
+ if (partition.find("id") != partition.end()) {
+ info.set_id(partition.at("id"));
+ }
if (partition.find("fingerprint") != partition.end()) {
info.set_fingerprint(partition.at("fingerprint"));
}
@@ -72,13 +87,16 @@ class UpdateVerifierTest : public ::testing::Test {
UpdateVerifier verifier_;
TemporaryDir care_map_dir_;
+ std::string care_map_prefix_;
std::string care_map_pb_;
std::string care_map_txt_;
+
+ std::string property_id_;
+ std::string fingerprint_;
};
TEST_F(UpdateVerifierTest, verify_image_no_care_map) {
- // Non-existing care_map is allowed.
- ASSERT_FALSE(verifier_.ParseCareMap("/doesntexist"));
+ ASSERT_FALSE(verifier_.ParseCareMap());
}
TEST_F(UpdateVerifierTest, verify_image_smoke) {
@@ -90,26 +108,26 @@ TEST_F(UpdateVerifierTest, verify_image_smoke) {
std::string content = "system\n2,0,1";
ASSERT_TRUE(android::base::WriteStringToFile(content, care_map_txt_));
- ASSERT_TRUE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_TRUE(verifier_.ParseCareMap());
ASSERT_TRUE(verifier_.VerifyPartitions());
// Leading and trailing newlines should be accepted.
ASSERT_TRUE(android::base::WriteStringToFile("\n" + content + "\n\n", care_map_txt_));
- ASSERT_TRUE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_TRUE(verifier_.ParseCareMap());
ASSERT_TRUE(verifier_.VerifyPartitions());
}
TEST_F(UpdateVerifierTest, verify_image_empty_care_map) {
- ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
}
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_txt_));
- ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
ASSERT_TRUE(android::base::WriteStringToFile("line1\nline2\nline3", care_map_txt_));
- ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
}
TEST_F(UpdateVerifierTest, verify_image_malformed_care_map) {
@@ -121,7 +139,7 @@ TEST_F(UpdateVerifierTest, verify_image_malformed_care_map) {
std::string content = "system\n2,1,0";
ASSERT_TRUE(android::base::WriteStringToFile(content, care_map_txt_));
- ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
}
TEST_F(UpdateVerifierTest, verify_image_legacy_care_map) {
@@ -133,7 +151,7 @@ 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_txt_));
- ASSERT_FALSE(verifier_.ParseCareMap(care_map_txt_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
}
TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_smoke) {
@@ -144,12 +162,17 @@ TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_smoke) {
}
std::vector<std::unordered_map<std::string, std::string>> partitions = {
- { { "name", "system" }, { "ranges", "2,0,1" } },
+ {
+ { "name", "system" },
+ { "ranges", "2,0,1" },
+ { "id", property_id_ },
+ { "fingerprint", fingerprint_ },
+ },
};
std::string proto = ConstructProto(partitions);
ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_pb_));
- ASSERT_TRUE(verifier_.ParseCareMap(care_map_pb_));
+ ASSERT_TRUE(verifier_.ParseCareMap());
ASSERT_TRUE(verifier_.VerifyPartitions());
}
@@ -161,12 +184,16 @@ TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_missing_name) {
}
std::vector<std::unordered_map<std::string, std::string>> partitions = {
- { { "ranges", "2,0,1" } },
+ {
+ { "ranges", "2,0,1" },
+ { "id", property_id_ },
+ { "fingerprint", fingerprint_ },
+ },
};
std::string proto = ConstructProto(partitions);
ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_pb_));
- ASSERT_FALSE(verifier_.ParseCareMap(care_map_pb_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
}
TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_bad_ranges) {
@@ -177,10 +204,55 @@ TEST_F(UpdateVerifierTest, verify_image_protobuf_care_map_bad_ranges) {
}
std::vector<std::unordered_map<std::string, std::string>> partitions = {
- { { "name", "system" }, { "ranges", "3,0,1" } },
+ {
+ { "name", "system" },
+ { "ranges", "3,0,1" },
+ { "id", property_id_ },
+ { "fingerprint", fingerprint_ },
+ },
+ };
+
+ std::string proto = ConstructProto(partitions);
+ ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_pb_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
+}
+
+TEST_F(UpdateVerifierTest, verify_image_protobuf_empty_fingerprint) {
+ // This test relies on dm-verity support.
+ if (!verity_supported) {
+ GTEST_LOG_(INFO) << "Test skipped on devices without dm-verity support.";
+ return;
+ }
+
+ std::vector<std::unordered_map<std::string, std::string>> partitions = {
+ {
+ { "name", "system" },
+ { "ranges", "2,0,1" },
+ },
+ };
+
+ std::string proto = ConstructProto(partitions);
+ ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_pb_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
+}
+
+TEST_F(UpdateVerifierTest, verify_image_protobuf_fingerprint_mismatch) {
+ // This test relies on dm-verity support.
+ if (!verity_supported) {
+ GTEST_LOG_(INFO) << "Test skipped on devices without dm-verity support.";
+ return;
+ }
+
+ std::vector<std::unordered_map<std::string, std::string>> partitions = {
+ {
+ { "name", "system" },
+ { "ranges", "2,0,1" },
+ { "id", property_id_ },
+ { "fingerprint", "unsupported_fingerprint" },
+ },
};
std::string proto = ConstructProto(partitions);
ASSERT_TRUE(android::base::WriteStringToFile(proto, care_map_pb_));
- ASSERT_FALSE(verifier_.ParseCareMap(care_map_pb_));
+ ASSERT_FALSE(verifier_.ParseCareMap());
}