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

Proposed by dobey on 2011-06-21
Status: Merged
Approved by: dobey on 2011-06-23
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) 2011-06-21 Approve on 2011-06-23
Natalia Bidart 2011-06-21 Approve on 2011-06-23
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.
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 on 2011-06-23

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

Natalia Bidart (nataliabidart) wrote :

It works very good now!

review: Approve
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 on 2011-06-23

undo the change to the out signature on CreateCollection

Alejandro J. Cura (alecu) :
review: Approve
726. By dobey on 2011-06-23

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
1=== modified file 'ubuntu_sso/utils/tests/test_txsecrets.py'
2--- ubuntu_sso/utils/tests/test_txsecrets.py 2011-04-15 19:56:34 +0000
3+++ ubuntu_sso/utils/tests/test_txsecrets.py 2011-06-23 17:53:25 +0000
4@@ -43,6 +43,10 @@
5 SAMPLE_CONTENT_TYPE = "text/plain; charset=utf8"
6
7
8+class InvalidProperty(Exception):
9+ """An exception for when invalid properties are passed in."""
10+
11+
12 class SampleMiscException(Exception):
13 """An exception that will be turned into a DBus Exception."""
14
15@@ -129,6 +133,10 @@
16 unlock_prompts = False
17 item_mock_class = ItemMock
18
19+ item_attrs_property = txsecrets.ITEM_ATTRIBUTES_PROPERTY_OLD
20+ item_label_property = txsecrets.ITEM_LABEL_PROPERTY_OLD
21+ clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY_OLD
22+
23 def __init__(self, label, *args, **kwargs):
24 """Initialize this instance."""
25 super(BaseCollectionMock, self).__init__(*args, **kwargs)
26@@ -145,8 +153,8 @@
27 raise SampleMiscException()
28 if self.locked:
29 raise SampleMiscException(ERROR_CREATE_BUT_LOCKED)
30- attributes = properties[txsecrets.ATTRIBUTES_PROPERTY]
31- item_label = properties[txsecrets.LABEL_PROPERTY]
32+ attributes = properties[self.item_attrs_property]
33+ item_label = properties[self.item_label_property]
34 value = secret[2]
35 item_path = create_object_path(make_coll_path(self.label))
36 item = self.dbus_publish(item_path, self.item_mock_class, self,
37@@ -165,8 +173,10 @@
38 in_signature="ss", out_signature="v")
39 def Get(self, interface, propname):
40 """The only property implemented is Label."""
41- if interface == txsecrets.COLLECTION_IFACE and propname == "Label":
42+ if interface == txsecrets.COLLECTION_IFACE and \
43+ propname == self.clxn_label_property:
44 return dbus.String(self.label)
45+ raise InvalidProperty("Invalid property: {}".format(propname))
46
47
48 class CollectionMock(BaseCollectionMock):
49@@ -202,6 +212,9 @@
50 dismissed = False
51 collection_mock_class = CollectionMock
52
53+ clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY_OLD
54+ collections_property = txsecrets.COLLECTIONS_PROPERTY_OLD
55+
56 def __init__(self, *args, **kwargs):
57 """Initialize this instance."""
58 super(SecretServiceMock, self).__init__(*args, **kwargs)
59@@ -226,7 +239,7 @@
60 """Create a new collection with the specified properties."""
61 if self.create_collection_fail:
62 raise SampleMiscException()
63- label = str(properties[txsecrets.LABEL_PROPERTY])
64+ label = str(properties[self.clxn_label_property])
65 coll_path = make_coll_path(label)
66 collection = self.dbus_publish(coll_path, self.collection_mock_class,
67 label)
68@@ -313,9 +326,11 @@
69 in_signature="ss", out_signature="v")
70 def Get(self, interface, propname):
71 """The only property implemented is Collections."""
72- if interface == txsecrets.SERVICE_IFACE and propname == "Collections":
73+ if interface == txsecrets.SERVICE_IFACE and \
74+ propname == self.collections_property:
75 coll_paths = [make_coll_path(l) for l in self.collections]
76 return dbus.Array(coll_paths, signature="o", variant_level=1)
77+ raise InvalidProperty("Invalid property: {}".format(propname))
78
79
80 class AltItemMock(ItemMock):
81@@ -335,6 +350,10 @@
82
83 item_mock_class = AltItemMock
84
85+ item_attrs_property = txsecrets.ITEM_ATTRIBUTES_PROPERTY
86+ item_label_property = txsecrets.ITEM_LABEL_PROPERTY
87+ clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY
88+
89 @dbus.service.method(dbus_interface=txsecrets.COLLECTION_IFACE,
90 in_signature="a{sv}(oayays)b", out_signature="oo",
91 byte_arrays=True)
92@@ -349,6 +368,9 @@
93
94 collection_mock_class = AltCollectionMock
95
96+ clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY
97+ collections_property = txsecrets.COLLECTIONS_PROPERTY
98+
99
100 def create_object_path(base):
101 """Create a random object path given a base path."""
102
103=== modified file 'ubuntu_sso/utils/txsecrets.py'
104--- ubuntu_sso/utils/txsecrets.py 2011-04-15 19:56:34 +0000
105+++ ubuntu_sso/utils/txsecrets.py 2011-06-23 17:53:25 +0000
106@@ -45,9 +45,14 @@
107
108 ALGORITHM = "plain"
109 ALGORITHM_PARAMS = ""
110-LABEL_PROPERTY = "Label"
111-ATTRIBUTES_PROPERTY = "Attributes"
112-COLLECTIONS_PROPERTY = "Collections"
113+CLXN_LABEL_PROPERTY = "org.freedesktop.Secret.Collection.Label"
114+CLXN_LABEL_PROPERTY_OLD = "Label"
115+ITEM_LABEL_PROPERTY = "org.freedesktop.Secret.Item.Label"
116+ITEM_LABEL_PROPERTY_OLD = "Label"
117+ITEM_ATTRIBUTES_PROPERTY = "org.freedesktop.Secret.Item.Attributes"
118+ITEM_ATTRIBUTES_PROPERTY_OLD = "Attributes"
119+COLLECTIONS_PROPERTY = "org.freedesktop.Secret.Service.Collections"
120+COLLECTIONS_PROPERTY_OLD = "Collections"
121 DEFAULT_LABEL = "default"
122
123
124@@ -163,10 +168,21 @@
125 else:
126 d.callback(collection)
127
128- properties = {LABEL_PROPERTY: dbus.String(label, variant_level=1)}
129+ def error_fallback(error):
130+ """Fall back to using the old property name."""
131+ properties = {CLXN_LABEL_PROPERTY_OLD: dbus.String(
132+ label,
133+ variant_level=1)}
134+ self.service.CreateCollection(
135+ properties,
136+ reply_handler=createcollection_handler,
137+ error_handler=d.errback)
138+
139+ properties = {CLXN_LABEL_PROPERTY: dbus.String(label,
140+ variant_level=1)}
141 self.service.CreateCollection(properties,
142 reply_handler=createcollection_handler,
143- error_handler=d.errback)
144+ error_handler=error_fallback)
145
146 d.addCallback(lambda p: Collection(self, p))
147 return d
148@@ -183,9 +199,15 @@
149 result.append(collection)
150 d.callback(result)
151
152+ def error_fallback(error):
153+ """Fall back to the old property name."""
154+ self.properties.Get(SERVICE_IFACE, COLLECTIONS_PROPERTY_OLD,
155+ reply_handler=propertyget_handler,
156+ error_handler=d.errback)
157+
158 self.properties.Get(SERVICE_IFACE, COLLECTIONS_PROPERTY,
159 reply_handler=propertyget_handler,
160- error_handler=d.errback)
161+ error_handler=error_fallback)
162 return d
163
164 def get_default_collection(self):
165@@ -268,8 +290,16 @@
166 def get_label(self):
167 """Return the label for this collection from the keyring."""
168 d = Deferred()
169- self.properties.Get(COLLECTION_IFACE, LABEL_PROPERTY,
170- reply_handler=d.callback, error_handler=d.errback)
171+
172+ def error_fallback(error):
173+ """Fall back to the old property name."""
174+ self.properties.Get(COLLECTION_IFACE, CLXN_LABEL_PROPERTY_OLD,
175+ reply_handler=d.callback,
176+ error_handler=d.errback)
177+
178+ self.properties.Get(COLLECTION_IFACE, CLXN_LABEL_PROPERTY,
179+ reply_handler=d.callback,
180+ error_handler=error_fallback)
181 return d
182
183 def create_item(self, label, attr, value, replace=True):
184@@ -287,24 +317,28 @@
185 else:
186 d.callback(item)
187
188- def createitem_error(error):
189- """An error creating the item, try older signature."""
190- secret = (self.service.session, parameters, value_bytes)
191- self.collection_iface.CreateItem(properties, secret, replace,
192- reply_handler=createitem_handler,
193- error_handler=d.errback)
194-
195 properties = dbus.Dictionary(signature="sv")
196- properties[LABEL_PROPERTY] = label
197+ properties[ITEM_LABEL_PROPERTY] = label
198 attributes = dbus.Dictionary(attr, signature="ss")
199- properties[ATTRIBUTES_PROPERTY] = attributes
200+ properties[ITEM_ATTRIBUTES_PROPERTY] = attributes
201 parameters = dbus.ByteArray(ALGORITHM_PARAMS)
202 value_bytes = dbus.ByteArray(value)
203 secret = (self.service.session, parameters, value_bytes,
204 SECRET_CONTENT_TYPE)
205+
206+ def error_fallback(error):
207+ """A fallback for using old property names and signature."""
208+ oldprops = dbus.Dictionary(signature="sv")
209+ oldprops[ITEM_LABEL_PROPERTY_OLD] = label
210+ oldprops[ITEM_ATTRIBUTES_PROPERTY_OLD] = attributes
211+ secret = (self.service.session, parameters, value_bytes)
212+ self.collection_iface.CreateItem(oldprops, secret, replace,
213+ reply_handler=createitem_handler,
214+ error_handler=d.errback)
215+
216 self.collection_iface.CreateItem(properties, secret, replace,
217 reply_handler=createitem_handler,
218- error_handler=createitem_error)
219+ error_handler=error_fallback)
220 return d
221
222

Subscribers

People subscribed via source and target branches