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 import samba.xattr_native, samba.xattr_tdb
21 from samba.dcerpc import xattr
22 from samba.ndr import ndr_pack
23 from samba.tests import TestCase, TestSkipped
27 class XattrTests(TestCase):
29 def _tmpfilename(self):
31 path = os.environ['SELFTEST_PREFIX']
32 return os.path.join(path, "pytests"+str(int(100000*random.random())))
35 return os.path.join(os.environ['SELFTEST_PREFIX'], "eadb.tdb")
37 def test_set_xattr_native(self):
38 if not samba.xattr_native.is_xattr_supported():
42 tempf = self._tmpfilename()
43 open(tempf, 'w').write("empty")
45 samba.xattr_native.wrap_setxattr(tempf, "user.unittests",
48 raise TestSkipped("the filesystem where the tests are runned do not support XATTR")
51 def test_set_and_get_native(self):
52 if not samba.xattr_native.is_xattr_supported():
54 tempf = self._tmpfilename()
55 reftxt = "this is a test"
56 open(tempf, 'w').write("empty")
58 samba.xattr_native.wrap_setxattr(tempf, "user.unittests", reftxt)
59 text = samba.xattr_native.wrap_getxattr(tempf, "user.unittests")
60 self.assertEquals(text, reftxt)
62 raise TestSkipped("the filesystem where the tests are runned do not support XATTR")
65 def test_set_xattr_tdb(self):
66 tempf = self._tmpfilename()
67 eadb_path = self._eadbpath()
70 open(tempf, 'w').write("empty")
72 samba.xattr_tdb.wrap_setxattr(eadb_path,
73 tempf, "user.unittests", ndr_pack(ntacl))
78 def test_set_tdb_not_open(self):
79 tempf = self._tmpfilename()
82 open(tempf, 'w').write("empty")
84 self.assertRaises(IOError, samba.xattr_tdb.wrap_setxattr,
85 os.path.join("nonexistent", "eadb.tdb"), tempf,
86 "user.unittests", ndr_pack(ntacl))
90 def test_set_and_get_tdb(self):
91 tempf = self._tmpfilename()
92 eadb_path = self._eadbpath()
93 reftxt = "this is a test"
94 open(tempf, 'w').write("empty")
96 samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests",
98 text = samba.xattr_tdb.wrap_getxattr(eadb_path, tempf,
100 self.assertEquals(text, reftxt)