Skip to content

Commit

Permalink
Merge "Fix formpost with queries without user_agent."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jun 13, 2013
2 parents cc4589c + d462393 commit 6001b45
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion swift/common/middleware/formpost.py
Expand Up @@ -312,7 +312,9 @@ def __call__(self, env, start_response):
_parse_attrs(env.get('CONTENT_TYPE') or '')
if content_type == 'multipart/form-data' and \
'boundary' in attrs:
env['HTTP_USER_AGENT'] += ' FormPost'
http_user_agent = "%s FormPost" % (
env.get('HTTP_USER_AGENT', ''))
env['HTTP_USER_AGENT'] = http_user_agent.strip()
status, headers, body = self._translate_form(
env, attrs['boundary'])
start_response(status, headers)
Expand Down
25 changes: 24 additions & 1 deletion test/unit/common/middleware/test_formpost.py
Expand Up @@ -304,7 +304,7 @@ def _make_request(self, path, **kwargs):
return req

def _make_sig_env_body(self, path, redirect, max_file_size, max_file_count,
expires, key):
expires, key, user_agent=True):
sig = hmac.new(
key,
'%s\n%s\n%s\n%s\n%s' % (
Expand Down Expand Up @@ -379,6 +379,9 @@ def _make_sig_env_body(self, path, redirect, max_file_size, max_file_count,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0),
}
if user_agent is False:
del env['HTTP_USER_AGENT']

return sig, env, body

def test_passthrough(self):
Expand Down Expand Up @@ -1173,6 +1176,26 @@ def start_response(s, h, e=None):
in body)
self.assertEquals(len(self.app.requests), 0)

def test_formpost_without_useragent(self):
key = 'abc'
sig, env, body = self._make_sig_env_body(
'/v1/AUTH_test/container', 'http://redirect', 1024, 10,
int(time() + 86400), key, user_agent=False)
env['wsgi.input'] = StringIO('\r\n'.join(body))
env['swift.cache'] = FakeMemcache()
env['swift.cache'].set('temp-url-key/AUTH_test', key)
self.app = FakeApp(iter([('201 Created', {}, ''),
('201 Created', {}, '')]))
self.auth = tempauth.filter_factory({})(self.app)
self.formpost = formpost.filter_factory({})(self.auth)

def start_response(s, h, e=None):
pass
body = ''.join(self.formpost(env, start_response))
self.assertTrue('User-Agent' in self.app.requests[0].headers)
self.assertEquals(self.app.requests[0].headers['User-Agent'],
'FormPost')

def test_redirect(self):
key = 'abc'
sig, env, body = self._make_sig_env_body(
Expand Down

0 comments on commit 6001b45

Please sign in to comment.