-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into Updating-Trivy
Updating working branch with changes in main branch.
- Loading branch information
Showing
15 changed files
with
325 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,11 @@ | |
"old_domains": ["company.com"], | ||
"email_transformation": {"new_email_regex": "_", "old_email_expr": "."}, | ||
}, | ||
{ | ||
"new_domain": "company5.com", | ||
"old_domains": ["company6.com", "company6andsuffix.com"], | ||
"email_transformation": {"new_email_regex": "[.]", "old_email_expr": "_"}, | ||
}, | ||
{"new_domain": "newcompany.com", "old_domains": ["company.com"]}, | ||
] | ||
|
||
|
@@ -60,12 +65,33 @@ | |
"last_login": "2023-01-01 00:00:00.000000+00:00", | ||
"self_group": {"name": "[email protected]"}, | ||
}, | ||
{ | ||
"id": 6, | ||
"email": "[email protected]", | ||
"deleted": False, | ||
"last_login": "2023-01-01 00:00:00.000000+00:00", | ||
"self_group": {"name": "[email protected]"}, | ||
}, | ||
{ | ||
"id": 7, | ||
"email": "[email protected]", | ||
"deleted": False, | ||
"last_login": "2023-01-01 00:00:00.000000+00:00", | ||
"self_group": {"name": "[email protected]"}, | ||
}, | ||
] | ||
|
||
EVENT_IP = "0.0.0.0" | ||
|
||
|
||
class MockGroup(object): | ||
def __init__(self, **kwargs): | ||
self.name = kwargs.get("name") or "" | ||
self.group_id = kwargs.get("group_id") or "" | ||
self.scope = kwargs.get("scope") or [] | ||
self.features = kwargs.get("features") or {} | ||
self.admin = kwargs.get("admin") or False | ||
self.allowlist = kwargs.get("allowlist") or False | ||
|
||
def save(self): | ||
pass | ||
|
@@ -88,6 +114,9 @@ def __init__(self, **kwargs): | |
self_group = kwargs.get("self_group") or None | ||
if self_group: | ||
self.self_group = MockGroup(name=self_group.get("name")) | ||
self.scope = kwargs.get("scope") or [] | ||
self.features = kwargs.get("features") or {} | ||
self.admin = kwargs.get("admin") or False | ||
|
||
def save(self): | ||
for user in MockUser.users: | ||
|
@@ -118,6 +147,10 @@ def get(email: str, **kwargs): | |
_get_update_or_create_user = authorizer.handlers._get_update_or_create_user.__wrapped__ | ||
|
||
|
||
@patch("authorizer.handlers.AuditLogger.group_created", lambda *x, **y: None) | ||
@patch("authorizer.handlers.AuditLogger.group_modified", lambda *x, **y: None) | ||
@patch("authorizer.handlers.AuditLogger.user_created", lambda *x, **y: None) | ||
@patch("authorizer.handlers.AuditLogger.user_modified", lambda *x, **y: None) | ||
@patch("authorizer.handlers.EMAIL_DOMAIN_ALIASES", EMAIL_DOMAIN_ALIASES) | ||
@patch("authorizer.handlers.User", MockUser) | ||
@patch("authorizer.handlers.Group", MockGroup) | ||
|
@@ -128,7 +161,7 @@ def test_get_existing_user(self): | |
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == 1 | ||
and user.__dict__.get("email") == email | ||
|
@@ -141,7 +174,7 @@ def test_get_deleted_user(self): | |
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue(user == None) | ||
|
||
def test_get_nonexistent_user(self): | ||
|
@@ -151,7 +184,7 @@ def test_get_nonexistent_user(self): | |
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
expected_userid = MockUser.users[-1].get("id") + 1 | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == expected_userid | ||
and user.__dict__.get("email") == email | ||
|
@@ -165,7 +198,7 @@ def test_get_user_with_new_email(self): | |
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == 1 | ||
and user.__dict__.get("email") == email | ||
|
@@ -179,7 +212,7 @@ def test_get_user_with_new_email_with_transformation(self): | |
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == 2 | ||
and user.__dict__.get("email") == email | ||
|
@@ -193,7 +226,7 @@ def test_get_user_with_new_email_with_transformation2(self): | |
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == 4 | ||
and user.__dict__.get("email") == email | ||
|
@@ -207,7 +240,7 @@ def test_get_user_with_new_email_with_transformation3(self): | |
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == 1 | ||
and user.__dict__.get("email") == email | ||
|
@@ -221,7 +254,7 @@ def test_get_user_with_email_and_self_group_mismatch(self): | |
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == 5 | ||
and user.__dict__.get("email") == email | ||
|
@@ -236,9 +269,39 @@ def test_get_user_with_new_email_and_deleted_old_user(self): | |
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
expected_userid = MockUser.users[-1].get("id") + 1 | ||
user = _get_update_or_create_user(email=email) | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == expected_userid | ||
and user.__dict__.get("email") == email | ||
and user.__dict__.get("self_group").name == email | ||
) | ||
|
||
def test_get_user_with_new_email_and_multiple_old_domains_first_domain(self): | ||
""" | ||
User logs in with email "[email protected]" and has an existing acount with email "[email protected]" | ||
Existing account is found, and email and self group name are updated to the new email "[email protected]" | ||
This is distinct from other tests because there are multiple old domains mapped to new domain company5.com | ||
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == 6 | ||
and user.__dict__.get("email") == email | ||
and user.__dict__.get("self_group").name == email | ||
) | ||
|
||
def test_get_user_with_new_email_and_multiple_old_domains_second_domain(self): | ||
""" | ||
User logs in with email "[email protected]" and has an existing acount with email "[email protected]" | ||
Existing account is found, and email and self group name are updated to the new email "[email protected]" | ||
This is distinct from other tests because there are multiple old domains mapped to new domain company5.com | ||
""" | ||
MockUser.users = copy.deepcopy(USERS) | ||
email = "[email protected]" | ||
user = _get_update_or_create_user(email=email, source_ip=EVENT_IP) | ||
self.assertTrue( | ||
user.__dict__.get("id") == 7 | ||
and user.__dict__.get("email") == email | ||
and user.__dict__.get("self_group").name == email | ||
) |
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
Oops, something went wrong.