-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add allow_discord_access custom Okta Group profile attribute check (#195
- Loading branch information
1 parent
f757ac0
commit cf695de
Showing
3 changed files
with
84 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -13,6 +13,9 @@ | |
OKTA_USE_GROUP_OWNERS_API = os.getenv("OKTA_USE_GROUP_OWNERS_API", "False") == "True" | ||
CURRENT_OKTA_USER_EMAIL = os.getenv("CURRENT_OKTA_USER_EMAIL", "[email protected]") | ||
|
||
# Optional env var to set a custom Okta Group Profile attribute for Access management inclusion/exclusion | ||
OKTA_GROUP_PROFILE_CUSTOM_ATTR = os.getenv("OKTA_GROUP_PROFILE_CUSTOM_ATTR") | ||
|
||
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URI") | ||
SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
SQLALCHEMY_ECHO = ENV == "development" # or ENV == "test" | ||
|
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,62 @@ | ||
from unittest.mock import MagicMock, patch | ||
|
||
from okta.models.group_rule import GroupRule as OktaGroupRuleType | ||
|
||
from api.services.okta_service import is_managed_group | ||
|
||
|
||
def test_is_managed_group_with_allow_discord_access_false() -> None: | ||
"""Test that is_managed_group returns False when allow_discord_access is False.""" | ||
with patch("api.config.OKTA_GROUP_PROFILE_CUSTOM_ATTR", "allow_discord_access"): | ||
from api.config import OKTA_GROUP_PROFILE_CUSTOM_ATTR | ||
|
||
# Create a mock of the Group class | ||
group = MagicMock() | ||
group.profile = MagicMock() | ||
group.profile.allow_discord_access = False # Set the profile attribute to False | ||
group.type = "OKTA_GROUP" | ||
group.id = "123456789" # Example group ID | ||
|
||
group_ids_with_group_rules: dict[str, list[OktaGroupRuleType]] = {} # Empty dictionary for group rules | ||
|
||
# Call the function and assert the expected result | ||
result = is_managed_group(group, group_ids_with_group_rules, OKTA_GROUP_PROFILE_CUSTOM_ATTR) | ||
assert result is False | ||
|
||
|
||
def test_is_managed_group_with_allow_discord_access_true() -> None: | ||
"""Test that is_managed_group returns True when allow_discord_access is True.""" | ||
with patch("api.config.OKTA_GROUP_PROFILE_CUSTOM_ATTR", "allow_discord_access"): | ||
from api.config import OKTA_GROUP_PROFILE_CUSTOM_ATTR | ||
|
||
# Create a mock of the Group class | ||
group = MagicMock() | ||
group.profile = MagicMock() | ||
group.profile.allow_discord_access = True # Set the profile attribute to True | ||
group.type = "OKTA_GROUP" | ||
group.id = "123456789" # Example group ID | ||
|
||
group_ids_with_group_rules: dict[str, list[OktaGroupRuleType]] = {} # Empty dictionary for group rules | ||
|
||
# Call the function and assert the expected result | ||
result = is_managed_group(group, group_ids_with_group_rules, OKTA_GROUP_PROFILE_CUSTOM_ATTR) | ||
assert result is True | ||
|
||
|
||
def test_is_managed_group_with_allow_discord_access_undefined() -> None: | ||
"""Test that is_managed_group returns True when the custom attribute is undefined.""" | ||
with patch("api.config.OKTA_GROUP_PROFILE_CUSTOM_ATTR", None): | ||
from api.config import OKTA_GROUP_PROFILE_CUSTOM_ATTR | ||
|
||
# Create a mock of the Group class | ||
group = MagicMock() | ||
group.profile = MagicMock() | ||
group.profile.allow_discord_access = False # Set the profile attribute to False | ||
group.type = "OKTA_GROUP" | ||
group.id = "123456789" # Example group ID | ||
|
||
group_ids_with_group_rules: dict[str, list[OktaGroupRuleType]] = {} # Empty dictionary for group rules | ||
|
||
# Call the function and assert the expected result | ||
result = is_managed_group(group, group_ids_with_group_rules, OKTA_GROUP_PROFILE_CUSTOM_ATTR) | ||
assert result is True |