Merge lp:~facundo/magicicada-protocol/xenial-tests into lp:magicicada-protocol
- xenial-tests
- Merge into trunk
Proposed by
Facundo Batista
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 168 |
Merged at revision: | 167 |
Proposed branch: | lp:~facundo/magicicada-protocol/xenial-tests |
Merge into: | lp:magicicada-protocol |
Diff against target: |
480 lines (+124/-83) 12 files modified
run-tests (+2/-2) samples/easy_client.py (+3/-2) samples/ping_client.py (+3/-3) setup.py (+0/-2) tests/certs/cert1.pem (+29/-0) tests/certs/cert2.pem (+25/-0) tests/test_client.py (+47/-38) tests/test_context.py (+3/-27) tests/test_proxy_tunnel.py (+1/-1) ubuntuone/storageprotocol/client.py (+5/-5) ubuntuone/storageprotocol/content_hash.py (+5/-1) ubuntuone/storageprotocol/request.py (+1/-2) |
To merge this branch: | bzr merge lp:~facundo/magicicada-protocol/xenial-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Natalia Bidart | Approve | ||
Review via email: mp+306051@code.launchpad.net |
Commit message
Small changes for tests to run ok under xenial.
Description of the change
Small changes for tests to run ok under xenial.
Including:
- removed two tests that checked situations after having a protobuf message with an invalid value, and this is not possible anymore in modern protobuf (can not create the request itself, because of internal verifications at creation time).
- Stop patching the certificates loader, just set the proper env var in the test and use regular code. Also included the certificates in the project (previously they were being taken from SSO).
- Lot of aesthetic small details
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'run-tests' | |||
2 | --- run-tests 2014-02-24 18:38:33 +0000 | |||
3 | +++ run-tests 2016-09-19 02:06:21 +0000 | |||
4 | @@ -21,11 +21,11 @@ | |||
5 | 21 | 21 | ||
6 | 22 | /usr/bin/env python setup.py build | 22 | /usr/bin/env python setup.py build |
7 | 23 | # run the tests with pure python protobuf | 23 | # run the tests with pure python protobuf |
9 | 24 | PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python u1trial tests | 24 | SSL_CERTIFICATES_DIR=tests/certs PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python u1trial tests |
10 | 25 | if [ "$SYSNAME" != "Darwin" ]; then | 25 | if [ "$SYSNAME" != "Darwin" ]; then |
11 | 26 | # and with the cpp extension, for server (linux) only: | 26 | # and with the cpp extension, for server (linux) only: |
12 | 27 | if [ $PROTOC_VERSION_AS_INT -lt 2500 ]; then | 27 | if [ $PROTOC_VERSION_AS_INT -lt 2500 ]; then |
14 | 28 | PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp u1trial tests | 28 | SSL_CERTIFICATES_DIR=tests/certs PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp u1trial tests |
15 | 29 | fi | 29 | fi |
16 | 30 | fi | 30 | fi |
17 | 31 | 31 | ||
18 | 32 | 32 | ||
19 | === modified file 'samples/easy_client.py' | |||
20 | --- samples/easy_client.py 2012-03-29 20:28:09 +0000 | |||
21 | +++ samples/easy_client.py 2016-09-19 02:06:21 +0000 | |||
22 | @@ -256,8 +256,9 @@ | |||
23 | 256 | return failure | 256 | return failure |
24 | 257 | 257 | ||
25 | 258 | 258 | ||
28 | 259 | # deferred utilities | 259 | def skip_result(_, f, *args, **kwargs): |
29 | 260 | skip_result = lambda _, f, *args, **kwargs: f(*args, **kwargs) | 260 | """Deferred utilities.""" |
30 | 261 | return f(*args, **kwargs) | ||
31 | 261 | 262 | ||
32 | 262 | 263 | ||
33 | 263 | def sr_result(result, f, *args, **kwargs): | 264 | def sr_result(result, f, *args, **kwargs): |
34 | 264 | 265 | ||
35 | === modified file 'samples/ping_client.py' | |||
36 | --- samples/ping_client.py 2012-03-29 20:28:09 +0000 | |||
37 | +++ samples/ping_client.py 2016-09-19 02:06:21 +0000 | |||
38 | @@ -82,12 +82,12 @@ | |||
39 | 82 | reactor.connectTCP('75.101.137.174', 80, PingClientFactory()) | 82 | reactor.connectTCP('75.101.137.174', 80, PingClientFactory()) |
40 | 83 | 83 | ||
41 | 84 | # using ssl | 84 | # using ssl |
43 | 85 | #reactor.connectSSL('localhost', 20101, StorageClientFactory(), | 85 | # reactor.connectSSL('localhost', 20101, StorageClientFactory(), |
44 | 86 | # ssl.ClientContextFactory()) | 86 | # ssl.ClientContextFactory()) |
45 | 87 | 87 | ||
46 | 88 | # using ssl over a proxy | 88 | # using ssl over a proxy |
49 | 89 | #from ubuntuone.storageprotocol import proxy_tunnel | 89 | # from ubuntuone.storageprotocol import proxy_tunnel |
50 | 90 | #proxy_tunnel.connectHTTPS('localhost', 3128, | 90 | # proxy_tunnel.connectHTTPS('localhost', 3128, |
51 | 91 | # 'localhost', 20101, StorageClientFactory(), | 91 | # 'localhost', 20101, StorageClientFactory(), |
52 | 92 | # user="test", passwd="test") | 92 | # user="test", passwd="test") |
53 | 93 | 93 | ||
54 | 94 | 94 | ||
55 | === modified file 'setup.py' | |||
56 | --- setup.py 2013-05-28 22:07:40 +0000 | |||
57 | +++ setup.py 2016-09-19 02:06:21 +0000 | |||
58 | @@ -21,8 +21,6 @@ | |||
59 | 21 | import sys | 21 | import sys |
60 | 22 | import subprocess | 22 | import subprocess |
61 | 23 | 23 | ||
62 | 24 | sys.path.insert(0, os.path.abspath(".")) | ||
63 | 25 | |||
64 | 26 | from distutils.core import setup | 24 | from distutils.core import setup |
65 | 27 | from distutils.spawn import find_executable | 25 | from distutils.spawn import find_executable |
66 | 28 | from distutils.command import clean, build | 26 | from distutils.command import clean, build |
67 | 29 | 27 | ||
68 | === added directory 'tests/certs' | |||
69 | === added file 'tests/certs/cert1.pem' | |||
70 | --- tests/certs/cert1.pem 1970-01-01 00:00:00 +0000 | |||
71 | +++ tests/certs/cert1.pem 2016-09-19 02:06:21 +0000 | |||
72 | @@ -0,0 +1,29 @@ | |||
73 | 1 | -----BEGIN CERTIFICATE----- | ||
74 | 2 | MIIE3jCCA8agAwIBAgICAwEwDQYJKoZIhvcNAQEFBQAwYzELMAkGA1UEBhMCVVMx | ||
75 | 3 | ITAfBgNVBAoTGFRoZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28g | ||
76 | 4 | RGFkZHkgQ2xhc3MgMiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjExMTYw | ||
77 | 5 | MTU0MzdaFw0yNjExMTYwMTU0MzdaMIHKMQswCQYDVQQGEwJVUzEQMA4GA1UECBMH | ||
78 | 6 | QXJpem9uYTETMBEGA1UEBxMKU2NvdHRzZGFsZTEaMBgGA1UEChMRR29EYWRkeS5j | ||
79 | 7 | b20sIEluYy4xMzAxBgNVBAsTKmh0dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRkeS5j | ||
80 | 8 | b20vcmVwb3NpdG9yeTEwMC4GA1UEAxMnR28gRGFkZHkgU2VjdXJlIENlcnRpZmlj | ||
81 | 9 | YXRpb24gQXV0aG9yaXR5MREwDwYDVQQFEwgwNzk2OTI4NzCCASIwDQYJKoZIhvcN | ||
82 | 10 | AQEBBQADggEPADCCAQoCggEBAMQt1RWMnCZM7DI161+4WQFapmGBWTtwY6vj3D3H | ||
83 | 11 | KrjJM9N55DrtPDAjhI6zMBS2sofDPZVUBJ7fmd0LJR4h3mUpfjWoqVTr9vcyOdQm | ||
84 | 12 | VZWt7/v+WIbXnvQAjYwqDL1CBM6nPwT27oDyqu9SoWlm2r4arV3aLGbqGmu75RpR | ||
85 | 13 | SgAvSMeYddi5Kcju+GZtCpyz8/x4fKL4o/K1w/O5epHBp+YlLpyo7RJlbmr2EkRT | ||
86 | 14 | cDCVw5wrWCs9CHRK8r5RsL+H0EwnWGu1NcWdrxcx+AuP7q2BNgWJCJjPOq8lh8BJ | ||
87 | 15 | 6qf9Z/dFjpfMFDniNoW1fho3/Rb2cRGadDAW/hOUoz+EDU8CAwEAAaOCATIwggEu | ||
88 | 16 | MB0GA1UdDgQWBBT9rGEyk2xF1uLuhV+auud2mWjM5zAfBgNVHSMEGDAWgBTSxLDS | ||
89 | 17 | kdRMEXGzYcs9of7dqGrU4zASBgNVHRMBAf8ECDAGAQH/AgEAMDMGCCsGAQUFBwEB | ||
90 | 18 | BCcwJTAjBggrBgEFBQcwAYYXaHR0cDovL29jc3AuZ29kYWRkeS5jb20wRgYDVR0f | ||
91 | 19 | BD8wPTA7oDmgN4Y1aHR0cDovL2NlcnRpZmljYXRlcy5nb2RhZGR5LmNvbS9yZXBv | ||
92 | 20 | c2l0b3J5L2dkcm9vdC5jcmwwSwYDVR0gBEQwQjBABgRVHSAAMDgwNgYIKwYBBQUH | ||
93 | 21 | AgEWKmh0dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRkeS5jb20vcmVwb3NpdG9yeTAO | ||
94 | 22 | BgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQEFBQADggEBANKGwOy9+aG2Z+5mC6IG | ||
95 | 23 | OgRQjhVyrEp0lVPLN8tESe8HkGsz2ZbwlFalEzAFPIUyIXvJxwqoJKSQ3kbTJSMU | ||
96 | 24 | A2fCENZvD117esyfxVgqwcSeIaha86ykRvOe5GPLL5CkKSkB2XIsKd83ASe8T+5o | ||
97 | 25 | 0yGPwLPk9Qnt0hCqU7S+8MxZC9Y7lhyVJEnfzuz9p0iRFEUOOjZv2kWzRaJBydTX | ||
98 | 26 | RE4+uXR21aITVSzGh6O1mawGhId/dQb8vxRMDsxuxN89txJx9OjxUUAiKEngHUuH | ||
99 | 27 | qDTMBqLdElrRhjZkAzVvb3du6/KFUJheqwNTrZEjYx8WnM25sgVjOuH0aBsXBTWV | ||
100 | 28 | U+4= | ||
101 | 29 | -----END CERTIFICATE----- | ||
102 | 0 | 30 | ||
103 | === added file 'tests/certs/cert2.pem' | |||
104 | --- tests/certs/cert2.pem 1970-01-01 00:00:00 +0000 | |||
105 | +++ tests/certs/cert2.pem 2016-09-19 02:06:21 +0000 | |||
106 | @@ -0,0 +1,25 @@ | |||
107 | 1 | -----BEGIN CERTIFICATE----- | ||
108 | 2 | MIIEADCCAuigAwIBAgIBADANBgkqhkiG9w0BAQUFADBjMQswCQYDVQQGEwJV | ||
109 | 3 | UzEhMB8GA1UEChMYVGhlIEdvIERhZGR5IEdyb3VwLCBJbmMuMTEwLwYDVQQL | ||
110 | 4 | EyhHbyBEYWRkeSBDbGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4X | ||
111 | 5 | DTA0MDYyOTE3MDYyMFoXDTM0MDYyOTE3MDYyMFowYzELMAkGA1UEBhMCVVMx | ||
112 | 6 | ITAfBgNVBAoTGFRoZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMo | ||
113 | 7 | R28gRGFkZHkgQ2xhc3MgMiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCCASAw | ||
114 | 8 | DQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBAN6d1+pXGEmhW+vXX0iG6r7d | ||
115 | 9 | /+TvZxz0ZWizV3GgXne77ZtJ6XCAPVYYYwhv2vLM0D9/AlQiVBDYsoHUwHU9 | ||
116 | 10 | S3/Hd8M+eKsaA7Ugay9qK7HFiH7Eux6wwdhFJ2+qN1j3hybX2C32qRe3H3I2 | ||
117 | 11 | TqYXP2WYktsqbl2i/ojgC95/5Y0V4evLOtXiEqITLdiOr18SPaAIBQi2XKVl | ||
118 | 12 | OARFmR6jYGB0xUGlcmIbYsUfb18aQr4CUWWoriMYavx4A6lNf4DD+qta/KFA | ||
119 | 13 | pMoZFv6yyO9ecw3ud72a9nmYvLEHZ6IVDd2gWMZEewo+YihfukEHU1jPEX44 | ||
120 | 14 | dMX4/7VpkI+EdOqXG68CAQOjgcAwgb0wHQYDVR0OBBYEFNLEsNKR1EwRcbNh | ||
121 | 15 | yz2h/t2oatTjMIGNBgNVHSMEgYUwgYKAFNLEsNKR1EwRcbNhyz2h/t2oatTj | ||
122 | 16 | oWekZTBjMQswCQYDVQQGEwJVUzEhMB8GA1UEChMYVGhlIEdvIERhZGR5IEdy | ||
123 | 17 | b3VwLCBJbmMuMTEwLwYDVQQLEyhHbyBEYWRkeSBDbGFzcyAyIENlcnRpZmlj | ||
124 | 18 | YXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEF | ||
125 | 19 | BQADggEBADJL87LKPpH8EsahB4yOd6AzBhRckB4Y9wimPQoZ+YeAEW5p5JYX | ||
126 | 20 | MP80kWNyOO7MHAGjHZQopDH2esRU1/blMVgDoszOYtuURXO1v0XJJLXVggKt | ||
127 | 21 | I3lpjbi2Tc7PTMozI+gciKqdi0FuFskg5YmezTvacPd+mSYgFFQlq25zheab | ||
128 | 22 | IZ0KbIIOqPjCDPoQHmyW74cNxA9hi63ugyuV+I6ShHI56yDqg+2DzZduCLzr | ||
129 | 23 | Tia2cyvk0/ZM/iZx4mERdEr/VxqHD3VILs9RaRegAhJhldXRQLIQTO7ErBBD | ||
130 | 24 | pqWeCtWVYpoNz4iCxTIM5CufReYNnyicsbkqWletNw+vHX/bvZ8= | ||
131 | 25 | -----END CERTIFICATE----- | ||
132 | 0 | 26 | ||
133 | === modified file 'tests/test_client.py' | |||
134 | --- tests/test_client.py 2015-05-18 17:23:03 +0000 | |||
135 | +++ tests/test_client.py 2016-09-19 02:06:21 +0000 | |||
136 | @@ -135,6 +135,10 @@ | |||
137 | 135 | message.share.access_level = 0 | 135 | message.share.access_level = 0 |
138 | 136 | 136 | ||
139 | 137 | 137 | ||
140 | 138 | def noop_callback(*a): | ||
141 | 139 | """No op callback.""" | ||
142 | 140 | |||
143 | 141 | |||
144 | 138 | class MethodMock(object): | 142 | class MethodMock(object): |
145 | 139 | """A class to overwrite methods to know if they were called. | 143 | """A class to overwrite methods to know if they were called. |
146 | 140 | 144 | ||
147 | @@ -258,9 +262,8 @@ | |||
148 | 258 | 262 | ||
149 | 259 | def test_set_volume_deleted_callback(self): | 263 | def test_set_volume_deleted_callback(self): |
150 | 260 | """Test callback setting.""" | 264 | """Test callback setting.""" |
154 | 261 | a_callback = lambda x: None | 265 | self.client.set_volume_deleted_callback(noop_callback) |
155 | 262 | self.client.set_volume_deleted_callback(a_callback) | 266 | self.assertTrue(self.client._volume_deleted_callback is noop_callback) |
153 | 263 | self.assertTrue(self.client._volume_deleted_callback is a_callback) | ||
156 | 264 | 267 | ||
157 | 265 | def test_callback_must_be_callable(self): | 268 | def test_callback_must_be_callable(self): |
158 | 266 | """Test set callback parameters.""" | 269 | """Test set callback parameters.""" |
159 | @@ -275,31 +278,33 @@ | |||
160 | 275 | 278 | ||
161 | 276 | def test_set_volume_created_callback(self): | 279 | def test_set_volume_created_callback(self): |
162 | 277 | """Test callback setting.""" | 280 | """Test callback setting.""" |
166 | 278 | a_callback = lambda y, z: None | 281 | self.client.set_volume_created_callback(noop_callback) |
167 | 279 | self.client.set_volume_created_callback(a_callback) | 282 | self.assertIs(self.client._volume_created_callback, noop_callback) |
165 | 280 | self.assertTrue(self.client._volume_created_callback is a_callback) | ||
168 | 281 | 283 | ||
169 | 282 | def test_set_volume_new_generation_callback(self): | 284 | def test_set_volume_new_generation_callback(self): |
170 | 283 | """Test callback setting.""" | 285 | """Test callback setting.""" |
174 | 284 | cback = lambda y, z: None | 286 | self.client.set_volume_new_generation_callback(noop_callback) |
175 | 285 | self.client.set_volume_new_generation_callback(cback) | 287 | self.assertIs(self.client._volume_new_generation_callback, |
176 | 286 | self.assertTrue(self.client._volume_new_generation_callback is cback) | 288 | noop_callback) |
177 | 287 | 289 | ||
178 | 288 | # share notification callbacks | 290 | # share notification callbacks |
179 | 289 | def test_share_change_callback(self): | 291 | def test_share_change_callback(self): |
180 | 290 | """Test share_change callback usage.""" | 292 | """Test share_change callback usage.""" |
181 | 291 | self.assertRaises(TypeError, self.client.set_share_change_callback, | 293 | self.assertRaises(TypeError, self.client.set_share_change_callback, |
182 | 292 | 'hello') | 294 | 'hello') |
184 | 293 | #create a response and message | 295 | # create a response and message |
185 | 294 | share_resp = sharersp.NotifyShareHolder.from_params( | 296 | share_resp = sharersp.NotifyShareHolder.from_params( |
186 | 295 | uuid.uuid4(), uuid.uuid4(), 'sname', 'byu', 'tou', 'View') | 297 | uuid.uuid4(), uuid.uuid4(), 'sname', 'byu', 'tou', 'View') |
187 | 296 | proto_msg = protocol_pb2.Message() | 298 | proto_msg = protocol_pb2.Message() |
188 | 297 | proto_msg.type = protocol_pb2.Message.NOTIFY_SHARE | 299 | proto_msg.type = protocol_pb2.Message.NOTIFY_SHARE |
189 | 298 | share_resp.dump_to_msg(proto_msg.notify_share) | 300 | share_resp.dump_to_msg(proto_msg.notify_share) |
190 | 299 | 301 | ||
192 | 300 | #wire up a call back and make sure it's correct | 302 | # wire up a call back and make sure it's correct |
193 | 301 | self.share_notif = None | 303 | self.share_notif = None |
195 | 302 | a_callback = lambda notif: setattr(self, 'share_notif', notif) | 304 | |
196 | 305 | def a_callback(notif): | ||
197 | 306 | setattr(self, 'share_notif', notif) | ||
198 | 307 | |||
199 | 303 | self.client.set_share_change_callback(a_callback) | 308 | self.client.set_share_change_callback(a_callback) |
200 | 304 | self.assertTrue(self.client._share_change_callback is a_callback) | 309 | self.assertTrue(self.client._share_change_callback is a_callback) |
201 | 305 | self.client.handle_NOTIFY_SHARE(proto_msg) | 310 | self.client.handle_NOTIFY_SHARE(proto_msg) |
202 | @@ -315,9 +320,12 @@ | |||
203 | 315 | proto_msg.type = protocol_pb2.Message.SHARE_DELETED | 320 | proto_msg.type = protocol_pb2.Message.SHARE_DELETED |
204 | 316 | proto_msg.share_deleted.share_id = str(share_id) | 321 | proto_msg.share_deleted.share_id = str(share_id) |
205 | 317 | 322 | ||
207 | 318 | #wire up a call back and make sure it's correct | 323 | # wire up a call back and make sure it's correct |
208 | 319 | self.deleted_share_id = None | 324 | self.deleted_share_id = None |
210 | 320 | a_callback = lambda notif: setattr(self, 'deleted_share_id', notif) | 325 | |
211 | 326 | def a_callback(notif): | ||
212 | 327 | setattr(self, 'deleted_share_id', notif) | ||
213 | 328 | |||
214 | 321 | self.client.set_share_delete_callback(a_callback) | 329 | self.client.set_share_delete_callback(a_callback) |
215 | 322 | self.assertTrue(self.client._share_delete_callback is a_callback) | 330 | self.assertTrue(self.client._share_delete_callback is a_callback) |
216 | 323 | self.client.handle_SHARE_DELETED(proto_msg) | 331 | self.client.handle_SHARE_DELETED(proto_msg) |
217 | @@ -334,9 +342,12 @@ | |||
218 | 334 | proto_msg.share_accepted.share_id = str(share_id) | 342 | proto_msg.share_accepted.share_id = str(share_id) |
219 | 335 | proto_msg.share_accepted.answer = protocol_pb2.ShareAccepted.YES | 343 | proto_msg.share_accepted.answer = protocol_pb2.ShareAccepted.YES |
220 | 336 | 344 | ||
222 | 337 | #wire up a call back and make sure it's correct | 345 | # wire up a call back and make sure it's correct |
223 | 338 | self.answer = None | 346 | self.answer = None |
225 | 339 | a_callback = lambda s, a: setattr(self, 'answer', (s, a)) | 347 | |
226 | 348 | def a_callback(s, a): | ||
227 | 349 | setattr(self, 'answer', (s, a)) | ||
228 | 350 | |||
229 | 340 | self.client.set_share_answer_callback(a_callback) | 351 | self.client.set_share_answer_callback(a_callback) |
230 | 341 | self.assertTrue(self.client._share_answer_callback is a_callback) | 352 | self.assertTrue(self.client._share_answer_callback is a_callback) |
231 | 342 | self.client.handle_SHARE_ACCEPTED(proto_msg) | 353 | self.client.handle_SHARE_ACCEPTED(proto_msg) |
232 | @@ -347,8 +358,8 @@ | |||
233 | 347 | """Test handle_VOLUME_NEW_GENERATION with an uuid id.""" | 358 | """Test handle_VOLUME_NEW_GENERATION with an uuid id.""" |
234 | 348 | # set the callback to record the info | 359 | # set the callback to record the info |
235 | 349 | called = [] | 360 | called = [] |
238 | 350 | f = lambda *a: called.append(a) | 361 | self.client.set_volume_new_generation_callback( |
239 | 351 | self.client.set_volume_new_generation_callback(f) | 362 | lambda *a: called.append(a)) |
240 | 352 | 363 | ||
241 | 353 | # create the message | 364 | # create the message |
242 | 354 | message = protocol_pb2.Message() | 365 | message = protocol_pb2.Message() |
243 | @@ -365,8 +376,8 @@ | |||
244 | 365 | """Test handle_VOLUME_NEW_GENERATION for ROOT.""" | 376 | """Test handle_VOLUME_NEW_GENERATION for ROOT.""" |
245 | 366 | # set the callback to record the info | 377 | # set the callback to record the info |
246 | 367 | called = [] | 378 | called = [] |
249 | 368 | f = lambda *a: called.append(a) | 379 | self.client.set_volume_new_generation_callback( |
250 | 369 | self.client.set_volume_new_generation_callback(f) | 380 | lambda *a: called.append(a)) |
251 | 370 | 381 | ||
252 | 371 | # create the message | 382 | # create the message |
253 | 372 | message = protocol_pb2.Message() | 383 | message = protocol_pb2.Message() |
254 | @@ -393,7 +404,10 @@ | |||
255 | 393 | def test_handle_root_created_passes_a_root(self): | 404 | def test_handle_root_created_passes_a_root(self): |
256 | 394 | """Test handle_VOLUME_CREATED parameter passing.""" | 405 | """Test handle_VOLUME_CREATED parameter passing.""" |
257 | 395 | self.volume = None | 406 | self.volume = None |
259 | 396 | a_callback = lambda vol: setattr(self, 'volume', vol) | 407 | |
260 | 408 | def a_callback(vol): | ||
261 | 409 | setattr(self, 'volume', vol) | ||
262 | 410 | |||
263 | 397 | self.client.set_volume_created_callback(a_callback) | 411 | self.client.set_volume_created_callback(a_callback) |
264 | 398 | 412 | ||
265 | 399 | message = build_volume_created() | 413 | message = build_volume_created() |
266 | @@ -406,7 +420,10 @@ | |||
267 | 406 | def test_handle_udf_created_passes_a_udf(self): | 420 | def test_handle_udf_created_passes_a_udf(self): |
268 | 407 | """Test handle_VOLUME_CREATED parameter passing.""" | 421 | """Test handle_VOLUME_CREATED parameter passing.""" |
269 | 408 | self.volume = None | 422 | self.volume = None |
271 | 409 | a_callback = lambda vol: setattr(self, 'volume', vol) | 423 | |
272 | 424 | def a_callback(vol): | ||
273 | 425 | setattr(self, 'volume', vol) | ||
274 | 426 | |||
275 | 410 | self.client.set_volume_created_callback(a_callback) | 427 | self.client.set_volume_created_callback(a_callback) |
276 | 411 | 428 | ||
277 | 412 | message = build_volume_created() | 429 | message = build_volume_created() |
278 | @@ -419,7 +436,10 @@ | |||
279 | 419 | def test_handle_share_created_passes_a_share(self): | 436 | def test_handle_share_created_passes_a_share(self): |
280 | 420 | """Test handle_VOLUME_CREATED parameter passing.""" | 437 | """Test handle_VOLUME_CREATED parameter passing.""" |
281 | 421 | self.volume = None | 438 | self.volume = None |
283 | 422 | a_callback = lambda vol: setattr(self, 'volume', vol) | 439 | |
284 | 440 | def a_callback(vol): | ||
285 | 441 | setattr(self, 'volume', vol) | ||
286 | 442 | |||
287 | 423 | self.client.set_volume_created_callback(a_callback) | 443 | self.client.set_volume_created_callback(a_callback) |
288 | 424 | 444 | ||
289 | 425 | message = build_volume_created() | 445 | message = build_volume_created() |
290 | @@ -429,14 +449,6 @@ | |||
291 | 429 | self.client.handle_VOLUME_CREATED(message) | 449 | self.client.handle_VOLUME_CREATED(message) |
292 | 430 | self.assertEquals(share, self.volume) | 450 | self.assertEquals(share, self.volume) |
293 | 431 | 451 | ||
294 | 432 | def test_handle_volume_created_if_volume_is_buggy(self): | ||
295 | 433 | """Test handle_VOLUME_CREATED if the volume is buggy.""" | ||
296 | 434 | message = build_volume_created() | ||
297 | 435 | message.volume_created.type = -1 # invalid type! | ||
298 | 436 | self.client.set_volume_created_callback(lambda vol: None) | ||
299 | 437 | self.assertRaises(TypeError, self.client.handle_VOLUME_CREATED, | ||
300 | 438 | message) | ||
301 | 439 | |||
302 | 440 | def test_handle_volume_created_if_callback_is_none(self): | 452 | def test_handle_volume_created_if_callback_is_none(self): |
303 | 441 | """Test handle_VOLUME_CREATED if callback is none.""" | 453 | """Test handle_VOLUME_CREATED if callback is none.""" |
304 | 442 | message = build_volume_created() | 454 | message = build_volume_created() |
305 | @@ -456,7 +468,10 @@ | |||
306 | 456 | def test_handle_volume_deleted_passes_the_id(self): | 468 | def test_handle_volume_deleted_passes_the_id(self): |
307 | 457 | """Test handle_VOLUME_DELETED.""" | 469 | """Test handle_VOLUME_DELETED.""" |
308 | 458 | self.volume = None | 470 | self.volume = None |
310 | 459 | a_callback = lambda vol_id: setattr(self, 'volume', vol_id) | 471 | |
311 | 472 | def a_callback(vol): | ||
312 | 473 | setattr(self, 'volume', vol) | ||
313 | 474 | |||
314 | 460 | self.client.set_volume_deleted_callback(a_callback) | 475 | self.client.set_volume_deleted_callback(a_callback) |
315 | 461 | 476 | ||
316 | 462 | message = build_volume_deleted() | 477 | message = build_volume_deleted() |
317 | @@ -566,12 +581,6 @@ | |||
318 | 566 | message = protocol_pb2.Message() | 581 | message = protocol_pb2.Message() |
319 | 567 | self.assertRaises(FakedError, self.request.processMessage, message) | 582 | self.assertRaises(FakedError, self.request.processMessage, message) |
320 | 568 | 583 | ||
321 | 569 | def test_process_message_error_when_incorrect_volume(self): | ||
322 | 570 | """Test error condition when incorrect volume type.""" | ||
323 | 571 | message = build_list_volumes() | ||
324 | 572 | message.list_volumes.type = -1 | ||
325 | 573 | self.assertRaises(FakedError, self.request.processMessage, message) | ||
326 | 574 | |||
327 | 575 | def test_process_message_volume_created(self): | 584 | def test_process_message_volume_created(self): |
328 | 576 | """Test request processMessage on sucess.""" | 585 | """Test request processMessage on sucess.""" |
329 | 577 | message = build_list_volumes() | 586 | message = build_list_volumes() |
330 | 578 | 587 | ||
331 | === modified file 'tests/test_context.py' | |||
332 | --- tests/test_context.py 2015-05-18 17:23:03 +0000 | |||
333 | +++ tests/test_context.py 2016-09-19 02:06:21 +0000 | |||
334 | @@ -36,12 +36,6 @@ | |||
335 | 36 | 36 | ||
336 | 37 | from ubuntuone.storageprotocol import context | 37 | from ubuntuone.storageprotocol import context |
337 | 38 | 38 | ||
338 | 39 | try: | ||
339 | 40 | from ubuntu_sso.utils import get_cert_dir | ||
340 | 41 | except ImportError: | ||
341 | 42 | # old system, let's support Precise | ||
342 | 43 | get_cert_dir = lambda: '/etc/ssl/certs' | ||
343 | 44 | |||
344 | 45 | 39 | ||
345 | 46 | class FakeCerts(object): | 40 | class FakeCerts(object): |
346 | 47 | """CA and Server certificate.""" | 41 | """CA and Server certificate.""" |
347 | @@ -123,24 +117,6 @@ | |||
348 | 123 | """Tests for the context.get_ssl_context function.""" | 117 | """Tests for the context.get_ssl_context function.""" |
349 | 124 | 118 | ||
350 | 125 | @defer.inlineCallbacks | 119 | @defer.inlineCallbacks |
351 | 126 | def setUp(self): | ||
352 | 127 | yield super(SSLContextTestCase, self).setUp() | ||
353 | 128 | self.patch(context, "get_certificates", self.get_certificates) | ||
354 | 129 | |||
355 | 130 | def get_certificates(self): | ||
356 | 131 | """Get the uninstalled certificates, for testing.""" | ||
357 | 132 | certs = [] | ||
358 | 133 | data_dir = get_cert_dir() | ||
359 | 134 | |||
360 | 135 | for certname in ['UbuntuOne-Go_Daddy_Class_2_CA.pem', | ||
361 | 136 | 'UbuntuOne-Go_Daddy_CA.pem']: | ||
362 | 137 | cert_path = os.path.abspath(os.path.join(data_dir, certname)) | ||
363 | 138 | c = ssl.Certificate.loadPEM(file(cert_path, 'r').read()) | ||
364 | 139 | certs.append(c.original) | ||
365 | 140 | |||
366 | 141 | return certs | ||
367 | 142 | |||
368 | 143 | @defer.inlineCallbacks | ||
369 | 144 | def verify_context(self, server_context, client_context): | 120 | def verify_context(self, server_context, client_context): |
370 | 145 | """Verify a client context with a given server context.""" | 121 | """Verify a client context with a given server context.""" |
371 | 146 | site = server.Site(FakeResource()) | 122 | site = server.Site(FakeResource()) |
372 | @@ -177,7 +153,7 @@ | |||
373 | 177 | 153 | ||
374 | 178 | d = self.verify_context(server_context, client_context) | 154 | d = self.verify_context(server_context, client_context) |
375 | 179 | e = yield self.assertFailure(d, SSL.Error) | 155 | e = yield self.assertFailure(d, SSL.Error) |
377 | 180 | self.assertEqual(e[0][0][1], "SSL3_GET_SERVER_CERTIFICATE") | 156 | self.assertEqual(e[0][0][1], "ssl3_get_server_certificate") |
378 | 181 | 157 | ||
379 | 182 | @defer.inlineCallbacks | 158 | @defer.inlineCallbacks |
380 | 183 | def test_fails_hostname(self): | 159 | def test_fails_hostname(self): |
381 | @@ -191,7 +167,7 @@ | |||
382 | 191 | 167 | ||
383 | 192 | d = self.verify_context(server_context, client_context) | 168 | d = self.verify_context(server_context, client_context) |
384 | 193 | e = yield self.assertFailure(d, SSL.Error) | 169 | e = yield self.assertFailure(d, SSL.Error) |
386 | 194 | self.assertEqual(e[0][0][1], "SSL3_GET_SERVER_CERTIFICATE") | 170 | self.assertEqual(e[0][0][1], "ssl3_get_server_certificate") |
387 | 195 | 171 | ||
388 | 196 | @defer.inlineCallbacks | 172 | @defer.inlineCallbacks |
389 | 197 | def test_matches_all(self): | 173 | def test_matches_all(self): |
390 | @@ -212,7 +188,7 @@ | |||
391 | 212 | def test_load_all_certificates(self): | 188 | def test_load_all_certificates(self): |
392 | 213 | """Load all available certificates.""" | 189 | """Load all available certificates.""" |
393 | 214 | certs = FakeCerts(self, "localhost") | 190 | certs = FakeCerts(self, "localhost") |
395 | 215 | self.patch(context, 'get_cert_dir', lambda: certs.cert_dir) | 191 | os.environ['SSL_CERTIFICATES_DIR'] = certs.cert_dir |
396 | 216 | # remove the key | 192 | # remove the key |
397 | 217 | os.unlink(certs.server_key_path) | 193 | os.unlink(certs.server_key_path) |
398 | 218 | loaded = context.get_certificates() | 194 | loaded = context.get_certificates() |
399 | 219 | 195 | ||
400 | === modified file 'tests/test_proxy_tunnel.py' | |||
401 | --- tests/test_proxy_tunnel.py 2012-03-29 20:28:09 +0000 | |||
402 | +++ tests/test_proxy_tunnel.py 2016-09-19 02:06:21 +0000 | |||
403 | @@ -135,7 +135,7 @@ | |||
404 | 135 | if auth is not None: | 135 | if auth is not None: |
405 | 136 | auth_line = "Proxy-Authorization: Basic " + \ | 136 | auth_line = "Proxy-Authorization: Basic " + \ |
406 | 137 | base64.b64encode("test:test") | 137 | base64.b64encode("test:test") |
408 | 138 | if not auth_line in data: | 138 | if auth_line not in data: |
409 | 139 | proto.dataReceived("HTTP/1.0 403 Forbidden\r\n\r\n") | 139 | proto.dataReceived("HTTP/1.0 403 Forbidden\r\n\r\n") |
410 | 140 | else: | 140 | else: |
411 | 141 | proto.dataReceived(response_string) | 141 | proto.dataReceived(response_string) |
412 | 142 | 142 | ||
413 | === modified file 'ubuntuone/storageprotocol/client.py' | |||
414 | --- ubuntuone/storageprotocol/client.py 2015-05-18 17:23:03 +0000 | |||
415 | +++ ubuntuone/storageprotocol/client.py 2016-09-19 02:06:21 +0000 | |||
416 | @@ -1689,8 +1689,8 @@ | |||
417 | 1689 | """ | 1689 | """ |
418 | 1690 | delayed_call = getattr(self, call_id) | 1690 | delayed_call = getattr(self, call_id) |
419 | 1691 | # check if we already have a DelayedCall running | 1691 | # check if we already have a DelayedCall running |
422 | 1692 | if delayed_call is None or (not delayed_call.active() | 1692 | if delayed_call is None or ( |
423 | 1693 | and delayed_call.cancelled): | 1693 | not delayed_call.active() and delayed_call.cancelled): |
424 | 1694 | return self.callLater(period, func) | 1694 | return self.callLater(period, func) |
425 | 1695 | return delayed_call | 1695 | return delayed_call |
426 | 1696 | 1696 | ||
427 | @@ -1837,12 +1837,12 @@ | |||
428 | 1837 | reactor.connectTCP('localhost', 20100, StorageClientFactory()) | 1837 | reactor.connectTCP('localhost', 20100, StorageClientFactory()) |
429 | 1838 | 1838 | ||
430 | 1839 | # using ssl | 1839 | # using ssl |
432 | 1840 | #reactor.connectSSL('localhost', 20101, StorageClientFactory(), | 1840 | # reactor.connectSSL('localhost', 20101, StorageClientFactory(), |
433 | 1841 | # ssl.ClientContextFactory()) | 1841 | # ssl.ClientContextFactory()) |
434 | 1842 | 1842 | ||
435 | 1843 | # using ssl over a proxy | 1843 | # using ssl over a proxy |
438 | 1844 | #from ubuntuone.storageprotocol import proxy_tunnel | 1844 | # from ubuntuone.storageprotocol import proxy_tunnel |
439 | 1845 | #proxy_tunnel.connectHTTPS('localhost', 3128, | 1845 | # proxy_tunnel.connectHTTPS('localhost', 3128, |
440 | 1846 | # 'localhost', 20101, StorageClientFactory(), | 1846 | # 'localhost', 20101, StorageClientFactory(), |
441 | 1847 | # user="test", passwd="test") | 1847 | # user="test", passwd="test") |
442 | 1848 | 1848 | ||
443 | 1849 | 1849 | ||
444 | === modified file 'ubuntuone/storageprotocol/content_hash.py' | |||
445 | --- ubuntuone/storageprotocol/content_hash.py 2012-03-29 20:28:09 +0000 | |||
446 | +++ ubuntuone/storageprotocol/content_hash.py 2016-09-19 02:06:21 +0000 | |||
447 | @@ -36,6 +36,10 @@ | |||
448 | 36 | import zlib | 36 | import zlib |
449 | 37 | 37 | ||
450 | 38 | 38 | ||
451 | 39 | def noop(): | ||
452 | 40 | """No op.""" | ||
453 | 41 | |||
454 | 42 | |||
455 | 39 | class ContentHash(object): | 43 | class ContentHash(object): |
456 | 40 | """Encapsulate the generation of content hashes. | 44 | """Encapsulate the generation of content hashes. |
457 | 41 | 45 | ||
458 | @@ -43,7 +47,7 @@ | |||
459 | 43 | composition to get similar methods. | 47 | composition to get similar methods. |
460 | 44 | 48 | ||
461 | 45 | """ | 49 | """ |
463 | 46 | method = lambda: None | 50 | method = noop |
464 | 47 | method_name = "" | 51 | method_name = "" |
465 | 48 | 52 | ||
466 | 49 | def __init__(self): | 53 | def __init__(self): |
467 | 50 | 54 | ||
468 | === modified file 'ubuntuone/storageprotocol/request.py' | |||
469 | --- ubuntuone/storageprotocol/request.py 2013-08-01 21:32:53 +0000 | |||
470 | +++ ubuntuone/storageprotocol/request.py 2016-09-19 02:06:21 +0000 | |||
471 | @@ -214,8 +214,7 @@ | |||
472 | 214 | 214 | ||
473 | 215 | if is_invalid: | 215 | if is_invalid: |
474 | 216 | self.log.error("Validation error: " + ", ".join(is_invalid)) | 216 | self.log.error("Validation error: " + ", ".join(is_invalid)) |
477 | 217 | comment = ("Validation error:\n" | 217 | comment = "Validation error:\n" + "\n".join(is_invalid) |
476 | 218 | + "\n".join(is_invalid)) | ||
478 | 219 | if len(comment) > MAX_PAYLOAD_SIZE - 100: | 218 | if len(comment) > MAX_PAYLOAD_SIZE - 100: |
479 | 220 | comment = comment[:MAX_PAYLOAD_SIZE - 112] + ' [truncated]' | 219 | comment = comment[:MAX_PAYLOAD_SIZE - 112] + ' [truncated]' |
480 | 221 | error_message = protocol_pb2.Message() | 220 | error_message = protocol_pb2.Message() |
Looks good! Thanks