forked from inveniosoftware/invenio-oauthclient
-
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.
* roles integration for groups handler * added dummy handler for groups * closes inveniosoftware/invenio-app-rdm#2186 Co-authored-by: jrcastro2 <[email protected]>
- Loading branch information
Showing
8 changed files
with
153 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
from flask_security import login_user, logout_user | ||
from flask_security.confirmable import _security | ||
from helpers import check_response_redirect_url_args | ||
from invenio_accounts.models import Role | ||
from werkzeug.routing import BuildError | ||
|
||
from invenio_oauthclient import InvenioOAuthClientREST, current_oauthclient | ||
|
@@ -71,6 +72,49 @@ def test_authorized_signup_handler(remote, app_rest, models_fixture): | |
check_response_redirect_url_args(resp, expected_url_args) | ||
|
||
|
||
@pytest.mark.parametrize("remote", REMOTE_APPS, indirect=["remote"]) | ||
def test_group_handler(remote, app_rest, models_fixture): | ||
"""Test group handler.""" | ||
datastore = app_rest.extensions["invenio-accounts"].datastore | ||
existing_email = "[email protected]" | ||
user = datastore.find_user(email=existing_email) | ||
example_group = [ | ||
{ | ||
"id": "rdm-developers", | ||
"name": "rdm-developers", | ||
"description": "People contributing to RDM.", | ||
} | ||
] | ||
|
||
example_response = {"access_token": "test_access_token"} | ||
example_account_info = { | ||
"user": { | ||
"email": existing_email, | ||
}, | ||
"external_id": "1234", | ||
"external_method": "test_method", | ||
} | ||
|
||
# Mock remote app's handler | ||
current_oauthclient.signup_handlers[remote.name] = { | ||
"info": lambda resp: example_account_info, | ||
"groups": lambda resp: example_group, | ||
} | ||
|
||
_security.confirmable = True | ||
_security.login_without_confirmation = False | ||
user.confirmed_at = None | ||
|
||
authorized_signup_handler(example_response, remote) | ||
|
||
# Assert that the group handler works correctly | ||
roles = Role.query.all() | ||
assert 1 == len(roles) | ||
assert roles[0].id == example_group[0]["id"] | ||
assert roles[0].name == example_group[0]["name"] | ||
assert roles[0].description == example_group[0]["description"] | ||
|
||
|
||
@pytest.mark.parametrize("remote", REMOTE_APPS, indirect=["remote"]) | ||
def test_unauthorized_signup(remote, app_rest, models_fixture): | ||
"""Test unauthorized redirect on signup callback handler.""" | ||
|
@@ -82,9 +126,9 @@ def test_unauthorized_signup(remote, app_rest, models_fixture): | |
example_account_info = { | ||
"user": { | ||
"email": existing_email, | ||
"external_id": "1234", | ||
"external_method": "test_method", | ||
} | ||
}, | ||
"external_id": "1234", | ||
"external_method": "test_method", | ||
} | ||
|
||
# Mock remote app's handler | ||
|
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 |
---|---|---|
|
@@ -37,12 +37,21 @@ def test_authorized_signup_handler(remote, app, models_fixture): | |
"""Test authorized signup handler.""" | ||
datastore = app.extensions["invenio-accounts"].datastore | ||
user = datastore.find_user(email="[email protected]") | ||
existing_email = "[email protected]" | ||
|
||
example_response = {"access_token": "test_access_token"} | ||
example_account_info = { | ||
"user": { | ||
"email": existing_email, | ||
}, | ||
"external_id": "1234", | ||
"external_method": "test_method", | ||
} | ||
|
||
# Mock remote app's handler | ||
current_oauthclient.signup_handlers[remote.name] = { | ||
"setup": lambda token, resp: None | ||
"setup": lambda token, resp: None, | ||
"info": lambda resp: example_account_info, | ||
} | ||
|
||
# Authenticate user | ||
|
@@ -67,9 +76,9 @@ def test_unauthorized_signup(remote, app, models_fixture): | |
example_account_info = { | ||
"user": { | ||
"email": existing_email, | ||
"external_id": "1234", | ||
"external_method": "test_method", | ||
} | ||
}, | ||
"external_id": "1234", | ||
"external_method": "test_method", | ||
} | ||
|
||
# Mock remote app's handler | ||
|
@@ -81,9 +90,8 @@ def test_unauthorized_signup(remote, app, models_fixture): | |
_security.login_without_confirmation = False | ||
user.confirmed_at = None | ||
app.config["OAUTHCLIENT_REMOTE_APPS"][remote.name] = {} | ||
|
||
resp = authorized_signup_handler(example_response, remote) | ||
check_redirect_location(resp, lambda x: x.startswith("/login/")) | ||
check_redirect_location(resp, lambda x: x.startswith("/login")) | ||
|
||
|
||
def test_signup_handler(remote, app, models_fixture): | ||
|