|
11 | 11 | from test_app.models import User |
12 | 12 |
|
13 | 13 |
|
| 14 | +@pytest.fixture |
| 15 | +def oidc_authenticator_plugin_uid_key_overridden(oidc_authenticator, random_name): |
| 16 | + oidc_authenticator.configuration['ID_KEY'] = random_name |
| 17 | + oidc_authenticator.save() |
| 18 | + yield (oidc_authenticator, random_name) |
| 19 | + |
| 20 | + |
14 | 21 | @pytest.mark.django_db |
15 | 22 | class TestAuthenticationUtilsAuthentication: |
16 | 23 | logger = 'ansible_base.authentication.utils.authentication.logger' |
@@ -200,16 +207,26 @@ def test_determine_username_from_uid_social_happy_path(self, ldap_authenticator) |
200 | 207 | ) |
201 | 208 | assert response == {'username': 'Bob'} |
202 | 209 |
|
| 210 | + def test_determine_username_from_uid_social_authenticator_ID_KEY(self, oidc_authenticator_plugin_uid_key_overridden): |
| 211 | + backend_authenticator_class, uid_key = oidc_authenticator_plugin_uid_key_overridden |
| 212 | + backend = get_authenticator_class(backend_authenticator_class.type)(database_instance=backend_authenticator_class) |
| 213 | + kwargs = { |
| 214 | + 'backend': backend, |
| 215 | + } |
| 216 | + with pytest.raises(AuthException) as ae: |
| 217 | + authentication.determine_username_from_uid_social(**kwargs) |
| 218 | + assert f'Unable to get associated username from attribute {uid_key}' in ae.value.backend |
| 219 | + |
203 | 220 | @pytest.mark.parametrize( |
204 | 221 | "kwargs,expected_uid_field", |
205 | 222 | [ |
206 | 223 | ({}, 'username'), |
207 | 224 | ({'backend': None}, 'username'), |
208 | | - ({'backend': SimpleNamespace(ID_KEY='testing')}, 'testing'), |
209 | | - ({'backend': SimpleNamespace(ID_KEY=None)}, 'testing'), |
| 225 | + ({'backend': SimpleNamespace(ID_KEY="id_key_test_value")}, 'id_key_test_value'), |
| 226 | + ({'backend': SimpleNamespace(ID_KEY=None)}, 'username'), |
210 | 227 | ], |
211 | 228 | ) |
212 | | - def test_determine_username_from_uid_social_authenticator_ID_KEY(self, kwargs, expected_uid_field): |
| 229 | + def test_determine_username_from_uid_social_authenticator_ID_KEY_fallback(self, kwargs, expected_uid_field): |
213 | 230 | with pytest.raises(AuthException) as ae: |
214 | 231 | authentication.determine_username_from_uid_social(**kwargs) |
215 | | - assert f'Unable to get associated username from attribute {expected_uid_field}' in ae |
| 232 | + assert f'Unable to get associated username from attribute {expected_uid_field}' in ae.value.backend |
0 commit comments