Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't use default value in LimitingReader
We can't simply pass the None default on to the read operation as this
default is handled differently between different wsgi implementations.

Change-Id: I337e797b8dee3dfcf9299fe361cf197a176c8fe2
Fixes: bug 1213106
  • Loading branch information
Jamie Lennox committed Oct 9, 2013
1 parent df0a963 commit 12fd2aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion keystone/common/utils.py
Expand Up @@ -290,7 +290,12 @@ def __iter__(self):
yield chunk

def read(self, i=None):
result = self.data.read(i)
# NOTE(jamielennox): We can't simply provide the default to the read()
# call as the expected default differs between mod_wsgi and eventlet
if i is None:
result = self.data.read()
else:
result = self.data.read(i)
self.bytes_read += len(result)
if self.bytes_read > self.limit:
raise exception.RequestTooLarge()
Expand Down
23 changes: 23 additions & 0 deletions keystone/tests/test_utils.py
Expand Up @@ -105,3 +105,26 @@ def _test_unixtime():
for d in ['+0', '-11', '-8', '-5', '+5', '+8', '+14']:
TZ = 'UTC' + d
_test_unixtime()


class LimitingReaderTests(tests.TestCase):

def test_read_default_value(self):

class FakeData(object):
def read(self, *args, **kwargs):
self.read_args = args
self.read_kwargs = kwargs
return 'helloworld'

data = FakeData()
utils.LimitingReader(data, 100)

self.assertEqual(data.read(), 'helloworld')
self.assertEqual(len(data.read_args), 0)
self.assertEqual(len(data.read_kwargs), 0)

self.assertEqual(data.read(10), 'helloworld')
self.assertEqual(len(data.read_args), 1)
self.assertEqual(len(data.read_kwargs), 0)
self.assertEqual(data.read_args[0], 10)

0 comments on commit 12fd2aa

Please sign in to comment.