2021-08-17 16:38:37 +01:00
|
|
|
|
from unittest.mock import ANY, Mock, call
|
2016-03-01 17:23:23 +00:00
|
|
|
|
|
2018-07-05 11:45:09 +01:00
|
|
|
|
import pytest
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from flask import url_for
|
2021-08-17 16:38:37 +01:00
|
|
|
|
from freezegun import freeze_time
|
2018-03-08 12:47:24 +00:00
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2018-02-20 11:22:17 +00:00
|
|
|
|
|
2016-03-04 14:42:52 +00:00
|
|
|
|
import app
|
2021-05-19 10:56:13 +01:00
|
|
|
|
from tests import service_json
|
2018-07-05 11:45:09 +01:00
|
|
|
|
from tests.conftest import (
|
|
|
|
|
|
SERVICE_ONE_ID,
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user,
|
|
|
|
|
|
create_active_user_with_permissions,
|
2019-12-19 11:19:28 +00:00
|
|
|
|
normalize_spaces,
|
2018-07-05 11:45:09 +01:00
|
|
|
|
)
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
2024-01-09 10:19:03 -08:00
|
|
|
|
FAKE_ONE_OFF_NOTIFICATION = {
|
|
|
|
|
|
"links": {},
|
|
|
|
|
|
"notifications": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"api_key": None,
|
|
|
|
|
|
"billable_units": 0,
|
|
|
|
|
|
"carrier": None,
|
|
|
|
|
|
"client_reference": None,
|
|
|
|
|
|
"created_at": "2023-12-14T20:35:55+00:00",
|
|
|
|
|
|
"created_by": {
|
|
|
|
|
|
"email_address": "grsrbsrgsrf@fake.gov",
|
|
|
|
|
|
"id": "de059e0a-42e5-48bb-939e-4f76804ab739",
|
|
|
|
|
|
"name": "grsrbsrgsrf",
|
|
|
|
|
|
},
|
|
|
|
|
|
"document_download_count": None,
|
|
|
|
|
|
"id": "a3442b43-0ba1-4854-9e0a-d2fba1cc9b81",
|
|
|
|
|
|
"international": False,
|
|
|
|
|
|
"job": {
|
|
|
|
|
|
"id": "55b242b5-9f62-4271-aff7-039e9c320578",
|
|
|
|
|
|
"original_file_name": "1127b78e-a4a8-4b70-8f4f-9f4fbf03ece2.csv",
|
|
|
|
|
|
},
|
|
|
|
|
|
"job_row_number": 0,
|
|
|
|
|
|
"key_name": None,
|
|
|
|
|
|
"key_type": "normal",
|
|
|
|
|
|
"normalised_to": "+16615555555",
|
|
|
|
|
|
"notification_type": "sms",
|
|
|
|
|
|
"personalisation": {
|
|
|
|
|
|
"dayofweek": "2",
|
|
|
|
|
|
"favecolor": "3",
|
|
|
|
|
|
"phonenumber": "+16615555555",
|
|
|
|
|
|
},
|
|
|
|
|
|
"phone_prefix": "1",
|
|
|
|
|
|
"provider_response": None,
|
|
|
|
|
|
"rate_multiplier": 1.0,
|
|
|
|
|
|
"reference": None,
|
|
|
|
|
|
"reply_to_text": "development",
|
|
|
|
|
|
"sent_at": None,
|
|
|
|
|
|
"sent_by": None,
|
|
|
|
|
|
"service": "f62d840f-8bcb-4b36-b959-4687e16dd1a1",
|
|
|
|
|
|
"status": "created",
|
|
|
|
|
|
"template": {
|
|
|
|
|
|
"content": "((day of week)) and ((fave color))",
|
|
|
|
|
|
"id": "bd9caa7e-00ee-4c5a-839e-10ae1a7e6f73",
|
|
|
|
|
|
"name": "personalized",
|
|
|
|
|
|
"redact_personalisation": False,
|
|
|
|
|
|
"subject": None,
|
|
|
|
|
|
"template_type": "sms",
|
|
|
|
|
|
"version": 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
"to": "+16615555555",
|
|
|
|
|
|
"updated_at": None,
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
"page_size": 50,
|
|
|
|
|
|
"total": 1,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-26 11:29:03 -08:00
|
|
|
|
MOCK_JOBS = {
|
|
|
|
|
|
"data": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"archived": False,
|
|
|
|
|
|
"created_at": "2024-01-04T20:43:52+00:00",
|
|
|
|
|
|
"created_by": {
|
|
|
|
|
|
"id": "mocked_user_id",
|
|
|
|
|
|
"name": "mocked_user",
|
|
|
|
|
|
},
|
|
|
|
|
|
"id": "mocked_notification_id",
|
|
|
|
|
|
"job_status": "finished",
|
|
|
|
|
|
"notification_count": 1,
|
|
|
|
|
|
"original_file_name": "mocked_file.csv",
|
|
|
|
|
|
"processing_finished": "2024-01-25T23:02:25+00:00",
|
|
|
|
|
|
"processing_started": "2024-01-25T23:02:24+00:00",
|
|
|
|
|
|
"scheduled_for": None,
|
|
|
|
|
|
"service": "21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3",
|
|
|
|
|
|
"service_name": {"name": "Mock Texting Service"},
|
|
|
|
|
|
"statistics": [{"count": 1, "status": "sending"}],
|
|
|
|
|
|
"template": "6a456418-498c-4c86-b0cd-9403c14a216c",
|
|
|
|
|
|
"template_name": "Mock Template Name",
|
2024-01-09 10:19:03 -08:00
|
|
|
|
"template_type": "sms",
|
2024-01-26 11:29:03 -08:00
|
|
|
|
"template_version": 3,
|
|
|
|
|
|
"updated_at": "2024-01-25T23:02:25+00:00",
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
2024-01-09 10:19:03 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-26 11:32:42 -08:00
|
|
|
|
|
2021-05-25 16:54:37 +01:00
|
|
|
|
@pytest.fixture()
|
2023-09-25 17:55:42 -04:00
|
|
|
|
def _mock_no_users_for_service(mocker):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch("app.models.user.Users.client_method", return_value=[])
|
2021-05-25 16:54:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.fixture()
|
2021-05-25 17:20:04 +01:00
|
|
|
|
def mock_get_existing_user_by_email(mocker, api_user_active):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user_by_email", return_value=api_user_active
|
|
|
|
|
|
)
|
2021-05-25 17:00:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.fixture()
|
2021-05-25 17:55:52 +01:00
|
|
|
|
def mock_check_invite_token(mocker, sample_invite):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
return mocker.patch("app.invite_api_client.check_token", return_value=sample_invite)
|
2021-05-25 17:55:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@freeze_time("2021-12-12 12:12:12")
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_check_invite_token,
|
2021-05-25 17:20:04 +01:00
|
|
|
|
mock_get_existing_user_by_email,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_add_user_to_service,
|
2017-11-15 17:19:32 +00:00
|
|
|
|
mock_get_service,
|
2017-11-01 16:02:05 +00:00
|
|
|
|
mocker,
|
2021-03-05 12:19:36 +00:00
|
|
|
|
mock_events,
|
|
|
|
|
|
mock_get_user,
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
expected_service = service_one["id"]
|
|
|
|
|
|
expected_permissions = {
|
|
|
|
|
|
"view_activity",
|
|
|
|
|
|
"send_messages",
|
|
|
|
|
|
"manage_service",
|
|
|
|
|
|
"manage_api_keys",
|
|
|
|
|
|
}
|
2016-02-29 17:35:21 +00:00
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
"main.service_dashboard", service_id=expected_service
|
|
|
|
|
|
),
|
2022-01-04 15:40:42 +00:00
|
|
|
|
)
|
2016-02-29 17:35:21 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_check_invite_token.assert_called_with("thisisnotarealtoken")
|
|
|
|
|
|
mock_get_existing_user_by_email.assert_called_with("invited_user@test.gsa.gov")
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert mock_accept_invite.call_count == 1
|
2019-05-23 15:27:35 +01:00
|
|
|
|
mock_add_user_to_service.assert_called_with(
|
|
|
|
|
|
expected_service,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
api_user_active["id"],
|
2019-05-23 15:27:35 +01:00
|
|
|
|
expected_permissions,
|
|
|
|
|
|
[],
|
|
|
|
|
|
)
|
2016-02-29 17:35:21 +00:00
|
|
|
|
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2019-03-15 14:57:39 +00:00
|
|
|
|
def test_existing_user_with_no_permissions_or_folder_permissions_accept_invite(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_check_invite_token,
|
2021-05-25 17:20:04 +01:00
|
|
|
|
mock_get_existing_user_by_email,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_add_user_to_service,
|
2017-11-15 17:19:32 +00:00
|
|
|
|
mock_get_service,
|
2021-03-05 12:19:36 +00:00
|
|
|
|
mock_events,
|
|
|
|
|
|
mock_get_user,
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
expected_service = service_one["id"]
|
|
|
|
|
|
sample_invite["permissions"] = ""
|
2018-03-01 16:59:01 +00:00
|
|
|
|
expected_permissions = set()
|
2019-03-15 14:57:39 +00:00
|
|
|
|
expected_folder_permissions = []
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch("app.invite_api_client.accept_invite", return_value=sample_invite)
|
2016-03-11 12:50:25 +00:00
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_add_user_to_service.assert_called_with(
|
|
|
|
|
|
expected_service,
|
|
|
|
|
|
api_user_active["id"],
|
|
|
|
|
|
expected_permissions,
|
|
|
|
|
|
expected_folder_permissions,
|
|
|
|
|
|
)
|
2016-03-11 12:50:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_if_existing_user_accepts_twice_they_redirect_to_sign_in(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
sample_invite,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service,
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
|
|
|
|
|
# Logging out updates the current session ID to `None`
|
|
|
|
|
|
mock_update_user_attribute.reset_mock()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["status"] = "accepted"
|
2016-03-10 11:57:40 +00:00
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-02-16 13:33:32 +00:00
|
|
|
|
assert (
|
|
|
|
|
|
page.h1.string,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page.select("main p")[0].text.strip(),
|
2017-02-16 13:33:32 +00:00
|
|
|
|
) == (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"You need to sign in again",
|
2024-03-19 15:53:38 -04:00
|
|
|
|
# TODO: Improve this given Login.gov configuration.
|
2024-04-15 15:50:42 -04:00
|
|
|
|
"We signed you out because you have not used Notify for a while.",
|
2017-02-16 13:33:32 +00:00
|
|
|
|
)
|
2021-08-17 16:38:37 +01:00
|
|
|
|
# We don’t let people update `email_access_validated_at` using an
|
|
|
|
|
|
# already-accepted invite
|
|
|
|
|
|
assert mock_update_user_attribute.called is False
|
2016-03-10 11:57:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2018-07-05 11:45:09 +01:00
|
|
|
|
def test_invite_goes_in_session(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_check_invite_token,
|
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
|
mock_add_user_to_service,
|
|
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["email_address"] = "test@user.gsa.gov"
|
2018-07-05 11:45:09 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2018-07-05 11:45:09 +01:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.service_dashboard",
|
2018-07-05 11:45:09 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
),
|
|
|
|
|
|
_follow_redirects=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert session["invited_user_id"] == sample_invite["id"]
|
2018-07-05 11:45:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("user", "landing_page_title"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(create_active_user_with_permissions(), "Dashboard"),
|
|
|
|
|
|
(create_active_caseworking_user(), "Templates"),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2018-07-05 11:45:09 +01:00
|
|
|
|
def test_accepting_invite_removes_invite_from_session(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_check_invite_token,
|
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
|
mock_add_user_to_service,
|
|
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_template_statistics,
|
2020-09-28 14:28:23 +01:00
|
|
|
|
mock_has_no_jobs,
|
2018-07-05 11:45:09 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-11-01 17:11:58 +00:00
|
|
|
|
mock_get_template_folders,
|
2022-04-29 16:25:58 +01:00
|
|
|
|
mock_get_annual_usage_for_service,
|
|
|
|
|
|
mock_get_monthly_usage_for_service,
|
2019-10-25 13:27:46 +01:00
|
|
|
|
mock_get_free_sms_fragment_limit,
|
2018-07-05 11:45:09 +01:00
|
|
|
|
mock_get_inbound_sms_summary,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_api_keys,
|
2018-07-05 11:45:09 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
user,
|
|
|
|
|
|
landing_page_title,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["email_address"] = user["email_address"]
|
2018-07-05 11:45:09 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.login(user)
|
2024-01-26 11:29:03 -08:00
|
|
|
|
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
2024-01-09 10:38:29 -08:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notifications_for_service",
|
|
|
|
|
|
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
|
|
|
|
|
)
|
2018-07-05 11:45:09 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2018-07-05 11:45:09 +01:00
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("h1").text) == landing_page_title
|
2018-07-05 11:45:09 +01:00
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "invited_user_id" not in session
|
2018-07-05 11:45:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@freeze_time("2021-12-12T12:12:12")
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_existing_user_of_service_get_redirected_to_signin(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_user_by_email,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_accept_invite,
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute,
|
2017-02-03 10:42:01 +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"] = api_user_active["email_address"]
|
|
|
|
|
|
mocker.patch("app.models.user.Users.client_method", return_value=[api_user_active])
|
2016-03-15 15:32:30 +00:00
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-02-16 13:33:32 +00:00
|
|
|
|
assert (
|
|
|
|
|
|
page.h1.string,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page.select("main p")[0].text.strip(),
|
2017-02-16 13:33:32 +00:00
|
|
|
|
) == (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"You need to sign in again",
|
2024-03-19 15:53:38 -04:00
|
|
|
|
# TODO: Improve this given Login.gov configuration.
|
2024-04-15 15:50:42 -04:00
|
|
|
|
"We signed you out because you have not used Notify for a while.",
|
2017-02-16 13:33:32 +00:00
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert mock_accept_invite.call_count == 1
|
2016-03-15 15:32:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2020-05-19 13:49:17 +01:00
|
|
|
|
def test_accept_invite_redirects_if_api_raises_an_error_that_they_are_already_part_of_the_service(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2020-05-19 13:49:17 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
sample_invite,
|
2021-05-25 17:27:30 +01:00
|
|
|
|
mock_get_existing_user_by_email,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2020-05-19 13:49:17 +01:00
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_get_service,
|
2021-03-05 12:19:36 +00:00
|
|
|
|
mock_get_user,
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute,
|
2020-05-19 13:49:17 +01: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.add_user_to_service",
|
|
|
|
|
|
side_effect=HTTPError(
|
|
|
|
|
|
response=Mock(
|
|
|
|
|
|
status_code=400,
|
|
|
|
|
|
json={
|
|
|
|
|
|
"result": "error",
|
|
|
|
|
|
"message": {
|
|
|
|
|
|
f"User id: {api_user_active['id']} already part of service id: {SERVICE_ONE_ID}"
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
message=f"User id: {api_user_active['id']} already part of service id: {SERVICE_ONE_ID}",
|
2020-05-19 13:49:17 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2020-05-19 13:49:17 +01:00
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_follow_redirects=False,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_redirect=url_for("main.service_dashboard", service_id=SERVICE_ONE_ID),
|
2022-01-04 15:40:42 +00:00
|
|
|
|
)
|
2020-05-19 13:49:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_check_invite_token,
|
2021-05-25 17:20:04 +01:00
|
|
|
|
mock_get_existing_user_by_email,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_add_user_to_service,
|
|
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_get_service,
|
2017-11-01 16:02:05 +00:00
|
|
|
|
mocker,
|
2021-03-05 12:19:36 +00:00
|
|
|
|
mock_events,
|
|
|
|
|
|
mock_get_user,
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
expected_service = service_one["id"]
|
|
|
|
|
|
expected_permissions = {
|
|
|
|
|
|
"view_activity",
|
|
|
|
|
|
"send_messages",
|
|
|
|
|
|
"manage_service",
|
|
|
|
|
|
"manage_api_keys",
|
|
|
|
|
|
}
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_check_invite_token.assert_called_with("thisisnotarealtoken")
|
|
|
|
|
|
mock_get_existing_user_by_email.assert_called_with("invited_user@test.gsa.gov")
|
|
|
|
|
|
mock_add_user_to_service.assert_called_with(
|
|
|
|
|
|
expected_service,
|
|
|
|
|
|
api_user_active["id"],
|
|
|
|
|
|
expected_permissions,
|
|
|
|
|
|
sample_invite["folder_permissions"],
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert mock_accept_invite.call_count == 1
|
2017-02-16 13:33:32 +00:00
|
|
|
|
assert (
|
|
|
|
|
|
page.h1.string,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page.select("main p")[0].text.strip(),
|
2017-02-16 13:33:32 +00:00
|
|
|
|
) == (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"You need to sign in again",
|
2024-03-19 15:53:38 -04:00
|
|
|
|
# TODO: Improve this given Login.gov configuration.
|
2024-04-15 15:50:42 -04:00
|
|
|
|
"We signed you out because you have not used Notify for a while.",
|
2017-02-16 13:33:32 +00:00
|
|
|
|
)
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_new_user_accept_invite_calls_api_and_redirects_to_registration(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
mock_check_invite_token,
|
|
|
|
|
|
mock_dont_get_user_by_email,
|
|
|
|
|
|
mock_add_user_to_service,
|
|
|
|
|
|
mock_get_service,
|
2017-11-01 16:02:05 +00:00
|
|
|
|
mocker,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
|
|
|
|
|
_expected_redirect="/register-from-invite",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
)
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_check_invite_token.assert_called_with("thisisnotarealtoken")
|
|
|
|
|
|
mock_dont_get_user_by_email.assert_called_with("invited_user@test.gsa.gov")
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_new_user_accept_invite_calls_api_and_views_registration_page(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
service_one,
|
2021-05-25 17:20:04 +01:00
|
|
|
|
sample_invite,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_check_invite_token,
|
|
|
|
|
|
mock_dont_get_user_by_email,
|
2021-03-08 12:51:35 +00:00
|
|
|
|
mock_get_invited_user_by_id,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_add_user_to_service,
|
|
|
|
|
|
mock_get_service,
|
2017-11-01 16:02:05 +00:00
|
|
|
|
mocker,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
2016-03-07 11:55:18 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_check_invite_token.assert_called_with("thisisnotarealtoken")
|
|
|
|
|
|
mock_dont_get_user_by_email.assert_called_with("invited_user@test.gsa.gov")
|
|
|
|
|
|
mock_get_invited_user_by_id.assert_called_once_with(sample_invite["id"])
|
2016-03-07 11:55:18 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.h1.string.strip() == "Create an account"
|
2016-03-07 11:55:18 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("main p").text) == (
|
|
|
|
|
|
"Your account will be created with this email address: "
|
|
|
|
|
|
"invited_user@test.gsa.gov"
|
2018-07-02 09:16:48 +01:00
|
|
|
|
)
|
2016-03-07 11:55:18 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form = page.find("form")
|
|
|
|
|
|
name = form.find("input", id="name")
|
|
|
|
|
|
password = form.find("input", id="password")
|
|
|
|
|
|
service = form.find("input", type="hidden", id="service")
|
|
|
|
|
|
email = form.find("input", type="hidden", id="email_address")
|
2016-03-09 11:21:53 +00:00
|
|
|
|
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert email
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert email.attrs["value"] == "invited_user@test.gsa.gov"
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert name
|
|
|
|
|
|
assert password
|
|
|
|
|
|
assert service
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert service.attrs["value"] == service_one["id"]
|
2016-03-07 11:55:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_cancelled_invited_user_accepts_invited_redirect_to_cancelled_invitation(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_get_service,
|
2019-12-19 11:19:28 +00:00
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_check_invite_token,
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
|
|
|
|
|
mock_update_user_attribute.reset_mock()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["status"] = "cancelled"
|
|
|
|
|
|
page = client_request.get("main.accept_invite", token="thisisnotarealtoken")
|
2016-03-04 14:42:52 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
app.invite_api_client.check_token.assert_called_with("thisisnotarealtoken")
|
2022-01-04 15:40:42 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.h1.string.strip() == "The invitation you were sent has been cancelled"
|
2021-08-17 16:38:37 +01:00
|
|
|
|
# We don’t let people update `email_access_validated_at` using an
|
|
|
|
|
|
# cancelled invite
|
|
|
|
|
|
assert mock_update_user_attribute.called is False
|
2016-03-04 14:42:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("admin_endpoint", "api_endpoint"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
("main.accept_invite", "app.invite_api_client.check_token"),
|
|
|
|
|
|
("main.accept_org_invite", "app.org_invite_api_client.check_token"),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2018-03-08 12:47:24 +00:00
|
|
|
|
def test_new_user_accept_invite_with_malformed_token(
|
2020-03-06 11:53:55 +00:00
|
|
|
|
admin_endpoint,
|
|
|
|
|
|
api_endpoint,
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2018-03-08 12:47:24 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
api_endpoint,
|
|
|
|
|
|
side_effect=HTTPError(
|
|
|
|
|
|
response=Mock(
|
|
|
|
|
|
status_code=400,
|
|
|
|
|
|
json={
|
|
|
|
|
|
"result": "error",
|
|
|
|
|
|
"message": {
|
|
|
|
|
|
"invitation": {
|
|
|
|
|
|
"Something’s wrong with this link. Make sure you’ve copied the whole thing."
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
message={
|
|
|
|
|
|
"invitation": "Something’s wrong with this link. Make sure you’ve copied the whole thing."
|
|
|
|
|
|
},
|
2018-03-08 12:47:24 +00:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2018-03-08 12:47:24 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
admin_endpoint, token="thisisnotarealtoken", _follow_redirects=True
|
|
|
|
|
|
)
|
2018-03-08 12:47:24 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
normalize_spaces(page.select_one(".banner-dangerous").text)
|
|
|
|
|
|
== "Something’s wrong with this link. Make sure you’ve copied the whole thing."
|
|
|
|
|
|
)
|
2018-03-08 12:47:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_new_user_accept_invite_completes_new_registration_redirects_to_verify(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_check_invite_token,
|
|
|
|
|
|
mock_dont_get_user_by_email,
|
2018-02-19 16:53:29 +00:00
|
|
|
|
mock_email_is_not_already_in_use,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_register_user,
|
|
|
|
|
|
mock_send_verify_code,
|
2021-03-08 12:51:35 +00:00
|
|
|
|
mock_get_invited_user_by_id,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_add_user_to_service,
|
|
|
|
|
|
mock_get_service,
|
2017-11-01 16:02:05 +00:00
|
|
|
|
mocker,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
expected_redirect_location = "/register-from-invite"
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_expected_redirect=expected_redirect_location,
|
|
|
|
|
|
)
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert session.get("invited_user_id") == sample_invite["id"]
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
data = {
|
|
|
|
|
|
"service": sample_invite["service"],
|
|
|
|
|
|
"email_address": sample_invite["email_address"],
|
|
|
|
|
|
"from_user": sample_invite["from_user"],
|
|
|
|
|
|
"password": "longpassword",
|
|
|
|
|
|
"mobile_number": "+12027890123",
|
|
|
|
|
|
"name": "Invited User",
|
|
|
|
|
|
"auth_type": "email_auth",
|
|
|
|
|
|
}
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
expected_redirect_location = "/verify"
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.register_from_invite",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_data=data,
|
|
|
|
|
|
_expected_redirect=expected_redirect_location,
|
|
|
|
|
|
)
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_send_verify_code.assert_called_once_with(ANY, "sms", data["mobile_number"])
|
|
|
|
|
|
mock_get_invited_user_by_id.assert_called_once_with(sample_invite["id"])
|
2016-03-15 16:58:26 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_register_user.assert_called_with(
|
|
|
|
|
|
data["name"],
|
|
|
|
|
|
data["email_address"],
|
|
|
|
|
|
data["mobile_number"],
|
|
|
|
|
|
data["password"],
|
|
|
|
|
|
data["auth_type"],
|
|
|
|
|
|
)
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert mock_accept_invite.call_count == 1
|
2016-06-08 11:52:26 +01:00
|
|
|
|
|
2016-03-02 15:25:04 +00:00
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_signed_in_existing_user_cannot_use_anothers_invite(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_users_for_service", return_value=[api_user_active]
|
|
|
|
|
|
)
|
2016-03-30 16:16:34 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
_expected_status=403,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.h1.string.strip() == "You’re not allowed to see this page"
|
|
|
|
|
|
flash_banners = page.find_all("div", class_="banner-dangerous")
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert len(flash_banners) == 1
|
2020-05-29 17:25:11 +01:00
|
|
|
|
banner_contents = normalize_spaces(flash_banners[0].text)
|
2022-08-05 00:25:03 -07:00
|
|
|
|
assert "You’re signed in as test@user.gsa.gov." in banner_contents
|
2017-02-03 12:07:21 +00:00
|
|
|
|
assert "This invite is for another email address." in banner_contents
|
|
|
|
|
|
assert "Sign out and click the link again to accept this invite." in banner_contents
|
|
|
|
|
|
assert mock_accept_invite.call_count == 0
|
2016-03-30 16:16:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-12-21 16:42:16 +00:00
|
|
|
|
def test_accept_invite_does_not_treat_email_addresses_as_case_sensitive(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-12-21 16:42:16 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_accept_invite,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_get_user_by_email,
|
2017-12-21 16:42:16 +00:00
|
|
|
|
):
|
2022-08-05 00:25:03 -07:00
|
|
|
|
# the email address of api_user_active is 'test@user.gsa.gov'
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["email_address"] = "TEST@user.gsa.gov"
|
|
|
|
|
|
mocker.patch("app.models.user.Users.client_method", return_value=[api_user_active])
|
2017-12-21 16:42:16 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.service_dashboard",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2017-12-21 16:42:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
2024-04-19 13:53:32 -07:00
|
|
|
|
@pytest.mark.skip("TODO unskip asap")
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2017-11-14 13:30:31 +00:00
|
|
|
|
def test_new_invited_user_verifies_and_added_to_service(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-11-14 13:30:31 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_check_invite_token,
|
|
|
|
|
|
mock_dont_get_user_by_email,
|
2018-02-19 16:53:29 +00:00
|
|
|
|
mock_email_is_not_already_in_use,
|
2017-11-14 13:30:31 +00:00
|
|
|
|
mock_register_user,
|
|
|
|
|
|
mock_send_verify_code,
|
|
|
|
|
|
mock_check_verify_code,
|
|
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_update_user_attribute,
|
|
|
|
|
|
mock_add_user_to_service,
|
|
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_get_service,
|
2021-03-08 12:51:35 +00:00
|
|
|
|
mock_get_invited_user_by_id,
|
2017-11-14 13:30:31 +00:00
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_template_statistics,
|
2020-09-28 14:28:23 +01:00
|
|
|
|
mock_has_no_jobs,
|
2017-11-14 13:30:31 +00:00
|
|
|
|
mock_has_permissions,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2022-04-29 16:25:58 +01:00
|
|
|
|
mock_get_annual_usage_for_service,
|
2019-10-25 13:27:46 +01:00
|
|
|
|
mock_get_free_sms_fragment_limit,
|
2018-05-02 10:27:01 +01:00
|
|
|
|
mock_create_event,
|
2017-11-14 13:30:31 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2024-04-19 13:53:32 -07:00
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.main.views.verify.service_api_client.retrieve_service_invite_data",
|
|
|
|
|
|
return_value={},
|
|
|
|
|
|
)
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
|
|
|
|
|
|
2017-11-14 13:30:31 +00:00
|
|
|
|
# visit accept token page
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
|
|
|
|
|
_expected_redirect=url_for("main.register_from_invite"),
|
2022-01-04 15:40:42 +00:00
|
|
|
|
)
|
2024-01-26 11:29:03 -08:00
|
|
|
|
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
2024-01-09 10:19:03 -08:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notifications_for_service",
|
|
|
|
|
|
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
|
|
|
|
|
)
|
2017-11-14 13:30:31 +00:00
|
|
|
|
|
|
|
|
|
|
# get redirected to register from invite
|
|
|
|
|
|
data = {
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"service": sample_invite["service"],
|
|
|
|
|
|
"email_address": sample_invite["email_address"],
|
|
|
|
|
|
"from_user": sample_invite["from_user"],
|
|
|
|
|
|
"password": "longpassword",
|
|
|
|
|
|
"mobile_number": "+12027890123",
|
|
|
|
|
|
"name": "Invited User",
|
|
|
|
|
|
"auth_type": "sms_auth",
|
2017-11-14 13:30:31 +00:00
|
|
|
|
}
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.register_from_invite",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_data=data,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_redirect=url_for("main.verify"),
|
2022-01-04 15:40:42 +00:00
|
|
|
|
)
|
2017-11-14 13:30:31 +00:00
|
|
|
|
|
|
|
|
|
|
# that sends user on to verify
|
2022-01-04 15:40:42 +00:00
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.verify",
|
|
|
|
|
|
_data={"sms_code": "123456"},
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
2017-11-14 13:30:31 +00:00
|
|
|
|
|
|
|
|
|
|
# when they post codes back to admin user should be added to
|
|
|
|
|
|
# service and sent on to dash board
|
2023-08-25 09:12:23 -07:00
|
|
|
|
expected_permissions = {
|
|
|
|
|
|
"view_activity",
|
|
|
|
|
|
"send_messages",
|
|
|
|
|
|
"manage_service",
|
|
|
|
|
|
"manage_api_keys",
|
|
|
|
|
|
}
|
2017-11-14 13:30:31 +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
|
|
|
|
assert "invited_user_id" not in session
|
|
|
|
|
|
new_user_id = session["user_id"]
|
|
|
|
|
|
mock_add_user_to_service.assert_called_with(
|
|
|
|
|
|
data["service"], new_user_id, expected_permissions, []
|
|
|
|
|
|
)
|
|
|
|
|
|
mock_accept_invite.assert_called_with(data["service"], sample_invite["id"])
|
|
|
|
|
|
mock_check_verify_code.assert_called_once_with(new_user_id, "123456", "sms")
|
|
|
|
|
|
assert service_one["id"] == session["service_id"]
|
2017-11-14 13:30:31 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.find("h1").text == "Dashboard"
|
2017-11-14 13:30:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("service_permissions", "trial_mode", "expected_endpoint", "extra_args"),
|
|
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
([], True, "main.service_dashboard", {}),
|
|
|
|
|
|
([], False, "main.service_dashboard", {}),
|
2023-09-25 17:55:42 -04:00
|
|
|
|
],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2024-04-19 13:53:32 -07:00
|
|
|
|
@pytest.mark.skip("TODO unskip asap")
|
2021-05-19 10:56:13 +01:00
|
|
|
|
def test_new_invited_user_is_redirected_to_correct_place(
|
|
|
|
|
|
mocker,
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2021-05-19 10:56:13 +01:00
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_check_invite_token,
|
|
|
|
|
|
mock_check_verify_code,
|
|
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_dont_get_user_by_email,
|
|
|
|
|
|
mock_add_user_to_service,
|
|
|
|
|
|
mock_get_invited_user_by_id,
|
|
|
|
|
|
mock_events,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
service_permissions,
|
|
|
|
|
|
trial_mode,
|
|
|
|
|
|
expected_endpoint,
|
|
|
|
|
|
extra_args,
|
|
|
|
|
|
):
|
2024-04-19 13:53:32 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.main.views.verify.service_api_client.retrieve_service_invite_data",
|
|
|
|
|
|
return_value={},
|
|
|
|
|
|
)
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.service_api_client.get_service",
|
|
|
|
|
|
return_value={
|
|
|
|
|
|
"data": service_json(
|
|
|
|
|
|
sample_invite["service"],
|
|
|
|
|
|
restricted=trial_mode,
|
|
|
|
|
|
permissions=service_permissions,
|
|
|
|
|
|
)
|
|
|
|
|
|
},
|
|
|
|
|
|
)
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
)
|
2021-05-19 10:56:13 +01: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["user_details"] = {
|
|
|
|
|
|
"email": sample_invite["email_address"],
|
|
|
|
|
|
"id": sample_invite["id"],
|
2021-05-19 10:56:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.verify",
|
|
|
|
|
|
_data={"sms_code": "123456"},
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
expected_endpoint, service_id=sample_invite["service"], **extra_args
|
|
|
|
|
|
),
|
2021-05-19 10:56:13 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@freeze_time("2021-12-12 12:12:12")
|
2017-11-15 17:19:32 +00:00
|
|
|
|
def test_existing_user_accepts_and_sets_email_auth(
|
2017-11-15 14:59:03 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
sample_invite,
|
2021-05-25 17:20:04 +01:00
|
|
|
|
mock_get_existing_user_by_email,
|
2017-11-15 14:59:03 +00:00
|
|
|
|
mock_accept_invite,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2017-11-15 14:59:03 +00:00
|
|
|
|
mock_update_user_attribute,
|
|
|
|
|
|
mock_add_user_to_service,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker,
|
2017-11-15 14:59:03 +00:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["email_address"] = api_user_active["email_address"]
|
2017-11-15 14:59:03 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"].append("email_auth")
|
|
|
|
|
|
sample_invite["auth_type"] = "email_auth"
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2017-11-15 14:59:03 +00:00
|
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
"main.service_dashboard", service_id=service_one["id"]
|
|
|
|
|
|
),
|
2017-11-15 14:59:03 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_get_existing_user_by_email.assert_called_once_with("test@user.gsa.gov")
|
2021-08-17 16:38:37 +01:00
|
|
|
|
assert mock_update_user_attribute.call_args_list == [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
call(api_user_active["id"], email_access_validated_at="2021-12-12T12:12:12"),
|
|
|
|
|
|
call(api_user_active["id"], auth_type="email_auth"),
|
2021-08-17 16:38:37 +01:00
|
|
|
|
]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_add_user_to_service.assert_called_once_with(
|
|
|
|
|
|
ANY, api_user_active["id"], ANY, ANY
|
|
|
|
|
|
)
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@freeze_time("2021-12-12 12:12:12")
|
2021-05-25 15:58:33 +01:00
|
|
|
|
def test_platform_admin_user_accepts_and_preserves_auth(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
sample_invite,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2021-05-25 15:58:33 +01:00
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_add_user_to_service,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker,
|
2021-05-25 15:58:33 +01:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["email_address"] = platform_admin_user["email_address"]
|
|
|
|
|
|
sample_invite["auth_type"] = "email_auth"
|
|
|
|
|
|
service_one["permissions"].append("email_auth")
|
2021-05-25 15:58:33 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user_by_email", return_value=platform_admin_user
|
|
|
|
|
|
)
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.user_api_client.update_user_attribute",
|
2021-08-17 16:38:37 +01:00
|
|
|
|
return_value=platform_admin_user,
|
|
|
|
|
|
)
|
2021-05-25 15:58:33 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2021-05-25 15:58:33 +01:00
|
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
"main.service_dashboard", service_id=service_one["id"]
|
|
|
|
|
|
),
|
2021-05-25 15:58:33 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute.assert_called_once_with(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
platform_admin_user["id"],
|
|
|
|
|
|
email_access_validated_at="2021-12-12T12:12:12",
|
2021-08-17 16:38:37 +01:00
|
|
|
|
)
|
2021-05-25 15:58:33 +01:00
|
|
|
|
assert mock_add_user_to_service.called
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@freeze_time("2021-12-12 12:12:12")
|
2017-11-15 17:19:32 +00:00
|
|
|
|
def test_existing_user_doesnt_get_auth_changed_by_service_without_permission(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
sample_invite,
|
|
|
|
|
|
mock_get_user_by_email,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2017-11-15 17:19:32 +00:00
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_update_user_attribute,
|
|
|
|
|
|
mock_add_user_to_service,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker,
|
2017-11-15 17:19:32 +00:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["email_address"] = api_user_active["email_address"]
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "email_auth" not in service_one["permissions"]
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["auth_type"] = "email_auth"
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2017-11-15 17:19:32 +00:00
|
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
"main.service_dashboard", service_id=service_one["id"]
|
|
|
|
|
|
),
|
2017-11-15 17:19:32 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute.assert_called_once_with(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
api_user_active["id"],
|
|
|
|
|
|
email_access_validated_at="2021-12-12T12:12:12",
|
2021-08-17 16:38:37 +01:00
|
|
|
|
)
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@freeze_time("2021-12-12 12:12:12")
|
2017-11-15 17:19:32 +00:00
|
|
|
|
def test_existing_email_auth_user_without_phone_cannot_set_sms_auth(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
sample_invite,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2017-11-15 17:19:32 +00:00
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_update_user_attribute,
|
|
|
|
|
|
mock_add_user_to_service,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker,
|
2017-11-15 17:19:32 +00:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["email_address"] = api_user_active["email_address"]
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"].append("email_auth")
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
api_user_active["auth_type"] = "email_auth"
|
|
|
|
|
|
api_user_active["mobile_number"] = None
|
|
|
|
|
|
sample_invite["auth_type"] = "sms_auth"
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch("app.user_api_client.get_user_by_email", return_value=api_user_active)
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2017-11-15 17:19:32 +00:00
|
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
"main.service_dashboard", service_id=service_one["id"]
|
|
|
|
|
|
),
|
2017-11-15 17:19:32 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-08-17 16:38:37 +01:00
|
|
|
|
mock_update_user_attribute.assert_called_once_with(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
api_user_active["id"],
|
|
|
|
|
|
email_access_validated_at="2021-12-12T12:12:12",
|
2021-08-17 16:38:37 +01:00
|
|
|
|
)
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 17:55:42 -04:00
|
|
|
|
@pytest.mark.usefixtures("_mock_no_users_for_service")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@freeze_time("2021-12-12 12:12:12")
|
2017-11-15 17:19:32 +00:00
|
|
|
|
def test_existing_email_auth_user_with_phone_can_set_sms_auth(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
sample_invite,
|
2021-05-25 17:20:04 +01:00
|
|
|
|
mock_get_existing_user_by_email,
|
2021-05-25 17:54:37 +01:00
|
|
|
|
mock_check_invite_token,
|
2017-11-15 17:19:32 +00:00
|
|
|
|
mock_accept_invite,
|
|
|
|
|
|
mock_update_user_attribute,
|
|
|
|
|
|
mock_add_user_to_service,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker,
|
2017-11-15 17:19:32 +00:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
sample_invite["email_address"] = api_user_active["email_address"]
|
|
|
|
|
|
service_one["permissions"].append("email_auth")
|
|
|
|
|
|
sample_invite["auth_type"] = "sms_auth"
|
2017-11-15 17:19:32 +00:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.accept_invite",
|
|
|
|
|
|
token="thisisnotarealtoken",
|
2017-11-15 17:19:32 +00:00
|
|
|
|
_expected_status=302,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
"main.service_dashboard", service_id=service_one["id"]
|
|
|
|
|
|
),
|
2017-11-15 17:19:32 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_get_existing_user_by_email.assert_called_once_with(
|
|
|
|
|
|
sample_invite["email_address"]
|
|
|
|
|
|
)
|
2021-08-17 16:38:37 +01:00
|
|
|
|
assert mock_update_user_attribute.call_args_list == [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
call(api_user_active["id"], email_access_validated_at="2021-12-12T12:12:12"),
|
|
|
|
|
|
call(api_user_active["id"], auth_type="sms_auth"),
|
2021-08-17 16:38:37 +01:00
|
|
|
|
]
|