Exemplo n.º 1
0
    def process_request(self, request):
        self._clear_cookie = False

        if request.path.startswith(settings.MEDIA_URL):
            # no need to test media requests (which sometimes come via
            # via django during development)
            return None

        if "HTTP_USER_AGENT" not in request.META:
            return None

        user_agent = request.META["HTTP_USER_AGENT"]
        parsed_user_agent = httpagentparser.detect(user_agent)

        # Set the browser information on the request object
        request.browser = parsed_user_agent

        if not hasattr(settings, "BADBROWSER_REQUIREMENTS"):
            return None  # no requirements have been setup

        if request.path == reverse("django-badbrowser-ignore"):
            # Allow through any requests for the ignore page
            return None

        if check_user_agent(parsed_user_agent, settings.BADBROWSER_REQUIREMENTS):
            self._clear_cookie = True
            return None  # continue as normal
        else:
            if self._user_ignored_warning(request):
                return None

            from django_badbrowser.views import unsupported

            return unsupported(request)
Exemplo n.º 2
0
 def process_request(self, request):
     self._clear_cookie = False
     
     if request.path.startswith(settings.MEDIA_URL):
         # no need to test media requests (which sometimes come via 
         # via django during development)
         return None
     
     if "HTTP_USER_AGENT" not in request.META:
         return None
     
     user_agent = request.META["HTTP_USER_AGENT"]
     parsed_user_agent = httpagentparser.detect(user_agent)
     
     # Set the browser information on the request object
     request.browser = parsed_user_agent
     
     if not hasattr(settings, "BADBROWSER_REQUIREMENTS"):
         return None # no requirements have been setup
     
     if request.path == reverse("django-badbrowser-ignore"):
         # Allow through any requests for the ignore page
         return None
     
     if check_user_agent(parsed_user_agent, settings.BADBROWSER_REQUIREMENTS):
         self._clear_cookie = True
         return None # continue as normal
     else:
         if self._user_ignored_warning(request):
             return None 
         
         return unsupported(request)
Exemplo n.º 3
0
 def test_user_agents_ie6_bad(self):
     requirements = (("Microsoft Internet Explorer", "7"),)
     
     for user_agent in self._get_ua_strings("ie6"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 4
0
 def test_user_agents_ie7_bad(self):
     requirements = (("Microsoft Internet Explorer", "8"),)
     
     for user_agent in self._get_ua_strings("ie7"):
         self.assertFalse(check_user_agent(user_agent, requirements))
Exemplo n.º 5
0
 def test_user_agents_ie7b_bad(self):
     requirements = (("Microsoft Internet Explorer", "7.0"),) # "7a" or "7b" will allow beta, "7" will not
     
     for user_agent in self._get_ua_strings("ie7b"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 6
0
 def test_equal_version(self):
     user_agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.1.375.126 Safari/533.4"
     requirements = (("Chrome", "5.1.375.126"),)
     self.assertTrue(check_user_agent(user_agent, requirements))
Exemplo n.º 7
0
 def test_equal_version(self):
     user_agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.1.375.126 Safari/533.4"
     requirements = (("Chrome", "5.1.375.126"),)
     self.assertTrue(check_user_agent(user_agent, requirements))
Exemplo n.º 8
0
 def test_user_agents_ff_1_1_bad(self):
     requirements = (("FIREFOX", "1.0.1"),)
     
     for user_agent in self._get_ua_strings("ff1.0"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 9
0
    def test_user_agents_ff_3_1_b_3_bad(self):
        requirements = (("FIREFOX", "3.1"),) # "3.1 beta 4" will not work here

        for user_agent in self._get_ua_strings("ff3.1b3"):
            self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 10
0
 def test_user_agents_ff_1_1_bad(self):
     requirements = (("FIREFOX", "1.0.1"),)
     
     for user_agent in self._get_ua_strings("ff1.0"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 11
0
 def test_user_agents_ff_3_1_b_3_ok(self):
     requirements = (("fireFox", "3.1 beta 3"),) # "3.1b3" will not work here
     
     for user_agent in self._get_ua_strings("ff3.1b3"):
         self.assertTrue(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 12
0
 def test_user_agents_chrome_6_8_458_1_bad(self):
     requirements = (("chromE", "6.0.458.2"),)
     
     for user_agent in self._get_ua_strings("chrome6.0.458.1"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 13
0
 def test_user_agents_ff_1_1_ok(self):
     requirements = (("fireFox", "1.0"),)
     
     for user_agent in self._get_ua_strings("ff1.0"):
         self.assertTrue(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 14
0
 def test_user_agents_ie6_bad(self):
     requirements = (("Microsoft Internet Explorer", "7"),)
     
     for user_agent in self._get_ua_strings("ie6"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 15
0
 def test_user_agents_ie7b_bad(self):
     requirements = (("Microsoft Internet Explorer", "7.0"),) # "7a" or "7b" will allow beta, "7" will not
     
     for user_agent in self._get_ua_strings("ie7b"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 16
0
 def test_user_agents_ie7_bad(self):
     requirements = (("Microsoft Internet Explorer", "8"),)
     
     for user_agent in self._get_ua_strings("ie7"):
         self.assertFalse(check_user_agent(user_agent, requirements))
Exemplo n.º 17
0
 def test_user_agents_chrome_6_8_458_1_bad(self):
     requirements = (("chromE", "6.0.458.2"),)
     
     for user_agent in self._get_ua_strings("chrome6.0.458.1"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 18
0
 def test_user_agents_ff_3_1_b_3_bad(self):
     requirements = (("FIREFOX", "3.1"),) # "3.1 beta 4" will not work here
     
     for user_agent in self._get_ua_strings("ff3.1b3"):
         self.assertFalse(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 19
0
 def test_user_agents_ff_1_1_ok(self):
     requirements = (("fireFox", "1.0"),)
     
     for user_agent in self._get_ua_strings("ff1.0"):
         self.assertTrue(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 20
0
 def test_requirement_version_none(self):
     user_agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.126 Safari/533.4"
     requirements = (("Chrome", None),)
     self.assertFalse(check_user_agent(user_agent, requirements))
Exemplo n.º 21
0
 def test_user_agents_ff_3_1_b_3_ok(self):
     requirements = (("fireFox", "3.1 beta 3"),) # "3.1b3" will not work here
     
     for user_agent in self._get_ua_strings("ff3.1b3"):
         self.assertTrue(check_user_agent(user_agent, requirements), "Failed for ua '%s'" % user_agent)
Exemplo n.º 22
0
 def test_old_major_version_dict(self):
     user_agent = {'flavor': {'version': 'X 10_6_4', 'name': 'MacOS'}, 'os': {'name': 'Macintosh'}, 'browser': {'version': '4.0.375.126', 'name': 'Chrome'}}
     requirements = (("Chrome", "5.0.175.126"),)
     self.assertFalse(check_user_agent(user_agent, requirements))
Exemplo n.º 23
0
 def test_requirement_version_none(self):
     user_agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.126 Safari/533.4"
     requirements = (("Chrome", None),)
     self.assertFalse(check_user_agent(user_agent, requirements))
Exemplo n.º 24
0
 def test_old_major_version_dict(self):
     user_agent = {'flavor': {'version': 'X 10_6_4', 'name': 'MacOS'}, 'os': {'name': 'Macintosh'}, 'browser': {'version': '4.0.375.126', 'name': 'Chrome'}}
     requirements = (("Chrome", "5.0.175.126"),)
     self.assertFalse(check_user_agent(user_agent, requirements))