1 # Unix SMB/CIFS implementation. Tests for xattr manipulation
2 # Copyright (C) Matthieu Patou <mat@matws.net> 2009
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for samba.xattr_native and samba.xattr_tdb."""
20 import samba.xattr_native, samba.xattr_tdb, samba.posix_eadb
21 from samba.xattr import copytree_with_xattrs
22 from samba.dcerpc import xattr
23 from samba.ndr import ndr_pack
24 from samba.tests import (
33 class XattrTests(TestCase):
35 def _tmpfilename(self):
37 path = os.environ['SELFTEST_PREFIX']
38 return os.path.join(path, "pytests"+str(int(100000*random.random())))
41 return os.path.join(os.environ['SELFTEST_PREFIX'], "eadb.tdb")
43 def test_set_xattr_native(self):
44 if not samba.xattr_native.is_xattr_supported():
48 tempf = self._tmpfilename()
49 open(tempf, 'w').write("empty")
51 samba.xattr_native.wrap_setxattr(tempf, "user.unittests",
54 raise SkipTest("the filesystem where the tests are runned do not support XATTR")
57 def test_set_and_get_native(self):
58 if not samba.xattr_native.is_xattr_supported():
60 tempf = self._tmpfilename()
61 reftxt = b"this is a test"
62 open(tempf, 'w').write("empty")
64 samba.xattr_native.wrap_setxattr(tempf, "user.unittests", reftxt)
65 text = samba.xattr_native.wrap_getxattr(tempf, "user.unittests")
66 self.assertEquals(text, reftxt)
68 raise SkipTest("the filesystem where the tests are runned do not support XATTR")
71 def test_set_xattr_tdb(self):
72 tempf = self._tmpfilename()
73 eadb_path = self._eadbpath()
76 open(tempf, 'w').write("empty")
78 samba.xattr_tdb.wrap_setxattr(eadb_path,
79 tempf, "user.unittests", ndr_pack(ntacl))
84 def test_set_tdb_not_open(self):
85 tempf = self._tmpfilename()
88 open(tempf, 'w').write("empty")
90 self.assertRaises(IOError, samba.xattr_tdb.wrap_setxattr,
91 os.path.join("nonexistent", "eadb.tdb"), tempf,
92 "user.unittests", ndr_pack(ntacl))
96 def test_set_and_get_tdb(self):
97 tempf = self._tmpfilename()
98 eadb_path = self._eadbpath()
99 reftxt = b"this is a test"
100 open(tempf, 'w').write("empty")
102 samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests",
104 text = samba.xattr_tdb.wrap_getxattr(eadb_path, tempf,
106 self.assertEquals(text, reftxt)
111 def test_set_posix_eadb(self):
112 tempf = self._tmpfilename()
113 eadb_path = self._eadbpath()
114 ntacl = xattr.NTACL()
116 open(tempf, 'w').write("empty")
118 samba.posix_eadb.wrap_setxattr(eadb_path,
119 tempf, "user.unittests", ndr_pack(ntacl))
124 def test_set_and_get_posix_eadb(self):
125 tempf = self._tmpfilename()
126 eadb_path = self._eadbpath()
127 reftxt = b"this is a test"
128 open(tempf, 'w').write("empty")
130 samba.posix_eadb.wrap_setxattr(eadb_path, tempf, "user.unittests",
132 text = samba.posix_eadb.wrap_getxattr(eadb_path, tempf,
134 self.assertEquals(text, reftxt)
140 class TestCopyTreeWithXattrs(TestCaseInTempDir):
142 def test_simple(self):
143 os.chdir(self.tempdir)
147 f = open('a/b/c/d', 'w')
152 copytree_with_xattrs("a", "b")