mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-28 05:21:54 -05:00
Validate recipient for restricted service w/ utils
Implements https://github.com/alphagov/notifications-utils/pull/16 Once https://github.com/alphagov/notifications-admin/pull/376 is merged it will no longer be possible for a user to upload a CSV file containing recipients that they’re not allowed to send to. So this commit also removes any restricted service checks in the task, because any public phone numbers/email addresses no longer have any way of reach this point if the service is restricted.
This commit is contained in:
@@ -343,31 +343,6 @@ def test_should_send_sms_if_restricted_service_and_valid_number(notify_db, notif
|
||||
)
|
||||
|
||||
|
||||
def test_should_not_send_sms_if_restricted_service_and_invalid_number(notify_db, notify_db_session, mocker):
|
||||
user = sample_user(notify_db, notify_db_session, mobile_numnber="07700 900205")
|
||||
service = sample_service(notify_db, notify_db_session, user=user, restricted=True)
|
||||
template = sample_template(notify_db, notify_db_session, service=service)
|
||||
|
||||
notification = {
|
||||
"template": template.id,
|
||||
"to": "07700 900849"
|
||||
}
|
||||
mocker.patch('app.encryption.decrypt', return_value=notification)
|
||||
mocker.patch('app.firetext_client.send_sms')
|
||||
mocker.patch('app.firetext_client.get_name', return_value="firetext")
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
now = datetime.utcnow()
|
||||
send_sms(
|
||||
service.id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now.strftime(DATETIME_FORMAT)
|
||||
)
|
||||
|
||||
firetext_client.send_sms.assert_not_called()
|
||||
|
||||
|
||||
def test_should_send_email_if_restricted_service_and_valid_email(notify_db, notify_db_session, mocker):
|
||||
user = sample_user(notify_db, notify_db_session, email="test@restricted.com")
|
||||
service = sample_service(notify_db, notify_db_session, user=user, restricted=True)
|
||||
|
||||
@@ -879,7 +879,7 @@ def test_should_not_send_email_if_restricted_and_not_a_service_user(notify_api,
|
||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert 'Email address not permitted for restricted service' in json_resp['message']['to']
|
||||
assert 'Invalid email address for restricted service' in json_resp['message']['to']
|
||||
|
||||
|
||||
def test_should_not_send_email_for_job_if_restricted_and_not_a_service_user(
|
||||
@@ -915,7 +915,7 @@ def test_should_not_send_email_for_job_if_restricted_and_not_a_service_user(
|
||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert 'Email address not permitted for restricted service' in json_resp['message']['to']
|
||||
assert 'Invalid email address for restricted service' in json_resp['message']['to']
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
from app.models import User, Service
|
||||
from app.validation import allowed_send_to_number, allowed_send_to_email
|
||||
|
||||
|
||||
def test_allowed_send_to_number_returns_true_for_restricted_service_with_same_number():
|
||||
mobile_number = '07524609792'
|
||||
service = _create_service_data(mobile_number)
|
||||
assert allowed_send_to_number(service, mobile_number)
|
||||
|
||||
|
||||
def test_allowed_send_to_number_returns_false_for_restricted_service_with_different_number():
|
||||
mobile_number = '00447524609792'
|
||||
service = _create_service_data(mobile_number)
|
||||
assert not allowed_send_to_number(service, '+447344609793')
|
||||
|
||||
|
||||
def test_allowed_send_to_number_returns_true_for_unrestricted_service_with_different_number():
|
||||
mobile_number = '+447524609792'
|
||||
service = _create_service_data(mobile_number, False)
|
||||
assert allowed_send_to_number(service, '+447344609793')
|
||||
|
||||
|
||||
def test_allowed_send_to_email__returns_true_for_restricted_service_with_same_email():
|
||||
email = 'testing@it.gov.uk'
|
||||
service = _create_service_data(email_address=email)
|
||||
assert allowed_send_to_email(service, email)
|
||||
|
||||
|
||||
def test_allowed_send_to_email__returns_false_for_restricted_service_with_different_email():
|
||||
email = 'testing@it.gov.uk'
|
||||
service = _create_service_data(email_address=email)
|
||||
assert not allowed_send_to_email(service, 'another@it.gov.uk')
|
||||
|
||||
|
||||
def test_allowed_send_to_email__returns_false_for_restricted_service_with_different_email():
|
||||
email = 'testing@it.gov.uk'
|
||||
service = _create_service_data(email_address=email)
|
||||
assert not allowed_send_to_email(service, 'another@it.gov.uk')
|
||||
|
||||
|
||||
def test_allowed_send_to_email__returns_true_for_unrestricted_service_with_different_email():
|
||||
email = 'testing@it.gov.uk'
|
||||
service = _create_service_data(email_address=email, restricted=False)
|
||||
assert allowed_send_to_number(service, 'another@it.gov.uk')
|
||||
|
||||
|
||||
def _create_service_data(mobile_number='+447524609792', restricted=True, email_address='test_user@it.gov.uk'):
|
||||
usr = {
|
||||
'name': 'Test User',
|
||||
'email_address': email_address,
|
||||
'password': 'password',
|
||||
'mobile_number': mobile_number,
|
||||
'state': 'active'
|
||||
}
|
||||
user = User(**usr)
|
||||
data = {
|
||||
'name': 'Test service',
|
||||
'limit': 10,
|
||||
'active': False,
|
||||
'restricted': restricted,
|
||||
'email_from': 'test_service@it.gov.uk'
|
||||
}
|
||||
service = Service(**data)
|
||||
service.users = [user]
|
||||
return service
|
||||
Reference in New Issue
Block a user