Merge lp:~canonical-isd-hackers/canonical-identity-provider/sso-piston-api-unquoted-params into lp:canonical-identity-provider/release

Proposed by Ricardo Kirkner
Status: Merged
Approved by: Anthony Lenton
Approved revision: no longer in the source branch.
Merged at revision: 174
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/sso-piston-api-unquoted-params
Merge into: lp:canonical-identity-provider/release
Diff against target: 56 lines (+33/-1)
2 files modified
identityprovider/api10/handlers.py (+5/-1)
identityprovider/tests/test_handlers.py (+28/-0)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/sso-piston-api-unquoted-params
Reviewer Review Type Date Requested Status
Anthony Lenton (community) Approve
Review via email: mp+67239@code.launchpad.net

Commit message

Fix a bug in the piston api that doesn't correctly handle unquoted parameters

Description of the change

Overview
========

Fix a bug in the piston api that doesn't correctly handle unquoted parameters

To post a comment you must log in.
Revision history for this message
Anthony Lenton (elachuni) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/api10/handlers.py'
2--- identityprovider/api10/handlers.py 2011-07-07 18:16:53 +0000
3+++ identityprovider/api10/handlers.py 2011-07-07 18:33:34 +0000
4@@ -118,7 +118,11 @@
5 for key in serialized:
6 if key == 'ws.op':
7 continue
8- data[key] = simplejson.loads(serialized[key])
9+ try:
10+ value = simplejson.loads(serialized[key])
11+ except (ValueError, TypeError):
12+ value = serialized[key]
13+ data[key] = value
14 return data
15
16
17
18=== modified file 'identityprovider/tests/test_handlers.py'
19--- identityprovider/tests/test_handlers.py 2011-06-15 22:24:43 +0000
20+++ identityprovider/tests/test_handlers.py 2011-07-07 18:33:34 +0000
21@@ -1,3 +1,6 @@
22+import base64
23+
24+from django.utils import simplejson
25 from mock import patch
26
27 from identityprovider.tests.utils import SQLCachedTestCase
28@@ -175,3 +178,28 @@
29 account = self.authentication.account_by_openid(request)
30
31 self.assertTrue(account is None)
32+
33+ def test_authenticate_unquoted_token(self):
34+ expected_keys = ['consumer_key', 'consumer_secret', 'name', 'token',
35+ 'token_secret']
36+
37+ extra = {'HTTP_AUTHORIZATION': 'basic ' + base64.b64encode('mark@example.com:test')}
38+ response = self.client.get('/api/1.0/authentications', data={
39+ 'ws.op': 'authenticate', 'token_name': 'some-token'}, **extra)
40+
41+ content = simplejson.loads(response.content)
42+ self.assertEqual(set(content.keys()), set(expected_keys))
43+ self.assertEqual(content['name'], 'some-token')
44+
45+ def test_authenticate_quoted_token(self):
46+ expected_keys = ['consumer_key', 'consumer_secret', 'name', 'token',
47+ 'token_secret']
48+
49+ extra = {'HTTP_AUTHORIZATION': 'basic ' + base64.b64encode('mark@example.com:test')}
50+ response = self.client.get('/api/1.0/authentications', data={
51+ 'ws.op': 'authenticate', 'token_name': '"some-token"'}, **extra)
52+
53+ content = simplejson.loads(response.content)
54+ self.assertEqual(set(content.keys()), set(expected_keys))
55+ self.assertEqual(content['name'], 'some-token')
56+