From 43cdc29669741568a898dc87eee3e09280887bba Mon Sep 17 00:00:00 2001 From: Kota Tsuyuzaki Date: Tue, 13 Oct 2015 00:22:31 -0700 Subject: [PATCH] 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 --- test/unit/common/middleware/test_staticweb.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/unit/common/middleware/test_staticweb.py b/test/unit/common/middleware/test_staticweb.py index ff3bc8cbd3..640a4917f4 100644 --- a/test/unit/common/middleware/test_staticweb.py +++ b/test/unit/common/middleware/test_staticweb.py @@ -15,6 +15,7 @@ import json import unittest +import mock from swift.common.swob import Request, Response 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) 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__': unittest.main()