-
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.
Update create user to expect users from Entra (#1429)
* Update create user to expect users from Entra To enable CICA users to access the CP, we will enable a new connection in Auth0 with EntraID. This updates the code we use to create a user from the ID token to normalize their name, and store their email as the justice_email, to avoid them having to reauth to capture it. * Use users slug rather than username in helm Previously the username would be used when installing user helm charts. This was fine when all users came from github, as their usernames were guaranteed to be valid with helm. However this is not the case with usernames from Entra, as they can include invalid characters such as '.' which results in an error after the user logs in trying to provision the user. This changes uses the slug, which is valid for helm, however accessing tools will still not be compatible so tooling will not be available for these users. * Improve justice email validation * Revert "Use users slug rather than username in helm" This reverts commit 93cb6cd. We will resolve the issue these changes were meant to fix in a different way when we fully implement access with EntraID * Limit access unless user is created via GitHub auth * Additional test for creating user * Fix typo * Fix failing tests
- Loading branch information
1 parent
7ce69da
commit a584722
Showing
19 changed files
with
137 additions
and
33 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
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
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 |
---|---|---|
|
@@ -84,6 +84,17 @@ def test_with_justice_email(self, client, users): | |
assert response.status_code == 302 | ||
assert response.url == reverse("list-tools") | ||
|
||
def test_not_tool_user(self, client, users): | ||
user = users["non_tool_user"] | ||
user.justice_email = "[email protected]" | ||
user.save() | ||
client.force_login(user) | ||
|
||
response = client.get("/") | ||
|
||
assert response.status_code == 302 | ||
assert response.url == reverse("help") | ||
|
||
|
||
class TestPost: | ||
|
||
|
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
# Standard library | ||
from unittest.mock import Mock | ||
from unittest.mock import Mock, patch | ||
|
||
# Third-party | ||
import pytest | ||
from django.conf import settings | ||
|
||
# First-party/Local | ||
from controlpanel.oidc import StateMismatchHandler | ||
from controlpanel.oidc import OIDCSubAuthenticationBackend, StateMismatchHandler | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -24,3 +25,27 @@ def test_success_url(users, email, success_url): | |
view.request = request | ||
view.user = user | ||
assert view.success_url == success_url | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize( | ||
"email, name, expected_name, expected_justice_email", | ||
[ | ||
("[email protected]", "User, Test", "Test User", None), | ||
("[email protected]", "Test User", "Test User", None), | ||
("[email protected]", "User, Test", "Test User", "[email protected]"), | ||
("[email protected]", "Test User", "Test User", "[email protected]"), | ||
], | ||
) | ||
def test_create_user(email, name, expected_name, expected_justice_email): | ||
with patch("controlpanel.api.cluster.User.create"): | ||
user = OIDCSubAuthenticationBackend().create_user( | ||
{ | ||
"sub": "123", | ||
settings.OIDC_FIELD_USERNAME: "testuser", | ||
settings.OIDC_FIELD_EMAIL: email, | ||
settings.OIDC_FIELD_NAME: name, | ||
} | ||
) | ||
assert user.name == expected_name | ||
assert user.justice_email == expected_justice_email |