Merge lp:~salgado/launchpad/bug-452525 into lp:launchpad

Proposed by Guilherme Salgado
Status: Merged
Approved by: Aaron Bentley
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~salgado/launchpad/bug-452525
Merge into: lp:launchpad
Diff against target: 84 lines
3 files modified
lib/canonical/launchpad/browser/logintoken.py (+2/-1)
lib/canonical/launchpad/browser/tests/test_password_reset.py (+55/-0)
lib/devscripts/ec2test/instance.py (+1/-1)
To merge this branch: bzr merge lp:~salgado/launchpad/bug-452525
Reviewer Review Type Date Requested Status
Aaron Bentley (community) code Approve
Review via email: mp+13873@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote :

= Summary =

Today, if you try to reset the password of an account in the NOACCOUNT
state, the password will be changed but the account will be left
unusable.

== Proposed fix ==

Just like we do when resetting the password of a DEACTIVATED account,
activate the account (in the NOACCOUNT state) for which the password is
being reset.

The actual bug was triggered through the login service, but a test for
that would have to go into the canonical-identity-provider, whereas the
fix (as you can see) is in launchpad. What I'd like to do is land this
fix with the LP-specific test and open an extra task on bug 452525 for
canonical-identity-provider to have a similar test there. The test
there would be really trivial as it'd just have to inherit from
TestPasswordReset (added here).

== Tests ==

./bin/test -vvt test_password_reset

== Demo and Q/A ==

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/canonical/launchpad/browser/tests/test_password_reset.py
  lib/devscripts/ec2test/instance.py
  lib/canonical/launchpad/browser/logintoken.py

== Pylint notices ==

lib/devscripts/ec2test/instance.py
    409: [W0703, EC2Instance.set_up_and_run] Catch "Exception"

Revision history for this message
Aaron Bentley (abentley) wrote :

As discussed on IRC, it would be nice to change the brower test to a view test, but I think this is landable as-is.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/launchpad/browser/logintoken.py'
--- lib/canonical/launchpad/browser/logintoken.py 2009-09-18 01:09:10 +0000
+++ lib/canonical/launchpad/browser/logintoken.py 2009-10-26 15:06:13 +0000
@@ -221,7 +221,8 @@
221221
222 naked_account = removeSecurityProxy(account)222 naked_account = removeSecurityProxy(account)
223 # Reset password can be used to reactivate a deactivated account.223 # Reset password can be used to reactivate a deactivated account.
224 if account.status == AccountStatus.DEACTIVATED:224 inactive_states = [AccountStatus.DEACTIVATED, AccountStatus.NOACCOUNT]
225 if account.status in inactive_states:
225 self.reactivate(data)226 self.reactivate(data)
226 self.request.response.addInfoNotification(227 self.request.response.addInfoNotification(
227 _('Welcome back to Launchpad.'))228 _('Welcome back to Launchpad.'))
228229
=== added file 'lib/canonical/launchpad/browser/tests/test_password_reset.py'
--- lib/canonical/launchpad/browser/tests/test_password_reset.py 1970-01-01 00:00:00 +0000
+++ lib/canonical/launchpad/browser/tests/test_password_reset.py 2009-10-26 15:06:13 +0000
@@ -0,0 +1,55 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4import unittest
5
6from zope.component import getUtility
7
8import transaction
9from canonical.launchpad.browser.logintoken import ResetPasswordView
10from canonical.launchpad.ftests import LaunchpadFormHarness
11from canonical.launchpad.interfaces.account import AccountStatus
12from canonical.launchpad.interfaces.authtoken import LoginTokenType
13from canonical.launchpad.interfaces.emailaddress import EmailAddressStatus
14from canonical.launchpad.interfaces.logintoken import ILoginTokenSet
15from lp.testing import TestCaseWithFactory
16from canonical.testing import DatabaseFunctionalLayer
17
18
19class TestPasswordReset(TestCaseWithFactory):
20 layer = DatabaseFunctionalLayer
21
22 def setUp(self):
23 TestCaseWithFactory.setUp(self)
24 self.email = 'foo@example.com'
25 self.person = self.factory.makePerson(
26 email=self.email, email_address_status=EmailAddressStatus.NEW)
27 self.account = self.person.account
28
29 def test_inactive_accounts_are_activated(self):
30 # Resetting the password of an account in the NOACCOUNT state will
31 # activate it.
32 self.assertEquals(self.account.status, AccountStatus.NOACCOUNT)
33 token = getUtility(ILoginTokenSet).new(
34 self.person, self.email, self.email,
35 LoginTokenType.PASSWORDRECOVERY)
36 self._completePasswordReset(token)
37 self.assertEquals(self.account.status, AccountStatus.ACTIVE)
38 self.assertEquals(
39 self.account.preferredemail.email, 'foo@example.com')
40
41 def _completePasswordReset(self, token):
42 harness = LaunchpadFormHarness(token, ResetPasswordView)
43 form = {'field.email': self.email,
44 'field.password': 'test',
45 'field.password_dupe': 'test'}
46 harness.submit('continue', form)
47 self.assertFalse(harness.hasErrors())
48 # Need to manually commit because we're interested in testing the
49 # changes done by the view on the token's requester (i.e.
50 # self.person).
51 transaction.commit()
52
53
54def test_suite():
55 return unittest.TestLoader().loadTestsFromName(__name__)
056
=== modified file 'lib/devscripts/ec2test/instance.py'
--- lib/devscripts/ec2test/instance.py 2009-10-05 19:20:37 +0000
+++ lib/devscripts/ec2test/instance.py 2009-10-26 15:06:13 +0000
@@ -169,7 +169,7 @@
169EC2Instance is available as `instance`.169EC2Instance is available as `instance`.
170Also try these:170Also try these:
171 http://%(dns)s/current_test.log171 http://%(dns)s/current_test.log
172 ssh -A %(dns)s172 ssh -A ec2test@%(dns)s
173"""173"""
174174
175175