+ if sys.platform == 'linux':
+ self.assertEqual(ex.exception.errno, errno.ERANGE) # This is the behavior of BTRFS
+ else:
+ self.assertEqual(ex.exception.errno, errno.ENAMETOOLONG)
+
+ #########################################################
+ # On Linux: The test fails as the max value is detected before reaching the filesystem
+ # On OSX: Works on fuse_xattr but fails on HFS+ (doesn't has limit)
+ @unittest.skipIf(sys.platform == "linux", "Skipping test on Linux")
+ def test_xattr_set_value_max_size(self):
+ enc = "utf-8"
+ key = "user.foo"
+ value = "x" * (64 * 1024 + 1) # we want max 64KiB of data
+ with self.assertRaises(OSError) as ex:
+ xattr.setxattr(self.randomFile, key, bytes(value, enc)) # NOTE: This test fail on HFS+ (doesn't have limit)
+
+ self.assertEqual(ex.exception.errno, errno.ENOSPC)
+
+ # on fuse_xattr we get "Argument list too long"
+ # the error is thrown by fuse, not by fuse_xattr code
+
+ #########################################################
+ # Those tests are going to pass on Linux but fail on BSD
+ # BSD doesn't support namespaces.
+ @unittest.skipIf(skipNamespaceTests, "Namespace tests disabled")
+ def test_xattr_set_namespaces(self):
+ with self.assertRaises(OSError) as ex:
+ xattr.setxattr(self.randomFile, "system.foo", bytes("bar", "utf-8"))
+ self.assertEqual(ex.exception.errno, 95)
+ self.assertEqual(ex.exception.strerror, "Operation not supported")
+
+ with self.assertRaises(OSError) as ex:
+ xattr.setxattr(self.randomFile, "trust.foo", bytes("bar", "utf-8"))
+ self.assertEqual(ex.exception.errno, 95)
+ self.assertEqual(ex.exception.strerror, "Operation not supported")
+
+ with self.assertRaises(OSError) as ex:
+ xattr.setxattr(self.randomFile, "foo.foo", bytes("bar", "utf-8"))
+ self.assertEqual(ex.exception.errno, 95)
+ self.assertEqual(ex.exception.strerror, "Operation not supported")
+
+ with self.assertRaises(PermissionError) as ex:
+ xattr.setxattr(self.randomFile, "security.foo", bytes("bar", "utf-8"))
+ self.assertEqual(ex.exception.errno, 1)
+ self.assertEqual(ex.exception.strerror, "Operation not permitted")
+
+
+######################################################################
+# The following tests should fail if they are running on a normal FS
+class TestFuseXATTR(TestXAttrBase):
+
+ def test_hide_sidecar(self):
+ xattr.setxattr(self.randomFile, "user.foo", bytes("bar", "utf-8"))
+ self.assertTrue(os.path.isfile(self.randomFile))
+ self.assertFalse(os.path.isfile(self.randomFileSidecar))
+
+ sidecarFilename = self.randomFilename + ".xattr"
+ files_mount = os.listdir(self.mountDir)
+ self.assertTrue(self.randomFilename in files_mount)
+ self.assertTrue(sidecarFilename not in files_mount)
+
+ files_source = os.listdir(self.sourceDir)
+ self.assertTrue(self.randomFilename in files_source)
+ self.assertTrue(sidecarFilename in files_source)
+
+ def test_fuse_xattr_create_new_file(self):
+ test_filename = "test_create_new_file"
+ self.assertFalse(os.path.isfile(self.sourceDir + test_filename))
+ self.assertFalse(os.path.isfile(self.mountDir + test_filename))
+
+ open(self.mountDir + test_filename, "a").close()
+ self.assertTrue(os.path.isfile(self.sourceDir + test_filename))
+ self.assertTrue(os.path.isfile(self.mountDir + test_filename))
+ # FIXME: if one assert fails, the file isn't going to be deleted
+ os.remove(self.mountDir + test_filename)
+
+ def test_fuse_xattr_remove_file_with_sidecar(self):
+ xattr.setxattr(self.randomFile, "user.foo", bytes("bar", "utf-8"))
+ self.assertTrue(os.path.isfile(self.randomFile))
+ self.assertTrue(os.path.isfile(self.randomSourceFile))
+ self.assertTrue(os.path.isfile(self.randomSourceFileSidecar))
+
+ os.remove(self.randomFile)
+ self.assertFalse(os.path.isfile(self.randomFile))
+ self.assertFalse(os.path.isfile(self.randomSourceFile))
+ self.assertFalse(os.path.isfile(self.randomSourceFileSidecar))
+
+ def test_fuse_xattr_remove_file_without_sidecar(self):
+ self.assertTrue(os.path.isfile(self.randomFile))
+ self.assertTrue(os.path.isfile(self.randomSourceFile))
+ self.assertFalse(os.path.isfile(self.randomSourceFileSidecar))
+
+ os.remove(self.randomFile)
+ self.assertFalse(os.path.isfile(self.randomFile))
+ self.assertFalse(os.path.isfile(self.randomSourceFile))
+ self.assertFalse(os.path.isfile(self.randomSourceFileSidecar))