Ejemplo n.º 1
0
    def test_check_object_creation(self):
        req = Mock()
        req.headers = dict()

        valid_object_names = [
            "a/b/c/d", '/'.join(("1@3%&*0-", "};+=]|")), '/'.join(
                ('a' * 255, 'b' * 255, 'c' * 221))
        ]
        for o in valid_object_names:
            self.assertFalse(cnt.check_object_creation(req, o))

        invalid_object_names = [
            "a/./b", "a/b/../d", "a//b", "a/c//", '/'.join(
                ('a' * 256, 'b' * 255, 'c' * 221)), '/'.join(
                    ('a' * 255, 'b' * 255, 'c' * 222))
        ]
        for o in invalid_object_names:
            self.assertTrue(cnt.check_object_creation(req, o))

        # Check for creation of directory marker objects that ends with slash
        with patch.dict(req.headers,
                        {'content-type': 'application/directory'}):
            self.assertFalse(cnt.check_object_creation(req, "a/b/c/d/"))

        # Check creation of objects ending with slash having any other content
        # type than application/directory is not allowed
        for content_type in ('text/plain', 'text/html', 'image/jpg',
                             'application/octet-stream', 'blah/blah'):
            with patch.dict(req.headers, {'content-type': content_type}):
                self.assertTrue(cnt.check_object_creation(req, "a/b/c/d/"))
Ejemplo n.º 2
0
    def test_check_object_creation(self):
        req = Mock()
        req.headers = dict()

        valid_object_names = ["a/b/c/d", "/".join(("1@3%&*0-", "};+=]|")), "/".join(("a" * 255, "b" * 255, "c" * 221))]
        for o in valid_object_names:
            self.assertFalse(cnt.check_object_creation(req, o))

        invalid_object_names = [
            "a/./b",
            "a/b/../d",
            "a//b",
            "a/c//",
            "/".join(("a" * 256, "b" * 255, "c" * 221)),
            "/".join(("a" * 255, "b" * 255, "c" * 222)),
        ]
        for o in invalid_object_names:
            self.assertTrue(cnt.check_object_creation(req, o))

        # Check for creation of directory marker objects that ends with slash
        with patch.dict(req.headers, {"content-type": "application/directory"}):
            self.assertFalse(cnt.check_object_creation(req, "a/b/c/d/"))

        # Check creation of objects ending with slash having any other content
        # type than application/directory is not allowed
        for content_type in ("text/plain", "text/html", "image/jpg", "application/octet-stream", "blah/blah"):
            with patch.dict(req.headers, {"content-type": content_type}):
                self.assertTrue(cnt.check_object_creation(req, "a/b/c/d/"))
Ejemplo n.º 3
0
    def PUT(self, request):
        try:
            device, partition, account, container, obj, policy = \
                get_name_and_placement(request, 5, 5, True)

            # check swiftonfile constraints first
            error_response = check_object_creation(request, obj)
            if error_response:
                return error_response

            # now call swift's PUT method
            return server.ObjectController.PUT(self, request)
        except (AlreadyExistsAsFile, AlreadyExistsAsDir):
            device = \
                split_and_validate_path(request, 1, 5, True)
            return HTTPConflict(drive=device, request=request)
Ejemplo n.º 4
0
    def PUT(self, request):
        try:
            device, partition, account, container, obj, policy = \
                get_name_and_placement(request, 5, 5, True)

            # check swiftonfile constraints first
            error_response = check_object_creation(request, obj)
            if error_response:
                return error_response

            # now call swift's PUT method
            return server.ObjectController.PUT(self, request)
        except (AlreadyExistsAsFile, AlreadyExistsAsDir):
            device = \
                split_and_validate_path(request, 1, 5, True)
            return HTTPConflict(drive=device, request=request)