diff options
| author | Vlastimil Zíma <vlastimil.zima@gmail.com> | 2015-09-03 20:52:49 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-09-04 09:24:21 -0400 |
| commit | cf29b6b5610f242d18dcc31eb897c873109b67e2 (patch) | |
| tree | bd60ca9d686cd22a002e7a2e2f3d4ab288c1d9eb /tests | |
| parent | 4c0447b2ae57f4e8c44bcb2f371d160cb8daa930 (diff) | |
Fixed #25099 -- Fixed crash in AdminEmailHandler on DisallowedHost.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/logging_tests/tests.py | 19 | ||||
| -rw-r--r-- | tests/requests/tests.py | 12 | ||||
| -rw-r--r-- | tests/view_tests/tests/test_debug.py | 16 |
3 files changed, 47 insertions, 0 deletions
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 0b4abbfef6..9c39bb2d59 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -352,6 +352,25 @@ class AdminEmailHandlerTest(SimpleTestCase): self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, ['manager@example.com']) + @override_settings(ALLOWED_HOSTS='example.com') + def test_disallowed_host_doesnt_crash(self): + admin_email_handler = self.get_admin_email_handler(self.logger) + old_include_html = admin_email_handler.include_html + + # Text email + admin_email_handler.include_html = False + try: + self.client.get('/', HTTP_HOST='evil.com') + finally: + admin_email_handler.include_html = old_include_html + + # HTML email + admin_email_handler.include_html = True + try: + self.client.get('/', HTTP_HOST='evil.com') + finally: + admin_email_handler.include_html = old_include_html + class SettingsConfigTest(AdminScriptTestCase): """ diff --git a/tests/requests/tests.py b/tests/requests/tests.py index 8a0b32d1c0..3a3d7e7733 100644 --- a/tests/requests/tests.py +++ b/tests/requests/tests.py @@ -502,6 +502,18 @@ class RequestsTests(SimpleTestCase): with self.assertRaises(UnreadablePostError): request.FILES + @override_settings(ALLOWED_HOSTS=['example.com']) + def test_get_raw_uri(self): + factory = RequestFactory(HTTP_HOST='evil.com') + request = factory.get('////absolute-uri') + self.assertEqual(request.get_raw_uri(), 'http://evil.com//absolute-uri') + + request = factory.get('/?foo=bar') + self.assertEqual(request.get_raw_uri(), 'http://evil.com/?foo=bar') + + request = factory.get('/path/with:colons') + self.assertEqual(request.get_raw_uri(), 'http://evil.com/path/with:colons') + class HostValidationTests(SimpleTestCase): poisoned_hosts = [ diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 4f3a9d6161..b4e7f9c7fa 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -439,6 +439,14 @@ class ExceptionReporterTests(SimpleTestCase): "Evaluation exception reason not mentioned in traceback" ) + @override_settings(ALLOWED_HOSTS='example.com') + def test_disallowed_host(self): + "An exception report can be generated even for a disallowed host." + request = self.rf.get('/', HTTP_HOST='evil.com') + reporter = ExceptionReporter(request, None, None, None) + html = reporter.get_traceback_html() + self.assertIn("http://evil.com/", html) + class PlainTextReportTests(SimpleTestCase): rf = RequestFactory() @@ -495,6 +503,14 @@ class PlainTextReportTests(SimpleTestCase): reporter = ExceptionReporter(None, None, "I'm a little teapot", None) reporter.get_traceback_text() + @override_settings(ALLOWED_HOSTS='example.com') + def test_disallowed_host(self): + "An exception report can be generated even for a disallowed host." + request = self.rf.get('/', HTTP_HOST='evil.com') + reporter = ExceptionReporter(request, None, None, None) + text = reporter.get_traceback_text() + self.assertIn("http://evil.com/", text) + class ExceptionReportTestMixin(object): |
