-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add tests for oidc usernames #21655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jmchilton
merged 2 commits into
galaxyproject:dev
from
nuwang:improve_oidc_username_tests
Jan 28, 2026
Merged
Add tests for oidc usernames #21655
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -483,6 +483,40 @@ | |
| "notBefore": 0, | ||
| "groups": [] | ||
| }, | ||
| { | ||
| "id": "f5e8b2c4-9a1d-4e3f-8c6a-7b2d5e4f3c1a", | ||
| "createdTimestamp": 1694376671733, | ||
| "username": "rincewind_test", | ||
| "enabled": true, | ||
| "totp": false, | ||
| "emailVerified": true, | ||
| "firstName": "Rincewind", | ||
| "lastName": "Ankh-Morpork", | ||
| "email": "[email protected]", | ||
| "attributes": { | ||
| "preferred_username": [ | ||
| "Rincewind (Ankh-Morpork)" | ||
| ] | ||
| }, | ||
| "credentials": [ | ||
| { | ||
| "id": "e5d4c3b2-a1f0-9e8d-7c6b-5a4f3e2d1c0b", | ||
| "type": "password", | ||
| "userLabel": "My password", | ||
| "createdDate": 1694376754826, | ||
| "secretData": "{\"value\":\"uNBI+UnpCLpXWHhm/tPSnnhuINiNw2MNt1XeDmImJaQ=\",\"salt\":\"fHS/FpnORylnSIco16UHwA==\",\"additionalParameters\":{}}", | ||
| "credentialData": "{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\",\"additionalParameters\":{}}" | ||
| } | ||
| ], | ||
| "disableableCredentialTypes": [], | ||
| "requiredActions": [], | ||
| "realmRoles": [ | ||
| "galaxy-access-role", | ||
| "default-roles-gxyrealm" | ||
| ], | ||
| "notBefore": 0, | ||
| "groups": [] | ||
| }, | ||
| { | ||
| "id": "24ffa3ff-d351-4d5e-b10b-8d615082ec9d", | ||
| "createdTimestamp": 1694376671733, | ||
|
|
@@ -2565,4 +2599,4 @@ | |
| "clientPolicies": { | ||
| "policies": [] | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -261,6 +261,24 @@ def test_oidc_login_new_user(self): | |
| self._assert_status_code_is(response, 200) | ||
| assert response.json()["email"] == "[email protected]" | ||
|
|
||
| def test_oidc_login_username_sanitization(self): | ||
| """Test that OIDC usernames with special characters are properly sanitized.""" | ||
| _, response = self._login_via_keycloak("rincewind_test", KEYCLOAK_TEST_PASSWORD, save_cookies=True) | ||
|
|
||
| response = self._get("users/current") | ||
| self._assert_status_code_is(response, 200) | ||
| assert response.json()["email"] == "[email protected]" | ||
|
|
||
| username = response.json()["username"] | ||
| from galaxy.security.validate_user_input import validate_publicname_str | ||
|
|
||
| error = validate_publicname_str(username) | ||
| assert error == "", f"OIDC-created username '{username}' is invalid: {error}" | ||
| assert "(" not in username, f"Username '{username}' should not contain parentheses" | ||
| assert ")" not in username, f"Username '{username}' should not contain parentheses" | ||
| assert " " not in username, f"Username '{username}' should not contain spaces" | ||
| assert username == username.lower(), f"Username '{username}' should be lowercase" | ||
|
|
||
| def test_oidc_login_repeat_no_notification(self): | ||
| """ | ||
| Test that repeat logins do NOT show the 'identity has been linked' notification. | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really beautiful test setup - what a cool way to bootstrap auth-based testing! Not added here per se but I wanted to compliment it. These particular tests are also really clear and useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Claude helped with all the boilerplate.