Merge lp:~mikemc/ubiquity/keyring-double-keynames into lp:~mikemc/ubiquity/main-u1

Proposed by Mike McCracken
Status: Merged
Merged at revision: 5815
Proposed branch: lp:~mikemc/ubiquity/keyring-double-keynames
Merge into: lp:~mikemc/ubiquity/main-u1
Diff against target: 206 lines (+67/-44)
2 files modified
tests/test_ubi_ubuntuone.py (+58/-44)
ubiquity/plugins/ubi-ubuntuone.py (+9/-0)
To merge this branch: bzr merge lp:~mikemc/ubiquity/keyring-double-keynames
Reviewer Review Type Date Requested Status
dobey (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+151127@code.launchpad.net

Commit message

- Duplicate two keys in stored token for compatibility with v1 clients

Description of the change

- Duplicate two keys in stored token for compatibility with v1 clients

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

8 lines of code, 59 lines of tests :-)

review: Approve
5817. By Mike McCracken

merge with main-u1

Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/test_ubi_ubuntuone.py'
2--- tests/test_ubi_ubuntuone.py 2013-02-27 16:08:49 +0000
3+++ tests/test_ubi_ubuntuone.py 2013-03-01 19:02:21 +0000
4@@ -102,7 +102,7 @@
5
6 @patch('syslog.syslog', new=print)
7 @patch.object(ubi_ubuntuone, 'get_token_name')
8-@patch.object(Gtk, 'main')
9+@patch('gi.repository.Gtk')
10 class NextButtonActionTestCase(BaseTestPageGtk):
11
12 def _call_register(self, mock_token_name, create_success=True):
13@@ -132,13 +132,13 @@
14 ml.assert_called_once_with("foo@bar.com", "pw", 'tokenname',
15 ubi_ubuntuone.PAGE_REGISTER)
16
17- def test_call_register_success(self, mock_gtk_main, mock_token_name):
18+ def test_call_register_success(self, mock_gtk, mock_token_name):
19 self._call_register(mock_token_name)
20
21- def test_call_register_err(self, mock_gtk_main, mock_token_name):
22+ def test_call_register_err(self, mock_gtk, mock_token_name):
23 self._call_register(mock_token_name, create_success=False)
24
25- def test_call_login(self, mock_gtk_main, mock_token_name):
26+ def test_call_login(self, mock_gtk, mock_token_name):
27 mock_token_name.return_value = 'tokenname'
28
29 self.page.entry_existing_email.set_text("foo")
30@@ -152,7 +152,7 @@
31
32
33 @patch('syslog.syslog', new=print)
34-@patch.object(Gtk, 'main')
35+@patch('gi.repository.Gtk')
36 class SSOAPITestCase(BaseTestPageGtk):
37
38 def _call_handle_done(self, status, response_body, action, from_page):
39@@ -170,39 +170,39 @@
40 self.assertEqual(self.page.notebook_main.get_current_page(),
41 from_page)
42
43- def test_handle_done_token_OK(self, mock_gtk_main):
44- expected_body = "TESTBODY"
45- self._call_handle_done(http.client.OK, expected_body,
46- ubi_ubuntuone.TOKEN_CALLBACK_ACTION,
47- ubi_ubuntuone.PAGE_REGISTER)
48- self.assertEqual(self.page.oauth_token_json,
49- expected_body)
50-
51- def test_handle_done_token_CREATED(self, mock_gtk_main):
52- expected_body = "TESTBODY"
53- self._call_handle_done(http.client.CREATED,
54- expected_body,
55- ubi_ubuntuone.TOKEN_CALLBACK_ACTION,
56- ubi_ubuntuone.PAGE_REGISTER)
57- self.assertEqual(self.page.oauth_token_json,
58- expected_body)
59-
60- def test_handle_done_ping_OK(self, mock_gtk_main):
61- expected_body = "TESTBODY"
62- self._call_handle_done(http.client.OK, expected_body,
63- ubi_ubuntuone.PING_CALLBACK_ACTION,
64- ubi_ubuntuone.PAGE_REGISTER)
65- self.assertTrue(self.page.ping_successful)
66-
67- def test_handle_done_ping_CREATED(self, mock_gtk_main):
68- expected_body = "TESTBODY"
69- self._call_handle_done(http.client.CREATED,
70- expected_body,
71- ubi_ubuntuone.PING_CALLBACK_ACTION,
72- ubi_ubuntuone.PAGE_REGISTER)
73- self.assertTrue(self.page.ping_successful)
74-
75- def test_handle_done_error_token(self, mock_gtk_main):
76+ def test_handle_done_token_OK(self, mock_gtk):
77+ expected_body = "TESTBODY"
78+ self._call_handle_done(http.client.OK, expected_body,
79+ ubi_ubuntuone.TOKEN_CALLBACK_ACTION,
80+ ubi_ubuntuone.PAGE_REGISTER)
81+ self.assertEqual(self.page.oauth_token_json,
82+ expected_body)
83+
84+ def test_handle_done_token_CREATED(self, mock_gtk):
85+ expected_body = "TESTBODY"
86+ self._call_handle_done(http.client.CREATED,
87+ expected_body,
88+ ubi_ubuntuone.TOKEN_CALLBACK_ACTION,
89+ ubi_ubuntuone.PAGE_REGISTER)
90+ self.assertEqual(self.page.oauth_token_json,
91+ expected_body)
92+
93+ def test_handle_done_ping_OK(self, mock_gtk):
94+ expected_body = "TESTBODY"
95+ self._call_handle_done(http.client.OK, expected_body,
96+ ubi_ubuntuone.PING_CALLBACK_ACTION,
97+ ubi_ubuntuone.PAGE_REGISTER)
98+ self.assertTrue(self.page.ping_successful)
99+
100+ def test_handle_done_ping_CREATED(self, mock_gtk):
101+ expected_body = "TESTBODY"
102+ self._call_handle_done(http.client.CREATED,
103+ expected_body,
104+ ubi_ubuntuone.PING_CALLBACK_ACTION,
105+ ubi_ubuntuone.PAGE_REGISTER)
106+ self.assertTrue(self.page.ping_successful)
107+
108+ def test_handle_done_error_token(self, mock_gtk):
109 expected_body = json.dumps({"message": "tstmsg"})
110 # GONE or anything other than OK/CREATED:
111 self._call_handle_done(http.client.GONE, expected_body,
112@@ -212,7 +212,7 @@
113 self.assertEqual(self.page.label_global_error.get_text(),
114 "tstmsg")
115
116- def test_handle_done_error_ping(self, mock_gtk_main):
117+ def test_handle_done_error_ping(self, mock_gtk):
118 expected_body = "error"
119 with patch.object(self.page.label_global_error,
120 'get_text') as mock_get_text:
121@@ -226,7 +226,7 @@
122 "err")
123
124 @patch('json.dumps')
125- def test_login_to_sso(self, mock_json_dumps, mock_gtk_main):
126+ def test_login_to_sso(self, mock_json_dumps, mock_gtk):
127 email = 'email'
128 password = 'pass'
129 token_name = 'tok'
130@@ -266,7 +266,7 @@
131 self.assertEqual(mocks['session'].mock_calls, e)
132
133 @patch('json.dumps')
134- def test_register_new_sso_account(self, mock_json_dumps, mock_gtk_main):
135+ def test_register_new_sso_account(self, mock_json_dumps, mock_gtk):
136 email = 'email'
137 password = 'pass'
138 displayname = 'mr tester'
139@@ -306,7 +306,7 @@
140 @patch('json.loads')
141 @patch.multiple(ubi_ubuntuone, Client=DEFAULT, get_ping_info=DEFAULT)
142 def test_ping_u1_url(self, mock_json_loads,
143- mock_gtk_main, Client, get_ping_info):
144+ mock_gtk, Client, get_ping_info):
145
146 from_page = 1
147 email = 'email'
148@@ -354,15 +354,29 @@
149
150 class CreateKeyringTestCase(BaseTestPageGtk):
151
152+ def test_duplicate_token_data_for_v1(self):
153+ token = dict(token_key="token_key",
154+ token_name="token_name",
155+ other_key="other")
156+ newtoken = self.page._duplicate_token_data_for_v1(token)
157+ self.assertEqual(newtoken["token"], "token_key")
158+ self.assertEqual(newtoken["name"], "token_name")
159+ self.assertEqual(newtoken["other_key"], "other")
160+
161 @patch('ubiquity.misc.drop_all_privileges', sentinel.drop_privs)
162 @patch('subprocess.PIPE', sentinel.PIPE)
163 @patch('subprocess.Popen')
164 @patch('os.environ.get')
165 def test_create_keyring_urlencoded(self, mock_os_env_get, mock_Popen):
166 mock_os_env_get.return_value = 'cmd'
167- d_json = json.dumps({'A': 'b/f'})
168+ fake_token_dict = {'A': 'b/f'}
169+ d_json = json.dumps(fake_token_dict)
170 self.page._user_password = "test password"
171- self.page._create_keyring_and_store_u1_token(d_json)
172+ with patch.object(self.page,
173+ '_duplicate_token_data_for_v1') as mock_dup:
174+ mock_dup.side_effect = lambda x: x
175+ self.page._create_keyring_and_store_u1_token(d_json)
176+ mock_dup.assert_called_once_with(fake_token_dict)
177
178 mock_Popen.assert_called_with(['cmd'], stdin=sentinel.PIPE,
179 preexec_fn=sentinel.drop_privs)
180
181=== modified file 'ubiquity/plugins/ubi-ubuntuone.py'
182--- ubiquity/plugins/ubi-ubuntuone.py 2013-03-01 13:43:35 +0000
183+++ ubiquity/plugins/ubi-ubuntuone.py 2013-03-01 19:02:21 +0000
184@@ -316,6 +316,14 @@
185
186 return False
187
188+ def _duplicate_token_data_for_v1(self, token_dict):
189+ """Duplicate two keys in the stored token, for compatibility
190+ with clients expecting V1 API keys. See bug LP: #1136590 to
191+ check if we can remove this."""
192+ token_dict['token'] = token_dict['token_key']
193+ token_dict['name'] = token_dict['token_name']
194+ return token_dict
195+
196 def _create_keyring_and_store_u1_token(self, token_json):
197 """Helper that spawns a external helper to create the keyring"""
198 # this needs to be a external helper as ubiquity is running as
199@@ -324,6 +332,7 @@
200 # gnome-keyring daemon
201
202 token_dict = json.loads(token_json)
203+ token_dict = self._duplicate_token_data_for_v1(token_dict)
204 urlencoded_token = urlencode(token_dict)
205
206 cmd = os.environ.get("U1_KEYRING_HELPER",

Subscribers

People subscribed via source and target branches

to all changes: