示例#1
0
    def test_sys_meta_headers_PUT(self):
        # check that headers in sys meta namespace make it through
        # the container controller
        sys_meta_key = '%stest' % get_sys_meta_prefix('container')
        sys_meta_key = sys_meta_key.title()
        user_meta_key = 'X-Container-Meta-Test'
        controller = proxy_server.ContainerController(self.app, 'a', 'c')

        context = {}
        callback = self._make_callback_func(context)
        hdrs_in = {
            sys_meta_key: 'foo',
            user_meta_key: 'bar',
            'x-timestamp': '1.0'
        }
        req = Request.blank('/v1/a/c', headers=hdrs_in)
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200, 200, give_connect=callback)):
            controller.PUT(req)
        self.assertEqual(context['method'], 'PUT')
        self.assertTrue(sys_meta_key in context['headers'])
        self.assertEqual(context['headers'][sys_meta_key], 'foo')
        self.assertTrue(user_meta_key in context['headers'])
        self.assertEqual(context['headers'][user_meta_key], 'bar')
        self.assertNotEqual(context['headers']['x-timestamp'], '1.0')
示例#2
0
 def test_container_info_in_response_env(self):
     controller = proxy_server.ContainerController(self.app, 'a', 'c')
     with mock.patch('swift.proxy.controllers.base.http_connect',
                     fake_http_connect(200, 200, body='')):
         req = Request.blank('/a/c', {'PATH_INFO': '/a/c'})
         resp = controller.HEAD(req)
     self.assertEqual(2, resp.status_int // 100)
     self.assertTrue("swift.container/a/c" in resp.environ)
     self.assertEqual(headers_to_container_info(resp.headers),
                      resp.environ['swift.container/a/c'])
示例#3
0
    def _assert_responses(self, method, test_cases):
        controller = proxy_server.ContainerController(self.app, 'a', 'c')

        for responses, expected in test_cases:
            with mock.patch('swift.proxy.controllers.base.http_connect',
                            fake_http_connect(*responses)):
                req = Request.blank('/v1/a/c')
                resp = getattr(controller, method)(req)

            self.assertEqual(
                expected, resp.status_int,
                'Expected %s but got %s. Failed case: %s' %
                (expected, resp.status_int, str(responses)))
 def test_container_info_got_cached(self):
     controller = proxy_server.ContainerController(self.app, 'a', 'c')
     with mock.patch('swift.proxy.controllers.base.http_connect',
                     fake_http_connect(200, 200, body='')):
         req = Request.blank('/v1/a/c', {'PATH_INFO': '/v1/a/c'})
         resp = controller.HEAD(req)
     self.assertEqual(2, resp.status_int // 100)
     # Make sure it's in both swift.infocache and memcache
     self.assertIn("container/a/c", resp.environ['swift.infocache'])
     self.assertEqual(headers_to_container_info(resp.headers),
                      resp.environ['swift.infocache']['container/a/c'])
     from_memcache = self.app.memcache.get('container/a/c')
     self.assertTrue(from_memcache)
示例#5
0
    def test_container_cache_cleared_after_PUT(
            self, mock_make_requests, mock_clear_info_cache):
        parent_mock = mock.Mock()
        parent_mock.attach_mock(mock_make_requests, 'make_requests')
        parent_mock.attach_mock(mock_clear_info_cache, 'clear_info_cache')
        controller = proxy_server.ContainerController(self.app, 'a', 'c')
        callback = self._make_callback_func({})
        req = Request.blank('/v1/a/c')
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200, 200, give_connect=callback)):
            controller.PUT(req)

        # Ensure cache is cleared after the PUT request
        self.assertEqual(parent_mock.mock_calls[0][0], 'make_requests')
        self.assertEqual(parent_mock.mock_calls[1][0], 'clear_info_cache')
示例#6
0
    def test_swift_owner(self):
        owner_headers = {
            'x-container-read': 'value', 'x-container-write': 'value',
            'x-container-sync-key': 'value', 'x-container-sync-to': 'value'}
        controller = proxy_server.ContainerController(self.app, 'a', 'c')

        req = Request.blank('/v1/a/c')
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200, 200, headers=owner_headers)):
            resp = controller.HEAD(req)
        self.assertEqual(2, resp.status_int // 100)
        for key in owner_headers:
            self.assertTrue(key not in resp.headers)

        req = Request.blank('/v1/a/c', environ={'swift_owner': True})
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200, 200, headers=owner_headers)):
            resp = controller.HEAD(req)
        self.assertEqual(2, resp.status_int // 100)
        for key in owner_headers:
            self.assertTrue(key in resp.headers)