Fixed bugs re: make_pre_authed* and SCRIPT_NAME
There were bugs with SCRIPT_NAME and swift.common.wsgi.make_pre_authed* functions. 1) SCRIPT_NAME wasn't copied with PATH_INFO, which it should've been. 2) When a new path was given, SCRIPT_NAME wasn't set to an empty string but just omitted, which is allowed by spec, but really should be set. For completeness, if SCRIPT_NAME doesn't exist in the source env, it will be created in the new env, but as an empty string. Change-Id: Ifbc27ed8ff357038c54df4d37de46cfd5e31372e
This commit is contained in:
parent
6c6b84b3f5
commit
a94a283149
@ -329,14 +329,16 @@ def make_pre_authed_env(env, method=None, path=None, agent='Swift',
|
||||
newenv = {}
|
||||
for name in ('eventlet.posthooks', 'HTTP_USER_AGENT', 'HTTP_HOST',
|
||||
'PATH_INFO', 'QUERY_STRING', 'REMOTE_USER', 'REQUEST_METHOD',
|
||||
'SERVER_NAME', 'SERVER_PORT', 'SERVER_PROTOCOL',
|
||||
'swift.cache', 'swift.source', 'swift.trans_id'):
|
||||
'SCRIPT_NAME', 'SERVER_NAME', 'SERVER_PORT',
|
||||
'SERVER_PROTOCOL', 'swift.cache', 'swift.source',
|
||||
'swift.trans_id'):
|
||||
if name in env:
|
||||
newenv[name] = env[name]
|
||||
if method:
|
||||
newenv['REQUEST_METHOD'] = method
|
||||
if path:
|
||||
newenv['PATH_INFO'] = path
|
||||
newenv['SCRIPT_NAME'] = ''
|
||||
if query_string is not None:
|
||||
newenv['QUERY_STRING'] = query_string
|
||||
if agent:
|
||||
@ -348,4 +350,6 @@ def make_pre_authed_env(env, method=None, path=None, agent='Swift',
|
||||
newenv['swift.authorize_override'] = True
|
||||
newenv['REMOTE_USER'] = '.wsgi.pre_authed'
|
||||
newenv['wsgi.input'] = StringIO('')
|
||||
if 'SCRIPT_NAME' not in newenv:
|
||||
newenv['SCRIPT_NAME'] = ''
|
||||
return newenv
|
||||
|
@ -223,5 +223,20 @@ class TestWSGI(unittest.TestCase):
|
||||
{'QUERY_STRING': 'original'}, 'GET', 'path', 'the body')
|
||||
self.assertEquals(r.body, 'the body')
|
||||
|
||||
def test_pre_auth_creates_script_name(self):
|
||||
e = wsgi.make_pre_authed_env({})
|
||||
self.assertTrue('SCRIPT_NAME' in e)
|
||||
|
||||
def test_pre_auth_copies_script_name(self):
|
||||
e = wsgi.make_pre_authed_env({'SCRIPT_NAME': '/script_name'})
|
||||
self.assertEquals(e['SCRIPT_NAME'], '/script_name')
|
||||
|
||||
def test_pre_auth_copies_script_name_unless_path_overridden(self):
|
||||
e = wsgi.make_pre_authed_env({'SCRIPT_NAME': '/script_name'},
|
||||
path='/override')
|
||||
self.assertEquals(e['SCRIPT_NAME'], '')
|
||||
self.assertEquals(e['PATH_INFO'], '/override')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user