Merge lp:~alecu/ubuntu-sso-client/the-compleat-libsoup into lp:ubuntu-sso-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 850
Merged at revision: 846
Proposed branch: lp:~alecu/ubuntu-sso-client/the-compleat-libsoup
Merge into: lp:ubuntu-sso-client
Diff against target: 99 lines (+28/-14)
3 files modified
run-tests (+6/-10)
ubuntu_sso/utils/webclient/libsoup.py (+2/-1)
ubuntu_sso/utils/webclient/tests/test_webclient.py (+20/-3)
To merge this branch: bzr merge lp:~alecu/ubuntu-sso-client/the-compleat-libsoup
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+91481@code.launchpad.net

Commit message

- libsoup bindings need flattening to work around nul bytes in content (LP: #921822).

Description of the change

- libsoup bindings need flattening to work around nul bytes in content (LP: #921822).

To post a comment you must log in.
850. By Alejandro J. Cura

do not forget to make run-tests executable

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

Looks good to me.

review: Approve

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 2012-02-03 17:22:20 +0000
3+++ run-tests 2012-02-03 19:10:45 +0000
4@@ -45,17 +45,13 @@
5 XVFB_CMDLINE="$XVFB -a"
6 fi
7
8-echo "*** Running test suite for ""$MODULE"" ***"
9-$XVFB_CMDLINE u1trial --reactor=gi -p "$QT_TESTS_PATH, $GTK_TESTS_PATH" -i "test_windows.py" "$MODULE"
10-rm -rf _trial_temp
11-
12-echo "*** Running GTK test suite ***"
13-$XVFB_CMDLINE u1trial --reactor=gi --gui "$GTK_TESTS_PATH"
14-rm -rf _trial_temp
15-
16-echo "*** Running QT test suite ***"
17+echo "*** Running GTK test suite for ""$MODULE"" ***"
18+$XVFB_CMDLINE u1trial --reactor=gi --gui -p "$QT_TESTS_PATH" -i "test_windows.py" "$MODULE"
19+rm -rf _trial_temp
20+
21+echo "*** Running QT test suite for ""$MODULE"" ***"
22 ./setup.py build
23-USE_QT_MAINLOOP=True $XVFB_CMDLINE u1trial --reactor=qt4 --gui "$QT_TESTS_PATH"
24+USE_QT_MAINLOOP=True $XVFB_CMDLINE u1trial --reactor=qt4 --gui -p "$GTK_TESTS_PATH" -i "test_windows.py" "$MODULE"
25 rm -rf _trial_temp
26 rm -rf build
27
28
29=== modified file 'ubuntu_sso/utils/webclient/libsoup.py'
30--- ubuntu_sso/utils/webclient/libsoup.py 2012-01-17 20:44:33 +0000
31+++ ubuntu_sso/utils/webclient/libsoup.py 2012-02-03 19:10:45 +0000
32@@ -51,7 +51,8 @@
33 response_headers = message.get_property("response-headers")
34 add_header = lambda key, value, _: headers[key].append(value)
35 response_headers.foreach(add_header, None)
36- response = Response(message.response_body.data, headers)
37+ content = message.response_body.flatten().get_data()
38+ response = Response(content, headers)
39 d.callback(response)
40 elif message.status_code == httplib.UNAUTHORIZED:
41 e = UnauthorizedError(message.reason_phrase)
42
43=== modified file 'ubuntu_sso/utils/webclient/tests/test_webclient.py'
44--- ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-02-02 18:50:55 +0000
45+++ ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-02-03 19:10:45 +0000
46@@ -45,9 +45,11 @@
47 )
48 SAMPLE_HEADERS = {SAMPLE_KEY: SAMPLE_VALUE}
49 SAMPLE_POST_PARAMS = {"param1": "value1", "param2": "value2"}
50+SAMPLE_JPEG_HEADER = '\xff\xd8\xff\xe0\x00\x10JFIF'
51
52 SIMPLERESOURCE = "simpleresource"
53-POSTABLERESOURECE = "postableresourece"
54+BYTEZERORESOURCE = "bytezeroresource"
55+POSTABLERESOURCE = "postableresource"
56 THROWERROR = "throwerror"
57 UNAUTHORIZED = "unauthorized"
58 HEADONLY = "headonly"
59@@ -75,6 +77,14 @@
60 return SAMPLE_RESOURCE
61
62
63+class ByteZeroResource(resource.Resource):
64+ """A resource that has a nul byte in the middle of it."""
65+
66+ def render_GET(self, request):
67+ """Return the content of this resource."""
68+ return SAMPLE_JPEG_HEADER
69+
70+
71 class PostableResource(resource.Resource):
72 """A resource that only answers to POST requests."""
73
74@@ -155,7 +165,8 @@
75 """Get the root resource with all the children."""
76 root = resource.Resource()
77 root.putChild(SIMPLERESOURCE, SimpleResource())
78- root.putChild(POSTABLERESOURECE, PostableResource())
79+ root.putChild(BYTEZERORESOURCE, ByteZeroResource())
80+ root.putChild(POSTABLERESOURCE, PostableResource())
81
82 root.putChild(THROWERROR, resource.NoResource())
83
84@@ -248,9 +259,15 @@
85 webclient.WebClientError)
86
87 @defer.inlineCallbacks
88+ def test_zero_byte_in_content(self):
89+ """Test a reply with a nul byte in the middle of it."""
90+ result = yield self.wc.request(self.base_iri + BYTEZERORESOURCE)
91+ self.assertEqual(SAMPLE_JPEG_HEADER, result.content)
92+
93+ @defer.inlineCallbacks
94 def test_post(self):
95 """Test a post request."""
96- result = yield self.wc.request(self.base_iri + POSTABLERESOURECE,
97+ result = yield self.wc.request(self.base_iri + POSTABLERESOURCE,
98 method="POST")
99 self.assertEqual(SAMPLE_RESOURCE, result.content)
100

Subscribers

People subscribed via source and target branches