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
1=== modified file 'lib/canonical/launchpad/browser/logintoken.py'
2--- lib/canonical/launchpad/browser/logintoken.py 2009-09-18 01:09:10 +0000
3+++ lib/canonical/launchpad/browser/logintoken.py 2009-10-26 15:06:13 +0000
4@@ -221,7 +221,8 @@
5
6 naked_account = removeSecurityProxy(account)
7 # Reset password can be used to reactivate a deactivated account.
8- if account.status == AccountStatus.DEACTIVATED:
9+ inactive_states = [AccountStatus.DEACTIVATED, AccountStatus.NOACCOUNT]
10+ if account.status in inactive_states:
11 self.reactivate(data)
12 self.request.response.addInfoNotification(
13 _('Welcome back to Launchpad.'))
14
15=== added file 'lib/canonical/launchpad/browser/tests/test_password_reset.py'
16--- lib/canonical/launchpad/browser/tests/test_password_reset.py 1970-01-01 00:00:00 +0000
17+++ lib/canonical/launchpad/browser/tests/test_password_reset.py 2009-10-26 15:06:13 +0000
18@@ -0,0 +1,55 @@
19+# Copyright 2009 Canonical Ltd. This software is licensed under the
20+# GNU Affero General Public License version 3 (see the file LICENSE).
21+
22+import unittest
23+
24+from zope.component import getUtility
25+
26+import transaction
27+from canonical.launchpad.browser.logintoken import ResetPasswordView
28+from canonical.launchpad.ftests import LaunchpadFormHarness
29+from canonical.launchpad.interfaces.account import AccountStatus
30+from canonical.launchpad.interfaces.authtoken import LoginTokenType
31+from canonical.launchpad.interfaces.emailaddress import EmailAddressStatus
32+from canonical.launchpad.interfaces.logintoken import ILoginTokenSet
33+from lp.testing import TestCaseWithFactory
34+from canonical.testing import DatabaseFunctionalLayer
35+
36+
37+class TestPasswordReset(TestCaseWithFactory):
38+ layer = DatabaseFunctionalLayer
39+
40+ def setUp(self):
41+ TestCaseWithFactory.setUp(self)
42+ self.email = 'foo@example.com'
43+ self.person = self.factory.makePerson(
44+ email=self.email, email_address_status=EmailAddressStatus.NEW)
45+ self.account = self.person.account
46+
47+ def test_inactive_accounts_are_activated(self):
48+ # Resetting the password of an account in the NOACCOUNT state will
49+ # activate it.
50+ self.assertEquals(self.account.status, AccountStatus.NOACCOUNT)
51+ token = getUtility(ILoginTokenSet).new(
52+ self.person, self.email, self.email,
53+ LoginTokenType.PASSWORDRECOVERY)
54+ self._completePasswordReset(token)
55+ self.assertEquals(self.account.status, AccountStatus.ACTIVE)
56+ self.assertEquals(
57+ self.account.preferredemail.email, 'foo@example.com')
58+
59+ def _completePasswordReset(self, token):
60+ harness = LaunchpadFormHarness(token, ResetPasswordView)
61+ form = {'field.email': self.email,
62+ 'field.password': 'test',
63+ 'field.password_dupe': 'test'}
64+ harness.submit('continue', form)
65+ self.assertFalse(harness.hasErrors())
66+ # Need to manually commit because we're interested in testing the
67+ # changes done by the view on the token's requester (i.e.
68+ # self.person).
69+ transaction.commit()
70+
71+
72+def test_suite():
73+ return unittest.TestLoader().loadTestsFromName(__name__)
74
75=== modified file 'lib/devscripts/ec2test/instance.py'
76--- lib/devscripts/ec2test/instance.py 2009-10-05 19:20:37 +0000
77+++ lib/devscripts/ec2test/instance.py 2009-10-26 15:06:13 +0000
78@@ -169,7 +169,7 @@
79 EC2Instance is available as `instance`.
80 Also try these:
81 http://%(dns)s/current_test.log
82- ssh -A %(dns)s
83+ ssh -A ec2test@%(dns)s
84 """
85
86