Commit 74388ce5 authored by Solomon Kinard's avatar Solomon Kinard Committed by Chromium LUCI CQ

[Extensions][web_accessible_resources] use_dynamic_url validation.

The key |use_dynamic_url| is a valid key to the exclusion of |matches|
or |extension_ids| only if it's set to true. Otherwise one of the latter
two keys must be present. Prior to this change, a false value set for
the former would have acted as a wildcard for the latter two keys.

Bug: 1133624
Change-Id: Ic37253a5931968fc57284ecb7068d032f0bfac6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2612484
Commit-Queue: Solomon Kinard <solomonkinard@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843398}
parent bfdd7381
...@@ -125,11 +125,12 @@ TEST_F(WebAccessibleResourcesManifestTest, WebAccessibleResourcesV3Valid) { ...@@ -125,11 +125,12 @@ TEST_F(WebAccessibleResourcesManifestTest, WebAccessibleResourcesV3Valid) {
"unexpected_key": ["allowed"] "unexpected_key": ["allowed"]
} }
])"}, ])"},
{"Succeed if only the use_dynamic_url key is set, but not others.", {"Succeed if use_dynamic_url key is true, irrespective of matches or "
"extension_ids.",
R"([ R"([
{ {
"resources": ["test"], "resources": ["test"],
"use_dynamic_url": false "use_dynamic_url": true
} }
])"}, ])"},
}; };
...@@ -163,6 +164,16 @@ TEST_F(WebAccessibleResourcesManifestTest, WebAccessibleResourcesV3Invalid) { ...@@ -163,6 +164,16 @@ TEST_F(WebAccessibleResourcesManifestTest, WebAccessibleResourcesV3Invalid) {
])", ])",
"Invalid value for 'web_accessible_resources[0]'. Entry " "Invalid value for 'web_accessible_resources[0]'. Entry "
"must at least have resources, and one other valid key."}, "must at least have resources, and one other valid key."},
{"Error if use_dynamic_url is false, and missing extension_ids or "
"matches.",
R"([
{
"resources": ["test"],
"use_dynamic_url": false
}
])",
"Invalid value for 'web_accessible_resources[0]'. Entry "
"must at least have resources, and one other valid key."},
{"Error if incorrect keyed object type is present.", {"Error if incorrect keyed object type is present.",
R"([ R"([
{ {
...@@ -214,7 +225,8 @@ TEST_F(WebAccessibleResourcesManifestTest, WebAccessibleResourcesV3Invalid) { ...@@ -214,7 +225,8 @@ TEST_F(WebAccessibleResourcesManifestTest, WebAccessibleResourcesV3Invalid) {
} }
])", ])",
"Invalid value for 'web_accessible_resources[0]'. Invalid " "Invalid value for 'web_accessible_resources[0]'. Invalid "
"match pattern."}}; "match pattern."},
};
for (const auto& test_case : test_cases) { for (const auto& test_case : test_cases) {
SCOPED_TRACE(base::StringPrintf("Error: '%s'", test_case.title)); SCOPED_TRACE(base::StringPrintf("Error: '%s'", test_case.title));
LoadAndExpectError(GetManifestData(test_case.web_accessible_resources), LoadAndExpectError(GetManifestData(test_case.web_accessible_resources),
......
...@@ -125,7 +125,9 @@ std::unique_ptr<WebAccessibleResourcesInfo> ParseEntryList( ...@@ -125,7 +125,9 @@ std::unique_ptr<WebAccessibleResourcesInfo> ParseEntryList(
return nullptr; return nullptr;
} }
if (!(matches || extension_ids || use_dynamic_url)) { bool use_dynamic_url_bool = use_dynamic_url && use_dynamic_url->GetBool();
if (!matches && !extension_ids && !use_dynamic_url_bool) {
*error = get_error( *error = get_error(
i, "Entry must at least have resources, and one other valid key."); i, "Entry must at least have resources, and one other valid key.");
return nullptr; return nullptr;
...@@ -169,10 +171,6 @@ std::unique_ptr<WebAccessibleResourcesInfo> ParseEntryList( ...@@ -169,10 +171,6 @@ std::unique_ptr<WebAccessibleResourcesInfo> ParseEntryList(
extension_id_list.emplace_back(extension_id_str); extension_id_list.emplace_back(extension_id_str);
} }
} }
bool use_dynamic_url_bool = false;
if (use_dynamic_url) {
use_dynamic_url_bool = use_dynamic_url->GetBool();
}
info->web_accessible_resources.emplace_back( info->web_accessible_resources.emplace_back(
std::move(resource_set), std::move(match_set), std::move(resource_set), std::move(match_set),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment