예제 #1
0
 def wrapped(self, request, *args, **kwargs):
     if not has_sudo_privileges(request):
         # TODO(dcramer): support some kind of auth flow to allow this
         # externally
         data = {"error": "Account verification required.", "sudoRequired": True, "username": request.user.username}
         return HttpResponse(json.dumps(data), status=401)
     return func(self, request, *args, **kwargs)
예제 #2
0
    def test_cookie_bad_signature(self):
        self.login()

        def get_signed_cookie(key, salt='', max_age=None):
            raise BadSignature
        self.request.session[COOKIE_NAME] = 'abc123'
        self.assertFalse(has_sudo_privileges(self.request))
예제 #3
0
    def test_cookie_and_token_mismatch(self):
        self.login()

        def get_signed_cookie(key, salt='', max_age=None):
            return 'nope'
        self.request.session[COOKIE_NAME] = 'abc123'
        self.assertFalse(has_sudo_privileges(self.request))
예제 #4
0
파일: utils.py 프로젝트: tdruez/django-sudo
    def test_cookie_and_token_mismatch(self):
        self.login()

        def get_signed_cookie(key, salt='', max_age=None):
            return 'nope'

        self.request.session[COOKIE_NAME] = 'abc123'
        self.assertFalse(has_sudo_privileges(self.request))
예제 #5
0
    def test_cookie_bad_signature(self):
        self.login()

        def get_signed_cookie(key, salt="", max_age=None):
            raise BadSignature

        self.request.session[COOKIE_NAME] = "abc123"
        self.assertFalse(has_sudo_privileges(self.request))
예제 #6
0
    def test_cookie_and_token_match(self):
        self.login()

        def get_signed_cookie(key, salt="", max_age=None):
            return "abc123"

        self.request.session[COOKIE_NAME] = "abc123"
        self.request.get_signed_cookie = get_signed_cookie
        self.assertTrue(has_sudo_privileges(self.request))
예제 #7
0
    def test_cookie_and_token_match(self):
        self.login()

        def get_signed_cookie(key, salt="", max_age=None):
            return "abc123"

        self.request.session[COOKIE_NAME] = "abc123"
        self.request.get_signed_cookie = get_signed_cookie
        self.assertTrue(has_sudo_privileges(self.request))
예제 #8
0
 def test_revoked(self):
     self.login()
     grant_sudo_privileges(self.request)
     revoke_sudo_privileges(self.request)
     self.assertFalse(has_sudo_privileges(self.request))
예제 #9
0
 def test_user_logged_out(self):
     self.login()
     grant_sudo_privileges(self.request)
     self.assertTrue(has_sudo_privileges(self.request))
     user_logged_out.send_robust(sender=User, request=self.request)
     self.assertFalse(has_sudo_privileges(self.request))
예제 #10
0
 def test_untouched(self):
     self.assertFalse(has_sudo_privileges(self.request))
예제 #11
0
 def test_granted(self):
     self.login()
     grant_sudo_privileges(self.request)
     self.assertTrue(has_sudo_privileges(self.request))
예제 #12
0
 def test_untouched(self):
     self.assertFalse(has_sudo_privileges(self.request))
예제 #13
0
 def test_missing_keys(self):
     self.login()
     self.assertFalse(has_sudo_privileges(self.request))
예제 #14
0
 def has_sudo_privileges(self, request):
     # Override me to alter behavior
     return has_sudo_privileges(request)
예제 #15
0
 def has_sudo_privileges(self, request):
     # Override me to alter behavior
     return has_sudo_privileges(request)
예제 #16
0
 def test_grant(self):
     self.login()
     grant(User, self.request)
     self.assertTrue(has_sudo_privileges(self.request))
예제 #17
0
 def test_cookie_and_token_mismatch(self):
     self.login()
     self.request.COOKIES[COOKIE_NAME] = 'nope'
     self.request.session[COOKIE_NAME] = 'abc123'
     self.assertFalse(has_sudo_privileges(self.request))
예제 #18
0
 def test_user_logged_in(self):
     self.login()
     user_logged_in.send_robust(sender=User, request=self.request)
     self.assertTrue(has_sudo_privileges(self.request))
예제 #19
0
 def test_revoke(self):
     self.login()
     grant(User, self.request)
     revoke(User, self.request)
     self.assertFalse(has_sudo_privileges(self.request))
예제 #20
0
 def test_missing_keys(self):
     self.login()
     self.assertFalse(has_sudo_privileges(self.request))