Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions fxsharing/shares/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,19 @@ def test_create_increments_with_limit_reached_outcome(self):
assert response.status_code == 429
counter.add.assert_called_once_with(1, {"outcome": "limit_reached"})

def test_create_increments_with_banned_outcome(self):
banned = User.objects.create_user(fxa_id="a1b2c3d4e5f6banned", is_banned=True)
self.client.force_login(banned)
with patch("fxsharing.shares.metrics.share_created") as counter:
response = self.client.post(
reverse("create_share"),
data=self._payload(),
content_type="application/json",
)
assert response.status_code == 403
assert not Share.objects.filter(user=banned).exists()
counter.add.assert_called_once_with(1, {"outcome": "banned"})

def test_create_increments_with_unauthenticated_outcome(self):
with patch("fxsharing.shares.metrics.share_created") as counter:
response = self.client.post(
Expand Down
4 changes: 4 additions & 0 deletions fxsharing/shares/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def create_share(request):
metrics.share_created.add(1, {"outcome": "unauthenticated"})
return HttpResponse(status=401)

if request.user.is_banned:
metrics.share_created.add(1, {"outcome": "banned"})
return HttpResponse(status=403)

try:
data = json.loads(request.body)
validate(instance=data, schema=share_schema)
Expand Down