Merge "tests: Construct two bad packages at runtime for VerifierTest."

This commit is contained in:
Tao Bao
2017-03-29 00:37:04 +00:00
committed by Gerrit Code Review
3 changed files with 46 additions and 3 deletions

View File

@@ -115,6 +115,51 @@ TEST(VerifierTest, load_keys_invalid_keys) {
ASSERT_FALSE(load_keys(key_file5.path, certs));
}
TEST(VerifierTest, BadPackage_AlteredFooter) {
std::string testkey_v3;
ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3));
TemporaryFile key_file1;
ASSERT_TRUE(android::base::WriteStringToFile(testkey_v3, key_file1.path));
std::vector<Certificate> certs;
ASSERT_TRUE(load_keys(key_file1.path, certs));
std::string package;
ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("otasigned_v3.zip"), &package));
ASSERT_EQ(std::string("\xc0\x06\xff\xff\xd2\x06", 6), package.substr(package.size() - 6, 6));
// Alter the footer.
package[package.size() - 5] = '\x05';
ASSERT_EQ(VERIFY_FAILURE,
verify_file(reinterpret_cast<const unsigned char*>(package.data()), package.size(),
certs));
}
TEST(VerifierTest, BadPackage_AlteredContent) {
std::string testkey_v3;
ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3));
TemporaryFile key_file1;
ASSERT_TRUE(android::base::WriteStringToFile(testkey_v3, key_file1.path));
std::vector<Certificate> certs;
ASSERT_TRUE(load_keys(key_file1.path, certs));
std::string package;
ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("otasigned_v3.zip"), &package));
ASSERT_GT(package.size(), static_cast<size_t>(100));
// Alter the content.
std::string altered1(package);
altered1[50] += 1;
ASSERT_EQ(VERIFY_FAILURE,
verify_file(reinterpret_cast<const unsigned char*>(altered1.data()), altered1.size(),
certs));
std::string altered2(package);
altered2[10] += 1;
ASSERT_EQ(VERIFY_FAILURE,
verify_file(reinterpret_cast<const unsigned char*>(altered2.data()), altered2.size(),
certs));
}
TEST_P(VerifierSuccessTest, VerifySucceed) {
ASSERT_EQ(verify_file(memmap.addr, memmap.length, certs, nullptr), VERIFY_SUCCESS);
}
@@ -157,6 +202,4 @@ INSTANTIATE_TEST_CASE_P(WrongHash, VerifierFailureTest,
INSTANTIATE_TEST_CASE_P(BadPackage, VerifierFailureTest,
::testing::Values(
std::vector<std::string>({"random.zip", "v1"}),
std::vector<std::string>({"fake-eocd.zip", "v1"}),
std::vector<std::string>({"alter-metadata.zip", "v1"}),
std::vector<std::string>({"alter-footer.zip", "v1"})));
std::vector<std::string>({"fake-eocd.zip", "v1"})));

Binary file not shown.

Binary file not shown.