-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: implement single prefix #32
Merged
+207
−130
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright © Idiap Research Institute <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
"""Test Configuration""" | ||
import pytest | ||
|
||
from ..multiauthenticator import PREFIX_SEPARATOR | ||
|
||
|
||
@pytest.fixture(params=[f"test me{PREFIX_SEPARATOR}", f"second{PREFIX_SEPARATOR} test"]) | ||
def invalid_name(request): | ||
yield request.param |
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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright © Idiap Research Institute <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
"""Test module for the deprecated features of the MultiAuthenticator class""" | ||
import pytest | ||
|
||
from jupyterhub.auth import PAMAuthenticator | ||
from oauthenticator.gitlab import GitLabOAuthenticator | ||
from oauthenticator.google import GoogleOAuthenticator | ||
|
||
from ..multiauthenticator import PREFIX_SEPARATOR | ||
from ..multiauthenticator import MultiAuthenticator | ||
|
||
|
||
def test_service_name(): | ||
gitlab_service_name = "gitlab-service" | ||
google_service_name = "google-service" | ||
authenticators = [ | ||
( | ||
GitLabOAuthenticator, | ||
"/gitlab", | ||
{ | ||
"service_name": gitlab_service_name, | ||
"client_id": "xxxx", | ||
"client_secret": "xxxx", | ||
"oauth_callback_url": "http://example.com/hub/gitlab/oauth_callback", | ||
}, | ||
), | ||
( | ||
GoogleOAuthenticator, | ||
"/google", | ||
{ | ||
"service_name": google_service_name, | ||
"client_id": "xxxx", | ||
"client_secret": "xxxx", | ||
"oauth_callback_url": "http://example.com/hub/othergoogle/oauth_callback", | ||
}, | ||
), | ||
] | ||
MultiAuthenticator.authenticators = authenticators | ||
|
||
multi_authenticator = MultiAuthenticator() | ||
|
||
custom_html = multi_authenticator.get_custom_html("http://example.com") | ||
|
||
assert f"Sign in with {gitlab_service_name}" in custom_html | ||
assert f"Sign in with {google_service_name}" in custom_html | ||
|
||
|
||
def test_same_authenticators(): | ||
MultiAuthenticator.authenticators = [ | ||
( | ||
GoogleOAuthenticator, | ||
"/mygoogle", | ||
{ | ||
"service_name": "My Google", | ||
"client_id": "yyyyy", | ||
"client_secret": "yyyyy", | ||
"oauth_callback_url": "http://example.com/hub/mygoogle/oauth_callback", | ||
}, | ||
), | ||
( | ||
GoogleOAuthenticator, | ||
"/othergoogle", | ||
{ | ||
"service_name": "Other Google", | ||
"client_id": "xxxx", | ||
"client_secret": "xxxx", | ||
"oauth_callback_url": "http://example.com/hub/othergoogle/oauth_callback", | ||
}, | ||
), | ||
] | ||
|
||
multi_authenticator = MultiAuthenticator() | ||
assert len(multi_authenticator._authenticators) == 2 | ||
assert multi_authenticator.get_custom_html("").count("\n") == 13 | ||
|
||
handlers = multi_authenticator.get_handlers("") | ||
assert len(handlers) == 6 | ||
for path, handler in handlers: | ||
assert isinstance(handler.authenticator, GoogleOAuthenticator) | ||
if "mygoogle" in path: | ||
assert handler.authenticator.service_name == "My Google" | ||
elif "othergoogle" in path: | ||
assert handler.authenticator.service_name == "Other Google" | ||
else: | ||
raise ValueError(f"Unknown path: {path}") | ||
|
||
|
||
def test_username_prefix_validation_with_service_name(invalid_name, caplog): | ||
MultiAuthenticator.authenticators = [ | ||
( | ||
PAMAuthenticator, | ||
"/pam", | ||
{"service_name": invalid_name, "allowed_users": {"test"}}, | ||
), | ||
] | ||
|
||
with pytest.raises(ValueError) as excinfo: | ||
MultiAuthenticator() | ||
|
||
assert f"Service name cannot contain {PREFIX_SEPARATOR}" in str(excinfo.value) | ||
assert len(caplog.records) == 1 | ||
assert ( | ||
caplog.records[0].message | ||
== "service_name is deprecated, please create a subclass and set the login_service class variable" | ||
) |
Oops, something went wrong.
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.
Another option (not better/worse, just another option) is to have this as a
Callable(...)
which takes the authenticator as a parameter and returns the prefix, with the default being the current behaviour.The advantage is flexibility since you could have a mix of shared and unique prefixes, the downside is someone has to define a callable instead of a string if they want a common/no prefix
c.MultiAuthenticator.username_prefix=lambda a: ""
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.
That's an interesting take !
@lahwaacz since you are behind the feature request, I would like to know whether you would prefer @manics suggestion over the current implementation.