コード例 #1
0
 def test_process_response_elevate_revoked_without_cookie(self):
     self.login()
     self.middleware.process_request(self.request)
     grant_elevated_privileges(self.request)
     revoke_elevated_privileges(self.request)
     response = self.middleware.process_response(self.request,
                                                 HttpResponse())
     morsels = list(response.cookies.items())
     self.assertEqual(len(morsels), 0)
コード例 #2
0
    def test_process_response_elevate_revoked_removes_cookie(self):
        self.login()
        self.middleware.process_request(self.request)
        grant_elevated_privileges(self.request)
        self.request.COOKIES[COOKIE_NAME] = self.request._elevate_token
        revoke_elevated_privileges(self.request)
        response = self.middleware.process_response(self.request,
                                                    HttpResponse())
        morsels = list(response.cookies.items())
        self.assertEqual(len(morsels), 1)
        self.assertEqual(morsels[0][0], COOKIE_NAME)
        _, elevate = morsels[0]

        # Deleting a cookie is just setting it's value to empty
        # and telling it to expire
        self.assertEqual(elevate.key, COOKIE_NAME)
        self.assertFalse(elevate.value)
        self.assertEqual(elevate['max-age'], 0)
コード例 #3
0
ファイル: signals.py プロジェクト: justinmayer/django-elevate
def revoke(sender, request, **kwargs):
    """
    Automatically revoke elevated privileges when logging out.
    """
    revoke_elevated_privileges(request)
コード例 #4
0
 def test_revoked(self):
     self.login()
     grant_elevated_privileges(self.request)
     revoke_elevated_privileges(self.request)
     self.assertFalse(has_elevated_privileges(self.request))
コード例 #5
0
 def test_revoke_elevated_privileges(self):
     self.login()
     grant_elevated_privileges(self.request)
     revoke_elevated_privileges(self.request)
     self.assertRequestNotElevated(self.request)
コード例 #6
0
 def test_revoke_elevated_privileges_noop(self):
     revoke_elevated_privileges(self.request)
     self.assertRequestNotElevated(self.request)