Skip to content

Commit

Permalink
Add regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
malexmave authored and twwd committed Oct 1, 2024
1 parent 8b0d3c3 commit 5325861
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from kcwarden.auditors.idp.identity_provider_with_mappers_without_force_sync_mode import (
IdentityProviderWithMappersWithoutForceSyncMode,
)
from kcwarden.custom_types import config_keys


class TestIdentityProviderWithMappersWithoutForceSyncMode:
Expand Down Expand Up @@ -76,3 +77,21 @@ def test_audit_function_multiple_idps(self, auditor):
auditor._DB.get_all_identity_providers.return_value = [idp1, idp2, idp3]
results = list(auditor.audit())
assert len(results) == 1 # Expect findings from idp1 only

def test_ignore_list_functionality(self, auditor, mock_idp):
# Setup IDP without force sync mode and with mappers
mock_idp.get_sync_mode.return_value = "INHERIT"
mock_idp.get_identity_provider_mappers.return_value = [{"name": "mapper1"}]
mock_idp.get_alias.return_value = "ignored_idp"
mock_idp.get_name.return_value = mock_idp.get_alias.return_value
auditor._DB.get_all_identity_providers.return_value = [mock_idp]

# Add the IDP to the ignore list
auditor._CONFIG = {
config_keys.AUDITOR_CONFIG: {
auditor.get_classname(): ["ignored_idp"]
}
}

results = list(auditor.audit())
assert len(results) == 0 # No findings due to ignore list
19 changes: 19 additions & 0 deletions tests/auditors/idp/test_identity_provider_with_one_time_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import Mock

from kcwarden.auditors.idp.identity_provider_with_one_time_sync import IdentityProviderWithOneTimeSync
from kcwarden.custom_types import config_keys


class TestIdentityProviderWithOneTimeSync:
Expand Down Expand Up @@ -59,3 +60,21 @@ def test_audit_function_multiple_idps(self, auditor):
auditor._DB.get_all_identity_providers.return_value = [idp1, idp2, idp3]
results = list(auditor.audit())
assert len(results) == 2 # Expect findings from idp1 and idp3, but not from idp2

def test_ignore_list_functionality(self, auditor, mock_idp):
# Setup IDP without force sync mode and with mappers
# Setup IDP without correct PKCE configuration
mock_idp.get_sync_mode.return_value = "INHERIT"
mock_idp.get_alias.return_value = "ignored_idp"
mock_idp.get_name.return_value = mock_idp.get_alias.return_value
auditor._DB.get_all_identity_providers.return_value = [mock_idp]

# Add the IDP to the ignore list
auditor._CONFIG = {
config_keys.AUDITOR_CONFIG: {
auditor.get_classname(): ["ignored_idp"]
}
}

results = list(auditor.audit())
assert len(results) == 0 # No findings due to ignore list
20 changes: 20 additions & 0 deletions tests/auditors/idp/test_oidc_identity_provider_without_pkce.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import Mock

from kcwarden.auditors.idp.oidc_identity_provider_without_pkce import OIDCIdentityProviderWithoutPKCE
from kcwarden.custom_types import config_keys


class TestOIDCIdentityProviderWithoutPKCE:
Expand Down Expand Up @@ -75,3 +76,22 @@ def test_audit_function_multiple_idps(self, auditor):
auditor._DB.get_all_identity_providers.return_value = [idp1, idp2, idp3]
results = list(auditor.audit())
assert len(results) == 2 # Expect findings from idp2 and idp3

def test_ignore_list_functionality(self, auditor, mock_idp):
# Setup IDP without force sync mode and with mappers
# Setup IDP without correct PKCE configuration
mock_idp.get_provider_id.return_value = "oidc"
mock_idp.get_config.return_value = {"pkceEnabled": "false"}
mock_idp.get_alias.return_value = "ignored_idp"
mock_idp.get_name.return_value = mock_idp.get_alias.return_value
auditor._DB.get_all_identity_providers.return_value = [mock_idp]

# Add the IDP to the ignore list
auditor._CONFIG = {
config_keys.AUDITOR_CONFIG: {
auditor.get_classname(): ["ignored_idp"]
}
}

results = list(auditor.audit())
assert len(results) == 0 # No findings due to ignore list

0 comments on commit 5325861

Please sign in to comment.