-
-
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.
Merge branch 'issue-185-oidc-user-registration' into 'main'
oidc user registration Closes #185 See merge request yaal/canaille!164
- Loading branch information
Showing
13 changed files
with
204 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,14 @@ | |
Tests the behavior of Canaille depending on the OIDC 'prompt' parameter. | ||
https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint | ||
""" | ||
import datetime | ||
import uuid | ||
from urllib.parse import parse_qs | ||
from urllib.parse import urlsplit | ||
|
||
from canaille.app import models | ||
from canaille.core.account import RegistrationPayload | ||
from flask import url_for | ||
|
||
|
||
def test_prompt_none(testclient, logged_user, client): | ||
|
@@ -98,3 +101,125 @@ def test_prompt_no_consent(testclient, logged_user, client): | |
status=200, | ||
) | ||
assert "consent_required" == res.json.get("error") | ||
|
||
|
||
def test_prompt_create_logged(testclient, logged_user, client): | ||
""" | ||
If prompt=create and user is already logged in, | ||
then go straight to the consent page. | ||
""" | ||
testclient.app.config["ENABLE_REGISTRATION"] = True | ||
|
||
consent = models.Consent( | ||
consent_id=str(uuid.uuid4()), | ||
client=client, | ||
subject=logged_user, | ||
scope=["openid", "profile"], | ||
) | ||
consent.save() | ||
|
||
res = testclient.get( | ||
"/oauth/authorize", | ||
params=dict( | ||
response_type="code", | ||
client_id=client.client_id, | ||
scope="openid profile", | ||
nonce="somenonce", | ||
prompt="create", | ||
), | ||
status=302, | ||
) | ||
assert res.location.startswith(client.redirect_uris[0]) | ||
|
||
consent.delete() | ||
|
||
|
||
def test_prompt_create_registration_disabled(testclient, trusted_client, smtpd): | ||
""" | ||
If prompt=create but Canaille registration is disabled, | ||
an error response should be returned. | ||
If the OpenID Provider receives a prompt value that it does | ||
not support (not declared in the prompt_values_supported | ||
metadata field) the OP SHOULD respond with an HTTP 400 (Bad | ||
Request) status code and an error value of invalid_request. | ||
It is RECOMMENDED that the OP return an error_description | ||
value identifying the invalid parameter value. | ||
""" | ||
res = testclient.get( | ||
"/oauth/authorize", | ||
params=dict( | ||
response_type="code", | ||
client_id=trusted_client.client_id, | ||
scope="openid profile", | ||
nonce="somenonce", | ||
prompt="create", | ||
), | ||
status=400, | ||
) | ||
assert res.json == { | ||
"error": "invalid_request", | ||
"error_description": "prompt 'create' value is not supported", | ||
} | ||
|
||
|
||
def test_prompt_create_not_logged(testclient, trusted_client, smtpd): | ||
""" | ||
If prompt=create and user is not logged in, | ||
then display the registration form. | ||
Check that the user is correctly redirected to | ||
the client page after the registration process. | ||
""" | ||
testclient.app.config["ENABLE_REGISTRATION"] = True | ||
|
||
res = testclient.get( | ||
"/oauth/authorize", | ||
params=dict( | ||
response_type="code", | ||
client_id=trusted_client.client_id, | ||
scope="openid profile", | ||
nonce="somenonce", | ||
prompt="create", | ||
), | ||
) | ||
|
||
# Display the registration form | ||
res = res.follow() | ||
res.form["email"] = "[email protected]" | ||
res = res.form.submit() | ||
|
||
# Checks the registration mail is sent | ||
assert len(smtpd.messages) == 1 | ||
|
||
# Simulate a click on the validation link in the mail | ||
payload = RegistrationPayload( | ||
creation_date_isoformat=datetime.datetime.now( | ||
datetime.timezone.utc | ||
).isoformat(), | ||
user_name="", | ||
user_name_editable=True, | ||
email="[email protected]", | ||
groups=[], | ||
) | ||
registration_url = url_for( | ||
"core.account.registration", | ||
data=payload.b64(), | ||
hash=payload.build_hash(), | ||
_external=True, | ||
) | ||
|
||
# Fill the user creation form | ||
res = testclient.get(registration_url) | ||
res.form["user_name"] = "newuser" | ||
res.form["password1"] = "password" | ||
res.form["password2"] = "password" | ||
res.form["family_name"] = "newuser" | ||
res = res.form.submit() | ||
|
||
assert res.flashes == [ | ||
("success", "Your account has been created successfully."), | ||
] | ||
|
||
# Return to the client | ||
res = res.follow() | ||
assert res.location.startswith(trusted_client.redirect_uris[0]) |
Oops, something went wrong.