Beispiel #1
0
def sudo(request, template_name='sudo/sudo.html', extra_context=None):
    """
    The default view for the sudo mode page. The role of this page is to
    prompt the user for their password again, and if successful, redirect
    them back to ``next``.
    """
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, REDIRECT_URL)
    # Make sure we're not redirecting to other sites
    if not is_safe_url(url=redirect_to, host=request.get_host()):
        redirect_to = resolve_url(REDIRECT_URL)

    if request.is_sudo():
        return HttpResponseRedirect(redirect_to)

    form = SudoForm(request.user, request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            grant_sudo_privileges(request)
            return HttpResponseRedirect(redirect_to)

    context = {
        'form': form,
        REDIRECT_FIELD_NAME: redirect_to,
    }
    if extra_context is not None:
        context.update(extra_context)
    return TemplateResponse(request, template_name, context)
Beispiel #2
0
 def test_integration_custom_user(self):
     self.login(EmailUser)
     self.assertTrue(SudoForm(self.user, {"password": "******"}).is_valid())
Beispiel #3
0
 def test_clean_password_secondary_auth_valid_password(self):
     password = "******"
     self.assertEqual(
         SudoForm(self.user, {
             "password": password
         }).clean_password(), password)
Beispiel #4
0
 def test_clean_password_valid_password(self):
     password = "******"
     self.assertEqual(
         SudoForm(self.user, {
             "password": password
         }).clean_password(), password)
Beispiel #5
0
 def test_clean_password_invalid_password(self):
     with self.assertRaises(ValidationError):
         SudoForm(self.user, {"password": "******"}).clean_password()
Beispiel #6
0
 def test_integration_secondary_auth_valid_password(self):
     self.assertTrue(SudoForm(self.user, {"password": "******"}).is_valid())
Beispiel #7
0
 def test_integration_valid_password(self):
     self.assertTrue(SudoForm(self.user, {"password": "******"}).is_valid())
Beispiel #8
0
 def test_integration_invalid_password(self):
     self.assertFalse(SudoForm(self.user, {"password": "******"}).is_valid())
Beispiel #9
0
 def test_integration_empty(self):
     self.assertFalse(SudoForm(self.user).is_valid())
Beispiel #10
0
 def test_clean_password_secondary_auth_valid_password(self):
     password = '******'
     self.assertEqual(
         SudoForm(self.user, {'password': password}).clean_password(),
         password
     )
Beispiel #11
0
 def test_clean_password_valid_password(self):
     password = '******'
     self.assertEqual(
         SudoForm(self.user, {'password': password}).clean_password(),
         password
     )
Beispiel #12
0
 def test_integration_valid_password(self):
     self.assertTrue(
         SudoForm(self.user, {'password': '******'}).is_valid()
     )
Beispiel #13
0
 def test_integration_invalid_password(self):
     self.assertFalse(
         SudoForm(self.user, {'password': '******'}).is_valid()
     )