summaryrefslogtreecommitdiffstats
path: root/tests/component
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-03-23 14:34:20 +0100
committerTao Bao <tbao@google.com>2017-03-23 14:52:45 +0100
commitdb56eb073e595a862f620e244e23471665f63527 (patch)
tree894359381e21804f18317b6442e66d6b402d922b /tests/component
parentMerge "Remove malloc in edify functions" (diff)
downloadandroid_bootable_recovery-db56eb073e595a862f620e244e23471665f63527.tar
android_bootable_recovery-db56eb073e595a862f620e244e23471665f63527.tar.gz
android_bootable_recovery-db56eb073e595a862f620e244e23471665f63527.tar.bz2
android_bootable_recovery-db56eb073e595a862f620e244e23471665f63527.tar.lz
android_bootable_recovery-db56eb073e595a862f620e244e23471665f63527.tar.xz
android_bootable_recovery-db56eb073e595a862f620e244e23471665f63527.tar.zst
android_bootable_recovery-db56eb073e595a862f620e244e23471665f63527.zip
Diffstat (limited to 'tests/component')
-rw-r--r--tests/component/updater_test.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index ef121a973..5652ddf46 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -127,6 +127,55 @@ TEST_F(UpdaterTest, sha1_check) {
expect(nullptr, "sha1_check()", kArgsParsingFailure);
}
+TEST_F(UpdaterTest, apply_patch_check) {
+ // Zero-argument is not valid.
+ expect(nullptr, "apply_patch_check()", kArgsParsingFailure);
+
+ // File not found.
+ expect("", "apply_patch_check(\"/doesntexist\")", kNoCause);
+
+ std::string src_file = from_testdata_base("old.file");
+ std::string src_content;
+ ASSERT_TRUE(android::base::ReadFileToString(src_file, &src_content));
+ size_t src_size = src_content.size();
+ std::string src_hash = get_sha1(src_content);
+
+ // One-argument with EMMC:file:size:sha1 should pass the check.
+ std::string filename = android::base::Join(
+ std::vector<std::string>{ "EMMC", src_file, std::to_string(src_size), src_hash }, ":");
+ std::string cmd = "apply_patch_check(\"" + filename + "\")";
+ expect("t", cmd.c_str(), kNoCause);
+
+ // EMMC:file:(size-1):sha1:(size+1):sha1 should fail the check.
+ std::string filename_bad = android::base::Join(
+ std::vector<std::string>{ "EMMC", src_file, std::to_string(src_size - 1), src_hash,
+ std::to_string(src_size + 1), src_hash },
+ ":");
+ cmd = "apply_patch_check(\"" + filename_bad + "\")";
+ expect("", cmd.c_str(), kNoCause);
+
+ // EMMC:file:(size-1):sha1:size:sha1:(size+1):sha1 should pass the check.
+ filename_bad =
+ android::base::Join(std::vector<std::string>{ "EMMC", src_file, std::to_string(src_size - 1),
+ src_hash, std::to_string(src_size), src_hash,
+ std::to_string(src_size + 1), src_hash },
+ ":");
+ cmd = "apply_patch_check(\"" + filename_bad + "\")";
+ expect("t", cmd.c_str(), kNoCause);
+
+ // Multiple arguments.
+ cmd = "apply_patch_check(\"" + filename + "\", \"wrong_sha1\", \"wrong_sha2\")";
+ expect("", cmd.c_str(), kNoCause);
+
+ cmd = "apply_patch_check(\"" + filename + "\", \"wrong_sha1\", \"" + src_hash +
+ "\", \"wrong_sha2\")";
+ expect("t", cmd.c_str(), kNoCause);
+
+ cmd = "apply_patch_check(\"" + filename_bad + "\", \"wrong_sha1\", \"" + src_hash +
+ "\", \"wrong_sha2\")";
+ expect("t", cmd.c_str(), kNoCause);
+}
+
TEST_F(UpdaterTest, file_getprop) {
// file_getprop() expects two arguments.
expect(nullptr, "file_getprop()", kArgsParsingFailure);