From a324c6e5cdfad77e8f91ec9869deb6b78425807e Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Thu, 19 May 2016 15:33:07 +0530 Subject: Fix validation of marker dir objects For marker directory objects, validate_object() always returned False. This was because st_size from stat was being compared to Content-Length stored in metadata. Unlike files, for directories st_size is always 4096. Hence the comparison would always be '4096 == 0' which would fail. This patch makes the following changes: * Do size comparison of st_size and Content-Length only for files. * Get rid of _is_dir everywhere. This will simplify things. Change-Id: Ib75e06c4e3bce36bab11ce7d029ff327f33c3146 Signed-off-by: Prashanth Pai Reviewed-on: http://review.gluster.org/14423 Reviewed-by: Thiago da Silva Tested-by: Thiago da Silva --- test/unit/common/test_utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'test/unit/common/test_utils.py') diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index f88229a..8ba9a2a 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -810,9 +810,19 @@ class TestUtils(unittest.TestCase): utils.X_CONTENT_LENGTH: '12345', utils.X_TYPE: utils.OBJECT, utils.X_OBJECT_TYPE: 'na'} - fake_stat = Mock(st_size=12346) + fake_stat = Mock(st_size=12346, st_mode=33188) self.assertFalse(utils.validate_object(md, fake_stat)) - fake_stat = Mock(st_size=12345) + fake_stat = Mock(st_size=12345, st_mode=33188) + self.assertTrue(utils.validate_object(md, fake_stat)) + + def test_validate_object_marker_dir(self): + md = {utils.X_TIMESTAMP: 'na', + utils.X_CONTENT_TYPE: 'application/directory', + utils.X_ETAG: 'bad', + utils.X_CONTENT_LENGTH: '0', + utils.X_TYPE: utils.OBJECT, + utils.X_OBJECT_TYPE: utils.DIR_OBJECT} + fake_stat = Mock(st_size=4096, st_mode=16744) self.assertTrue(utils.validate_object(md, fake_stat)) -- cgit