diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-02 15:53:06 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-02 15:53:06 +0000 |
commit | 5d099a3c4a7a913ca2eadbe06ea4c44353d188bb (patch) | |
tree | 724f6619fb52adfa17c74a7137418bf972e4f0bc /chrome/browser/extensions | |
parent | 0152b52ad24a092dc966536e8dd7e334482463a0 (diff) | |
download | chromium_src-5d099a3c4a7a913ca2eadbe06ea4c44353d188bb.zip chromium_src-5d099a3c4a7a913ca2eadbe06ea4c44353d188bb.tar.gz chromium_src-5d099a3c4a7a913ca2eadbe06ea4c44353d188bb.tar.bz2 |
Validate privacy blacklist format when validating an extension
containing a privacy blacklist.
TEST=Covered by unit_tests.
BUG=21541
Review URL: http://codereview.chromium.org/453016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_file_util.cc | 22 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_file_util_unittest.cc | 35 |
2 files changed, 52 insertions, 5 deletions
diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc index 0bb2ff8..a1cace7 100644 --- a/chrome/browser/extensions/extension_file_util.cc +++ b/chrome/browser/extensions/extension_file_util.cc @@ -10,6 +10,8 @@ #include "base/scoped_temp_dir.h" #include "base/string_util.h" #include "chrome/browser/extensions/extension_prefs.h" +#include "chrome/browser/privacy_blacklist/blacklist.h" +#include "chrome/browser/privacy_blacklist/blacklist_io.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_l10n_util.h" #include "chrome/common/extensions/extension_constants.h" @@ -224,13 +226,23 @@ bool ValidateExtension(Extension* extension, std::string* error) { } } - // Validate claimed privacy blacklists paths. + // Validate claimed privacy blacklists. for (size_t i = 0; i < extension->privacy_blacklists().size(); ++i) { - const Extension::PrivacyBlacklistInfo& blacklist = + const Extension::PrivacyBlacklistInfo& blacklist_info = extension->privacy_blacklists()[i]; - if (!file_util::PathExists(blacklist.path)) { - *error = StringPrintf("Could not load '%s' for privacy blacklist.", - WideToUTF8(blacklist.path.ToWStringHack()).c_str()); + std::string path_utf8(WideToUTF8(blacklist_info.path.ToWStringHack())); + if (!file_util::PathExists(blacklist_info.path)) { + *error = StringPrintf("Could not load '%s' for privacy blacklist: " + "file does not exist.", + path_utf8.c_str()); + return false; + } + Blacklist blacklist; + std::string parsing_error; + if (!BlacklistIO::ReadText(&blacklist, blacklist_info.path, + &parsing_error)) { + *error = StringPrintf("Could not load '%s' for privacy blacklist: %s", + path_utf8.c_str(), parsing_error.c_str()); return false; } } diff --git a/chrome/browser/extensions/extension_file_util_unittest.cc b/chrome/browser/extensions/extension_file_util_unittest.cc index c462032..6e00eb0 100644 --- a/chrome/browser/extensions/extension_file_util_unittest.cc +++ b/chrome/browser/extensions/extension_file_util_unittest.cc @@ -6,6 +6,7 @@ #include "base/file_util.h" #include "base/scoped_temp_dir.h" +#include "base/string_util.h" #include "base/path_service.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension.h" @@ -220,6 +221,40 @@ TEST(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnBadManifest) { "Line: 2, column: 16, Syntax error.", error.c_str()); } +TEST(ExtensionFileUtil, MissingPrivacyBlacklist) { + FilePath install_dir; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); + install_dir = install_dir.AppendASCII("extensions") + .AppendASCII("privacy_blacklists") + .AppendASCII("missing_blacklist"); + + std::string error; + scoped_ptr<Extension> extension( + extension_file_util::LoadExtension(install_dir, false, &error)); + ASSERT_TRUE(extension == NULL); + ASSERT_FALSE(error.empty()); + EXPECT_TRUE(MatchPattern(error, + "Could not load '*privacy_blacklist.pbl' for privacy blacklist: " + "file does not exist.")) << error; +} + +TEST(ExtensionFileUtil, InvalidPrivacyBlacklist) { + FilePath install_dir; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); + install_dir = install_dir.AppendASCII("extensions") + .AppendASCII("privacy_blacklists") + .AppendASCII("invalid_blacklist"); + + std::string error; + scoped_ptr<Extension> extension( + extension_file_util::LoadExtension(install_dir, false, &error)); + ASSERT_TRUE(extension == NULL); + ASSERT_FALSE(error.empty()); + EXPECT_TRUE(MatchPattern(error, + "Could not load '*privacy_blacklist.pbl' for privacy blacklist: " + "Incorrect header.")) << error; +} + // TODO(aa): More tests as motivation allows. Maybe steal some from // ExtensionsService? Many of them could probably be tested here without the // MessageLoop shenanigans. |