summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-04-19 21:37:12 +0200
committerTao Bao <tbao@google.com>2017-04-20 02:10:34 +0200
commitf2784b6a43e54ed67bc30ac456f66f11bd16bc74 (patch)
tree3e57d003a5c64ba1ce403901319b954c5ae536de
parentMerge "Call libvintf to verify package compatibility." (diff)
downloadandroid_bootable_recovery-f2784b6a43e54ed67bc30ac456f66f11bd16bc74.tar
android_bootable_recovery-f2784b6a43e54ed67bc30ac456f66f11bd16bc74.tar.gz
android_bootable_recovery-f2784b6a43e54ed67bc30ac456f66f11bd16bc74.tar.bz2
android_bootable_recovery-f2784b6a43e54ed67bc30ac456f66f11bd16bc74.tar.lz
android_bootable_recovery-f2784b6a43e54ed67bc30ac456f66f11bd16bc74.tar.xz
android_bootable_recovery-f2784b6a43e54ed67bc30ac456f66f11bd16bc74.tar.zst
android_bootable_recovery-f2784b6a43e54ed67bc30ac456f66f11bd16bc74.zip
Diffstat (limited to '')
-rw-r--r--tests/component/install_test.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/component/install_test.cpp b/tests/component/install_test.cpp
index 2143dd7bb..40201d76f 100644
--- a/tests/component/install_test.cpp
+++ b/tests/component/install_test.cpp
@@ -15,14 +15,17 @@
*/
#include <stdio.h>
+#include <unistd.h>
#include <string>
#include <vector>
+#include <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android-base/test_utils.h>
#include <gtest/gtest.h>
+#include <vintf/VintfObjectRecovery.h>
#include <ziparchive/zip_archive.h>
#include <ziparchive/zip_writer.h>
@@ -112,6 +115,87 @@ TEST(InstallTest, read_metadata_from_package_no_entry) {
CloseArchive(zip);
}
+TEST(InstallTest, verify_package_compatibility_with_libvintf_malformed_xml) {
+ TemporaryFile compatibility_zip_file;
+ FILE* compatibility_zip = fdopen(compatibility_zip_file.fd, "w");
+ ZipWriter compatibility_zip_writer(compatibility_zip);
+ ASSERT_EQ(0, compatibility_zip_writer.StartEntry("system_manifest.xml", kCompressDeflated));
+ std::string malformed_xml = "malformed";
+ ASSERT_EQ(0, compatibility_zip_writer.WriteBytes(malformed_xml.data(), malformed_xml.size()));
+ ASSERT_EQ(0, compatibility_zip_writer.FinishEntry());
+ ASSERT_EQ(0, compatibility_zip_writer.Finish());
+ ASSERT_EQ(0, fclose(compatibility_zip));
+
+ TemporaryFile temp_file;
+ FILE* zip_file = fdopen(temp_file.fd, "w");
+ ZipWriter writer(zip_file);
+ ASSERT_EQ(0, writer.StartEntry("compatibility.zip", kCompressStored));
+ std::string compatibility_zip_content;
+ ASSERT_TRUE(
+ android::base::ReadFileToString(compatibility_zip_file.path, &compatibility_zip_content));
+ ASSERT_EQ(0,
+ writer.WriteBytes(compatibility_zip_content.data(), compatibility_zip_content.size()));
+ ASSERT_EQ(0, writer.FinishEntry());
+ ASSERT_EQ(0, writer.Finish());
+ ASSERT_EQ(0, fclose(zip_file));
+
+ ZipArchiveHandle zip;
+ ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
+ std::vector<std::string> compatibility_info;
+ compatibility_info.push_back(malformed_xml);
+ // Malformed compatibility zip is expected to be rejected by libvintf. But we defer that to
+ // libvintf.
+ std::string err;
+ bool result =
+ android::vintf::VintfObjectRecovery::CheckCompatibility(compatibility_info, &err) == 0;
+ ASSERT_EQ(result, verify_package_compatibility(zip));
+ CloseArchive(zip);
+}
+
+TEST(InstallTest, verify_package_compatibility_with_libvintf_system_manifest_xml) {
+ static constexpr const char* system_manifest_xml_path = "/system/manifest.xml";
+ if (access(system_manifest_xml_path, R_OK) == -1) {
+ GTEST_LOG_(INFO) << "Test skipped on devices w/o /system/manifest.xml.";
+ return;
+ }
+ std::string system_manifest_xml_content;
+ ASSERT_TRUE(
+ android::base::ReadFileToString(system_manifest_xml_path, &system_manifest_xml_content));
+ TemporaryFile compatibility_zip_file;
+ FILE* compatibility_zip = fdopen(compatibility_zip_file.fd, "w");
+ ZipWriter compatibility_zip_writer(compatibility_zip);
+ ASSERT_EQ(0, compatibility_zip_writer.StartEntry("system_manifest.xml", kCompressDeflated));
+ ASSERT_EQ(0, compatibility_zip_writer.WriteBytes(system_manifest_xml_content.data(),
+ system_manifest_xml_content.size()));
+ ASSERT_EQ(0, compatibility_zip_writer.FinishEntry());
+ ASSERT_EQ(0, compatibility_zip_writer.Finish());
+ ASSERT_EQ(0, fclose(compatibility_zip));
+
+ TemporaryFile temp_file;
+ FILE* zip_file = fdopen(temp_file.fd, "w");
+ ZipWriter writer(zip_file);
+ ASSERT_EQ(0, writer.StartEntry("compatibility.zip", kCompressStored));
+ std::string compatibility_zip_content;
+ ASSERT_TRUE(
+ android::base::ReadFileToString(compatibility_zip_file.path, &compatibility_zip_content));
+ ASSERT_EQ(0,
+ writer.WriteBytes(compatibility_zip_content.data(), compatibility_zip_content.size()));
+ ASSERT_EQ(0, writer.FinishEntry());
+ ASSERT_EQ(0, writer.Finish());
+ ASSERT_EQ(0, fclose(zip_file));
+
+ ZipArchiveHandle zip;
+ ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
+ std::vector<std::string> compatibility_info;
+ compatibility_info.push_back(system_manifest_xml_content);
+ std::string err;
+ bool result =
+ android::vintf::VintfObjectRecovery::CheckCompatibility(compatibility_info, &err) == 0;
+ // Make sure the result is consistent with libvintf library.
+ ASSERT_EQ(result, verify_package_compatibility(zip));
+ CloseArchive(zip);
+}
+
TEST(InstallTest, update_binary_command_smoke) {
#ifdef AB_OTA_UPDATER
TemporaryFile temp_file;