Beispiel #1
0
    def test_GETorHEAD_base(self):
        base = Controller(self.app)
        req = Request.blank("/v1/a/c/o/with/slashes")
        ring = FakeRing()
        nodes = list(ring.get_part_nodes(0)) + list(ring.get_more_nodes(0))
        with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, "object", iter(nodes), "part", "/a/c/o/with/slashes")
        self.assertTrue("swift.object/a/c/o/with/slashes" in resp.environ)
        self.assertEqual(resp.environ["swift.object/a/c/o/with/slashes"]["status"], 200)
        req = Request.blank("/v1/a/c/o")
        with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, "object", iter(nodes), "part", "/a/c/o")
        self.assertTrue("swift.object/a/c/o" in resp.environ)
        self.assertEqual(resp.environ["swift.object/a/c/o"]["status"], 200)
        req = Request.blank("/v1/a/c")
        with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, "container", iter(nodes), "part", "/a/c")
        self.assertTrue("swift.container/a/c" in resp.environ)
        self.assertEqual(resp.environ["swift.container/a/c"]["status"], 200)

        req = Request.blank("/v1/a")
        with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, "account", iter(nodes), "part", "/a")
        self.assertTrue("swift.account/a" in resp.environ)
        self.assertEqual(resp.environ["swift.account/a"]["status"], 200)
    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.assertEquals(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.assertEquals(2, resp.status_int // 100)
        for key in owner_headers:
            self.assertTrue(key in resp.headers)
Beispiel #3
0
    def setUp(self):
        skip_if_no_xattrs()
        self.app = proxy.Application(None,
                                     FakeMemcache(),
                                     logger=debug_logger('proxy-ut'),
                                     account_ring=FakeRing(replicas=1),
                                     container_ring=FakeRing(replicas=1))
        self.copy_app = ServerSideCopyMiddleware(self.app, {})
        monkey_patch_mimetools()
        self.tmpdir = mkdtemp()
        self.testdir = os.path.join(self.tmpdir,
                                    'tmp_test_object_server_ObjectController')
        mkdirs(os.path.join(self.testdir, 'sda', 'tmp'))
        conf = {'devices': self.testdir, 'mount_check': 'false'}
        self.obj_ctlr = object_server.ObjectController(
            conf, logger=debug_logger('obj-ut'))

        http_connect = get_http_connect(fake_http_connect(200),
                                        fake_http_connect(200),
                                        FakeServerConnection(self.obj_ctlr))

        self.orig_base_http_connect = swift.proxy.controllers.base.http_connect
        self.orig_obj_http_connect = swift.proxy.controllers.obj.http_connect
        swift.proxy.controllers.base.http_connect = http_connect
        swift.proxy.controllers.obj.http_connect = http_connect
Beispiel #4
0
    def test_GETorHEAD_base(self):
        base = Controller(self.app)
        req = Request.blank('/v1/a/c/o/with/slashes')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'object', FakeRing(), 'part',
                                       '/a/c/o/with/slashes')
        self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ)
        self.assertEqual(
            resp.environ['swift.object/a/c/o/with/slashes']['status'], 200)
        req = Request.blank('/v1/a/c/o')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'object', FakeRing(), 'part',
                                       '/a/c/o')
        self.assertTrue('swift.object/a/c/o' in resp.environ)
        self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200)
        req = Request.blank('/v1/a/c')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'container', FakeRing(), 'part',
                                       '/a/c')
        self.assertTrue('swift.container/a/c' in resp.environ)
        self.assertEqual(resp.environ['swift.container/a/c']['status'], 200)

        req = Request.blank('/v1/a')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'account', FakeRing(), 'part',
                                       '/a')
        self.assertTrue('swift.account/a' in resp.environ)
        self.assertEqual(resp.environ['swift.account/a']['status'], 200)
Beispiel #5
0
    def test_GETorHEAD_base(self):
        base = Controller(self.app)
        req = Request.blank('/v1/a/c/o/with/slashes')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'object', FakeRing(), 'part',
                                       '/a/c/o/with/slashes')
        self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ)
        self.assertEqual(
            resp.environ['swift.object/a/c/o/with/slashes']['status'], 200)
        req = Request.blank('/v1/a/c/o')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'object', FakeRing(), 'part',
                                       '/a/c/o')
        self.assertTrue('swift.object/a/c/o' in resp.environ)
        self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200)
        req = Request.blank('/v1/a/c')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'container', FakeRing(), 'part',
                                       '/a/c')
        self.assertTrue('swift.container/a/c' in resp.environ)
        self.assertEqual(resp.environ['swift.container/a/c']['status'], 200)

        req = Request.blank('/v1/a')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'account', FakeRing(), 'part',
                                       '/a')
        self.assertTrue('swift.account/a' in resp.environ)
        self.assertEqual(resp.environ['swift.account/a']['status'], 200)
Beispiel #6
0
    def test_GETorHEAD_base(self):
        base = Controller(self.app)
        req = Request.blank("/a/c")
        with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, "container", FakeRing(), "part", "/a/c")
        self.assertTrue("swift.container/a/c" in resp.environ)
        self.assertEqual(resp.environ["swift.container/a/c"]["status"], 200)

        req = Request.blank("/a")
        with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, "account", FakeRing(), "part", "/a")
        self.assertTrue("swift.account/a" in resp.environ)
        self.assertEqual(resp.environ["swift.account/a"]["status"], 200)
Beispiel #7
0
 def test_sys_meta_headers_PUT(self):
     # check that headers in sys meta namespace make it through
     # the proxy controller
     sys_meta_key = '%stest' % get_sys_meta_prefix('account')
     sys_meta_key = sys_meta_key.title()
     user_meta_key = 'X-Account-Meta-Test'
     # allow PUTs to account...
     self.app.allow_account_management = True
     controller = proxy_server.AccountController(self.app, 'a')
     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', 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.assertIn(sys_meta_key, context['headers'])
     self.assertEqual(context['headers'][sys_meta_key], 'foo')
     self.assertIn(user_meta_key, context['headers'])
     self.assertEqual(context['headers'][user_meta_key], 'bar')
     self.assertNotEqual(context['headers']['x-timestamp'], '1.0')
Beispiel #8
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')
    def test_get_deleted_account_410(self):
        resp_headers = {'x-account-status': 'deleted'}

        req = Request.blank('/v1/a')
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(404, headers=resp_headers)):
            info = get_account_info(req.environ, self.app)
        self.assertEqual(410, info.get('status'))
Beispiel #10
0
    def test_get_deleted_account_410(self):
        resp_headers = {'x-account-status': 'deleted'}

        req = Request.blank('/v1/a')
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(404, headers=resp_headers)):
            info = get_account_info(req.environ, self.app)
        self.assertEqual(410, info.get('status'))
 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("/v1/a/c", {"PATH_INFO": "/v1/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"])
Beispiel #12
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'])
Beispiel #13
0
    def setUp(self):
        self.app = proxy.Application(None, FakeMemcache(),
                                     logger=debug_logger('proxy-ut'),
                                     account_ring=FakeRing(replicas=1),
                                     container_ring=FakeRing(replicas=1))
        monkey_patch_mimetools()
        self.testdir = \
            os.path.join(mkdtemp(), 'tmp_test_object_server_ObjectController')
        mkdirs(os.path.join(self.testdir, 'sda1', 'tmp'))
        conf = {'devices': self.testdir, 'mount_check': 'false'}
        self.obj_ctlr = object_server.ObjectController(
            conf, logger=debug_logger('obj-ut'))

        http_connect = get_http_connect(fake_http_connect(200),
                                        fake_http_connect(200),
                                        FakeServerConnection(self.obj_ctlr))

        swift.proxy.controllers.base.http_connect = http_connect
        swift.proxy.controllers.obj.http_connect = http_connect
Beispiel #14
0
 def test_account_info_in_response_env(self):
     controller = proxy_server.AccountController(self.app, 'AUTH_bob')
     with mock.patch('swift.proxy.controllers.base.http_connect',
                     fake_http_connect(200, body='')):
         req = Request.blank('/v1/AUTH_bob', {'PATH_INFO': '/v1/AUTH_bob'})
         resp = controller.HEAD(req)
     self.assertEqual(2, resp.status_int // 100)
     self.assertTrue('swift.account/AUTH_bob' in resp.environ)
     self.assertEqual(headers_to_account_info(resp.headers),
                      resp.environ['swift.account/AUTH_bob'])
Beispiel #15
0
    def test_long_acct_names(self):
        long_acct_name = '%sLongAccountName' % ('Very' * (MAX_ANAME_LEN // 4))
        controller = proxy_server.AccountController(self.app, long_acct_name)

        req = Request.blank('/v1/%s' % long_acct_name)
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200)):
            resp = controller.HEAD(req)
        self.assertEquals(400, resp.status_int)

        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200)):
            resp = controller.GET(req)
        self.assertEquals(400, resp.status_int)

        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200)):
            resp = controller.POST(req)
        self.assertEquals(400, resp.status_int)
Beispiel #16
0
    def test_long_acct_names(self):
        long_acct_name = '%sLongAccountName' % ('Very' * (MAX_ANAME_LEN // 4))
        controller = proxy_server.AccountController(self.app, long_acct_name)

        req = Request.blank('/%s' % long_acct_name)
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200)):
            resp = controller.HEAD(req)
        self.assertEquals(400, resp.status_int)

        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200)):
            resp = controller.GET(req)
        self.assertEquals(400, resp.status_int)

        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200)):
            resp = controller.POST(req)
        self.assertEquals(400, resp.status_int)
Beispiel #17
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'])
Beispiel #18
0
 def test_account_info_in_response_env(self):
     controller = proxy_server.AccountController(self.app, 'AUTH_bob')
     with mock.patch('swift.proxy.controllers.base.http_connect',
                     fake_http_connect(200, body='')):
         req = Request.blank('/v1/AUTH_bob', {'PATH_INFO': '/v1/AUTH_bob'})
         resp = controller.HEAD(req)
     self.assertEqual(2, resp.status_int // 100)
     self.assertTrue('swift.account/AUTH_bob' in resp.environ)
     self.assertEqual(headers_to_account_info(resp.headers),
                      resp.environ['swift.account/AUTH_bob'])
Beispiel #19
0
    def test_get_deleted_account(self):
        resp_headers = {
            'x-account-status': 'deleted',
        }
        controller = proxy_server.AccountController(self.app, 'a')

        req = Request.blank('/v1/a')
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(404, headers=resp_headers)):
            resp = controller.HEAD(req)
        self.assertEqual(410, resp.status_int)
Beispiel #20
0
 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)
Beispiel #21
0
    def test_get_deleted_account(self):
        resp_headers = {
            'x-account-status': 'deleted',
        }
        controller = proxy_server.AccountController(self.app, 'a')

        req = Request.blank('/v1/a')
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(404, headers=resp_headers)):
            resp = controller.HEAD(req)
        self.assertEquals(410, resp.status_int)
Beispiel #22
0
    def test_swift_owner(self):
        owner_headers = {
            'x-account-meta-temp-url-key': 'value',
            'x-account-meta-temp-url-key-2': 'value'}
        controller = proxy_server.AccountController(self.app, 'a')

        req = Request.blank('/v1/a')
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(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', environ={'swift_owner': True})
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(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)
Beispiel #23
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)
Beispiel #24
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)
Beispiel #25
0
def set_http_connect(*args, **kwargs):
    old_connect = swift.proxy.controllers.base.http_connect
    new_connect = fake_http_connect(*args, **kwargs)
    swift.proxy.controllers.base.http_connect = new_connect
    swift.proxy.controllers.obj.http_connect = new_connect
    swift.proxy.controllers.account.http_connect = new_connect
    swift.proxy.controllers.container.http_connect = new_connect
    yield new_connect
    swift.proxy.controllers.base.http_connect = old_connect
    swift.proxy.controllers.obj.http_connect = old_connect
    swift.proxy.controllers.account.http_connect = old_connect
    swift.proxy.controllers.container.http_connect = old_connect
Beispiel #26
0
    def test_swift_owner(self):
        owner_headers = {
            'x-account-meta-temp-url-key': 'value',
            'x-account-meta-temp-url-key-2': 'value'}
        controller = proxy_server.AccountController(self.app, 'a')

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

        req = Request.blank('/v1/a', environ={'swift_owner': True})
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200, headers=owner_headers)):
            resp = controller.HEAD(req)
        self.assertEquals(2, resp.status_int // 100)
        for key in owner_headers:
            self.assertTrue(key in resp.headers)
Beispiel #27
0
def set_http_connect(*args, **kwargs):
    old_connect = swift.proxy.controllers.base.http_connect
    new_connect = fake_http_connect(*args, **kwargs)
    swift.proxy.controllers.base.http_connect = new_connect
    swift.proxy.controllers.obj.http_connect = new_connect
    swift.proxy.controllers.account.http_connect = new_connect
    swift.proxy.controllers.container.http_connect = new_connect
    yield new_connect
    swift.proxy.controllers.base.http_connect = old_connect
    swift.proxy.controllers.obj.http_connect = old_connect
    swift.proxy.controllers.account.http_connect = old_connect
    swift.proxy.controllers.container.http_connect = old_connect
 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)
Beispiel #29
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)))
Beispiel #30
0
    def test_account_info_in_response_env(self):
        controller = proxy_server.AccountController(self.app, 'AUTH_bob')
        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(200, body='')):
            req = Request.blank('/v1/AUTH_bob', {'PATH_INFO': '/v1/AUTH_bob'})
            resp = controller.HEAD(req)
        self.assertEqual(2, resp.status_int // 100)
        info_cache = resp.environ['swift.infocache']
        self.assertIn('account/AUTH_bob', info_cache)
        header_info = headers_to_account_info(resp.headers)
        self.assertEqual(header_info, info_cache['account/AUTH_bob'])

        with mock.patch('swift.proxy.controllers.base.http_connect',
                        fake_http_connect(500, body='')):
            req = Request.blank('/v1/AUTH_bob', {
                'PATH_INFO': '/v1/AUTH_bob', 'swift.infocache': info_cache})
            resp = controller.HEAD(req)
        self.assertEqual(5, resp.status_int // 100)
        self.assertIs(info_cache, resp.environ['swift.infocache'])
        # The *old* header info is all still there
        self.assertIn('account/AUTH_bob', info_cache)
        self.assertEqual(header_info, info_cache['account/AUTH_bob'])
Beispiel #31
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)),
            )
Beispiel #32
0
 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)
Beispiel #33
0
    def setUp(self):
        skip_if_no_xattrs()
        self.app = proxy.Application(None, FakeMemcache(),
                                     logger=debug_logger('proxy-ut'),
                                     account_ring=FakeRing(replicas=1),
                                     container_ring=FakeRing(replicas=1))
        self.copy_app = ServerSideCopyMiddleware(self.app, {})
        self.tmpdir = mkdtemp()
        self.testdir = os.path.join(self.tmpdir,
                                    'tmp_test_object_server_ObjectController')
        mkdirs(os.path.join(self.testdir, 'sda', 'tmp'))
        conf = {'devices': self.testdir, 'mount_check': 'false'}
        self.obj_ctlr = object_server.ObjectController(
            conf, logger=debug_logger('obj-ut'))

        http_connect = get_http_connect(fake_http_connect(200),
                                        fake_http_connect(200),
                                        FakeServerConnection(self.obj_ctlr))

        self.orig_base_http_connect = swift.proxy.controllers.base.http_connect
        self.orig_obj_http_connect = swift.proxy.controllers.obj.http_connect
        swift.proxy.controllers.base.http_connect = http_connect
        swift.proxy.controllers.obj.http_connect = http_connect
Beispiel #34
0
    def setUp(self):
        self.app = proxy.Application(
            None,
            FakeMemcache(),
            logger=debug_logger("proxy-ut"),
            account_ring=FakeRing(replicas=1),
            container_ring=FakeRing(replicas=1),
        )
        monkey_patch_mimetools()
        self.tmpdir = mkdtemp()
        self.testdir = os.path.join(self.tmpdir, "tmp_test_object_server_ObjectController")
        mkdirs(os.path.join(self.testdir, "sda", "tmp"))
        conf = {"devices": self.testdir, "mount_check": "false"}
        self.obj_ctlr = object_server.ObjectController(conf, logger=debug_logger("obj-ut"))

        http_connect = get_http_connect(
            fake_http_connect(200), fake_http_connect(200), FakeServerConnection(self.obj_ctlr)
        )

        self.orig_base_http_connect = swift.proxy.controllers.base.http_connect
        self.orig_obj_http_connect = swift.proxy.controllers.obj.http_connect
        swift.proxy.controllers.base.http_connect = http_connect
        swift.proxy.controllers.obj.http_connect = http_connect
Beispiel #35
0
    def test_options_unauthorized(self):
        base = Controller(self.app)
        base.account_name = 'a'
        base.container_name = 'c'
        self.app.cors_allow_origin = ['http://NOT_IT']
        req = Request.blank('/v1/a/c/o',
                            environ={'swift.cache': FakeCache()},
                            headers={'Origin': 'http://m.com',
                                     'Access-Control-Request-Method': 'GET'})

        with mock.patch('swift.proxy.controllers.base.'
                        'http_connect', fake_http_connect(200)):
            resp = base.OPTIONS(req)
        self.assertEqual(resp.status_int, 401)
Beispiel #36
0
    def test_options_unauthorized(self):
        base = Controller(self.app)
        base.account_name = "a"
        base.container_name = "c"
        self.app.cors_allow_origin = ["http://NOT_IT"]
        req = Request.blank(
            "/v1/a/c/o",
            environ={"swift.cache": FakeCache()},
            headers={"Origin": "http://m.com", "Access-Control-Request-Method": "GET"},
        )

        with patch("swift.proxy.controllers.base." "http_connect", fake_http_connect(200)):
            resp = base.OPTIONS(req)
        self.assertEqual(resp.status_int, 401)
Beispiel #37
0
    def test_options_unauthorized(self):
        base = Controller(self.app)
        base.account_name = 'a'
        base.container_name = 'c'
        self.app.cors_allow_origin = ['http://NOT_IT']
        req = Request.blank('/v1/a/c/o',
                            environ={'swift.cache': FakeCache()},
                            headers={'Origin': 'http://m.com',
                                     'Access-Control-Request-Method': 'GET'})

        with mock.patch('swift.proxy.controllers.base.'
                        'http_connect', fake_http_connect(200)):
            resp = base.OPTIONS(req)
        self.assertEqual(resp.status_int, 401)
Beispiel #38
0
    def _assert_responses(self, method, test_cases):
        if method in ('PUT', 'DELETE'):
            self.app.allow_account_management = True
        controller = proxy_server.AccountController(self.app, 'AUTH_bob')

        for responses, expected in test_cases:
            with mock.patch('swift.proxy.controllers.base.http_connect',
                            fake_http_connect(*responses)):
                req = Request.blank('/v1/AUTH_bob')
                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)))
Beispiel #39
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')
Beispiel #40
0
    def _assert_responses(self, method, test_cases):
        if method in ('PUT', 'DELETE'):
            self.app.allow_account_management = True
        controller = proxy_server.AccountController(self.app, 'AUTH_bob')

        for responses, expected in test_cases:
            with mock.patch(
                    'swift.proxy.controllers.base.http_connect',
                    fake_http_connect(*responses)):
                req = Request.blank('/v1/AUTH_bob')
                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)))
Beispiel #41
0
def set_http_connect(*args, **kwargs):
    old_connect = swift.proxy.controllers.base.http_connect
    new_connect = fake_http_connect(*args, **kwargs)
    try:
        swift.proxy.controllers.base.http_connect = new_connect
        swift.proxy.controllers.obj.http_connect = new_connect
        swift.proxy.controllers.account.http_connect = new_connect
        swift.proxy.controllers.container.http_connect = new_connect
        yield new_connect
        left_over_status = list(new_connect.code_iter)
        if left_over_status:
            raise AssertionError('left over status %r' % left_over_status)
    finally:
        swift.proxy.controllers.base.http_connect = old_connect
        swift.proxy.controllers.obj.http_connect = old_connect
        swift.proxy.controllers.account.http_connect = old_connect
        swift.proxy.controllers.container.http_connect = old_connect
Beispiel #42
0
def set_http_connect(*args, **kwargs):
    old_connect = swift.proxy.controllers.base.http_connect
    new_connect = fake_http_connect(*args, **kwargs)
    try:
        swift.proxy.controllers.base.http_connect = new_connect
        swift.proxy.controllers.obj.http_connect = new_connect
        swift.proxy.controllers.account.http_connect = new_connect
        swift.proxy.controllers.container.http_connect = new_connect
        yield new_connect
        left_over_status = list(new_connect.code_iter)
        if left_over_status:
            raise AssertionError('left over status %r' % left_over_status)
    finally:
        swift.proxy.controllers.base.http_connect = old_connect
        swift.proxy.controllers.obj.http_connect = old_connect
        swift.proxy.controllers.account.http_connect = old_connect
        swift.proxy.controllers.container.http_connect = old_connect
Beispiel #43
0
    def test_options_with_null_allow_origin(self):
        base = Controller(self.app)
        base.account_name = 'a'
        base.container_name = 'c'

        def my_container_info(*args):
            return {
                'cors': {
                    'allow_origin': '*',
                }
            }
        base.container_info = my_container_info
        req = Request.blank('/v1/a/c/o',
                            environ={'swift.cache': FakeCache()},
                            headers={'Origin': '*',
                                     'Access-Control-Request-Method': 'GET'})

        with mock.patch('swift.proxy.controllers.base.'
                        'http_connect', fake_http_connect(200)):
            resp = base.OPTIONS(req)
        self.assertEqual(resp.status_int, 200)
 def test_sys_meta_headers_POST(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.POST(req)
     self.assertEqual(context["method"], "POST")
     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")
Beispiel #45
0
    def test_options_with_null_allow_origin(self):
        base = Controller(self.app)
        base.account_name = 'a'
        base.container_name = 'c'

        def my_container_info(*args):
            return {
                'cors': {
                    'allow_origin': '*',
                }
            }
        base.container_info = my_container_info
        req = Request.blank('/v1/a/c/o',
                            environ={'swift.cache': FakeCache()},
                            headers={'Origin': '*',
                                     'Access-Control-Request-Method': 'GET'})

        with mock.patch('swift.proxy.controllers.base.'
                        'http_connect', fake_http_connect(200)):
            resp = base.OPTIONS(req)
        self.assertEqual(resp.status_int, 200)
Beispiel #46
0
 def test_sys_meta_headers_POST(self):
     # check that headers in sys meta namespace make it through
     # the proxy controller
     sys_meta_key = '%stest' % get_sys_meta_prefix('account')
     sys_meta_key = sys_meta_key.title()
     user_meta_key = 'X-Account-Meta-Test'
     controller = proxy_server.AccountController(self.app, 'a')
     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', headers=hdrs_in)
     with mock.patch('swift.proxy.controllers.base.http_connect',
                     fake_http_connect(200, 200, give_connect=callback)):
         controller.POST(req)
     self.assertEqual(context['method'], 'POST')
     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')
Beispiel #47
0
    def test_GETorHEAD_base(self):
        base = Controller(self.app)
        req = Request.blank('/v1/a/c/o/with/slashes')
        ring = FakeRing()
        nodes = list(ring.get_part_nodes(0)) + list(ring.get_more_nodes(0))
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'object', iter(nodes), 'part',
                                       '/a/c/o/with/slashes')
        self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ)
        self.assertEqual(
            resp.environ['swift.object/a/c/o/with/slashes']['status'], 200)
        req = Request.blank('/v1/a/c/o')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'object', iter(nodes), 'part',
                                       '/a/c/o')
        self.assertTrue('swift.object/a/c/o' in resp.environ)
        self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200)
        req = Request.blank('/v1/a/c')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'container', iter(nodes), 'part',
                                       '/a/c')
        self.assertTrue('swift.container/a/c' in resp.environ)
        self.assertEqual(resp.environ['swift.container/a/c']['status'], 200)

        req = Request.blank('/v1/a')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'account', iter(nodes), 'part',
                                       '/a')
        self.assertTrue('swift.account/a' in resp.environ)
        self.assertEqual(resp.environ['swift.account/a']['status'], 200)

        # Run the above tests again, but this time with concurrent_reads
        # turned on
        policy = next(iter(POLICIES))
        concurrent_get_threads = policy.object_ring.replica_count
        for concurrency_timeout in (0, 2):
            self.app.concurrency_timeout = concurrency_timeout
            req = Request.blank('/v1/a/c/o/with/slashes')
            # NOTE: We are using slow_connect of fake_http_connect as using
            # a concurrency of 0 when mocking the connection is a little too
            # fast for eventlet. Network i/o will make this fine, but mocking
            # it seems is too instantaneous.
            with patch('swift.proxy.controllers.base.http_connect',
                       fake_http_connect(200, slow_connect=True)):
                resp = base.GETorHEAD_base(
                    req, 'object', iter(nodes), 'part', '/a/c/o/with/slashes',
                    concurrency=concurrent_get_threads)
            self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ)
            self.assertEqual(
                resp.environ['swift.object/a/c/o/with/slashes']['status'], 200)
            req = Request.blank('/v1/a/c/o')
            with patch('swift.proxy.controllers.base.http_connect',
                       fake_http_connect(200, slow_connect=True)):
                resp = base.GETorHEAD_base(
                    req, 'object', iter(nodes), 'part', '/a/c/o',
                    concurrency=concurrent_get_threads)
            self.assertTrue('swift.object/a/c/o' in resp.environ)
            self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200)
            req = Request.blank('/v1/a/c')
            with patch('swift.proxy.controllers.base.http_connect',
                       fake_http_connect(200, slow_connect=True)):
                resp = base.GETorHEAD_base(
                    req, 'container', iter(nodes), 'part', '/a/c',
                    concurrency=concurrent_get_threads)
            self.assertTrue('swift.container/a/c' in resp.environ)
            self.assertEqual(resp.environ['swift.container/a/c']['status'],
                             200)

            req = Request.blank('/v1/a')
            with patch('swift.proxy.controllers.base.http_connect',
                       fake_http_connect(200, slow_connect=True)):
                resp = base.GETorHEAD_base(
                    req, 'account', iter(nodes), 'part', '/a',
                    concurrency=concurrent_get_threads)
            self.assertTrue('swift.account/a' in resp.environ)
            self.assertEqual(resp.environ['swift.account/a']['status'], 200)
Beispiel #48
0
    def test_GETorHEAD_base(self):
        base = Controller(self.app)
        req = Request.blank('/v1/a/c/o/with/slashes')
        ring = FakeRing()
        nodes = list(ring.get_part_nodes(0)) + list(ring.get_more_nodes(0))
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'object', iter(nodes), 'part',
                                       '/a/c/o/with/slashes')
        self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ)
        self.assertEqual(
            resp.environ['swift.object/a/c/o/with/slashes']['status'], 200)
        req = Request.blank('/v1/a/c/o')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'object', iter(nodes), 'part',
                                       '/a/c/o')
        self.assertTrue('swift.object/a/c/o' in resp.environ)
        self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200)
        req = Request.blank('/v1/a/c')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'container', iter(nodes), 'part',
                                       '/a/c')
        self.assertTrue('swift.container/a/c' in resp.environ)
        self.assertEqual(resp.environ['swift.container/a/c']['status'], 200)

        req = Request.blank('/v1/a')
        with patch('swift.proxy.controllers.base.'
                   'http_connect', fake_http_connect(200)):
            resp = base.GETorHEAD_base(req, 'account', iter(nodes), 'part',
                                       '/a')
        self.assertTrue('swift.account/a' in resp.environ)
        self.assertEqual(resp.environ['swift.account/a']['status'], 200)

        # Run the above tests again, but this time with concurrent_reads
        # turned on
        policy = next(iter(POLICIES))
        concurrent_get_threads = policy.object_ring.replica_count
        for concurrency_timeout in (0, 2):
            self.app.concurrency_timeout = concurrency_timeout
            req = Request.blank('/v1/a/c/o/with/slashes')
            # NOTE: We are using slow_connect of fake_http_connect as using
            # a concurrency of 0 when mocking the connection is a little too
            # fast for eventlet. Network i/o will make this fine, but mocking
            # it seems is too instantaneous.
            with patch('swift.proxy.controllers.base.http_connect',
                       fake_http_connect(200, slow_connect=True)):
                resp = base.GETorHEAD_base(req,
                                           'object',
                                           iter(nodes),
                                           'part',
                                           '/a/c/o/with/slashes',
                                           concurrency=concurrent_get_threads)
            self.assertTrue('swift.object/a/c/o/with/slashes' in resp.environ)
            self.assertEqual(
                resp.environ['swift.object/a/c/o/with/slashes']['status'], 200)
            req = Request.blank('/v1/a/c/o')
            with patch('swift.proxy.controllers.base.http_connect',
                       fake_http_connect(200, slow_connect=True)):
                resp = base.GETorHEAD_base(req,
                                           'object',
                                           iter(nodes),
                                           'part',
                                           '/a/c/o',
                                           concurrency=concurrent_get_threads)
            self.assertTrue('swift.object/a/c/o' in resp.environ)
            self.assertEqual(resp.environ['swift.object/a/c/o']['status'], 200)
            req = Request.blank('/v1/a/c')
            with patch('swift.proxy.controllers.base.http_connect',
                       fake_http_connect(200, slow_connect=True)):
                resp = base.GETorHEAD_base(req,
                                           'container',
                                           iter(nodes),
                                           'part',
                                           '/a/c',
                                           concurrency=concurrent_get_threads)
            self.assertTrue('swift.container/a/c' in resp.environ)
            self.assertEqual(resp.environ['swift.container/a/c']['status'],
                             200)

            req = Request.blank('/v1/a')
            with patch('swift.proxy.controllers.base.http_connect',
                       fake_http_connect(200, slow_connect=True)):
                resp = base.GETorHEAD_base(req,
                                           'account',
                                           iter(nodes),
                                           'part',
                                           '/a',
                                           concurrency=concurrent_get_threads)
            self.assertTrue('swift.account/a' in resp.environ)
            self.assertEqual(resp.environ['swift.account/a']['status'], 200)