Merge lp:~nataliabidart/ubuntu-sso-client/ping-url-can-be-none into lp:ubuntu-sso-client

Proposed by Natalia Bidart
Status: Merged
Approved by: dobey
Approved revision: 652
Merged at revision: 650
Proposed branch: lp:~nataliabidart/ubuntu-sso-client/ping-url-can-be-none
Merge into: lp:ubuntu-sso-client
Diff against target: 99 lines (+44/-24)
2 files modified
ubuntu_sso/credentials.py (+27/-24)
ubuntu_sso/tests/test_credentials.py (+17/-0)
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/ping-url-can-be-none
Reviewer Review Type Date Requested Status
dobey (community) Approve
Chad Miller (community) Approve
Alejandro J. Cura Pending
Review via email: mp+41177@code.launchpad.net

Commit message

* Credentials should not be cleared if the ping wasn't made due to empty ping url (LP: #676679).

To post a comment you must log in.
Revision history for this message
Chad Miller (cmiller) :
review: Approve
Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

There was a problem validating some authors of the branch. Authors must be either one of the listed Launchpad users, or a member of one of the listed teams on Launchpad.

Persons or Teams:

    contributor-agreement-canonical
    ubuntuone-hackers

Unaccepted Authors:

    Natalia B. Bidart <email address hidden>

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

There was a problem validating some authors of the branch. Authors must be either one of the listed Launchpad users, or a member of one of the listed teams on Launchpad.

Persons or Teams:

    contributor-agreement-canonical
    ubuntuone-hackers

Unaccepted Authors:

    Natalia B. Bidart <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/credentials.py'
2--- ubuntu_sso/credentials.py 2010-11-17 19:37:12 +0000
3+++ ubuntu_sso/credentials.py 2010-11-18 20:09:09 +0000
4@@ -194,11 +194,14 @@
5 creds = yield self.find_credentials()
6 if creds is not None:
7 assert len(creds) > 0, 'Creds are empty! This should not happen'
8- status = self._ping_url(app_name, email, creds)
9- if status is None:
10- yield self.clear_credentials()
11- else:
12- self.success_cb(creds)
13+ # ping a server with the credentials if we were requested to
14+ if self.ping_url is not None:
15+ status = self._ping_url(app_name, email, creds)
16+ if status is None:
17+ yield self.clear_credentials()
18+ return
19+
20+ self.success_cb(creds)
21
22 def _login_error_cb(self, dialog, app_name, error):
23 """Handle UI error when login/registration failed."""
24@@ -215,28 +218,28 @@
25 def _ping_url(self, app_name, email, credentials):
26 """Ping the self.ping_url with the email attached.
27
28- Sign the request with the user credentials.
29+ Sign the request with the user credentials. The self.ping_url must be
30+ defined if this method is being called.
31
32 """
33- logger.info('Maybe pinging server for app_name "%s", ping_url: "%s", '
34+ logger.info('Pinging server for app_name "%s", ping_url: "%s", '
35 'email "%s".', app_name, self.ping_url, email)
36- if self.ping_url is not None:
37- url = self.ping_url + email
38- consumer = oauth.OAuthConsumer(credentials['consumer_key'],
39- credentials['consumer_secret'])
40- token = oauth.OAuthToken(credentials['token'],
41- credentials['token_secret'])
42- get_request = oauth.OAuthRequest.from_consumer_and_token
43- oauth_req = get_request(oauth_consumer=consumer, token=token,
44- http_method='GET', http_url=url)
45- oauth_req.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(),
46- consumer, token)
47- request = urllib2.Request(url, headers=oauth_req.to_header())
48- logger.debug('Opening the url "%s" with urllib2.urlopen.',
49- request.get_full_url())
50- response = urllib2.urlopen(request)
51- logger.debug('Url opened. Response: %s.', response.code)
52- return response.code
53+ url = self.ping_url + email
54+ consumer = oauth.OAuthConsumer(credentials['consumer_key'],
55+ credentials['consumer_secret'])
56+ token = oauth.OAuthToken(credentials['token'],
57+ credentials['token_secret'])
58+ get_request = oauth.OAuthRequest.from_consumer_and_token
59+ oauth_req = get_request(oauth_consumer=consumer, token=token,
60+ http_method='GET', http_url=url)
61+ oauth_req.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(),
62+ consumer, token)
63+ request = urllib2.Request(url, headers=oauth_req.to_header())
64+ logger.debug('Opening the url "%s" with urllib2.urlopen.',
65+ request.get_full_url())
66+ response = urllib2.urlopen(request)
67+ logger.debug('Url opened. Response: %s.', response.code)
68+ return response.code
69
70 @handle_exceptions(msg='Problem opening the Ubuntu SSO user interface')
71 def _show_ui(self, login_only):
72
73=== modified file 'ubuntu_sso/tests/test_credentials.py'
74--- ubuntu_sso/tests/test_credentials.py 2010-11-16 20:20:56 +0000
75+++ ubuntu_sso/tests/test_credentials.py 2010-11-18 20:09:09 +0000
76@@ -323,6 +323,23 @@
77
78 self.assertEqual(self._url_pinged, ((APP_NAME, EMAIL, TOKEN), {}))
79
80+ @inlineCallbacks
81+ def test_no_ping_url_is_success(self):
82+ """Auth success + cred found + no ping url, success_cb is called.
83+
84+ Credentials are NOT removed.
85+
86+ """
87+ self.patch(credentials.Keyring, 'get_credentials',
88+ lambda kr, app: defer.succeed(TOKEN)) # auth success
89+ self.patch(self.obj, 'clear_credentials', self._set_called)
90+ self.obj.ping_url = None
91+
92+ yield self.obj._login_success_cb(dialog=None, app_name=APP_NAME,
93+ email=EMAIL)
94+
95+ self.assertEqual(self._called, (('success', APP_NAME, TOKEN), {}))
96+
97
98 class CredentialsLoginErrorTestCase(CredentialsTestCase):
99 """Test suite for the Credentials login error callback."""

Subscribers

People subscribed via source and target branches