+ self.assertEqual(ex.exception.errno, ENOATTR)
+
+ def test_xattr_set_name_max_length(self):
+ max_len = 255
+ if sys.platform != 'linux':
+ max_len = 127 # OSX VFS only support names up to 127 bytes
+
+ enc = "utf-8"
+ key = "user." + "x" * (max_len - 5)
+ value = "x"
+ self.assertEqual(len(key), max_len)
+ xattr.setxattr(self.randomFile, key, bytes(value, enc)) # NOTE: WILL FAIL IF RUNNING ON HFS+
+
+ key = "user." + "x" * (max_len - 5 + 1)
+ self.assertEqual(len(key), max_len + 1)
+ with self.assertRaises(OSError) as ex:
+ xattr.setxattr(self.randomFile, key, bytes(value, enc))
+
+ 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):