Skip to content

Commit

Permalink
Added missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Mar 19, 2024
1 parent e484803 commit fa25949
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions posthog/api/test/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,23 @@ def test_cant_reset_more_than_six_times(self):
# Six emails should be sent, seventh should not
self.assertEqual(len(mail.outbox), 6)

def test_is_rate_limited_on_email_not_ip(self):
set_instance_setting("EMAIL_HOST", "localhost")

for email in ["[email protected]", "[email protected]"]:
for i in range(7):
with self.settings(CELERY_TASK_ALWAYS_EAGER=True, SITE_URL="https://my.posthog.net"):
response = self.client.post("/api/users/@me/request_password_reset/", {"email": email})
if i < 6:
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
else:
# Fourth request should fail
self.assertEqual(response.status_code, status.HTTP_429_TOO_MANY_REQUESTS)
self.assertDictContainsSubset(
{"attr": None, "code": "throttled", "type": "throttled_error"},
response.json(),
)

# Token validation

def test_can_validate_token(self):
Expand Down

0 comments on commit fa25949

Please sign in to comment.