-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/sprint-18' of https://github.com/fecgov/fecfile…
…-web-api into release/sprint-18
- Loading branch information
Showing
5 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
from unittest.mock import Mock | ||
|
||
from django.test import RequestFactory, TestCase | ||
from fecfiler.authentication.models import Account | ||
from fecfiler.authentication.views import (handle_invalid_login, | ||
handle_valid_login, | ||
update_last_login_time) | ||
|
||
from .views import generate_username, login_dot_gov_logout | ||
from .views import (generate_username, | ||
login_dot_gov_logout, | ||
login_redirect, | ||
logout_redirect) | ||
|
||
|
||
class AuthenticationTest(TestCase): | ||
fixtures = ["test_accounts"] | ||
acc = None | ||
|
||
def setUp(self): | ||
self.user = Account.objects.get(cmtee_id="C12345678") | ||
self.factory = RequestFactory() | ||
self.acc = Account.objects.get(email="[email protected]") | ||
|
||
|
@@ -32,6 +35,17 @@ def test_login_dot_gov_logout_happy_path(self): | |
'&post_logout_redirect_uri=None' | ||
'&state=test_state')) | ||
|
||
def test_login_dot_gov_login_redirect(self): | ||
request = self.factory.get("/") | ||
request.user = self.user | ||
request.session = {} | ||
retval = login_redirect(request) | ||
self.assertEqual(retval.status_code, 302) | ||
|
||
def test_login_dot_gov_logout_redirect(self): | ||
retval = logout_redirect(self.factory.get('/')) | ||
self.assertEqual(retval.status_code, 302) | ||
|
||
def test_generate_username(self): | ||
test_uuid = 'test_uuid' | ||
retval = generate_username(test_uuid) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from fecfiler.authentication.views import delete_user_logged_in_cookies | ||
from rest_framework.views import exception_handler | ||
|
||
|
||
def custom_exception_handler(exc, context): | ||
# Call REST framework's default exception handler first, | ||
# to get the standard error response. | ||
response = exception_handler(exc, context) | ||
|
||
# Delete user cookies on forbidden http response. | ||
# this will ensure that when the user is redirected | ||
# to the login page due to the 403, any cookies | ||
# (such as indicating committee id) are removed to | ||
# allow for a clean new login. | ||
if response is not None and response.status_code == 403: | ||
delete_user_logged_in_cookies(response) | ||
|
||
return response |