Merge lp:~alecu/ubuntu-sso-client/store-creds-again into lp:ubuntu-sso-client

Proposed by Alejandro J. Cura on 2010-08-27
Status: Merged
Approved by: Rodrigo Moya on 2010-08-27
Approved revision: 602
Merged at revision: 603
Proposed branch: lp:~alecu/ubuntu-sso-client/store-creds-again
Merge into: lp:ubuntu-sso-client
Diff against target: 145 lines (+34/-13)
2 files modified
ubuntu_sso/main.py (+4/-2)
ubuntu_sso/tests/test_main.py (+30/-11)
To merge this branch: bzr merge lp:~alecu/ubuntu-sso-client/store-creds-again
Reviewer Review Type Date Requested Status
Rodrigo Moya (community) Approve on 2010-08-27
Natalia Bidart 2010-08-27 Approve on 2010-08-27
Review via email: mp+33954@code.launchpad.net

Commit message

Store the credentials after the email validation step (LP: #625003)

Description of the change

Store the credentials after the email validation step

To post a comment you must log in.
Natalia Bidart (nataliabidart) wrote :

Your awesomeness is awesome.

review: Approve
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/main.py'
2--- ubuntu_sso/main.py 2010-08-26 22:52:07 +0000
3+++ ubuntu_sso/main.py 2010-08-27 19:59:57 +0000
4@@ -231,7 +231,7 @@
5 errorsdict = self._format_webservice_errors(result['errors'])
6 raise EmailTokenError(errorsdict)
7 elif 'email' in result:
8- return result['email']
9+ return token
10 else:
11 raise EmailTokenError('Received invalid reply: %s' % result)
12
13@@ -399,8 +399,10 @@
14 def f():
15 """Inner function that will be run in a thread."""
16 token_name = get_token_name(app_name)
17- return self.processor().validate_email(email, password,
18+ credentials = self.processor().validate_email(email, password,
19 email_token, token_name)
20+ keyring_store_credentials(app_name, credentials)
21+ return email
22 blocking(f, app_name, self.EmailValidated, self.EmailValidationError)
23
24 # request_password_reset_token signals
25
26=== modified file 'ubuntu_sso/tests/test_main.py'
27--- ubuntu_sso/tests/test_main.py 2010-08-26 22:52:07 +0000
28+++ ubuntu_sso/tests/test_main.py 2010-08-27 19:59:57 +0000
29@@ -31,6 +31,7 @@
30 from twisted.internet.defer import Deferred
31 from twisted.trial.unittest import TestCase
32
33+import ubuntu_sso.keyring
34 import ubuntu_sso.main
35
36 from contrib.testing.testcase import MementoHandler
37@@ -279,7 +280,7 @@
38 """A email is succesfuy validated in the SSO server."""
39 self.login_kwargs['email_token'] = EMAIL_TOKEN # valid email token
40 result = self.processor.validate_email(**self.login_kwargs)
41- self.assertEqual(EMAIL, result, 'email validation was successful.')
42+ self.assertEqual(TOKEN, result, 'email validation was successful.')
43
44 def test_validate_email_if_status_error(self):
45 """Proper error is raised if email validation fails."""
46@@ -443,8 +444,11 @@
47 """Assert over token and app_name."""
48 self.assertEqual(k, APP_NAME)
49 self.assertEqual(v, TOKEN)
50+ self.keyring_was_set = True
51+ self.keyring_values = k, v
52
53 self.patch(ubuntu_sso.main, "keyring_store_credentials", ksc)
54+ self.keyring_was_set = False
55
56 def tearDown(self):
57 """Verify the mocking bus and shut it down."""
58@@ -457,8 +461,12 @@
59
60 def fake_err_blocking(self, f, a, cb, eb):
61 """A fake blocking function that fails."""
62- f()
63- eb(a, except_to_errdict(BlockingSampleException()))
64+ try:
65+ f()
66+ except Exception, e:
67+ eb(a, except_to_errdict(e))
68+ else:
69+ eb(a, except_to_errdict(BlockingSampleException()))
70
71 def test_creation(self):
72 """Test that the object creation is successful."""
73@@ -574,6 +582,7 @@
74 def verify(app_name, result):
75 self.assertEqual(result, EMAIL)
76 self.assertEqual(app_name, APP_NAME)
77+ self.assertTrue(self.keyring_was_set, "The keyring should be set")
78 d.callback(result)
79
80 client = SSOLogin(self.mockbusname,
81@@ -586,14 +595,20 @@
82 def test_login_error(self):
83 """Test that the login method fails as expected."""
84 d = Deferred()
85- self.create_mock_processor().login(EMAIL, PASSWORD, TOKEN_NAME)
86- self.mocker.result(TOKEN)
87+ self.mockprocessorclass = self.mocker.mock()
88 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
89+
90+ def fake_gtn(*args):
91+ """A fake get_token_name that fails."""
92+ raise BlockingSampleException()
93+
94+ self.patch(ubuntu_sso.main, "get_token_name", fake_gtn)
95 self.mocker.replay()
96
97 def verify(app_name, errdict):
98 self.assertEqual(app_name, APP_NAME)
99 self.assertEqual(errdict["errtype"], "BlockingSampleException")
100+ self.assertFalse(self.keyring_was_set, "Keyring should not be set")
101 d.callback("Ok")
102
103 client = SSOLogin(self.mockbusname,
104@@ -608,13 +623,14 @@
105 d = Deferred()
106 self.create_mock_processor().validate_email(EMAIL, PASSWORD,
107 EMAIL_TOKEN, TOKEN_NAME)
108- self.mocker.result(EMAIL)
109+ self.mocker.result(TOKEN)
110 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
111 self.mocker.replay()
112
113 def verify(app_name, result):
114 self.assertEqual(result, EMAIL)
115 self.assertEqual(app_name, APP_NAME)
116+ self.assertTrue(self.keyring_was_set, "The keyring should be set")
117 d.callback(result)
118
119 client = SSOLogin(self.mockbusname,
120@@ -627,17 +643,20 @@
121 def test_validate_email_error(self):
122 """Test that the validate_email method fails as expected."""
123 d = Deferred()
124- expected_result = "expected result"
125-
126- self.create_mock_processor().validate_email(EMAIL, PASSWORD,
127- EMAIL_TOKEN, TOKEN_NAME)
128- self.mocker.result(expected_result)
129+ self.mockprocessorclass = self.mocker.mock()
130 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
131+
132+ def fake_gtn(*args):
133+ """A fake get_token_name that fails."""
134+ raise BlockingSampleException()
135+
136+ self.patch(ubuntu_sso.main, "get_token_name", fake_gtn)
137 self.mocker.replay()
138
139 def verify(app_name, errdict):
140 self.assertEqual(app_name, APP_NAME)
141 self.assertEqual(errdict["errtype"], "BlockingSampleException")
142+ self.assertFalse(self.keyring_was_set, "Keyring should not be set")
143 d.callback("Ok")
144
145 client = SSOLogin(self.mockbusname,

Subscribers

People subscribed via source and target branches