def log_hit(self): # Make sure we get plain strings, not unicode #self.request.charset = None cur = self.request.str_GET.get('cur', None) ref = self.request.str_GET.get('ref', None) title = self.request.str_GET.get('title', None) if not cur: cur = self.request.headers.get('referer', None) if cur is not None: cur = get_unicode(unquote_plus(cur)) if ref is not None: ref = get_unicode(unquote_plus(ref)) if title is not None: title = get_unicode(unquote_plus(title)).strip() response = Response() response.headers['Content-Type'] = "image/gif" response.headers['Expires'] = "Sat, 26 Jul 1997 05:00:00 GMT" response.headers['Cache-Control'] = "no-cache, must-revalidate" response.body = self._image if not cur: return response visitor_ip = self.request.headers.get('X-Forwarded-For', None) if visitor_ip is None: visitor_ip = self.request.remote_addr hit = Hit(self._conf, cur, referrer=ref, title=title, visitor_ip=visitor_ip) if hit.is_whitelisted() and not hit.is_blacklisted(): self._storage.add_hit(hit) return response
def test_whitelist_multi_spaced(self): """Test path whitelisting - multi, with spaces""" testconf = deepcopy(self._conf) testconf['whitelist_lvl1'] = 'one, path , three' hit = Hit(testconf, u'http://abc.nl/path/to/page') self.assertEqual(hit.is_whitelisted(), True)
def test_whitelist_multi_nonmatching(self): """Test path whitelisting - multi, non-matching""" testconf = deepcopy(self._conf) testconf['whitelist_lvl1'] = 'one,two,three' hit = Hit(testconf, u'http://abc.nl/path/to/page') self.assertEqual(hit.is_whitelisted(), False)
def test_whitelist_single_nonmatching(self): """Test path whitelisting - single, non-matchingempty""" testconf = deepcopy(self._conf) testconf['whitelist_lvl1'] = 'anotherpath' hit = Hit(testconf, u'http://abc.nl/path/to/page') self.assertEqual(hit.is_whitelisted(), False)
def test_whitelist_single_matching(self): """Test path whitelisting - single, matching""" testconf = deepcopy(self._conf) testconf['whitelist_lvl1'] = 'path' hit = Hit(testconf, u'http://abc.nl/path/to/page') self.assertEqual(hit.is_whitelisted(), True)
def test_whitelist_empty(self): """Test path whitelisting - empty""" testconf = deepcopy(self._conf) testconf['whitelist_lvl1'] = '' hit = Hit(testconf, u'http://abc.nl/path/to/page') self.assertEqual(hit.is_whitelisted(), True)