Пример #1
0
 def test_sanitize_non_ascii_referrer(self):
     """Make sure referrers with non-ascii characters are handled."""
     page = mock.Mock()
     page.url = '/es/obtener-respuestas/'
     page.language = 'es'
     non_ascii_referrer = (
         'https://www.consumerfinance.gov/es/obtener-respuestas/'
         'buscar-por-etiqueta/línea_de_crédito_personal/')
     request = self.factory.get('/')
     request.META = {'HTTP_REFERER': non_ascii_referrer}
     handler = FeedbackHandler(page, request, block_value={})
     sanitized = handler.sanitize_referrer()
     self.assertIn('é', sanitized)
Пример #2
0
 def test_sanitize_referrer(self):
     """Make sure referrers with non-ascii characters are handled."""
     page = mock.Mock()
     page.url = '/es/obtener-respuestas/'
     page.language = 'es'
     non_ascii_referrers = [
         ('http://localhost:8000/es/obtener-respuestas/'
          'buscar-por-etiqueta/rescisi\xc3\xb3n/'),
         ('https://www.consumerfinance.gov/es/obtener-respuestas/'
          'buscar-por-etiqueta/l\xc3\xadnea_de_cr\xc3\xa9dito_personal/')]
     for referrer in non_ascii_referrers:
         request = self.factory.get('/')
         request.META = {'HTTP_REFERER': referrer}
         handler = FeedbackHandler(page, request, block_value={})
         sanitized = handler.sanitize_referrer()
         self.assertNotIn('\xc3', sanitized)
     misencoded_string = 'https://fake.com/cr\xc3\xb3dito'
     request = self.factory.get('/')
     request.META = {'HTTP_REFERER': misencoded_string}
     handler = FeedbackHandler(page, request, block_value={})
     sanitized = handler.sanitize_referrer()
     self.assertEqual(sanitized, 'fake.com/cr%C3%B3dito')
Пример #3
0
 def test_sanitize_referrer(self):
     """Make sure referrers with non-ascii characters are handled."""
     page = mock.Mock()
     page.url = '/es/obtener-respuestas/'
     page.language = 'es'
     non_ascii_referrers = [
         (b'http://localhost:8000/es/obtener-respuestas/'
          b'buscar-por-etiqueta/rescisi\xc3\xb3n/'),
         (b'https://www.consumerfinance.gov/es/obtener-respuestas/'
          b'buscar-por-etiqueta/l\xc3\xadnea_de_cr\xc3\xa9dito_personal/')]
     for referrer in non_ascii_referrers:
         request = self.factory.get('/')
         request.META = {'HTTP_REFERER': referrer}
         handler = FeedbackHandler(page, request, block_value={})
         sanitized = handler.sanitize_referrer()
         self.assertNotIn('\xc3', sanitized)
     misencoded_string = b'https://fake.com/cr\xc3\xb3dito'
     request = self.factory.get('/')
     request.META = {'HTTP_REFERER': misencoded_string}
     handler = FeedbackHandler(page, request, block_value={})
     sanitized = handler.sanitize_referrer()
     self.assertEqual(sanitized, '')