Merge lp:~vijit.chauhan/beeseek/fix-607076 into lp:beeseek

Proposed by vSC
Status: Merged
Approved by: Andrea Corbellini
Approved revision: 74
Merged at revision: 75
Proposed branch: lp:~vijit.chauhan/beeseek/fix-607076
Merge into: lp:beeseek
Diff against target: 60 lines (+30/-2)
2 files modified
node/bsnode/http.py (+8/-2)
tests/node/http.py (+22/-0)
To merge this branch: bzr merge lp:~vijit.chauhan/beeseek/fix-607076
Reviewer Review Type Date Requested Status
Andrea Corbellini Approve
Review via email: mp+31325@code.launchpad.net

Description of the change

Fix for bug 607076

To post a comment you must log in.
Revision history for this message
Andrea Corbellini (andrea.corbellini) wrote :

Your code is almost perfect, there are few and easy things to fix.

The major issue is that you are using tabs. You should instead use 4
spaces for indentation, like the rest of the code. This is the cause
of two of the exceptions you are seeing while running the test suite.

On Thu, Jul 29, 2010 at 10:23 PM, vSC <email address hidden> wrote:
> ...
> -                    remaining_bytes = int(remaining_bytes, 16)
> +                   try:
> +                       remaining_bytes = int(remaining_bytes, 16)
> +                   except ValueError:
> +                       raise HttpError('400 BAD REQUEST')

Here it'd be better to use '400 Bad Request' (capitalized, not upper
case), just to be consistent with the rest of the code).

> ...
> +    def test_invalid_chunk_size(self):
> +        client, server = socket.socketpair();
> +        client.sendall(
> +            'GET / HTTP/1.1 \r\n'

You ought to use PUT or POST instead of GET, otherwise the content
will be ignored. Also, you must remove the blank space between
'HTTP/1.1' and '\r\n': this is the cause of the third error in the
test suite.

> +            'Host: localhost\r\n'
> +            'Transfer-Encoding: chunked\r\n'

After this you must put a '\r\n' to indicate that headers are finished.

> +            's\r\n'
> +            '1234')
> +        def callback(handler):
> +            yield handler.parse_request()
> +            try:
> +                yield handler.read()
> +            except HttpError as err:
> +                self.assertEqual(error,('400 Bad Request'))

The right line is:

self.assertEqual(err.args, ('400 Bad Request',))

Note the last comma: it's very important in Python.

> +            else:
> +                self.fail()
> +
> +            conn = HttpConnection(server,callback,())
> +            conn.handle_incoming_bytes()

You should de-indent this last two lines.

These are just minor issues (that I can fix for you if you prefer) so
I'm approving the merge proposal. Great work, thanks!

Revision history for this message
Andrea Corbellini (andrea.corbellini) :
review: Approve
Revision history for this message
vSC (vijit.chauhan) wrote :

Thanks for the Approval and all the help. :-)

I will keep the code consistency in mind next time.

Thanks,
Vijit

On Fri, Jul 30, 2010 at 2:25 AM, Andrea Corbellini <
<email address hidden>> wrote:

> The proposal to merge lp:~vijit.chauhan/beeseek/fix-607076 into lp:beeseek
> has been updated.
>
> Status: Needs review => Approved
> --
> https://code.launchpad.net/~vijit.chauhan/beeseek/fix-607076/+merge/31325<https://code.launchpad.net/%7Evijit.chauhan/beeseek/fix-607076/+merge/31325>
> You are the owner of lp:~vijit.chauhan/beeseek/fix-607076.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'node/bsnode/http.py'
2--- node/bsnode/http.py 2010-07-20 16:12:17 +0000
3+++ node/bsnode/http.py 2010-07-29 20:23:40 +0000
4@@ -300,7 +300,10 @@
5 # chunk size (skipping blank lines).
6 while not remaining_bytes:
7 remaining_bytes = (yield self._raw_read_line()).rstrip()
8- remaining_bytes = int(remaining_bytes, 16)
9+ try:
10+ remaining_bytes = int(remaining_bytes, 16)
11+ except ValueError:
12+ raise HttpError('400 Bad Request')
13
14 if not remaining_bytes:
15 # This chunk has a size of zero. It means that the body is
16@@ -338,7 +341,10 @@
17 while not remaining_bytes:
18 remaining_bytes = (
19 yield self._raw_read_line()).rstrip()
20- remaining_bytes = int(remaining_bytes, 16)
21+ try:
22+ remaining_bytes = int(remaining_bytes, 16)
23+ except ValueError:
24+ raise HttpError('400 BAD REQUEST')
25
26 if not remaining_bytes:
27 # This chunk has a size of zero. It means that the body
28
29=== modified file 'tests/node/http.py'
30--- tests/node/http.py 2010-07-20 16:12:17 +0000
31+++ tests/node/http.py 2010-07-29 20:23:40 +0000
32@@ -108,6 +108,28 @@
33 # Check that the callback has been called the right number of times.
34 self.assertEqual(len(calls), 2)
35
36+ def test_invalid_chunk_size(self):
37+ client, server = socket.socketpair();
38+ client.sendall(
39+ 'GET / HTTP/1.1 \r\n'
40+ 'Host: localhost\r\n'
41+ 'Transfer-Encoding: chunked\r\n'
42+ 's\r\n'
43+ '1234')
44+ def callback(handler):
45+ yield handler.parse_request()
46+ try:
47+ yield handler.read()
48+ except HttpError as err:
49+ self.assertEqual(error,('400 Bad Request'))
50+ else:
51+ self.fail()
52+
53+ conn = HttpConnection(server,callback,())
54+ conn.handle_incoming_bytes()
55+
56+
57+
58
59 class TestRequestParser(TestCase):
60 """Check if requests are correctly parsed."""

Subscribers

People subscribed via source and target branches