-
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.
Signed-off-by: romartin <[email protected]>
- Loading branch information
Showing
8 changed files
with
94 additions
and
12 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
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 |
---|---|---|
|
@@ -25,7 +25,11 @@ | |
|
||
from ansible_ai_connect.test_utils import WisdomServiceLogAwareTestCase | ||
from ansible_ai_connect.users.constants import RHSSO_LIGHTSPEED_SCOPE | ||
from ansible_ai_connect.users.pipeline import load_extra_data, redhat_organization | ||
from ansible_ai_connect.users.pipeline import ( | ||
is_rh_email_domain, | ||
load_extra_data, | ||
redhat_organization, | ||
) | ||
|
||
|
||
def build_access_token(private_key, payload): | ||
|
@@ -310,9 +314,10 @@ def test_rh_employee_field(self): | |
"access_token": build_access_token( | ||
self.rsa_private_key, | ||
{ | ||
"realm_access": {"roles": ["redhat:employees"]}, | ||
"preferred_username": "jean-michel", | ||
"organization": {"id": "345"}, | ||
"email": "[email protected]", | ||
"email_verified": True, | ||
}, | ||
) | ||
} | ||
|
@@ -324,6 +329,59 @@ def test_rh_employee_field(self): | |
) | ||
self.assertEqual(answer["rh_employee"], True) | ||
|
||
def test_not_rh_employee_fields(self): | ||
response = { | ||
"access_token": build_access_token( | ||
self.rsa_private_key, | ||
{ | ||
"preferred_username": "jean-michel", | ||
"organization": {"id": "345"}, | ||
}, | ||
) | ||
} | ||
answer = redhat_organization( | ||
backend=DummyRHBackend(public_key=self.jwk_public_key), | ||
user=self.rh_user, | ||
response=response, | ||
) | ||
self.assertEqual(answer["rh_employee"], False) | ||
|
||
def test_rh_employee_field_not_rh_email(self): | ||
response = { | ||
"access_token": build_access_token( | ||
self.rsa_private_key, | ||
{ | ||
"email": "[email protected]", | ||
"preferred_username": "jean-michel", | ||
"organization": {"id": "345"}, | ||
}, | ||
) | ||
} | ||
answer = redhat_organization( | ||
backend=DummyRHBackend(public_key=self.jwk_public_key), | ||
user=self.rh_user, | ||
response=response, | ||
) | ||
self.assertEqual(answer["rh_employee"], False) | ||
|
||
def test_rh_employee_field_not_email_verified(self): | ||
response = { | ||
"access_token": build_access_token( | ||
self.rsa_private_key, | ||
{ | ||
"email": "[email protected]", | ||
"preferred_username": "jean-michel", | ||
"organization": {"id": "345"}, | ||
}, | ||
) | ||
} | ||
answer = redhat_organization( | ||
backend=DummyRHBackend(public_key=self.jwk_public_key), | ||
user=self.rh_user, | ||
response=response, | ||
) | ||
self.assertEqual(answer["rh_employee"], False) | ||
|
||
def test_rhoss_user_and_email(self): | ||
response = { | ||
"access_token": build_access_token( | ||
|
@@ -348,3 +406,12 @@ def test_rhoss_user_and_email(self): | |
self.assertEqual(self.rh_user.email, "[email protected]") | ||
self.assertEqual(self.rh_user.given_name, "Francis") | ||
self.assertEqual(self.rh_user.name, "Francis Drake") | ||
|
||
def test_is_rh_email_domain(self): | ||
self.assertFalse(is_rh_email_domain(None)) | ||
self.assertFalse(is_rh_email_domain("")) | ||
self.assertFalse(is_rh_email_domain("user.com")) | ||
self.assertFalse(is_rh_email_domain("[email protected]")) | ||
self.assertTrue(is_rh_email_domain("[email protected]")) | ||
self.assertTrue(is_rh_email_domain("[email protected]")) | ||
self.assertTrue(is_rh_email_domain("@REDHAT.com")) |