diff --git a/common/djangoapps/student/helpers.py b/common/djangoapps/student/helpers.py index c0a610765a..32f98e6dd2 100644 --- a/common/djangoapps/student/helpers.py +++ b/common/djangoapps/student/helpers.py @@ -337,7 +337,7 @@ def get_redirect_to(request): ) redirect_to = None elif 'text/html' not in header_accept: - log.warning( + log.info( u'Redirect to non html content %(content_type)r detected from %(user_agent)r' u' after login page: %(redirect_to)r', { diff --git a/common/djangoapps/student/tests/test_helpers.py b/common/djangoapps/student/tests/test_helpers.py index f7ff4ebafe..c366a3262e 100644 --- a/common/djangoapps/student/tests/test_helpers.py +++ b/common/djangoapps/student/tests/test_helpers.py @@ -9,6 +9,7 @@ from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import RequestFactory from django.test.utils import override_settings +from django.utils import http from mock import patch from testfixtures import LogCapture @@ -35,32 +36,32 @@ class TestLoginHelper(TestCase): request.session.save() @ddt.data( - ("https://www.amazon.com", "text/html", None, + (logging.WARNING, "WARNING", "https://www.amazon.com", "text/html", None, "Unsafe redirect parameter detected after login page: u'https://www.amazon.com'"), - ("testserver/edx.org/images/logo", "text/html", None, + (logging.WARNING, "WARNING", "testserver/edx.org/images/logo", "text/html", None, "Redirect to theme content detected after login page: u'testserver/edx.org/images/logo'"), - ("favicon.ico", "image/*", "test/agent", + (logging.INFO, "INFO", "favicon.ico", "image/*", "test/agent", "Redirect to non html content 'image/*' detected from 'test/agent' after login page: u'favicon.ico'"), - ("https://www.test.com/test.jpg", "image/*", None, + (logging.WARNING, "WARNING", "https://www.test.com/test.jpg", "image/*", None, "Unsafe redirect parameter detected after login page: u'https://www.test.com/test.jpg'"), - (static_url + "dummy.png", "image/*", "test/agent", + (logging.INFO, "INFO", static_url + "dummy.png", "image/*", "test/agent", "Redirect to non html content 'image/*' detected from 'test/agent' after login page: u'" + static_url + "dummy.png" + "'"), - ("test.png", "text/html", None, + (logging.WARNING, "WARNING", "test.png", "text/html", None, "Redirect to url path with specified filed type 'image/png' not allowed: u'test.png'"), - (static_url + "dummy.png", "text/html", None, + (logging.WARNING, "WARNING", static_url + "dummy.png", "text/html", None, "Redirect to url path with specified filed type 'image/png' not allowed: u'" + static_url + "dummy.png" + "'"), ) @ddt.unpack - def test_unsafe_next(self, unsafe_url, http_accept, user_agent, expected_log): + def test_unsafe_next(self, log_level, log_name, unsafe_url, http_accept, user_agent, expected_log): """ Test unsafe next parameter """ - with LogCapture(LOGGER_NAME, level=logging.WARNING) as logger: + with LogCapture(LOGGER_NAME, level=log_level) as logger: req = self.request.get(reverse("login") + "?next={url}".format(url=unsafe_url)) req.META["HTTP_ACCEPT"] = http_accept # pylint: disable=no-member req.META["HTTP_USER_AGENT"] = user_agent # pylint: disable=no-member get_next_url_for_login_page(req) logger.check( - (LOGGER_NAME, "WARNING", expected_log) + (LOGGER_NAME, log_name, expected_log) ) @ddt.data(