summaryrefslogtreecommitdiff
path: root/cmds/idmap2/tests/ResourceMappingTests.cpp
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-10-19 17:57:33 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-10-19 17:57:33 +0000
commit72864d29300adb65c1b677a676ab96de9440d1b0 (patch)
tree715f9c7a9dbf1ad9aaf806cf1202a829fafc61fa /cmds/idmap2/tests/ResourceMappingTests.cpp
parentb3230cd639be832c1650e419d5b91aef9f94a324 (diff)
parent70e02d428565b1cb9882ad2aa04ba7636fa3f099 (diff)
Merge changes I1d3e5e66,I86b869af,Iab4d3902,I645ee722
* changes: Fix <overlay-config-signature> comments Fix non-inclusive OMS test language Remove malloc/free for inline overlay values OMS: Add config_signature policy handling
Diffstat (limited to 'cmds/idmap2/tests/ResourceMappingTests.cpp')
-rw-r--r--cmds/idmap2/tests/ResourceMappingTests.cpp188
1 files changed, 112 insertions, 76 deletions
diff --git a/cmds/idmap2/tests/ResourceMappingTests.cpp b/cmds/idmap2/tests/ResourceMappingTests.cpp
index de039f440e33..185e9292346d 100644
--- a/cmds/idmap2/tests/ResourceMappingTests.cpp
+++ b/cmds/idmap2/tests/ResourceMappingTests.cpp
@@ -77,30 +77,61 @@ Result<ResourceMapping> TestGetResourceMapping(const android::StringPiece& local
fulfilled_policies, enforce_overlayable);
}
-Result<Unit> MappingExists(const ResourceMapping& mapping, const ResourceId& target_resource,
- const uint8_t type, const uint32_t value, bool rewrite) {
+Result<Unit> MappingExists(const ResourceMapping& mapping, ResourceId target_resource,
+ ResourceId overlay_resource, bool rewrite) {
auto target_map = mapping.GetTargetToOverlayMap();
auto entry_map = target_map.find(target_resource);
if (entry_map == target_map.end()) {
return Error("Failed to find mapping for target resource");
}
- if (entry_map->second.data_type != type) {
- return Error(R"(Expected type: "0x%02x" Actual type: "0x%02x")", type,
- entry_map->second.data_type);
+ auto actual_overlay_resource = std::get_if<ResourceId>(&entry_map->second);
+ if (actual_overlay_resource == nullptr) {
+ return Error("Target resource is not mapped to an overlay resource id");
}
- if (entry_map->second.data_value != value) {
- return Error(R"(Expected value: "0x%08x" Actual value: "0x%08x")", type,
- entry_map->second.data_value);
+ if (*actual_overlay_resource != overlay_resource) {
+ return Error(R"(Expected id: "0x%02x" Actual id: "0x%02x")", overlay_resource,
+ *actual_overlay_resource);
}
auto overlay_map = mapping.GetOverlayToTargetMap();
- auto overlay_iter = overlay_map.find(entry_map->second.data_value);
+ auto overlay_iter = overlay_map.find(overlay_resource);
if ((overlay_iter != overlay_map.end()) != rewrite) {
return Error(R"(Expected rewriting: "%s")", rewrite ? "true" : "false");
}
+ if (rewrite && overlay_iter->second != target_resource) {
+ return Error(R"(Expected rewrite id: "0x%02x" Actual id: "0x%02x")", target_resource,
+ overlay_iter->second);
+ }
+
+ return Result<Unit>({});
+}
+
+Result<Unit> MappingExists(const ResourceMapping& mapping, const ResourceId& target_resource,
+ const uint8_t type, const uint32_t value) {
+ auto target_map = mapping.GetTargetToOverlayMap();
+ auto entry_map = target_map.find(target_resource);
+ if (entry_map == target_map.end()) {
+ return Error("Failed to find mapping for target resource");
+ }
+
+ auto actual_overlay_value = std::get_if<TargetValue>(&entry_map->second);
+ if (actual_overlay_value == nullptr) {
+ return Error("Target resource is not mapped to an inline value");
+ }
+
+ if (actual_overlay_value->data_type != type) {
+ return Error(R"(Expected type: "0x%02x" Actual type: "0x%02x")", type,
+ actual_overlay_value->data_type);
+ }
+
+ if (actual_overlay_value->data_value != value) {
+ return Error(R"(Expected value: "0x%08x" Actual value: "0x%08x")", type,
+ actual_overlay_value->data_value);
+ }
+
return Result<Unit>({});
}
@@ -116,14 +147,14 @@ TEST(ResourceMappingTests, ResourcesFromApkAssetsLegacy) {
ASSERT_TRUE(resources) << resources.GetErrorMessage();
auto& res = *resources;
ASSERT_EQ(res.GetTargetToOverlayMap().size(), 4U);
- ASSERT_RESULT(MappingExists(res, R::target::integer::int1, Res_value::TYPE_REFERENCE,
- R::overlay::integer::int1, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::str1, Res_value::TYPE_REFERENCE,
- R::overlay::string::str1, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::str3, Res_value::TYPE_REFERENCE,
- R::overlay::string::str3, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::str4, Res_value::TYPE_REFERENCE,
- R::overlay::string::str4, false /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::integer::int1, R::overlay::integer::int1, false /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str1, R::overlay::string::str1, false /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str3, R::overlay::string::str3, false /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str4, R::overlay::string::str4, false /* rewrite */));
}
TEST(ResourceMappingTests, ResourcesFromApkAssetsNonMatchingNames) {
@@ -138,12 +169,12 @@ TEST(ResourceMappingTests, ResourcesFromApkAssetsNonMatchingNames) {
ASSERT_TRUE(resources) << resources.GetErrorMessage();
auto& res = *resources;
ASSERT_EQ(res.GetTargetToOverlayMap().size(), 3U);
- ASSERT_RESULT(MappingExists(res, R::target::string::str1, Res_value::TYPE_DYNAMIC_REFERENCE,
- R::overlay::string::str4, true /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::str3, Res_value::TYPE_DYNAMIC_REFERENCE,
- R::overlay::string::str1, true /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::str4, Res_value::TYPE_DYNAMIC_REFERENCE,
- R::overlay::string::str3, true /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str1, R::overlay::string::str4, true /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str3, R::overlay::string::str1, true /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str4, R::overlay::string::str3, true /* rewrite */));
}
TEST(ResourceMappingTests, DoNotRewriteNonOverlayResourceId) {
@@ -159,10 +190,9 @@ TEST(ResourceMappingTests, DoNotRewriteNonOverlayResourceId) {
auto& res = *resources;
ASSERT_EQ(res.GetTargetToOverlayMap().size(), 2U);
ASSERT_EQ(res.GetOverlayToTargetMap().size(), 1U);
- ASSERT_RESULT(MappingExists(res, R::target::string::str1, Res_value::TYPE_REFERENCE, 0x0104000a,
+ ASSERT_RESULT(MappingExists(res, R::target::string::str1, 0x0104000a,
false /* rewrite */)); // -> android:string/ok
- ASSERT_RESULT(MappingExists(res, R::target::string::str3, Res_value::TYPE_DYNAMIC_REFERENCE,
- 0x7f020001, true /* rewrite */));
+ ASSERT_RESULT(MappingExists(res, R::target::string::str3, 0x7f020001, true /* rewrite */));
}
TEST(ResourceMappingTests, InlineResources) {
@@ -180,10 +210,8 @@ TEST(ResourceMappingTests, InlineResources) {
ASSERT_EQ(res.GetTargetToOverlayMap().size(), 2U);
ASSERT_EQ(res.GetOverlayToTargetMap().size(), 0U);
ASSERT_RESULT(MappingExists(res, R::target::string::str1, Res_value::TYPE_STRING,
- overlay_string_pool_size + 0U,
- false /* rewrite */)); // -> "Hello World"
- ASSERT_RESULT(MappingExists(res, R::target::integer::int1, Res_value::TYPE_INT_DEC, 73U,
- false /* rewrite */)); // -> 73
+ overlay_string_pool_size + 0U)); // -> "Hello World"
+ ASSERT_RESULT(MappingExists(res, R::target::integer::int1, Res_value::TYPE_INT_DEC, 73U));
}
TEST(ResourceMappingTests, CreateIdmapFromApkAssetsPolicySystemPublic) {
@@ -195,13 +223,13 @@ TEST(ResourceMappingTests, CreateIdmapFromApkAssetsPolicySystemPublic) {
ASSERT_TRUE(resources) << resources.GetErrorMessage();
auto& res = *resources;
ASSERT_EQ(res.GetTargetToOverlayMap().size(), 3U);
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_public, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_public,
R::system_overlay::string::policy_public, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_system, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_system,
R::system_overlay::string::policy_system, false /* rewrite */));
- ASSERT_RESULT(
- MappingExists(res, R::target::string::policy_system_vendor, Res_value::TYPE_REFERENCE,
- R::system_overlay::string::policy_system_vendor, false /* rewrite */));
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_system_vendor,
+ R::system_overlay::string::policy_system_vendor,
+ false /* rewrite */));
}
// Resources that are not declared as overlayable and resources that a protected by policies the
@@ -215,15 +243,15 @@ TEST(ResourceMappingTests, CreateIdmapFromApkAssetsPolicySystemPublicInvalid) {
ASSERT_TRUE(resources) << resources.GetErrorMessage();
auto& res = *resources;
ASSERT_EQ(res.GetTargetToOverlayMap().size(), 3U);
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_public, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_public,
R::system_overlay_invalid::string::policy_public,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_system, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_system,
R::system_overlay_invalid::string::policy_system,
false /* rewrite */));
- ASSERT_RESULT(
- MappingExists(res, R::target::string::policy_system_vendor, Res_value::TYPE_REFERENCE,
- R::system_overlay_invalid::string::policy_system_vendor, false /* rewrite */));
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_system_vendor,
+ R::system_overlay_invalid::string::policy_system_vendor,
+ false /* rewrite */));
}
// Resources that are not declared as overlayable and resources that a protected by policies the
@@ -237,34 +265,37 @@ TEST(ResourceMappingTests, ResourcesFromApkAssetsPolicySystemPublicInvalidIgnore
ASSERT_TRUE(resources) << resources.GetErrorMessage();
auto& res = *resources;
- ASSERT_EQ(res.GetTargetToOverlayMap().size(), 10U);
- ASSERT_RESULT(MappingExists(res, R::target::string::not_overlayable, Res_value::TYPE_REFERENCE,
+ ASSERT_EQ(res.GetTargetToOverlayMap().size(), 11U);
+ ASSERT_RESULT(MappingExists(res, R::target::string::not_overlayable,
R::system_overlay_invalid::string::not_overlayable,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::other, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::other,
R::system_overlay_invalid::string::other, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_actor, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_actor,
R::system_overlay_invalid::string::policy_actor,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_odm, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_odm,
R::system_overlay_invalid::string::policy_odm, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_oem, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_oem,
R::system_overlay_invalid::string::policy_oem, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_product, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_product,
R::system_overlay_invalid::string::policy_product,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_public, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_public,
R::system_overlay_invalid::string::policy_public,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_signature, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_config_signature,
+ R::system_overlay_invalid::string::policy_config_signature,
+ false /* rewrite */));
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_signature,
R::system_overlay_invalid::string::policy_signature,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_system, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_system,
R::system_overlay_invalid::string::policy_system,
false /* rewrite */));
- ASSERT_RESULT(
- MappingExists(res, R::target::string::policy_system_vendor, Res_value::TYPE_REFERENCE,
- R::system_overlay_invalid::string::policy_system_vendor, false /* rewrite */));
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_system_vendor,
+ R::system_overlay_invalid::string::policy_system_vendor,
+ false /* rewrite */));
}
// Overlays that do not target an <overlayable> tag can overlay resources defined within any
@@ -277,14 +308,14 @@ TEST(ResourceMappingTests, ResourcesFromApkAssetsNoDefinedOverlayableAndNoTarget
ASSERT_TRUE(resources) << resources.GetErrorMessage();
auto& res = *resources;
ASSERT_EQ(res.GetTargetToOverlayMap().size(), 4U);
- ASSERT_RESULT(MappingExists(res, R::target::integer::int1, Res_value::TYPE_REFERENCE,
- R::overlay::integer::int1, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::str1, Res_value::TYPE_REFERENCE,
- R::overlay::string::str1, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::str3, Res_value::TYPE_REFERENCE,
- R::overlay::string::str3, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::str4, Res_value::TYPE_REFERENCE,
- R::overlay::string::str4, false /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::integer::int1, R::overlay::integer::int1, false /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str1, R::overlay::string::str1, false /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str3, R::overlay::string::str3, false /* rewrite */));
+ ASSERT_RESULT(
+ MappingExists(res, R::target::string::str4, R::overlay::string::str4, false /* rewrite */));
}
// Overlays that are neither pre-installed nor signed with the same signature as the target cannot
@@ -298,8 +329,9 @@ TEST(ResourceMappingTests, ResourcesFromApkAssetsDefaultPoliciesPublicFail) {
ASSERT_EQ(resources->GetTargetToOverlayMap().size(), 0U);
}
-// Overlays that are pre-installed or are signed with the same signature as the target can overlay
-// packages that have not defined overlayable resources.
+// Overlays that are pre-installed or are signed with the same signature as the target or are
+// signed with the same signature as the reference package can overlay packages that have not
+// defined overlayable resources.
TEST(ResourceMappingTests, ResourcesFromApkAssetsDefaultPolicies) {
auto CheckEntries = [&](const PolicyBitmask& fulfilled_policies) -> void {
auto resources = TestGetResourceMapping("/target/target-no-overlayable.apk",
@@ -309,39 +341,43 @@ TEST(ResourceMappingTests, ResourcesFromApkAssetsDefaultPolicies) {
ASSERT_TRUE(resources) << resources.GetErrorMessage();
auto& res = *resources;
- ASSERT_EQ(resources->GetTargetToOverlayMap().size(), 10U);
- ASSERT_RESULT(MappingExists(res, R::target::string::not_overlayable, Res_value::TYPE_REFERENCE,
+ ASSERT_EQ(resources->GetTargetToOverlayMap().size(), 11U);
+ ASSERT_RESULT(MappingExists(res, R::target::string::not_overlayable,
R::system_overlay_invalid::string::not_overlayable,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::other, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::other,
R::system_overlay_invalid::string::other, false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_actor, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_actor,
R::system_overlay_invalid::string::policy_actor,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_odm, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_odm,
R::system_overlay_invalid::string::policy_odm,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_oem, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_oem,
R::system_overlay_invalid::string::policy_oem,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_product, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_product,
R::system_overlay_invalid::string::policy_product,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_public, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_public,
R::system_overlay_invalid::string::policy_public,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_signature, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_config_signature,
+ R::system_overlay_invalid::string::policy_config_signature,
+ false /* rewrite */));
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_signature,
R::system_overlay_invalid::string::policy_signature,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(res, R::target::string::policy_system, Res_value::TYPE_REFERENCE,
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_system,
R::system_overlay_invalid::string::policy_system,
false /* rewrite */));
- ASSERT_RESULT(MappingExists(
- res, R::target::string::policy_system_vendor, Res_value::TYPE_REFERENCE,
- R::system_overlay_invalid::string::policy_system_vendor, false /* rewrite */));
+ ASSERT_RESULT(MappingExists(res, R::target::string::policy_system_vendor,
+ R::system_overlay_invalid::string::policy_system_vendor,
+ false /* rewrite */));
};
CheckEntries(PolicyFlags::SIGNATURE);
+ CheckEntries(PolicyFlags::CONFIG_SIGNATURE);
CheckEntries(PolicyFlags::PRODUCT_PARTITION);
CheckEntries(PolicyFlags::SYSTEM_PARTITION);
CheckEntries(PolicyFlags::VENDOR_PARTITION);