Beispiel #1
0
 def test_redirect_fix_bad_url(self):
     self.login()
     self.request.is_sudo = lambda: True
     self.request.GET = {REDIRECT_FIELD_NAME: 'http://mattrobenolt.com/lol'}
     response = sudo(self.request)
     self.assertEqual(response['Location'], REDIRECT_URL)
     self.request.GET = {
         REDIRECT_FIELD_NAME: 'http://%s\@mattrobenolt.com' % self.request.get_host(),
     }
     response = sudo(self.request)
     self.assertEqual(response['Location'], REDIRECT_URL)
Beispiel #2
0
 def test_redirect_fix_bad_url(self):
     self.login()
     self.request.is_sudo = lambda: True
     self.request.GET = {REDIRECT_FIELD_NAME: "http://mattrobenolt.com/lol"}
     response = sudo(self.request)
     self.assertEqual(response["Location"], REDIRECT_URL)
     self.request.GET = {
         REDIRECT_FIELD_NAME: "http://%s\@mattrobenolt.com"
         % self.request.get_host(),  # noqa: W605
     }
     response = sudo(self.request)
     self.assertEqual(response["Location"], REDIRECT_URL)
Beispiel #3
0
 def test_session_based_redirect_bad_url(self):
     self.login()
     self.request.is_sudo = lambda: False
     self.request.method = "POST"
     self.request.POST = {"password": "******"}
     self.request.session[REDIRECT_TO_FIELD_NAME] = "http://mattrobenolt.com/lol"
     self.request.csrf_processing_done = True
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response["Location"], REDIRECT_URL)
     self.assertFalse("redirect_to" in self.request.session)
     self.request.session[REDIRECT_TO_FIELD_NAME] = (
         "http://%s\@mattrobenolt.com" % self.request.get_host()  # noqa: W605
     )
     response = sudo(self.request)
     self.assertEqual(response["Location"], REDIRECT_URL)
Beispiel #4
0
 def test_redirect_if_already_sudo_with_next(self):
     self.login()
     self.request.GET = {REDIRECT_FIELD_NAME: '/lol'}
     self.request.is_sudo = lambda: True
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], '/lol')
Beispiel #5
0
 def test_session_based_redirect_bad_url(self):
     self.login()
     self.request.is_sudo = lambda: False
     self.request.method = 'POST'
     self.request.POST = {'password': '******'}
     self.request.session[
         REDIRECT_TO_FIELD_NAME] = 'http://mattrobenolt.com/lol'
     self.request.csrf_processing_done = True
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], REDIRECT_URL)
     self.assertFalse('redirect_to' in self.request.session)
     self.request.session[REDIRECT_TO_FIELD_NAME] = (
         'http://%s\@mattrobenolt.com' % self.request.get_host())
     response = sudo(self.request)
     self.assertEqual(response['Location'], REDIRECT_URL)
Beispiel #6
0
 def test_returns_template_response_with_next(self):
     self.login()
     self.request.GET = {REDIRECT_FIELD_NAME: '/lol'}
     self.request.is_sudo = lambda: False
     response = sudo(self.request)
     self.assertEqual(response.context_data[REDIRECT_FIELD_NAME],
                      '/lol')  # default
Beispiel #7
0
 def test_redirect_if_already_sudo_with_next(self):
     self.login()
     self.request.GET = {REDIRECT_FIELD_NAME: '/lol'}
     self.request.is_sudo = lambda: True
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], '/lol')
Beispiel #8
0
 def test_session_based_redirect_bad_url(self):
     self.login()
     self.request.is_sudo = lambda: False
     self.request.method = 'POST'
     self.request.POST = {'password': '******'}
     self.request.session[REDIRECT_TO_FIELD_NAME] = 'http://mattrobenolt.com/lol'
     self.request.csrf_processing_done = True
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], REDIRECT_URL)
     self.assertFalse('redirect_to' in self.request.session)
     self.request.session[REDIRECT_TO_FIELD_NAME] = (
         'http://%s\@mattrobenolt.com' % self.request.get_host()
     )
     response = sudo(self.request)
     self.assertEqual(response['Location'], REDIRECT_URL)
Beispiel #9
0
    def test_session_based_redirect(self):
        self.login()
        self.request.is_sudo = lambda: False
        self.request.method = 'GET'
        self.request.GET = {REDIRECT_FIELD_NAME: '/foobar'}
        sudo(self.request)

        self.request, self.request.session = self.post('/foo'), self.request.session
        self.login()
        self.request.is_sudo = lambda: False
        self.request.method = 'POST'
        self.request.POST = {'password': '******'}
        self.request.csrf_processing_done = True
        response = sudo(self.request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], '/foobar')
        self.assertNotEqual(response['Location'], REDIRECT_URL)
        self.assertFalse('redirect_to' in self.request.session)
Beispiel #10
0
    def test_session_based_redirect(self):
        self.login()
        self.request.is_sudo = lambda: False
        self.request.method = "GET"
        self.request.GET = {REDIRECT_FIELD_NAME: "/foobar"}
        sudo(self.request)

        self.request, self.request.session = self.post("/foo"), self.request.session
        self.login()
        self.request.is_sudo = lambda: False
        self.request.method = "POST"
        self.request.POST = {"password": "******"}
        self.request.csrf_processing_done = True
        response = sudo(self.request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], "/foobar")
        self.assertNotEqual(response["Location"], REDIRECT_URL)
        self.assertFalse("redirect_to" in self.request.session)
Beispiel #11
0
 def test_redirect_after_successful_post(self):
     self.login()
     self.request.is_sudo = lambda: False
     self.request.method = 'POST'
     self.request.csrf_processing_done = True
     self.request.POST = {'password': '******'}
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], REDIRECT_URL)
Beispiel #12
0
 def test_redirect_after_successful_post(self):
     self.login()
     self.request.is_sudo = lambda: False
     self.request.method = 'POST'
     self.request.csrf_processing_done = True
     self.request.POST = {'password': '******'}
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], REDIRECT_URL)
Beispiel #13
0
 def test_render_form_with_bad_password(self):
     self.login()
     self.request.is_sudo = lambda: False
     self.request.method = 'POST'
     self.request.csrf_processing_done = True
     self.request.POST = {'password': '******'}
     response = sudo(self.request)
     self.assertEqual(response.status_code, 200)
     form = response.context_data['form']
     self.assertFalse(form.is_valid())
Beispiel #14
0
    def test_session_based_redirect(self):
        self.login()
        self.request.is_sudo = lambda: False
        self.request.method = 'GET'
        self.request.GET = {REDIRECT_FIELD_NAME: '/foobar'}
        sudo(self.request)

        self.request, self.request.session = self.post(
            '/foo'), self.request.session
        self.login()
        self.request.is_sudo = lambda: False
        self.request.method = 'POST'
        self.request.POST = {'password': '******'}
        self.request.csrf_processing_done = True
        response = sudo(self.request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], '/foobar')
        self.assertNotEqual(response['Location'], REDIRECT_URL)
        self.assertFalse('redirect_to' in self.request.session)
Beispiel #15
0
 def test_returns_template_response(self):
     self.login()
     self.request.is_sudo = lambda: False
     response = sudo(self.request)
     self.assertIsInstance(response, TemplateResponse)
     self.assertEqual(response.template_name, "sudo/sudo.html")  # default
     self.assertEqual(response.context_data[REDIRECT_FIELD_NAME], REDIRECT_URL)  # default
     form = response.context_data["form"]
     self.assertIsInstance(form, SudoForm)
     self.assertEqual(form.user, self.user)
Beispiel #16
0
 def test_render_form_with_bad_password(self):
     self.login()
     self.request.is_sudo = lambda: False
     self.request.method = 'POST'
     self.request.csrf_processing_done = True
     self.request.POST = {'password': '******'}
     response = sudo(self.request)
     self.assertEqual(response.status_code, 200)
     form = response.context_data['form']
     self.assertFalse(form.is_valid())
Beispiel #17
0
 def test_returns_template_response(self):
     self.login()
     self.request.is_sudo = lambda: False
     response = sudo(self.request)
     self.assertIsInstance(response, TemplateResponse)
     self.assertEqual(response.template_name, 'sudo/sudo.html')  # default
     self.assertEqual(response.context_data[REDIRECT_FIELD_NAME], REDIRECT_URL)  # default
     form = response.context_data['form']
     self.assertIsInstance(form, SudoForm)
     self.assertEqual(form.user, self.user)
Beispiel #18
0
 def test_enforces_logged_in(self):
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], '/accounts/login/?next=/foo')
Beispiel #19
0
 def test_redirect_if_already_sudo(self):
     self.login()
     self.request.is_sudo = lambda: True
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], REDIRECT_URL)
Beispiel #20
0
 def test_returns_template_response_override_extra_context(self):
     self.login()
     self.request.is_sudo = lambda: False
     response = sudo(self.request, extra_context={'foo': 'bar'})
     self.assertEqual(response.context_data['foo'], 'bar')
Beispiel #21
0
 def test_returns_template_response_override_template(self):
     self.login()
     self.request.is_sudo = lambda: False
     response = sudo(self.request, template_name='foo.html')
     self.assertEqual(response.template_name, 'foo.html')
Beispiel #22
0
 def test_returns_template_response_with_next(self):
     self.login()
     self.request.GET = {REDIRECT_FIELD_NAME: '/lol'}
     self.request.is_sudo = lambda: False
     response = sudo(self.request)
     self.assertEqual(response.context_data[REDIRECT_FIELD_NAME], '/lol')  # default
Beispiel #23
0
 def test_returns_template_response_override_template(self):
     self.login()
     self.request.is_sudo = lambda: False
     response = sudo(self.request, template_name='foo.html')
     self.assertEqual(response.template_name, 'foo.html')
Beispiel #24
0
 def test_returns_template_response_override_extra_context(self):
     self.login()
     self.request.is_sudo = lambda: False
     response = sudo(self.request, extra_context={'foo': 'bar'})
     self.assertEqual(response.context_data['foo'], 'bar')
Beispiel #25
0
 def test_redirect_if_already_sudo(self):
     self.login()
     self.request.is_sudo = lambda: True
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], REDIRECT_URL)
Beispiel #26
0
 def test_redirect_fix_bad_url(self):
     self.login()
     self.request.is_sudo = lambda: True
     self.request.GET = {REDIRECT_FIELD_NAME: 'http://mattrobenolt.com/lol'}
     response = sudo(self.request)
     self.assertEqual(response['Location'], REDIRECT_URL)
Beispiel #27
0
 def test_enforces_logged_in(self):
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response["Location"], "/auth/login/?next=/foo")
Beispiel #28
0
 def test_returns_template_response_override_extra_context(self):
     self.login()
     self.request.is_sudo = lambda: False
     response = sudo(self.request, extra_context={"foo": "bar"})
     self.assertEqual(response.context_data["foo"], "bar")
Beispiel #29
0
 def test_enforces_logged_in(self):
     response = sudo(self.request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], '/accounts/login/?next=/foo')