-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update user group handling, update docs (#1367)
- Loading branch information
Showing
6 changed files
with
98 additions
and
24 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import uuid | ||
|
||
from django.conf import settings | ||
from django.contrib.auth.models import Group | ||
from django.core.exceptions import ValidationError | ||
from django.forms.models import model_to_dict | ||
from django.urls import reverse | ||
|
@@ -41,6 +42,10 @@ | |
REMOTE_LEVEL_VIEW_AVAIL = SODAR_CONSTANTS['REMOTE_LEVEL_VIEW_AVAIL'] | ||
REMOTE_LEVEL_READ_ROLES = SODAR_CONSTANTS['REMOTE_LEVEL_READ_ROLES'] | ||
REMOTE_LEVEL_REVOKED = SODAR_CONSTANTS['REMOTE_LEVEL_REVOKED'] | ||
USER_TYPE_LOCAL = SODAR_CONSTANTS['USER_TYPE_LOCAL'] | ||
USER_TYPE_LDAP = SODAR_CONSTANTS['USER_TYPE_LDAP'] | ||
USER_TYPE_OIDC = SODAR_CONSTANTS['USER_TYPE_OIDC'] | ||
OIDC_USER_GROUP = SODAR_CONSTANTS['OIDC_USER_GROUP'] | ||
|
||
# Local constants | ||
SECRET = 'rsd886hi8276nypuvw066sbvv0rb2a6x' | ||
|
@@ -1609,6 +1614,29 @@ def test_get_form_label_first_last(self): | |
'Full Name (testuser) <[email protected]>', | ||
) | ||
|
||
def test_get_auth_type_local(self): | ||
"""Test get_auth_type() with local user""" | ||
self.assertEqual(self.user.get_auth_type(), USER_TYPE_LOCAL) | ||
|
||
@override_settings(AUTH_LDAP_USERNAME_DOMAIN='TEST') | ||
def test_get_auth_type_ldap(self): | ||
"""Test get_auth_type() with LDAP user""" | ||
self.user.username = 'testuser@TEST' | ||
self.user.save() # NOTE: set_group() is called on user save() | ||
self.assertEqual(self.user.get_auth_type(), USER_TYPE_LDAP) | ||
|
||
def test_get_auth_type_ldap_no_group(self): | ||
"""Test get_auth_type() with LDAP username but no user group""" | ||
self.user.username = 'testuser@TEST' | ||
self.user.save() | ||
self.assertEqual(self.user.get_auth_type(), USER_TYPE_LOCAL) | ||
|
||
def test_get_auth_type_oidc(self): | ||
"""Test get_auth_type() with OIDC user""" | ||
group, _ = Group.objects.get_or_create(name=OIDC_USER_GROUP) | ||
group.user_set.add(self.user) | ||
self.assertEqual(self.user.get_auth_type(), USER_TYPE_OIDC) | ||
|
||
def test_update_full_name(self): | ||
"""Test update_full_name()""" | ||
self.assertEqual(self.user.name, '') | ||
|