-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eregcsc 2012 initial logins from eua (#991)
* EREGCSC-2012 - initial login from eua
- Loading branch information
Showing
5 changed files
with
134 additions
and
29 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
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,47 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from django.contrib.auth import get_user_model | ||
|
||
from ..admin import OidcAdminAuthenticationBackend | ||
|
||
User = get_user_model() | ||
|
||
|
||
class OidcAdminAuthenticationBackendTest(unittest.TestCase): | ||
def setUp(self): | ||
self.backend = OidcAdminAuthenticationBackend() | ||
self.mock_claims = { | ||
"sub": "00u1234567891234297", | ||
"name": "Homer Simpson", | ||
"lastName": "Simpson", | ||
"firstName": "Homer", | ||
"email": "[email protected]", | ||
"email_verified": True, | ||
"jobcodes": "cn=EREGS_ADMIN,ou=Groups,dc=cms,dc=hhs,dc=gov,cn=EXAMPLE_TEST,ou=Groups,dc=cms,dc=hhs,dc=gov" | ||
} | ||
|
||
@patch.object(OidcAdminAuthenticationBackend, 'create_user', return_value=User(email='[email protected]')) | ||
def test_verify_claims(self, mock_create_user): | ||
result = self.backend.verify_claims(self.mock_claims) | ||
self.assertTrue(result) | ||
|
||
invalid_claims = dict(self.mock_claims) | ||
invalid_claims["email_verified"] = False | ||
result = self.backend.verify_claims(invalid_claims) | ||
self.assertFalse(result) | ||
|
||
@patch.object(OidcAdminAuthenticationBackend, 'create_user') | ||
def test_user_is_active_if_have_jobcodes(self, mock_create_user): | ||
mock_create_user.return_value = User(email='[email protected]') | ||
user = self.backend.create_user(self.mock_claims) | ||
self.assertTrue(user.is_active) | ||
|
||
def test_user_is_not_created_if_no_jobcodes(self): | ||
self.mock_claims["jobcodes"] = "" | ||
user = self.backend.create_user(self.mock_claims) | ||
self.assertIsNone(user) | ||
|
||
|
||
if __name__ == '__main': | ||
unittest.main() |