forked from ansible/django-ansible-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store essential SAML attrs by default
Signed-off-by: Rick Elrod <[email protected]>
- Loading branch information
1 parent
b00db70
commit ba3e77a
Showing
2 changed files
with
100 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from types import SimpleNamespace | ||
from unittest import mock | ||
|
||
import pytest | ||
|
@@ -213,6 +214,91 @@ def __init__(self): | |
assert "mygroup" in rDict["Group"] | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize( | ||
"idp_fields,expected_results", | ||
[ | ||
( | ||
{ | ||
'attr_email': 'email', | ||
'attr_groups': 'Groups', | ||
'attr_username': 'username', | ||
'attr_last_name': 'last_name', | ||
'attr_first_name': 'first_name', | ||
'attr_user_permanent_id': 'name_id', | ||
}, | ||
{ | ||
'email': ['[email protected]'], | ||
'last_name': ['Admin'], | ||
'username': ['gateway_admin'], | ||
'first_name': ['Gateway'], | ||
'name_id': 'gateway_admin', | ||
}, | ||
), | ||
( | ||
{ | ||
'attr_email': 'not_email', | ||
'attr_groups': 'Groups', | ||
'attr_username': 'username', | ||
'attr_last_name': 'last_name', | ||
'attr_first_name': 'first_name', | ||
'attr_user_permanent_id': 'name_id', | ||
}, | ||
{ | ||
'last_name': ['Admin'], | ||
'username': ['gateway_admin'], | ||
'first_name': ['Gateway'], | ||
'name_id': 'gateway_admin', | ||
}, | ||
), | ||
( | ||
{ | ||
'attr_username': 'username', | ||
'attr_last_name': 'last_name', | ||
'attr_first_name': 'first_name', | ||
'attr_user_permanent_id': 'name_id', | ||
}, | ||
{ | ||
'last_name': ['Admin'], | ||
'username': ['gateway_admin'], | ||
'first_name': ['Gateway'], | ||
'name_id': 'gateway_admin', | ||
}, | ||
), | ||
], | ||
) | ||
def test_extra_data_default_attrs(idp_fields, expected_results): | ||
from ansible_base.authentication.authenticator_plugins.saml import idp_string | ||
from ansible_base.authentication.models import AuthenticatorUser | ||
|
||
ap = AuthenticatorPlugin() | ||
database_instance = SimpleNamespace() | ||
enabled_idps = { | ||
'ENABLED_IDPS': { | ||
idp_string: idp_fields, | ||
} | ||
} | ||
database_instance.configuration = enabled_idps | ||
ap.database_instance = database_instance | ||
|
||
response = { | ||
'idp_name': 'IdP', | ||
'attributes': { | ||
'email': ['[email protected]'], | ||
'last_name': ['Admin'], | ||
'is_superuser': ['true'], | ||
'username': ['gateway_admin'], | ||
'first_name': ['Gateway'], | ||
'Role': ['default-roles-gateway realm', 'manage-account', 'uma_authorization', 'view-profile', 'offline_access', 'manage-account-links'], | ||
'name_id': 'gateway_admin', | ||
}, | ||
} | ||
au = AuthenticatorUser() | ||
with mock.patch('social_core.backends.saml.SAMLAuth.extra_data', return_value={}): | ||
results = ap.extra_data(None, 'IdP:gateway_admin', response, **{'social': au}) | ||
assert results == expected_results | ||
|
||
|
||
def test_saml_create_via_api_without_callback_url(admin_api_client, saml_configuration): | ||
del saml_configuration['CALLBACK_URL'] | ||
|
||
|