Bug 1129287 - Fix not rejecting partial name matches for plugin blocklist entries. r=gfritzsche, a=sledru FIREFOX_BETA_36_END
authorHector Zhao <bzhao@mozilla.com>
Wed, 04 Feb 2015 12:27:54 +0800
changeset 245419 7d4016a05dd3
parent 245418 67d9db36737e
child 245420 a2ffa9047bf4
child 251651 54e3819150da
push id662
push userryanvm@gmail.com
push date2015-02-20 00:54 +0000
treeherdermozilla-release@a2ffa9047bf4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, sledru
bugs1129287
milestone36.0
Bug 1129287 - Fix not rejecting partial name matches for plugin blocklist entries. r=gfritzsche, a=sledru CLOSED TREE
toolkit/mozapps/extensions/nsBlocklistService.js
toolkit/mozapps/extensions/test/xpcshell/data/pluginInfoURL_block.xml
toolkit/mozapps/extensions/test/xpcshell/test_pluginInfoURL.js
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -269,25 +269,25 @@ function parseRegExp(aStr) {
  * Helper function to test if the blockEntry matches with the plugin.
  *
  * @param   blockEntry
  *          The plugin blocklist entries to compare against.
  * @param   plugin
  *          The nsIPluginTag to get the blocklist state for.
  * @returns True if the blockEntry matches the plugin, false otherwise.
  */
-function hasMatchingPluginName(blockEntry, plugin) {
+function matchesAllPluginNames(blockEntry, plugin) {
   for (let name in blockEntry.matches) {
-    if ((name in plugin) &&
-        typeof(plugin[name]) == "string" &&
-        blockEntry.matches[name].test(plugin[name])) {
-      return true;
+    if (!(name in plugin) ||
+        typeof(plugin[name]) != "string" ||
+        !blockEntry.matches[name].test(plugin[name])) {
+      return false;
     }
   }
-  return false;
+  return true;
 }
 
 /**
  * Manages the Blocklist. The Blocklist is a representation of the contents of
  * blocklist.xml and allows us to remotely disable / re-enable blocklisted
  * items managed by the Extension Manager with an item's appDisabled property.
  * It also blocklists plugins with data from blocklist.xml.
  */
@@ -1068,17 +1068,17 @@ Blocklist.prototype = {
   _getPluginBlockEntry: function (plugin) {
     if (!gBlocklistEnabled)
       return null;
 
     if (!this._isBlocklistLoaded())
       this._loadBlocklist();
 
     for each (let blockEntry in this._pluginEntries) {
-      if (hasMatchingPluginName(blockEntry, plugin)) {
+      if (matchesAllPluginNames(blockEntry, plugin)) {
         return blockEntry;
       }
     }
 
 	  return null;
   },
 
   /* See nsIBlocklistService */
--- a/toolkit/mozapps/extensions/test/xpcshell/data/pluginInfoURL_block.xml
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/pluginInfoURL_block.xml
@@ -1,15 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist">
   <emItems>
   </emItems>
   <pluginItems>
     <pluginItem blockID="test_plugin_wInfoURL">
       <match name="name" exp="^test_with_infoURL"/>
+      <match name="version" exp="^5"/>
       <infoURL>http://test.url.com/</infoURL>
     </pluginItem>
+    <pluginItem blockID="test_plugin_wAltInfoURL">
+      <match name="name" exp="^test_with_altInfoURL"/>
+      <match name="version" exp="^5"/>
+      <infoURL>http://alt.test.url.com/</infoURL>
+    </pluginItem>
     <pluginItem blockID="test_plugin_noInfoURL">
       <match name="name" exp="^test_no_infoURL"/>
     </pluginItem>
   </pluginItems>
 </blocklist>
--- a/toolkit/mozapps/extensions/test/xpcshell/test_pluginInfoURL.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_pluginInfoURL.js
@@ -24,16 +24,17 @@ MockPlugin.prototype = {
   get disabled() {
     return this.enabledState == Ci.nsIPluginTag.STATE_DISABLED;
   }
 };
 
 // The mocked blocked plugin used to test the blocklist.
 const PLUGINS = [
   new MockPlugin('test_with_infoURL', '5', Ci.nsIPluginTag.STATE_ENABLED),
+  new MockPlugin('test_with_altInfoURL', '5', Ci.nsIPluginTag.STATE_ENABLED),
   new MockPlugin('test_no_infoURL', '5', Ci.nsIPluginTag.STATE_ENABLED)
 ];
 
 /**
  * The entry point of the unit tests, which is also responsible of
  * copying the blocklist file to the profile folder.
  */
 function run_test() {
@@ -41,28 +42,39 @@ function run_test() {
 
   createAppInfo('xpcshell@tests.mozilla.org', 'XPCShell', '3', '8');
   startupManager();
 
   run_next_test();
 }
 
 /**
- * Test that the blocklist service correctly loads and returns the infoURL
- * from the blocklist file for a matched plugin.
+ * Test that the blocklist service correctly loads and returns the infoURL for
+ * a plugin that matches the first entry in the blocklist.
  */
 add_task(function* test_infoURL() {
   // The testInfoURL must match the value within the
   // <infoURL> tag in pluginInfoURL_block.xml.
   let testInfoURL = 'http://test.url.com/';
 
   Assert.strictEqual(Services.blocklist.getPluginInfoURL(PLUGINS[0]),
-    testInfoURL, 'Plugin info urls should match');
+    testInfoURL, 'Should be the provided url when an infoURL tag is available');
+});
+
+/**
+ * Test that the blocklist service correctly loads and returns the infoURL for
+ * a plugin that partially matches an earlier entry in the blocklist.
+ */
+add_task(function* test_altInfoURL() {
+  let altTestInfoURL = 'http://alt.test.url.com/';
+
+  Assert.strictEqual(Services.blocklist.getPluginInfoURL(PLUGINS[1]),
+    altTestInfoURL, 'Should be the alternative infoURL');
 });
 
 /**
  * Test that the blocklist service correctly returns null
  * if the infoURL tag is missing in the blocklist.xml file.
  */
 add_task(function* test_infoURL_missing() {
-  Assert.strictEqual(Services.blocklist.getPluginInfoURL(PLUGINS[1]), null,
+  Assert.strictEqual(Services.blocklist.getPluginInfoURL(PLUGINS[2]), null,
     'Should be null when no infoURL tag is available.');
 });