Add backend subrequest tests for staticweb

This is an followup for
https://review.openstack.org/#/c/227204

Above patch changes staticweb to use just make_env instead of
pre authed env. The tests included in this patch assert
"backend requests generated by staticweb *NEVER* include pre
authed information (i.e. authorize_override=True)".

Change-Id: Ifbbc43d3b5ac114bc3d5e4fcab9cacdf9a3f1a5c
This commit is contained in:
Kota Tsuyuzaki 2015-10-13 00:22:31 -07:00 committed by Alistair Coles
parent a7af802497
commit 43cdc29669

View File

@ -15,6 +15,7 @@
import json import json
import unittest import unittest
import mock
from swift.common.swob import Request, Response from swift.common.swob import Request, Response
from swift.common.middleware import staticweb from swift.common.middleware import staticweb
@ -722,5 +723,31 @@ class TestStaticWeb(unittest.TestCase):
resp = Request.blank('/v1/a/c3').get_response(self.test_staticweb) resp = Request.blank('/v1/a/c3').get_response(self.test_staticweb)
self.assertEqual(resp.status_int, 200) self.assertEqual(resp.status_int, 200)
def test_subrequest_not_override_auth(self):
app_call = \
'swift.common.middleware.staticweb._StaticWebContext._app_call'
orig_app_call = staticweb._StaticWebContext._app_call
_fail = self.fail
def hook_app_call(self, env):
if 'swift.authorize_override' in env:
_fail('staticweb must not create authorize info by itself')
return orig_app_call(self, env)
with mock.patch(app_call, hook_app_call):
# testing for _listing container
resp = Request.blank('/v1/a/c4/').get_response(self.test_staticweb)
self.assertEqual(resp.status_int, 200) # sanity
# testing for _listing object subdir
resp = Request.blank(
'/v1/a/c4/unknown').get_response(self.test_staticweb)
self.assertEqual(resp.status_int, 404)
# testing for _error_response
resp = Request.blank('/v1/a/c5/').get_response(self.test_staticweb)
self.assertEqual(resp.status_int, 503) # sanity
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()