Audit permissions when adding a user to a service

This is useful information to store for the event, which would be
lost if someone subsequently changed them.

Rather than updating lots of mock assertions, I've replaced them
with a single test / assert at a lower level, which is consistent
with auditing being a non-critical function.
This commit is contained in:
Ben Thorner
2021-07-15 12:13:42 +01:00
parent 171f911237
commit 9fafc092f7
6 changed files with 24 additions and 23 deletions

View File

@@ -46,7 +46,6 @@ def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(
):
expected_service = service_one['id']
expected_permissions = {'view_activity', 'send_messages', 'manage_service', 'manage_api_keys'}
mock_audit_event = mocker.patch('app.models.user.create_add_user_to_service_event')
response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'))
@@ -62,11 +61,6 @@ def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(
assert response.status_code == 302
assert response.location == url_for('main.service_dashboard', service_id=expected_service, _external=True)
mock_audit_event.assert_called_once_with(
invited_by_id=service_one['users'][0],
service_id=SERVICE_ONE_ID,
user_id=api_user_active['id'],
)
@pytest.mark.parametrize('trial_mode, expected_endpoint', (
@@ -270,8 +264,6 @@ def test_accept_invite_redirects_if_api_raises_an_error_that_they_are_already_pa
mock_no_users_for_service,
mock_get_user,
):
mock_audit_event = mocker.patch('app.models.user.create_add_user_to_service_event')
mocker.patch('app.user_api_client.add_user_to_service', side_effect=HTTPError(
response=Mock(
status_code=400,
@@ -285,7 +277,6 @@ def test_accept_invite_redirects_if_api_raises_an_error_that_they_are_already_pa
response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'), follow_redirects=False)
assert response.location == url_for('main.service_dashboard', service_id=SERVICE_ONE_ID, _external=True)
assert not mock_audit_event.called
def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(
@@ -574,8 +565,6 @@ def test_new_invited_user_verifies_and_added_to_service(
mock_create_event,
mocker,
):
mock_audit_event = mocker.patch('app.models.user.create_add_user_to_service_event')
# visit accept token page
response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'))
assert response.status_code == 302
@@ -611,10 +600,6 @@ def test_new_invited_user_verifies_and_added_to_service(
mock_check_verify_code.assert_called_once_with(new_user_id, '12345', 'sms')
assert service_one['id'] == session['service_id']
mock_audit_event.assert_called_once_with(invited_by_id=service_one['users'][0],
service_id=service_one['id'],
user_id=new_user_id)
raw_html = response.data.decode('utf-8')
page = BeautifulSoup(raw_html, 'html.parser')
assert page.find('h1').text == 'Dashboard'