Merge lp:~dobey/ubuntu-sso-client/new-kr-props into lp:ubuntu-sso-client

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 726
Merged at revision: 723
Proposed branch: lp:~dobey/ubuntu-sso-client/new-kr-props
Merge into: lp:ubuntu-sso-client
Diff against target: 220 lines (+79/-23)
2 files modified
ubuntu_sso/utils/tests/test_txsecrets.py (+27/-5)
ubuntu_sso/utils/txsecrets.py (+52/-18)
To merge this branch: bzr merge lp:~dobey/ubuntu-sso-client/new-kr-props
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+65419@code.launchpad.net

Commit message

Use the new property names for fdo secrets API

Description of the change

This seems to work on both versions of gnome-keyring (2.3x in 11.04, and 3.x in 11.10).

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

The code looks good, but when running this branch and having the control panel using it, I got the error below when trying to remove the current device:

2011-06-21 19:52:26,337:337.815999985 - ubuntu_sso.main - ERROR - CredentialsManagement: emitting CredentialsError with app_name "Ubuntu One" and error_dict {'errtype': 'DBusException', 'message': dbus.String(u'Invalid properties')}.

Same error when trying to store credentials in the keyring:

2011-06-21 19:56:07,373:373.473882675 - ubuntu_sso.main - DEBUG - SSOLogin: emitting LoginError with app_name "Ubuntu One" and error {'errtype': 'DBusException', 'message': dbus.String(u'Invalid properties')}

This test was made on a Natty (updated today) machine.

review: Needs Fixing
724. By dobey

Use fallbacks everywhere we use properties, and update the tests accordingly

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

It works very good now!

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

The code looks very good. Some comments:

 * Please change CLXN to COLLECTION for consistency, even if the constants are not exported.
 * why did you change the out_signature of SecretServiceMock.CreateCollection? I'm looking here, and it's still a "o", but perhaps it's changed on gnome-keyring 3: http://code.confuego.org/secrets-xdg-specs/re01.html

review: Needs Fixing
725. By dobey

undo the change to the out signature on CreateCollection

Revision history for this message
Alejandro J. Cura (alecu) :
review: Approve
726. By dobey

Add exception for when invalid properties are passed in to mock test objects

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntu_sso/utils/tests/test_txsecrets.py'
--- ubuntu_sso/utils/tests/test_txsecrets.py 2011-04-15 19:56:34 +0000
+++ ubuntu_sso/utils/tests/test_txsecrets.py 2011-06-23 17:53:25 +0000
@@ -43,6 +43,10 @@
43SAMPLE_CONTENT_TYPE = "text/plain; charset=utf8"43SAMPLE_CONTENT_TYPE = "text/plain; charset=utf8"
4444
4545
46class InvalidProperty(Exception):
47 """An exception for when invalid properties are passed in."""
48
49
46class SampleMiscException(Exception):50class SampleMiscException(Exception):
47 """An exception that will be turned into a DBus Exception."""51 """An exception that will be turned into a DBus Exception."""
4852
@@ -129,6 +133,10 @@
129 unlock_prompts = False133 unlock_prompts = False
130 item_mock_class = ItemMock134 item_mock_class = ItemMock
131135
136 item_attrs_property = txsecrets.ITEM_ATTRIBUTES_PROPERTY_OLD
137 item_label_property = txsecrets.ITEM_LABEL_PROPERTY_OLD
138 clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY_OLD
139
132 def __init__(self, label, *args, **kwargs):140 def __init__(self, label, *args, **kwargs):
133 """Initialize this instance."""141 """Initialize this instance."""
134 super(BaseCollectionMock, self).__init__(*args, **kwargs)142 super(BaseCollectionMock, self).__init__(*args, **kwargs)
@@ -145,8 +153,8 @@
145 raise SampleMiscException()153 raise SampleMiscException()
146 if self.locked:154 if self.locked:
147 raise SampleMiscException(ERROR_CREATE_BUT_LOCKED)155 raise SampleMiscException(ERROR_CREATE_BUT_LOCKED)
148 attributes = properties[txsecrets.ATTRIBUTES_PROPERTY]156 attributes = properties[self.item_attrs_property]
149 item_label = properties[txsecrets.LABEL_PROPERTY]157 item_label = properties[self.item_label_property]
150 value = secret[2]158 value = secret[2]
151 item_path = create_object_path(make_coll_path(self.label))159 item_path = create_object_path(make_coll_path(self.label))
152 item = self.dbus_publish(item_path, self.item_mock_class, self,160 item = self.dbus_publish(item_path, self.item_mock_class, self,
@@ -165,8 +173,10 @@
165 in_signature="ss", out_signature="v")173 in_signature="ss", out_signature="v")
166 def Get(self, interface, propname):174 def Get(self, interface, propname):
167 """The only property implemented is Label."""175 """The only property implemented is Label."""
168 if interface == txsecrets.COLLECTION_IFACE and propname == "Label":176 if interface == txsecrets.COLLECTION_IFACE and \
177 propname == self.clxn_label_property:
169 return dbus.String(self.label)178 return dbus.String(self.label)
179 raise InvalidProperty("Invalid property: {}".format(propname))
170180
171181
172class CollectionMock(BaseCollectionMock):182class CollectionMock(BaseCollectionMock):
@@ -202,6 +212,9 @@
202 dismissed = False212 dismissed = False
203 collection_mock_class = CollectionMock213 collection_mock_class = CollectionMock
204214
215 clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY_OLD
216 collections_property = txsecrets.COLLECTIONS_PROPERTY_OLD
217
205 def __init__(self, *args, **kwargs):218 def __init__(self, *args, **kwargs):
206 """Initialize this instance."""219 """Initialize this instance."""
207 super(SecretServiceMock, self).__init__(*args, **kwargs)220 super(SecretServiceMock, self).__init__(*args, **kwargs)
@@ -226,7 +239,7 @@
226 """Create a new collection with the specified properties."""239 """Create a new collection with the specified properties."""
227 if self.create_collection_fail:240 if self.create_collection_fail:
228 raise SampleMiscException()241 raise SampleMiscException()
229 label = str(properties[txsecrets.LABEL_PROPERTY])242 label = str(properties[self.clxn_label_property])
230 coll_path = make_coll_path(label)243 coll_path = make_coll_path(label)
231 collection = self.dbus_publish(coll_path, self.collection_mock_class,244 collection = self.dbus_publish(coll_path, self.collection_mock_class,
232 label)245 label)
@@ -313,9 +326,11 @@
313 in_signature="ss", out_signature="v")326 in_signature="ss", out_signature="v")
314 def Get(self, interface, propname):327 def Get(self, interface, propname):
315 """The only property implemented is Collections."""328 """The only property implemented is Collections."""
316 if interface == txsecrets.SERVICE_IFACE and propname == "Collections":329 if interface == txsecrets.SERVICE_IFACE and \
330 propname == self.collections_property:
317 coll_paths = [make_coll_path(l) for l in self.collections]331 coll_paths = [make_coll_path(l) for l in self.collections]
318 return dbus.Array(coll_paths, signature="o", variant_level=1)332 return dbus.Array(coll_paths, signature="o", variant_level=1)
333 raise InvalidProperty("Invalid property: {}".format(propname))
319334
320335
321class AltItemMock(ItemMock):336class AltItemMock(ItemMock):
@@ -335,6 +350,10 @@
335350
336 item_mock_class = AltItemMock351 item_mock_class = AltItemMock
337352
353 item_attrs_property = txsecrets.ITEM_ATTRIBUTES_PROPERTY
354 item_label_property = txsecrets.ITEM_LABEL_PROPERTY
355 clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY
356
338 @dbus.service.method(dbus_interface=txsecrets.COLLECTION_IFACE,357 @dbus.service.method(dbus_interface=txsecrets.COLLECTION_IFACE,
339 in_signature="a{sv}(oayays)b", out_signature="oo",358 in_signature="a{sv}(oayays)b", out_signature="oo",
340 byte_arrays=True)359 byte_arrays=True)
@@ -349,6 +368,9 @@
349368
350 collection_mock_class = AltCollectionMock369 collection_mock_class = AltCollectionMock
351370
371 clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY
372 collections_property = txsecrets.COLLECTIONS_PROPERTY
373
352374
353def create_object_path(base):375def create_object_path(base):
354 """Create a random object path given a base path."""376 """Create a random object path given a base path."""
355377
=== modified file 'ubuntu_sso/utils/txsecrets.py'
--- ubuntu_sso/utils/txsecrets.py 2011-04-15 19:56:34 +0000
+++ ubuntu_sso/utils/txsecrets.py 2011-06-23 17:53:25 +0000
@@ -45,9 +45,14 @@
4545
46ALGORITHM = "plain"46ALGORITHM = "plain"
47ALGORITHM_PARAMS = ""47ALGORITHM_PARAMS = ""
48LABEL_PROPERTY = "Label"48CLXN_LABEL_PROPERTY = "org.freedesktop.Secret.Collection.Label"
49ATTRIBUTES_PROPERTY = "Attributes"49CLXN_LABEL_PROPERTY_OLD = "Label"
50COLLECTIONS_PROPERTY = "Collections"50ITEM_LABEL_PROPERTY = "org.freedesktop.Secret.Item.Label"
51ITEM_LABEL_PROPERTY_OLD = "Label"
52ITEM_ATTRIBUTES_PROPERTY = "org.freedesktop.Secret.Item.Attributes"
53ITEM_ATTRIBUTES_PROPERTY_OLD = "Attributes"
54COLLECTIONS_PROPERTY = "org.freedesktop.Secret.Service.Collections"
55COLLECTIONS_PROPERTY_OLD = "Collections"
51DEFAULT_LABEL = "default"56DEFAULT_LABEL = "default"
5257
5358
@@ -163,10 +168,21 @@
163 else:168 else:
164 d.callback(collection)169 d.callback(collection)
165170
166 properties = {LABEL_PROPERTY: dbus.String(label, variant_level=1)}171 def error_fallback(error):
172 """Fall back to using the old property name."""
173 properties = {CLXN_LABEL_PROPERTY_OLD: dbus.String(
174 label,
175 variant_level=1)}
176 self.service.CreateCollection(
177 properties,
178 reply_handler=createcollection_handler,
179 error_handler=d.errback)
180
181 properties = {CLXN_LABEL_PROPERTY: dbus.String(label,
182 variant_level=1)}
167 self.service.CreateCollection(properties,183 self.service.CreateCollection(properties,
168 reply_handler=createcollection_handler,184 reply_handler=createcollection_handler,
169 error_handler=d.errback)185 error_handler=error_fallback)
170186
171 d.addCallback(lambda p: Collection(self, p))187 d.addCallback(lambda p: Collection(self, p))
172 return d188 return d
@@ -183,9 +199,15 @@
183 result.append(collection)199 result.append(collection)
184 d.callback(result)200 d.callback(result)
185201
202 def error_fallback(error):
203 """Fall back to the old property name."""
204 self.properties.Get(SERVICE_IFACE, COLLECTIONS_PROPERTY_OLD,
205 reply_handler=propertyget_handler,
206 error_handler=d.errback)
207
186 self.properties.Get(SERVICE_IFACE, COLLECTIONS_PROPERTY,208 self.properties.Get(SERVICE_IFACE, COLLECTIONS_PROPERTY,
187 reply_handler=propertyget_handler,209 reply_handler=propertyget_handler,
188 error_handler=d.errback)210 error_handler=error_fallback)
189 return d211 return d
190212
191 def get_default_collection(self):213 def get_default_collection(self):
@@ -268,8 +290,16 @@
268 def get_label(self):290 def get_label(self):
269 """Return the label for this collection from the keyring."""291 """Return the label for this collection from the keyring."""
270 d = Deferred()292 d = Deferred()
271 self.properties.Get(COLLECTION_IFACE, LABEL_PROPERTY,293
272 reply_handler=d.callback, error_handler=d.errback)294 def error_fallback(error):
295 """Fall back to the old property name."""
296 self.properties.Get(COLLECTION_IFACE, CLXN_LABEL_PROPERTY_OLD,
297 reply_handler=d.callback,
298 error_handler=d.errback)
299
300 self.properties.Get(COLLECTION_IFACE, CLXN_LABEL_PROPERTY,
301 reply_handler=d.callback,
302 error_handler=error_fallback)
273 return d303 return d
274304
275 def create_item(self, label, attr, value, replace=True):305 def create_item(self, label, attr, value, replace=True):
@@ -287,24 +317,28 @@
287 else:317 else:
288 d.callback(item)318 d.callback(item)
289319
290 def createitem_error(error):
291 """An error creating the item, try older signature."""
292 secret = (self.service.session, parameters, value_bytes)
293 self.collection_iface.CreateItem(properties, secret, replace,
294 reply_handler=createitem_handler,
295 error_handler=d.errback)
296
297 properties = dbus.Dictionary(signature="sv")320 properties = dbus.Dictionary(signature="sv")
298 properties[LABEL_PROPERTY] = label321 properties[ITEM_LABEL_PROPERTY] = label
299 attributes = dbus.Dictionary(attr, signature="ss")322 attributes = dbus.Dictionary(attr, signature="ss")
300 properties[ATTRIBUTES_PROPERTY] = attributes323 properties[ITEM_ATTRIBUTES_PROPERTY] = attributes
301 parameters = dbus.ByteArray(ALGORITHM_PARAMS)324 parameters = dbus.ByteArray(ALGORITHM_PARAMS)
302 value_bytes = dbus.ByteArray(value)325 value_bytes = dbus.ByteArray(value)
303 secret = (self.service.session, parameters, value_bytes,326 secret = (self.service.session, parameters, value_bytes,
304 SECRET_CONTENT_TYPE)327 SECRET_CONTENT_TYPE)
328
329 def error_fallback(error):
330 """A fallback for using old property names and signature."""
331 oldprops = dbus.Dictionary(signature="sv")
332 oldprops[ITEM_LABEL_PROPERTY_OLD] = label
333 oldprops[ITEM_ATTRIBUTES_PROPERTY_OLD] = attributes
334 secret = (self.service.session, parameters, value_bytes)
335 self.collection_iface.CreateItem(oldprops, secret, replace,
336 reply_handler=createitem_handler,
337 error_handler=d.errback)
338
305 self.collection_iface.CreateItem(properties, secret, replace,339 self.collection_iface.CreateItem(properties, secret, replace,
306 reply_handler=createitem_handler,340 reply_handler=createitem_handler,
307 error_handler=createitem_error)341 error_handler=error_fallback)
308 return d342 return d
309343
310344

Subscribers

People subscribed via source and target branches