Merge lp:~maxiberta/canonical-identity-provider/fix-429-crash into lp:canonical-identity-provider/release

Proposed by Maximiliano Bertacchini
Status: Merged
Approved by: Maximiliano Bertacchini
Approved revision: no longer in the source branch.
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~maxiberta/canonical-identity-provider/fix-429-crash
Merge into: lp:canonical-identity-provider/release
Diff against target: 78 lines (+26/-1)
2 files modified
src/webui/tests/test_views_registration.py (+16/-0)
src/webui/views/registration.py (+10/-1)
To merge this branch: bzr merge lp:~maxiberta/canonical-identity-provider/fix-429-crash
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
Review via email: mp+361148@code.launchpad.net

Commit message

Show a nice error message at user registration and reset password views when the API returns 429 - too many requests.

To post a comment you must log in.
Revision history for this message
Adam Collard (adam-collard) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/webui/tests/test_views_registration.py'
--- src/webui/tests/test_views_registration.py 2018-10-25 17:56:27 +0000
+++ src/webui/tests/test_views_registration.py 2018-12-20 18:24:52 +0000
@@ -38,6 +38,7 @@
38)38)
39from webui.views.registration import (39from webui.views.registration import (
40 ACCOUNT_CREATED,40 ACCOUNT_CREATED,
41 ERROR_TOO_MANY_REQUESTS,
41 VERIFY_EMAIL_SENT,42 VERIFY_EMAIL_SENT,
42 WEB_CREATION_SOURCE,43 WEB_CREATION_SOURCE,
43 new_account,44 new_account,
@@ -332,6 +333,13 @@
332 self.assert_form_displayed(response, email=VERIFY_EMAIL_MESSAGE)333 self.assert_form_displayed(response, email=VERIFY_EMAIL_MESSAGE)
333 self.assert_stat_calls(['error.email'])334 self.assert_stat_calls(['error.email'])
334335
336 def test_post_too_many_requests(self):
337 exc = api_errors.TooManyRequests(Mock())
338 self.mock_api_register.side_effect = exc
339 response = self.post(**self.TESTDATA)
340 self.assertContains(response, ERROR_TOO_MANY_REQUESTS)
341 self.assert_stat_calls(['error.too_many_requests'])
342
335343
336class RegisterTimelineTestCase(344class RegisterTimelineTestCase(
337 SSOBaseTestCase, RegisterTestMixin, TimelineActionMixin):345 SSOBaseTestCase, RegisterTestMixin, TimelineActionMixin):
@@ -565,6 +573,14 @@
565 self.assertEqual(response.status_code, 200)573 self.assertEqual(response.status_code, 200)
566 self.assert_stat_calls(['error.too_many_tokens'])574 self.assert_stat_calls(['error.too_many_tokens'])
567575
576 def test_post_too_many_requests(self):
577 exc = api_errors.TooManyRequests(Mock())
578 self.mock_api_request_password_reset.side_effect = exc
579 response = self.post(data=self.data)
580 self.assertEqual(response.status_code, 200)
581 self.assert_form_displayed(response, __all__=ERROR_TOO_MANY_REQUESTS)
582 self.assert_stat_calls(['error.too_many_requests'])
583
568 def test_reset_password(self):584 def test_reset_password(self):
569 response = self.post(data=self.data)585 response = self.post(data=self.data)
570586
571587
=== modified file 'src/webui/views/registration.py'
--- src/webui/views/registration.py 2018-10-16 19:32:57 +0000
+++ src/webui/views/registration.py 2018-12-20 18:24:52 +0000
@@ -74,9 +74,10 @@
74 'to reset the corresponding account\'s password.')74 'to reset the corresponding account\'s password.')
75ERROR_PASSWORD_RESET_GENERIC = _(75ERROR_PASSWORD_RESET_GENERIC = _(
76 'It is not possible to reset this account\'s password.')76 'It is not possible to reset this account\'s password.')
77ERROR_PASSWORD_RESET_TOO_MANY_TOKENS = (77ERROR_PASSWORD_RESET_TOO_MANY_TOKENS = _(
78 'Too many active password reset requests. An email has already been sent '78 'Too many active password reset requests. An email has already been sent '
79 'to your account; please verify your inbox.')79 'to your account; please verify your inbox.')
80ERROR_TOO_MANY_REQUESTS = _('Too many requests. Please try again later.')
8081
81WEB_CREATION_SOURCE = 'web-flow'82WEB_CREATION_SOURCE = 'web-flow'
8283
@@ -124,6 +125,10 @@
124 collect_stats('error.email')125 collect_stats('error.email')
125 form._errors['email'] = [VERIFY_EMAIL_MESSAGE]126 form._errors['email'] = [VERIFY_EMAIL_MESSAGE]
126127
128 except api_errors.TooManyRequests as e:
129 collect_stats('error.too_many_requests')
130 messages.error(request, ERROR_TOO_MANY_REQUESTS)
131
127 except Exception as e:132 except Exception as e:
128 return HttpResponseServerError("exception: " + str(e))133 return HttpResponseServerError("exception: " + str(e))
129 else:134 else:
@@ -227,6 +232,10 @@
227 ERROR_PASSWORD_RESET_TOO_MANY_TOKENS]232 ERROR_PASSWORD_RESET_TOO_MANY_TOKENS]
228 collect_stats('error.too_many_tokens')233 collect_stats('error.too_many_tokens')
229234
235 except api_errors.TooManyRequests as e:
236 form.errors['__all__'] = [ERROR_TOO_MANY_REQUESTS]
237 collect_stats('error.too_many_requests')
238
230 else:239 else:
231 msgs = {240 msgs = {
232 'email_to': email,241 'email_to': email,