def test_to_swift_req_subrequest_proxy_access_log(self): container = 'bucket' obj = 'obj' method = 'GET' # force_swift_request_proxy_log is True req = Request.blank('/%s/%s' % (container, obj), environ={'REQUEST_METHOD': method, 'swift.proxy_access_log_made': True}, headers={'Authorization': 'AWS test:tester:hmac'}) with nested(patch.object(Request, 'get_response'), patch.object(Request, 'remote_user', 'authorized'), patch('swift3.cfg.CONF.force_swift_request_proxy_log', True)) \ as (m_swift_resp, m_remote_user, m_cfg): m_swift_resp.return_value = FakeSwiftResponse() s3_req = S3AclRequest(req.environ, MagicMock()) sw_req = s3_req.to_swift_req(method, container, obj) self.assertFalse(sw_req.environ['swift.proxy_access_log_made']) # force_swift_request_proxy_log is False req = Request.blank('/%s/%s' % (container, obj), environ={'REQUEST_METHOD': method, 'swift.proxy_access_log_made': True}, headers={'Authorization': 'AWS test:tester:hmac'}) with nested(patch.object(Request, 'get_response'), patch.object(Request, 'remote_user', 'authorized')) \ as (m_swift_resp, m_remote_user): m_swift_resp.return_value = FakeSwiftResponse() s3_req = S3AclRequest(req.environ, MagicMock()) sw_req = s3_req.to_swift_req(method, container, obj) self.assertTrue(sw_req.environ['swift.proxy_access_log_made'])
def test_authenticate_delete_Authorization_from_s3req_headers(self): req = Request.blank('/bucket/obj', environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) with nested(patch.object(Request, 'get_response'), patch.object(Request, 'remote_user', 'authorized')) \ as (m_swift_resp, m_remote_user): m_swift_resp.return_value = FakeSwiftResponse() s3_req = S3AclRequest(req.environ, MagicMock()) self.assertTrue('HTTP_AUTHORIZATION' not in s3_req.environ) self.assertTrue('Authorization' not in s3_req.headers) self.assertEquals(s3_req.token, 'token')
def test_to_swift_req_Authorization_not_exist_in_swreq_headers(self): container = 'bucket' obj = 'obj' method = 'GET' req = Request.blank('/%s/%s' % (container, obj), environ={'REQUEST_METHOD': method}, headers={'Authorization': 'AWS test:tester:hmac'}) with nested(patch.object(Request, 'get_response'), patch.object(Request, 'remote_user', 'authorized')) \ as (m_swift_resp, m_remote_user): m_swift_resp.return_value = FakeSwiftResponse() s3_req = S3AclRequest(req.environ, MagicMock()) sw_req = s3_req.to_swift_req(method, container, obj) self.assertTrue('HTTP_AUTHORIZATION' not in sw_req.environ) self.assertTrue('Authorization' not in sw_req.headers) self.assertEquals(sw_req.headers['X-Auth-Token'], 'token')
def __call__(self, env, start_response): try: if CONF.s3_acl: req = S3AclRequest(env, self.app, self.slo_enabled) else: req = Request(env, self.slo_enabled) resp = self.handle_request(req) except NotS3Request: resp = self.app except ErrorResponse as err_resp: if isinstance(err_resp, InternalError): LOGGER.exception(err_resp) resp = err_resp except Exception as e: LOGGER.exception(e) resp = InternalError(reason=e) if isinstance(resp, ResponseBase) and 'swift.trans_id' in env: resp.headers['x-amz-id-2'] = env['swift.trans_id'] resp.headers['x-amz-request-id'] = env['swift.trans_id'] return resp(env, start_response)