From e94aeb7f1ca87bee41a8d33abbf1b8a81f866f16 Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Fri, 8 Mar 2013 18:56:19 +0100 Subject: [PATCH 1/2] Add request.environ[reseller_request] = True --- swauth/middleware.py | 2 ++ test_swauth/unit/test_middleware.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/swauth/middleware.py b/swauth/middleware.py index 2545e29..069600e 100644 --- a/swauth/middleware.py +++ b/swauth/middleware.py @@ -210,6 +210,8 @@ def __call__(self, env, start_response): '%s,%s' % (user, 's3' if s3 else token) env['swift.authorize'] = self.authorize env['swift.clean_acl'] = clean_acl + if '.reseller_admin' in groups: + env['reseller_request'] = True else: # Unauthorized token if self.reseller_prefix and token and \ diff --git a/test_swauth/unit/test_middleware.py b/test_swauth/unit/test_middleware.py index 29966b4..5d2baa2 100644 --- a/test_swauth/unit/test_middleware.py +++ b/test_swauth/unit/test_middleware.py @@ -471,6 +471,16 @@ def test_authorize_acl_referrer_access(self): req.acl = '.r:.example.com,.rlistings' self.assertEquals(self.test_auth.authorize(req), None) + def test_detect_reseller_request(self): + req = self._make_request('/v1/AUTH_admin', + headers={'X-Auth-Token': 'AUTH_t'}) + cache_key = 'AUTH_/auth/AUTH_t' + cache_entry = (time()+3600, '.reseller_admin') + req.environ['swift.cache'].set(cache_key, cache_entry) + resp = req.get_response(self.test_auth) + print req.environ + self.assertTrue(req.environ.get('reseller_request', False)) + def test_account_put_permissions(self): req = Request.blank('/v1/AUTH_new', environ={'REQUEST_METHOD': 'PUT'}) req.remote_user = 'act:usr,act' From c1462121dd524216f41387f433982cc48f6d1449 Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Wed, 3 Apr 2013 18:25:42 +0200 Subject: [PATCH 2/2] Fix test_detect_reseller_request --- test_swauth/unit/test_middleware.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test_swauth/unit/test_middleware.py b/test_swauth/unit/test_middleware.py index 5d2baa2..4743699 100644 --- a/test_swauth/unit/test_middleware.py +++ b/test_swauth/unit/test_middleware.py @@ -478,8 +478,7 @@ def test_detect_reseller_request(self): cache_entry = (time()+3600, '.reseller_admin') req.environ['swift.cache'].set(cache_key, cache_entry) resp = req.get_response(self.test_auth) - print req.environ - self.assertTrue(req.environ.get('reseller_request', False)) + self.assertTrue(req.environ.get('reseller_request')) def test_account_put_permissions(self): req = Request.blank('/v1/AUTH_new', environ={'REQUEST_METHOD': 'PUT'})