3 # Unix SMB/CIFS implementation. Tests for xattr manipulation
4 # Copyright (C) Matthieu Patou <mat@matws.net> 2009
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """Tests for samba.xattr_native and samba.xattr_tdb."""
22 import samba.xattr_native, samba.xattr_tdb
23 from samba.xattr import copytree_with_xattrs
24 from samba.dcerpc import xattr
25 from samba.ndr import ndr_pack
26 from samba.tests import (
35 class XattrTests(TestCase):
37 def _tmpfilename(self):
39 path = os.environ['SELFTEST_PREFIX']
40 return os.path.join(path, "pytests"+str(int(100000*random.random())))
43 return os.path.join(os.environ['SELFTEST_PREFIX'], "eadb.tdb")
45 def test_set_xattr_native(self):
46 if not samba.xattr_native.is_xattr_supported():
50 tempf = self._tmpfilename()
51 open(tempf, 'w').write("empty")
53 samba.xattr_native.wrap_setxattr(tempf, "user.unittests",
56 raise TestSkipped("the filesystem where the tests are runned do not support XATTR")
59 def test_set_and_get_native(self):
60 if not samba.xattr_native.is_xattr_supported():
62 tempf = self._tmpfilename()
63 reftxt = "this is a test"
64 open(tempf, 'w').write("empty")
66 samba.xattr_native.wrap_setxattr(tempf, "user.unittests", reftxt)
67 text = samba.xattr_native.wrap_getxattr(tempf, "user.unittests")
68 self.assertEquals(text, reftxt)
70 raise TestSkipped("the filesystem where the tests are runned do not support XATTR")
73 def test_set_xattr_tdb(self):
74 tempf = self._tmpfilename()
75 eadb_path = self._eadbpath()
78 open(tempf, 'w').write("empty")
80 samba.xattr_tdb.wrap_setxattr(eadb_path,
81 tempf, "user.unittests", ndr_pack(ntacl))
86 def test_set_tdb_not_open(self):
87 tempf = self._tmpfilename()
90 open(tempf, 'w').write("empty")
92 self.assertRaises(IOError, samba.xattr_tdb.wrap_setxattr,
93 os.path.join("nonexistent", "eadb.tdb"), tempf,
94 "user.unittests", ndr_pack(ntacl))
98 def test_set_and_get_tdb(self):
99 tempf = self._tmpfilename()
100 eadb_path = self._eadbpath()
101 reftxt = "this is a test"
102 open(tempf, 'w').write("empty")
104 samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests",
106 text = samba.xattr_tdb.wrap_getxattr(eadb_path, tempf,
108 self.assertEquals(text, reftxt)
114 class TestCopyTreeWithXattrs(TestCaseInTempDir):
116 def test_simple(self):
117 os.chdir(self.tempdir)
121 f = open('a/b/c/d', 'w')
126 copytree_with_xattrs("a", "b")