[Pkg-mozext-commits] [requestpolicy] 211/257: [fix] conflicting rules: handle redirects like "normal" requests

David Prévot taffit at moszumanska.debian.org
Thu Jan 28 03:20:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit 5ee2459f52c546a6b4cacb18d2a1d90736261a96
Author: Martin Kimmerle <dev at 256k.de>
Date:   Sun Dec 13 17:59:42 2015 +0100

    [fix] conflicting rules: handle redirects like "normal" requests
    
    Both "normal" requests and redirections should fall back to the
    default policy when both allow and deny rules apply to a
    request.
    
    Thanks to @arlsr for providing the fix as part of PR #555.
    
    Fixes #623, fixes #738.
---
 ChangeLog.md                                       |  1 +
 src/content/lib/request-processor.redirects.js     |  6 ++-
 .../tests/redirections/test_link_click_redirect.py | 60 +++++++++++++++++++++-
 3 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index 3ffb348..a75ea97 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -16,6 +16,7 @@ Note: ChangeLogs for the source code and unit tests, both not relevant for
     conditions are true: (#731, 49894f6)
     - the user is upgrading RP from v0.5 to v1.0
     - the v1.0 rules file doesn't exist yet.
+  * Redirections with conflicting rules: The default policy should apply (#623)
   * E10s issues
     * The "Allow" button on the redirection notification
       bar did not always work. (#620, a168f70)
diff --git a/src/content/lib/request-processor.redirects.js b/src/content/lib/request-processor.redirects.js
index f2beec6..973ec89 100644
--- a/src/content/lib/request-processor.redirects.js
+++ b/src/content/lib/request-processor.redirects.js
@@ -114,7 +114,11 @@ RequestProcessor = (function(self) {
     {
       let result = PolicyManager.checkRequestAgainstUserRules(originURIObj,
           destURIObj);
-      // For now, we always give priority to deny rules.
+      // For user rules, use the default policy if both types of rule match.
+      if (result.denyRulesExist() && result.allowRulesExist()) {
+        result.isAllowed = Prefs.isDefaultAllow();
+        return result;
+      }
       if (result.denyRulesExist()) {
         result.isAllowed = false;
         return result;
diff --git a/tests/marionette/tests/redirections/test_link_click_redirect.py b/tests/marionette/tests/redirections/test_link_click_redirect.py
index 3746e76..c7de255 100644
--- a/tests/marionette/tests/redirections/test_link_click_redirect.py
+++ b/tests/marionette/tests/redirections/test_link_click_redirect.py
@@ -3,6 +3,8 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from rp_ui_harness.testcases import RequestPolicyTestCase
+from marionette import SkipTest
+import random
 
 
 PREF_DEFAULT_ALLOW = "extensions.requestpolicy.defaultPolicy.allow"
@@ -40,6 +42,59 @@ class TestLinkClickRedirect(RequestPolicyTestCase):
         self._test_no_appear(self._get_url("redirect-meta-tag-07-different-formatting-delayed.html"))
         self._test_no_appear(self._get_url("redirect-meta-tag-09-relative.html"))
 
+    def test_r21n_no_appears__conflicting_rules(self):
+        self.prefs.set_pref(PREF_DEFAULT_ALLOW, True)
+
+        self.rules.create_rule({"o": {"h": "*.maindomain.test"},
+                                "d": {"h": "*.otherdomain.test"}},
+                               allow=True).add()
+        self.rules.create_rule({"d": {"h": "*.otherdomain.test"}},
+                               allow=False).add()
+
+        self._test_no_appear(self._get_url("redirect-js-document-location-link.html",
+                                           generate_page_with_link=False))
+        self._test_no_appear(self._get_url("redirect-http-location-header.php"))
+        self._test_no_appear(self._get_url("redirect-http-refresh-header.php"))
+        self._test_no_appear(self._get_url("redirect-js-document-location-auto.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-01-immediate.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-02-delayed.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-03-multiple.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-04-relative-without-slash.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-05-relative-with-slash.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-06-different-formatting.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-07-different-formatting-delayed.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-08.html"))
+        self._test_no_appear(self._get_url("redirect-meta-tag-09-relative.html"))
+
+        self.rules.remove_all()
+
+    def test_r21n_appear_then_no_appear(self):
+        raise SkipTest("FIXME")
+        # When fixed, remove the `append_random_querystring` option
+        # of `_get_url()`.
+
+        self.prefs.set_pref(PREF_DEFAULT_ALLOW, False)
+
+        rule = self.rules.create_rule({"o": {"h": "*.maindomain.test"},
+                                       "d": {"h": "*.otherdomain.test"}},
+                                      allow=True)
+
+        def test(test_filename):
+            test_url = self._get_url(test_filename,
+                                     append_random_querystring=False)
+            self._test_appear(test_url)
+            rule.add()
+            self._test_no_appear(test_url)
+            rule.remove()
+
+        test("redirect-http-location-header.php")
+        test("redirect-http-refresh-header.php")
+        test("redirect-js-document-location-auto.html")
+        test("redirect-meta-tag-01-immediate.html")
+        test("redirect-meta-tag-02-delayed.html")
+        test("redirect-meta-tag-03-multiple.html")
+        test("redirect-meta-tag-08.html")
+
     ##########################
     # Private Helper Methods #
     ##########################
@@ -66,7 +121,10 @@ class TestLinkClickRedirect(RequestPolicyTestCase):
             link = self.marionette.find_element("tag name", "a")
             link.click()
 
-    def _get_url(self, path, generate_page_with_link=True):
+    def _get_url(self, path, generate_page_with_link=True,
+                 append_random_querystring=True):
         if generate_page_with_link:
             path = "link.html?" + path
+            if append_random_querystring:
+                path = path + "?" + str(random.randint(1, 100))
         return "http://www.maindomain.test/" + path

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list