-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow email validation errors to be returned even when GENERIC_RESPON…
…SES is set to True. (#961) We need to be careful not to expose whether an account already exists - but syntax or other errors should be returned. This enables custom implementations of MailUtil to enforce their own conventions and return useful results to callers. closes #942
- Loading branch information
Showing
9 changed files
with
75 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
authenticate, | ||
check_xlation, | ||
get_form_input, | ||
init_app_with_options, | ||
json_authenticate, | ||
logout, | ||
) | ||
|
@@ -931,3 +932,27 @@ class MyRegisterForm(NewPasswordFormMixinEx, ConfirmRegisterForm): | |
) | ||
assert response.status_code == 400 | ||
assert "Really - don't start" in response.json["response"]["errors"][0] | ||
|
||
|
||
@pytest.mark.confirmable() | ||
@pytest.mark.settings(return_generic_responses=True) | ||
def test_my_mail_util(app, sqlalchemy_datastore): | ||
# Test that with generic_responses - we still can get syntax/validation errors. | ||
from flask_security import MailUtil, EmailValidateException | ||
|
||
class MyMailUtil(MailUtil): | ||
def validate(self, email): | ||
if email.startswith("mike"): | ||
raise EmailValidateException("No mikes allowed") | ||
|
||
init_app_with_options( | ||
app, sqlalchemy_datastore, **{"security_args": {"mail_util_cls": MyMailUtil}} | ||
) | ||
|
||
data = dict( | ||
email="[email protected]", | ||
password="awesome sunset", | ||
) | ||
client = app.test_client() | ||
response = client.post("/register", data=data) | ||
assert b"No mikes allowed" in response.data |