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
21 import samba
.xattr_tdb
22 import samba
.posix_eadb
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 (
36 class XattrTests(TestCase
):
38 def _tmpfilename(self
):
40 path
= os
.environ
['SELFTEST_PREFIX']
41 return os
.path
.join(path
, "pytests" +str(int(100000 * random
.random())))
44 return os
.path
.join(os
.environ
['SELFTEST_PREFIX'], "eadb.tdb")
46 def test_set_xattr_native(self
):
47 if not samba
.xattr_native
.is_xattr_supported():
51 tempf
= self
._tmpfilename
()
52 open(tempf
, 'w').write("empty")
54 samba
.xattr_native
.wrap_setxattr(tempf
, "user.unittests",
57 raise SkipTest("the filesystem where the tests are run does not "
61 def test_set_and_get_native(self
):
62 if not samba
.xattr_native
.is_xattr_supported():
64 tempf
= self
._tmpfilename
()
65 reftxt
= b
"this is a test"
66 open(tempf
, 'w').write("empty")
68 samba
.xattr_native
.wrap_setxattr(tempf
, "user.unittests", reftxt
)
69 text
= samba
.xattr_native
.wrap_getxattr(tempf
, "user.unittests")
70 self
.assertEqual(text
, reftxt
)
72 raise SkipTest("the filesystem where the tests are run does not "
76 def test_set_xattr_tdb(self
):
77 tempf
= self
._tmpfilename
()
78 eadb_path
= self
._eadbpath
()
81 open(tempf
, 'w').write("empty")
83 samba
.xattr_tdb
.wrap_setxattr(eadb_path
,
84 tempf
, "user.unittests", ndr_pack(ntacl
))
89 def test_set_tdb_not_open(self
):
90 tempf
= self
._tmpfilename
()
93 open(tempf
, 'w').write("empty")
95 self
.assertRaises(IOError, samba
.xattr_tdb
.wrap_setxattr
,
96 os
.path
.join("nonexistent", "eadb.tdb"), tempf
,
97 "user.unittests", ndr_pack(ntacl
))
101 def test_set_and_get_tdb(self
):
102 tempf
= self
._tmpfilename
()
103 eadb_path
= self
._eadbpath
()
104 reftxt
= b
"this is a test"
105 open(tempf
, 'w').write("empty")
107 samba
.xattr_tdb
.wrap_setxattr(eadb_path
, tempf
, "user.unittests",
109 text
= samba
.xattr_tdb
.wrap_getxattr(eadb_path
, tempf
,
111 self
.assertEqual(text
, reftxt
)
116 def test_set_posix_eadb(self
):
117 tempf
= self
._tmpfilename
()
118 eadb_path
= self
._eadbpath
()
119 ntacl
= xattr
.NTACL()
121 open(tempf
, 'w').write("empty")
123 samba
.posix_eadb
.wrap_setxattr(eadb_path
,
124 tempf
, "user.unittests", ndr_pack(ntacl
))
129 def test_set_and_get_posix_eadb(self
):
130 tempf
= self
._tmpfilename
()
131 eadb_path
= self
._eadbpath
()
132 reftxt
= b
"this is a test"
133 open(tempf
, 'w').write("empty")
135 samba
.posix_eadb
.wrap_setxattr(eadb_path
, tempf
, "user.unittests",
137 text
= samba
.posix_eadb
.wrap_getxattr(eadb_path
, tempf
,
139 self
.assertEqual(text
, reftxt
)
145 class TestCopyTreeWithXattrs(TestCaseInTempDir
):
147 def test_simple(self
):
148 os
.chdir(self
.tempdir
)
152 f
= open('a/b/c/d', 'w')
157 copytree_with_xattrs("a", "b")