Use swift.backend_path from Swift/s3api to extract account/container
Still use PATH_INFO by default if s3api not enabled and swift.backend_path not available Depends-On: https://review.opendev.org/#/c/718086/ Change-Id: Ibb5fc6a717b9bc938aa86c4550d156fe93dae65c
This commit is contained in:
parent
c6b90ec56a
commit
ba22defb59
|
@ -298,7 +298,7 @@ class Swift(object):
|
|||
env.get('swift.source') is not None):
|
||||
return
|
||||
|
||||
path = urlparse.quote(env['PATH_INFO'])
|
||||
path = urlparse.quote(env.get('swift.backend_path', env['PATH_INFO']))
|
||||
method = env['REQUEST_METHOD']
|
||||
headers = {}
|
||||
for header in env:
|
||||
|
|
|
@ -72,9 +72,12 @@ class TestSwift(tests_base.TestCase):
|
|||
def start_response(*args):
|
||||
pass
|
||||
|
||||
def get_request(self, path, environ=None, headers=None):
|
||||
return FakeRequest(path, environ=environ, headers=headers)
|
||||
|
||||
def test_get(self):
|
||||
app = swift.Swift(FakeApp(), {})
|
||||
req = FakeRequest('/1.0/account/container/obj',
|
||||
req = self.get_request('/1.0/account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
resp = app(req.environ, self.start_response)
|
||||
|
@ -96,7 +99,7 @@ class TestSwift(tests_base.TestCase):
|
|||
app = swift.Swift(FakeApp(),
|
||||
{"nonblocking_notify": "True",
|
||||
"send_queue_size": "1"})
|
||||
req = FakeRequest('/1.0/account/container/obj',
|
||||
req = self.get_request('/1.0/account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
with mock.patch('oslo_messaging.Notifier.info',
|
||||
side_effect=lambda *args, **kwargs: notified.set()
|
||||
|
@ -118,7 +121,7 @@ class TestSwift(tests_base.TestCase):
|
|||
|
||||
def test_put(self):
|
||||
app = swift.Swift(FakeApp(body=['']), {})
|
||||
req = FakeRequest(
|
||||
req = self.get_request(
|
||||
'/1.0/account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'PUT',
|
||||
'wsgi.input':
|
||||
|
@ -139,7 +142,7 @@ class TestSwift(tests_base.TestCase):
|
|||
|
||||
def test_post(self):
|
||||
app = swift.Swift(FakeApp(body=['']), {})
|
||||
req = FakeRequest(
|
||||
req = self.get_request(
|
||||
'/1.0/account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'POST',
|
||||
'wsgi.input': six.moves.cStringIO('some other stuff')})
|
||||
|
@ -159,7 +162,7 @@ class TestSwift(tests_base.TestCase):
|
|||
|
||||
def test_head(self):
|
||||
app = swift.Swift(FakeApp(body=['']), {})
|
||||
req = FakeRequest('/1.0/account/container/obj',
|
||||
req = self.get_request('/1.0/account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'HEAD'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
|
@ -176,7 +179,7 @@ class TestSwift(tests_base.TestCase):
|
|||
def test_bogus_request(self):
|
||||
"""Test even for arbitrary request method, this will still work."""
|
||||
app = swift.Swift(FakeApp(body=['']), {})
|
||||
req = FakeRequest('/1.0/account/container/obj',
|
||||
req = self.get_request('/1.0/account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'BOGUS'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
|
@ -192,7 +195,7 @@ class TestSwift(tests_base.TestCase):
|
|||
|
||||
def test_get_container(self):
|
||||
app = swift.Swift(FakeApp(), {})
|
||||
req = FakeRequest('/1.0/account/container',
|
||||
req = self.get_request('/1.0/account/container',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
|
@ -210,7 +213,7 @@ class TestSwift(tests_base.TestCase):
|
|||
|
||||
def test_no_metadata_headers(self):
|
||||
app = swift.Swift(FakeApp(), {})
|
||||
req = FakeRequest('/1.0/account/container',
|
||||
req = self.get_request('/1.0/account/container',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
|
@ -230,7 +233,7 @@ class TestSwift(tests_base.TestCase):
|
|||
app = swift.Swift(FakeApp(), {
|
||||
'metadata_headers': 'X_VAR1, x-var2, x-var3, token'
|
||||
})
|
||||
req = FakeRequest('/1.0/account/container',
|
||||
req = self.get_request('/1.0/account/container',
|
||||
environ={'REQUEST_METHOD': 'GET'},
|
||||
headers={'X_VAR1': 'value1',
|
||||
'X_VAR2': 'value2',
|
||||
|
@ -258,7 +261,7 @@ class TestSwift(tests_base.TestCase):
|
|||
'metadata_headers': 'unicode'
|
||||
})
|
||||
uni = u'\xef\xbd\xa1\xef\xbd\xa5'
|
||||
req = FakeRequest('/1.0/account/container',
|
||||
req = self.get_request('/1.0/account/container',
|
||||
environ={'REQUEST_METHOD': 'GET'},
|
||||
headers={'UNICODE': uni})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
|
@ -281,7 +284,7 @@ class TestSwift(tests_base.TestCase):
|
|||
app = swift.Swift(FakeApp(), {
|
||||
'metadata_headers': 'x-var3'
|
||||
})
|
||||
req = FakeRequest('/1.0/account/container',
|
||||
req = self.get_request('/1.0/account/container',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
|
@ -316,7 +319,7 @@ class TestSwift(tests_base.TestCase):
|
|||
def test_emit_event_fail(self, mocked_func):
|
||||
mocked_func.side_effect = Exception("a exception")
|
||||
app = swift.Swift(FakeApp(body=["test"]), {})
|
||||
req = FakeRequest('/1.0/account/container',
|
||||
req = self.get_request('/1.0/account/container',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
resp = list(app(req.environ, self.start_response))
|
||||
|
@ -325,7 +328,7 @@ class TestSwift(tests_base.TestCase):
|
|||
|
||||
def test_reseller_prefix(self):
|
||||
app = swift.Swift(FakeApp(), {})
|
||||
req = FakeRequest('/1.0/AUTH_account/container/obj',
|
||||
req = self.get_request('/1.0/AUTH_account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
|
@ -459,3 +462,14 @@ class TestSwift(tests_base.TestCase):
|
|||
app.ignore_projects)
|
||||
warning.assert_called_once_with(
|
||||
"fail to find project '%s' in keystone", "gnocchi")
|
||||
|
||||
|
||||
class TestSwiftS3Api(TestSwift):
|
||||
|
||||
def get_request(self, path, environ=None, headers=None):
|
||||
# Add Swift Path in environ, provided by swift s3api middleware
|
||||
environ['swift.backend_path'] = path
|
||||
# Emulate S3 api PATH_INFO by removing /v1 and account parts
|
||||
path = '/' + path.split('/', 3)[-1]
|
||||
|
||||
return FakeRequest(path, environ=environ, headers=headers)
|
||||
|
|
Loading…
Reference in New Issue