mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-03 13:18:57 -04:00
After investigating a 500 in the admin app, I found an edge case in the invitation registration flow that can cause an error.
The flow is as follows: If the invited user clicks on the /invitation/<token> link in the email (now on /register-from-invite), then goes to another browser and registers for Notify. Coming back to the other browser, submit the form for /register-from-invite. This PR fixes that bug and adds a couple tests for register_from_invite
This commit is contained in:
@@ -80,8 +80,8 @@ def _do_registration(form, service=None, send_sms=True, send_email=True):
|
||||
session['expiry_date'] = str(datetime.utcnow() + timedelta(hours=1))
|
||||
session['user_details'] = {"email": user.email_address, "id": user.id}
|
||||
else:
|
||||
user = user_api_client.get_user_by_email(form.email_address.data)
|
||||
if send_email:
|
||||
user = user_api_client.get_user_by_email(form.email_address.data)
|
||||
user_api_client.send_already_registered_email(user.id, user.email_address)
|
||||
session['expiry_date'] = str(datetime.utcnow() + timedelta(hours=1))
|
||||
session['user_details'] = {"email": user.email_address, "id": user.id}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import (
|
||||
url_for,
|
||||
session
|
||||
)
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from app.notify_client.models import InvitedUser
|
||||
|
||||
|
||||
def test_render_register_returns_template_with_form(app_):
|
||||
@@ -139,3 +141,53 @@ def test_register_with_existing_email_sends_emails(app_,
|
||||
data=user_data)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.registration_continue', _external=True)
|
||||
|
||||
|
||||
def test_register_from_invite_(app_,
|
||||
fake_uuid,
|
||||
mock_is_email_unique,
|
||||
mock_register_user,
|
||||
mock_send_verify_code,
|
||||
mock_accept_invite):
|
||||
|
||||
invited_user = InvitedUser(fake_uuid, fake_uuid, "",
|
||||
"invited@user.com",
|
||||
["manage_users"],
|
||||
"pending",
|
||||
datetime.utcnow())
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
session['invited_user'] = invited_user.serialize()
|
||||
response = client.post(url_for('main.register_from_invite'),
|
||||
data={'name': 'Registered in another Browser',
|
||||
'email_address': invited_user.email_address,
|
||||
'mobile_number': '+4407700900460',
|
||||
'service': str(invited_user.id),
|
||||
'password': 'somreallyhardthingtoguess'})
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.verify', _external=True)
|
||||
|
||||
|
||||
def test_register_from_invite_when_user_registers_in_another_browser(app_,
|
||||
api_user_active,
|
||||
mock_is_email_not_unique,
|
||||
mock_get_user_by_email,
|
||||
mock_accept_invite):
|
||||
invited_user = InvitedUser(api_user_active.id, api_user_active.id, "",
|
||||
api_user_active.email_address,
|
||||
["manage_users"],
|
||||
"pending",
|
||||
datetime.utcnow())
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
session['invited_user'] = invited_user.serialize()
|
||||
response = client.post(url_for('main.register_from_invite'),
|
||||
data={'name': 'Registered in another Browser',
|
||||
'email_address': api_user_active.email_address,
|
||||
'mobile_number': api_user_active.mobile_number,
|
||||
'service': str(api_user_active.id),
|
||||
'password': 'somreallyhardthingtoguess'})
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.verify', _external=True)
|
||||
|
||||
Reference in New Issue
Block a user