diff options
Diffstat (limited to 'apexd/apex_file_test.cpp')
-rw-r--r-- | apexd/apex_file_test.cpp | 70 |
1 files changed, 53 insertions, 17 deletions
diff --git a/apexd/apex_file_test.cpp b/apexd/apex_file_test.cpp index 711d024..9d2cf17 100644 --- a/apexd/apex_file_test.cpp +++ b/apexd/apex_file_test.cpp @@ -19,6 +19,8 @@ #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/scopeguard.h> +#include <android-base/strings.h> +#include <gmock/gmock.h> #include <gtest/gtest.h> #include <libavb/libavb.h> #include <ziparchive/zip_archive.h> @@ -34,8 +36,20 @@ namespace android { namespace apex { namespace { -TEST(ApexFileTest, GetOffsetOfSimplePackage) { - const std::string filePath = testDataDir + "apex.apexd_test.apex"; +struct ApexFileTestParam { + const char* type; + const char* prefix; +}; + +constexpr const ApexFileTestParam kParameters[] = { + {"ext4", "apex.apexd_test"}, {"f2fs", "apex.apexd_test_f2fs"}}; + +class ApexFileTest : public ::testing::TestWithParam<ApexFileTestParam> {}; + +INSTANTIATE_TEST_SUITE_P(Apex, ApexFileTest, testing::ValuesIn(kParameters)); + +TEST_P(ApexFileTest, GetOffsetOfSimplePackage) { + const std::string filePath = testDataDir + GetParam().prefix + ".apex"; Result<ApexFile> apexFile = ApexFile::Open(filePath); ASSERT_TRUE(apexFile.ok()); @@ -66,22 +80,21 @@ TEST(ApexFileTest, GetOffsetMissingFile) { const std::string filePath = testDataDir + "missing.apex"; Result<ApexFile> apexFile = ApexFile::Open(filePath); ASSERT_FALSE(apexFile.ok()); - EXPECT_NE(std::string::npos, - apexFile.error().message().find("Failed to open package")) - << apexFile.error(); + ASSERT_THAT(apexFile.error().message(), + testing::HasSubstr("Failed to open package")); } -TEST(ApexFileTest, GetApexManifest) { - const std::string filePath = testDataDir + "apex.apexd_test.apex"; +TEST_P(ApexFileTest, GetApexManifest) { + const std::string filePath = testDataDir + GetParam().prefix + ".apex"; Result<ApexFile> apexFile = ApexFile::Open(filePath); ASSERT_RESULT_OK(apexFile); EXPECT_EQ("com.android.apex.test_package", apexFile->GetManifest().name()); EXPECT_EQ(1u, apexFile->GetManifest().version()); } -TEST(ApexFileTest, VerifyApexVerity) { +TEST_P(ApexFileTest, VerifyApexVerity) { ASSERT_RESULT_OK(collectPreinstalledData({"/system_ext/apex"})); - const std::string filePath = testDataDir + "apex.apexd_test.apex"; + const std::string filePath = testDataDir + GetParam().prefix + ".apex"; Result<ApexFile> apexFile = ApexFile::Open(filePath); ASSERT_RESULT_OK(apexFile); @@ -93,10 +106,15 @@ TEST(ApexFileTest, VerifyApexVerity) { EXPECT_EQ(std::string("368a22e64858647bc45498e92f749f85482ac468" "50ca7ec8071f49dfa47a243c"), data.salt); - EXPECT_EQ( - std::string( - "8e841019e41e8c40bca6dd6304cbf163ea257ba0a268304832c4105eba1c2747"), - data.root_digest); + + const std::string digestPath = + testDataDir + GetParam().prefix + "_digest.txt"; + std::string rootDigest; + ASSERT_TRUE(android::base::ReadFileToString(digestPath, &rootDigest)) + << "Failed to read " << digestPath; + rootDigest = android::base::Trim(rootDigest); + + EXPECT_EQ(std::string(rootDigest), data.root_digest); } // TODO: May consider packaging a debug key in debug builds (again). @@ -109,8 +127,9 @@ TEST(ApexFileTest, DISABLED_VerifyApexVerityNoKeyDir) { ASSERT_FALSE(verity_or.ok()); } -TEST(ApexFileTest, VerifyApexVerityNoKeyInst) { - const std::string filePath = testDataDir + "apex.apexd_test_no_inst_key.apex"; +TEST_P(ApexFileTest, VerifyApexVerityNoKeyInst) { + const std::string filePath = + testDataDir + GetParam().prefix + "_no_inst_key.apex"; Result<ApexFile> apexFile = ApexFile::Open(filePath); ASSERT_RESULT_OK(apexFile); @@ -118,8 +137,8 @@ TEST(ApexFileTest, VerifyApexVerityNoKeyInst) { ASSERT_FALSE(verity_or.ok()); } -TEST(ApexFileTest, GetBundledPublicKey) { - const std::string filePath = testDataDir + "apex.apexd_test.apex"; +TEST_P(ApexFileTest, GetBundledPublicKey) { + const std::string filePath = testDataDir + GetParam().prefix + ".apex"; Result<ApexFile> apexFile = ApexFile::Open(filePath); ASSERT_RESULT_OK(apexFile); @@ -139,6 +158,23 @@ TEST(ApexFileTest, CorrutedApex_b146895998) { ASSERT_FALSE(apex->VerifyApexVerity()); } +TEST_P(ApexFileTest, RetrieveFsType) { + const std::string filePath = testDataDir + GetParam().prefix + ".apex"; + Result<ApexFile> apexFile = ApexFile::Open(filePath); + ASSERT_TRUE(apexFile.ok()); + + EXPECT_EQ(std::string(GetParam().type), apexFile->GetFsType()); +} + +TEST(ApexFileTest, OpenInvalidFilesystem) { + const std::string filePath = + testDataDir + "apex.apexd_test_corrupt_superblock_apex.apex"; + Result<ApexFile> apexFile = ApexFile::Open(filePath); + ASSERT_FALSE(apexFile.ok()); + ASSERT_THAT(apexFile.error().message(), + testing::HasSubstr("Failed to retrieve filesystem type")); +} + } // namespace } // namespace apex } // namespace android |