forked from CTFd/CTFd
-
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.
Strip spaces on registration and have reset password use email addres…
…s instead of names (CTFd#1218) * Usernames are now properly stripped before being used in registration checks * Reset password function now uses email addresses instead of user names for tokens * Prevent MLC users from resetting their password
- Loading branch information
Showing
7 changed files
with
71 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,13 @@ def test_register_duplicate_username(): | |
password="password", | ||
raise_for_error=False, | ||
) | ||
register_user( | ||
app, | ||
name="admin ", | ||
email="[email protected]", | ||
password="password", | ||
raise_for_error=False, | ||
) | ||
user_count = Users.query.count() | ||
assert user_count == 2 # There's the admin user and the first created user | ||
destroy_ctfd(app) | ||
|
@@ -353,11 +360,15 @@ def test_user_can_reset_password(mock_smtp): | |
|
||
# Build the email | ||
msg = ( | ||
"""Did you initiate a password reset? Click the following link to reset """ | ||
"""your password:\n\nhttp://localhost/reset_password/InVzZXIxIg.TxD0vg.-gvVg-KVy0RWkiclAE6JViv1I0M\n\n""" | ||
"Did you initiate a password reset? If you didn't initiate this request you can ignore this email." | ||
"\n\nClick the following link to reset your password:\n" | ||
"http://localhost/reset_password/InVzZXJAdXNlci5jb20i.TxD0vg.28dY_Gzqb1TH9nrcE_H7W8YFM-U\n" | ||
) | ||
ctf_name = get_config("ctf_name") | ||
email_msg = MIMEText(msg) | ||
email_msg["Subject"] = "Message from CTFd" | ||
email_msg["Subject"] = "Password Reset Request from {ctf_name}".format( | ||
ctf_name=ctf_name | ||
) | ||
email_msg["From"] = from_addr | ||
email_msg["To"] = to_addr | ||
|
||
|
@@ -374,9 +385,11 @@ def test_user_can_reset_password(mock_smtp): | |
data = {"nonce": sess.get("nonce"), "password": "passwordtwo"} | ||
|
||
# Do the password reset | ||
client.get("/reset_password/InVzZXIxIg.TxD0vg.-gvVg-KVy0RWkiclAE6JViv1I0M") | ||
client.get( | ||
"/reset_password/InVzZXJAdXNlci5jb20i.TxD0vg.28dY_Gzqb1TH9nrcE_H7W8YFM-U" | ||
) | ||
client.post( | ||
"/reset_password/InVzZXIxIg.TxD0vg.-gvVg-KVy0RWkiclAE6JViv1I0M", | ||
"/reset_password/InVzZXJAdXNlci5jb20i.TxD0vg.28dY_Gzqb1TH9nrcE_H7W8YFM-U", | ||
data=data, | ||
) | ||
|
||
|
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 |
---|---|---|
|
@@ -156,7 +156,6 @@ def test_sendmail_with_mailgun_from_db_config(fake_post_request): | |
|
||
|
||
@patch("smtplib.SMTP") | ||
@freeze_time("2012-01-14 03:21:34") | ||
def test_verify_email(mock_smtp): | ||
"""Does verify_email send emails""" | ||
app = create_ctfd() | ||
|
@@ -171,7 +170,8 @@ def test_verify_email(mock_smtp): | |
from_addr = get_config("mailfrom_addr") or app.config.get("MAILFROM_ADDR") | ||
to_addr = "[email protected]" | ||
|
||
verify_email_address(to_addr) | ||
with freeze_time("2012-01-14 03:21:34"): | ||
verify_email_address(to_addr) | ||
|
||
# This is currently not actually validated | ||
msg = ( | ||
|
@@ -182,7 +182,9 @@ def test_verify_email(mock_smtp): | |
|
||
ctf_name = get_config("ctf_name") | ||
email_msg = MIMEText(msg) | ||
email_msg["Subject"] = "Message from {0}".format(ctf_name) | ||
email_msg["Subject"] = "Confirm your account for {ctf_name}".format( | ||
ctf_name=ctf_name | ||
) | ||
email_msg["From"] = from_addr | ||
email_msg["To"] = to_addr | ||
|
||
|