2017-02-17 14:06:09 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
import pytest
|
2018-02-20 11:22:17 +00:00
|
|
|
from flask import url_for
|
2016-01-21 12:31:09 +00:00
|
|
|
|
2023-12-15 12:16:03 -08:00
|
|
|
from app.main.views.sign_in import _reformat_keystring
|
2019-05-23 15:27:35 +01:00
|
|
|
from app.models.user import User
|
2023-11-14 07:51:56 -08:00
|
|
|
from tests.conftest import SERVICE_ONE_ID, normalize_spaces
|
2019-05-23 15:27:35 +01:00
|
|
|
|
2015-11-27 09:47:29 +00:00
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
def test_render_sign_in_template_for_new_user(client_request):
|
2019-07-16 17:01:54 +01:00
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
page = client_request.get("main.sign_in")
|
|
|
|
|
assert normalize_spaces(page.select_one("h1").text) == "Sign in"
|
|
|
|
|
assert normalize_spaces(page.select("label")[0].text) == "Email address"
|
|
|
|
|
assert page.select_one("#email_address").get("value") is None
|
|
|
|
|
assert page.select_one("#email_address")["autocomplete"] == "email"
|
|
|
|
|
assert normalize_spaces(page.select("label")[1].text) == "Password"
|
|
|
|
|
assert page.select_one("#password").get("value") is None
|
|
|
|
|
assert page.select_one("#password")["autocomplete"] == "current-password"
|
2023-07-10 12:43:45 -04:00
|
|
|
# Removing for the pilot
|
|
|
|
|
# assert page.select('main a')[0].text == 'create one now'
|
|
|
|
|
# assert page.select('main a')[0]['href'] == url_for('main.register')
|
2024-02-26 17:59:18 -05:00
|
|
|
# TODO: Fix this test to be less brittle! If the Login.gov link is enabled,
|
|
|
|
|
# then these indices need to be 1 instead of 0.
|
2024-02-26 18:07:26 -05:00
|
|
|
# Currently it's not enabled for the test or production environments.
|
2024-02-26 17:59:18 -05:00
|
|
|
assert page.select("main a")[0].text == "Forgot your password?"
|
|
|
|
|
assert page.select("main a")[0]["href"] == url_for("main.forgot_password")
|
2023-08-25 09:12:23 -07:00
|
|
|
assert "Sign in again" not in normalize_spaces(page.text)
|
2017-02-17 14:06:09 +00:00
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
def test_render_sign_in_template_with_next_link_for_password_reset(client_request):
|
2020-10-05 15:38:34 +01:00
|
|
|
client_request.logout()
|
2020-10-12 12:01:39 +01:00
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
2020-10-12 12:01:39 +01:00
|
|
|
_optional_args=f"?next=/services/{SERVICE_ONE_ID}/templates",
|
2023-08-25 09:12:23 -07:00
|
|
|
_test_page_title=False,
|
|
|
|
|
)
|
|
|
|
|
forgot_password_link = page.find("a", class_="usa-link")
|
|
|
|
|
assert forgot_password_link.text == "Forgot your password?"
|
|
|
|
|
assert forgot_password_link["href"] == url_for(
|
|
|
|
|
"main.forgot_password", next=f"/services/{SERVICE_ONE_ID}/templates"
|
2020-10-12 12:01:39 +01:00
|
|
|
)
|
2020-10-05 15:38:34 +01:00
|
|
|
|
|
|
|
|
|
2023-12-15 12:16:03 -08:00
|
|
|
def test_reformat_keystring():
|
2024-01-17 07:46:27 -08:00
|
|
|
orig = "-----BEGIN PRIVATE KEY----- blah blah blah -----END PRIVATE KEY-----"
|
2023-12-15 12:07:54 -08:00
|
|
|
expected = """-----BEGIN PRIVATE KEY-----
|
2024-01-17 07:46:27 -08:00
|
|
|
blah
|
|
|
|
|
blah
|
|
|
|
|
blah
|
2023-12-15 12:07:54 -08:00
|
|
|
-----END PRIVATE KEY-----
|
|
|
|
|
"""
|
2023-12-15 12:16:03 -08:00
|
|
|
reformatted = _reformat_keystring(orig)
|
|
|
|
|
assert reformatted == expected
|
2023-12-15 12:07:54 -08:00
|
|
|
|
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
def test_sign_in_explains_session_timeout(client_request):
|
|
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
page = client_request.get("main.sign_in", next="/foo")
|
|
|
|
|
assert (
|
|
|
|
|
"We signed you out because you have not used Notify for a while." in page.text
|
|
|
|
|
)
|
2017-02-17 14:06:09 +00:00
|
|
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
def test_sign_in_explains_other_browser(client_request, api_user_active, mocker):
|
2023-08-25 09:12:23 -07:00
|
|
|
api_user_active["current_session_id"] = str(uuid.UUID(int=1))
|
|
|
|
|
mocker.patch("app.user_api_client.get_user", return_value=api_user_active)
|
2017-02-17 14:06:09 +00:00
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
session["current_session_id"] = str(uuid.UUID(int=2))
|
2017-02-17 14:06:09 +00:00
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
page = client_request.get("main.sign_in", next="/foo")
|
2017-02-17 14:06:09 +00:00
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
assert (
|
|
|
|
|
"We signed you out because you logged in to Notify on another device"
|
|
|
|
|
in page.text
|
|
|
|
|
)
|
2017-02-17 14:06:09 +00:00
|
|
|
|
|
|
|
|
|
2018-03-08 16:51:53 +00:00
|
|
|
def test_doesnt_redirect_to_sign_in_if_no_session_info(
|
2019-04-18 12:44:18 +01:00
|
|
|
client_request,
|
|
|
|
|
api_user_active,
|
2023-07-12 12:09:44 -04:00
|
|
|
mock_get_organization_by_domain,
|
2018-03-08 16:51:53 +00:00
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
api_user_active["current_session_id"] = str(uuid.UUID(int=1))
|
2018-03-08 16:51:53 +00:00
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
session["current_session_id"] = None
|
2017-02-17 14:06:09 +00:00
|
|
|
|
2023-11-08 07:51:57 -08:00
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
session["current_session_id"] = None
|
|
|
|
|
|
|
|
|
|
client_request.get("main.add_service")
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
("db_sess_id", "cookie_sess_id"),
|
2023-08-25 09:12:23 -07:00
|
|
|
[
|
|
|
|
|
(None, None),
|
|
|
|
|
(None, uuid.UUID(int=1)), # BAD - cookie doesn't match db
|
|
|
|
|
(
|
|
|
|
|
uuid.UUID(int=1),
|
|
|
|
|
None,
|
|
|
|
|
), # BAD - has used other browsers before but this is a brand new browser with no cookie
|
|
|
|
|
(
|
|
|
|
|
uuid.UUID(int=1),
|
|
|
|
|
uuid.UUID(int=2),
|
|
|
|
|
), # BAD - this person has just signed in on a different browser
|
|
|
|
|
],
|
|
|
|
|
)
|
2017-02-17 14:06:09 +00:00
|
|
|
def test_redirect_to_sign_in_if_logged_in_from_other_browser(
|
2023-08-25 09:12:23 -07:00
|
|
|
client_request, api_user_active, mocker, db_sess_id, cookie_sess_id
|
2017-02-17 14:06:09 +00:00
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
api_user_active["current_session_id"] = db_sess_id
|
|
|
|
|
mocker.patch("app.user_api_client.get_user", return_value=api_user_active)
|
2021-12-31 12:08:14 +00:00
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
session["current_session_id"] = str(cookie_sess_id)
|
2017-02-17 14:06:09 +00:00
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.choose_account",
|
2021-12-31 12:08:14 +00:00
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
_expected_redirect=url_for("main.sign_in", next="/accounts"),
|
2021-12-31 12:08:14 +00:00
|
|
|
)
|
2015-11-27 09:47:29 +00:00
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
def test_logged_in_user_redirects_to_account(client_request):
|
2018-11-15 15:38:43 +00:00
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
2018-11-15 15:38:43 +00:00
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
_expected_redirect=url_for("main.show_accounts_or_dashboard"),
|
2018-11-15 15:38:43 +00:00
|
|
|
)
|
2016-01-22 17:24:14 +00:00
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
def test_logged_in_user_redirects_to_next_url(client_request):
|
2021-07-14 23:10:49 +01:00
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
|
|
|
|
next="/user-profile",
|
2021-07-14 23:10:49 +01:00
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
_expected_redirect=url_for("main.user_profile"),
|
2021-07-14 23:10:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
def test_logged_in_user_doesnt_do_evil_redirect(client_request):
|
2021-07-14 23:10:49 +01:00
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
|
|
|
|
next="http://www.evil.com",
|
2021-07-14 23:10:49 +01:00
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
_expected_redirect=url_for("main.show_accounts_or_dashboard"),
|
2021-07-14 23:10:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"redirect_url",
|
|
|
|
|
[
|
|
|
|
|
None,
|
|
|
|
|
f"/services/{SERVICE_ONE_ID}/templates",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
("email_address", "password"),
|
2023-08-25 09:12:23 -07:00
|
|
|
[
|
|
|
|
|
("valid@example.gsa.gov", "val1dPassw0rd!"),
|
|
|
|
|
(" valid@example.gsa.gov ", " val1dPassw0rd! "),
|
|
|
|
|
],
|
|
|
|
|
)
|
2017-11-07 16:11:31 +00:00
|
|
|
def test_process_sms_auth_sign_in_return_2fa_template(
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
api_user_active,
|
|
|
|
|
mock_send_verify_code,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_verify_password,
|
2017-12-06 20:24:25 +00:00
|
|
|
email_address,
|
2017-12-11 16:09:19 +00:00
|
|
|
password,
|
2023-08-25 09:12:23 -07:00
|
|
|
redirect_url,
|
2017-02-03 10:42:01 +00:00
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
2022-01-04 15:40:42 +00:00
|
|
|
next=redirect_url,
|
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
"email_address": email_address,
|
|
|
|
|
"password": password,
|
2022-01-04 15:40:42 +00:00
|
|
|
},
|
2023-08-25 09:12:23 -07:00
|
|
|
_expected_redirect=url_for(".two_factor_sms", next=redirect_url),
|
2022-01-04 15:40:42 +00:00
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
mock_verify_password.assert_called_with(api_user_active["id"], password)
|
|
|
|
|
mock_get_user_by_email.assert_called_with("valid@example.gsa.gov")
|
2015-11-27 16:25:56 +00:00
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"redirect_url",
|
|
|
|
|
[
|
|
|
|
|
None,
|
|
|
|
|
f"/services/{SERVICE_ONE_ID}/templates",
|
|
|
|
|
],
|
|
|
|
|
)
|
2017-11-07 16:11:31 +00:00
|
|
|
def test_process_email_auth_sign_in_return_2fa_template(
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request,
|
2017-11-07 16:11:31 +00:00
|
|
|
api_user_active_email_auth,
|
|
|
|
|
mock_send_verify_code,
|
|
|
|
|
mock_verify_password,
|
2020-10-09 11:41:06 +01:00
|
|
|
mocker,
|
2023-08-25 09:12:23 -07:00
|
|
|
redirect_url,
|
2017-11-07 16:11:31 +00:00
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
mocker.patch(
|
|
|
|
|
"app.user_api_client.get_user", return_value=api_user_active_email_auth
|
|
|
|
|
)
|
|
|
|
|
mocker.patch(
|
|
|
|
|
"app.user_api_client.get_user_by_email", return_value=api_user_active_email_auth
|
2022-01-04 15:40:42 +00:00
|
|
|
)
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
client_request.post(
|
|
|
|
|
"main.sign_in",
|
|
|
|
|
next=redirect_url,
|
|
|
|
|
_data={
|
|
|
|
|
"email_address": "valid@example.gsa.gov",
|
|
|
|
|
"password": "val1dPassw0rd!",
|
|
|
|
|
},
|
|
|
|
|
_expected_redirect=url_for(".two_factor_email_sent", next=redirect_url),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mock_send_verify_code.assert_called_with(
|
|
|
|
|
api_user_active_email_auth["id"], "email", None, redirect_url
|
|
|
|
|
)
|
|
|
|
|
mock_verify_password.assert_called_with(
|
|
|
|
|
api_user_active_email_auth["id"], "val1dPassw0rd!"
|
|
|
|
|
)
|
2017-11-07 16:11:31 +00:00
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
def test_should_return_locked_out_true_when_user_is_locked(
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
mock_get_user_by_email_locked,
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
2022-01-04 15:40:42 +00:00
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
"email_address": "valid@example.gsa.gov",
|
|
|
|
|
"password": "whatIsMyPassword!",
|
2022-01-04 15:40:42 +00:00
|
|
|
},
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
assert "The email address or password you entered is incorrect" in page.text
|
2015-11-30 16:52:28 +00:00
|
|
|
|
2015-11-30 16:44:59 +00:00
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
def test_should_return_200_when_user_does_not_exist(
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
mock_get_user_by_email_not_found,
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
|
|
|
|
_data={"email_address": "notfound@gsa.gov", "password": "doesNotExist!"},
|
2022-01-04 15:40:42 +00:00
|
|
|
_expected_status=200,
|
|
|
|
|
)
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
assert "The email address or password you entered is incorrect" in page.text
|
2015-12-09 12:11:43 +00:00
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
def test_should_return_redirect_when_user_is_pending(
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
mock_get_user_by_email_pending,
|
2021-06-10 19:07:35 +01:00
|
|
|
api_user_pending,
|
2017-02-03 10:42:01 +00:00
|
|
|
mock_verify_password,
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
2022-01-04 15:40:42 +00:00
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
"email_address": "pending_user@example.gsa.gov",
|
|
|
|
|
"password": "val1dPassw0rd!",
|
2022-01-04 15:40:42 +00:00
|
|
|
},
|
2023-08-25 09:12:23 -07:00
|
|
|
_expected_redirect=url_for("main.resend_email_verification"),
|
2021-06-10 19:07:35 +01:00
|
|
|
)
|
2022-01-04 15:40:42 +00:00
|
|
|
with client_request.session_transaction() as s:
|
2023-08-25 09:12:23 -07:00
|
|
|
assert s["user_details"] == {
|
|
|
|
|
"email": api_user_pending["email_address"],
|
|
|
|
|
"id": api_user_pending["id"],
|
2021-06-10 19:07:35 +01:00
|
|
|
}
|
2016-09-06 15:44:33 +01:00
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"redirect_url",
|
|
|
|
|
[
|
|
|
|
|
None,
|
|
|
|
|
f"/services/{SERVICE_ONE_ID}/templates",
|
|
|
|
|
],
|
|
|
|
|
)
|
2017-02-03 10:42:01 +00:00
|
|
|
def test_should_attempt_redirect_when_user_is_pending(
|
2023-08-25 09:12:23 -07:00
|
|
|
client_request, mock_get_user_by_email_pending, mock_verify_password, redirect_url
|
2017-02-03 10:42:01 +00:00
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
2022-01-04 15:40:42 +00:00
|
|
|
next=redirect_url,
|
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
"email_address": "pending_user@example.gsa.gov",
|
|
|
|
|
"password": "val1dPassw0rd!",
|
2022-01-04 15:40:42 +00:00
|
|
|
},
|
2023-08-25 09:12:23 -07:00
|
|
|
_expected_redirect=url_for("main.resend_email_verification", next=redirect_url),
|
2022-01-04 15:40:42 +00:00
|
|
|
)
|
2017-12-21 16:42:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_email_address_is_treated_case_insensitively_when_signing_in_as_invited_user(
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request,
|
2017-12-21 16:42:16 +00:00
|
|
|
mocker,
|
|
|
|
|
mock_verify_password,
|
|
|
|
|
api_user_active,
|
|
|
|
|
sample_invite,
|
|
|
|
|
mock_accept_invite,
|
2021-03-16 17:58:27 +00:00
|
|
|
mock_send_verify_code,
|
|
|
|
|
mock_get_invited_user_by_id,
|
2017-12-21 16:42:16 +00:00
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
sample_invite["email_address"] = "TEST@user.gsa.gov"
|
2017-12-21 16:42:16 +00:00
|
|
|
|
2019-05-23 15:27:35 +01:00
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
"app.models.user.User.from_email_address_and_password_or_none",
|
2019-05-23 15:27:35 +01:00
|
|
|
return_value=User(api_user_active),
|
|
|
|
|
)
|
2017-12-21 16:42:16 +00:00
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
session["invited_user_id"] = sample_invite["id"]
|
2017-12-21 16:42:16 +00:00
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
|
|
|
|
_data={"email_address": "test@user.gsa.gov", "password": "val1dPassw0rd!"},
|
2022-01-04 15:40:42 +00:00
|
|
|
)
|
2017-12-21 16:42:16 +00:00
|
|
|
|
|
|
|
|
assert mock_accept_invite.called
|
|
|
|
|
assert mock_send_verify_code.called
|
2023-08-25 09:12:23 -07:00
|
|
|
mock_get_invited_user_by_id.assert_called_once_with(sample_invite["id"])
|
2021-07-02 18:11:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_when_signing_in_as_invited_user_you_cannot_accept_an_invite_for_another_email_address(
|
|
|
|
|
client_request,
|
|
|
|
|
mocker,
|
|
|
|
|
mock_verify_password,
|
|
|
|
|
api_user_active,
|
|
|
|
|
sample_invite,
|
|
|
|
|
mock_accept_invite,
|
|
|
|
|
mock_send_verify_code,
|
|
|
|
|
mock_get_invited_user_by_id,
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
sample_invite["email_address"] = "some_other_user@user.gsa.gov"
|
2021-07-02 18:11:53 +01:00
|
|
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
"app.models.user.User.from_email_address_and_password_or_none",
|
2021-07-02 18:11:53 +01:00
|
|
|
return_value=User(api_user_active),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
client_request.logout()
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
session["invited_user_id"] = sample_invite["id"]
|
2021-07-02 18:11:53 +01:00
|
|
|
|
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
"main.sign_in",
|
|
|
|
|
_data={"email_address": "test@user.gsa.gov", "password": "val1dPassw0rd!"},
|
|
|
|
|
_expected_status=403,
|
2021-07-02 18:11:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert mock_accept_invite.called is False
|
|
|
|
|
assert mock_send_verify_code.called is False
|
2023-08-25 09:12:23 -07:00
|
|
|
assert (
|
|
|
|
|
page.select_one(".banner-dangerous").text.strip()
|
|
|
|
|
== "You cannot accept an invite for another person."
|
|
|
|
|
)
|