-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent unauthorised remove-users access (#3791)
- Loading branch information
1 parent
37fec5b
commit 05353a5
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1797,3 +1797,66 @@ def test_doesnt_retrieve_stale_api_usage_notifications( | |
# Then | ||
assert response.status_code == status.HTTP_200_OK | ||
assert len(response.data["results"]) == 0 | ||
|
||
|
||
def test_non_organisation_user_cannot_remove_user_from_organisation( | ||
staff_user: FFAdminUser, organisation: Organisation, api_client: APIClient | ||
) -> None: | ||
# Given | ||
another_organisation = Organisation.objects.create(name="another organisation") | ||
another_user = FFAdminUser.objects.create(email="[email protected]") | ||
another_user.add_organisation(another_organisation) | ||
api_client.force_authenticate(another_user) | ||
|
||
url = reverse( | ||
"api-v1:organisations:organisation-remove-users", args=[organisation.id] | ||
) | ||
|
||
data = [{"id": staff_user.id}] | ||
|
||
# When | ||
response = api_client.post( | ||
url, data=json.dumps(data), content_type="application/json" | ||
) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_403_FORBIDDEN | ||
|
||
|
||
def test_non_admin_user_cannot_remove_user_from_organisation( | ||
staff_user: FFAdminUser, | ||
organisation: Organisation, | ||
staff_client: APIClient, | ||
admin_user: FFAdminUser, | ||
) -> None: | ||
# Given | ||
url = reverse( | ||
"api-v1:organisations:organisation-remove-users", args=[organisation.id] | ||
) | ||
|
||
data = [{"id": admin_user.id}] | ||
|
||
# When | ||
response = staff_client.post( | ||
url, data=json.dumps(data), content_type="application/json" | ||
) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_403_FORBIDDEN | ||
|
||
|
||
def test_validation_error_if_non_numeric_organisation_id( | ||
staff_client: APIClient, | ||
) -> None: | ||
# Given | ||
url = reverse("api-v1:organisations:organisation-remove-users", args=["foo"]) | ||
|
||
data = [] | ||
|
||
# When | ||
response = staff_client.post( | ||
url, data=json.dumps(data), content_type="application/json" | ||
) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST |