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 runned do not support XATTR")
60 def test_set_and_get_native(self
):
61 if not samba
.xattr_native
.is_xattr_supported():
63 tempf
= self
._tmpfilename
()
64 reftxt
= b
"this is a test"
65 open(tempf
, 'w').write("empty")
67 samba
.xattr_native
.wrap_setxattr(tempf
, "user.unittests", reftxt
)
68 text
= samba
.xattr_native
.wrap_getxattr(tempf
, "user.unittests")
69 self
.assertEquals(text
, reftxt
)
71 raise SkipTest("the filesystem where the tests are runned do not support XATTR")
74 def test_set_xattr_tdb(self
):
75 tempf
= self
._tmpfilename
()
76 eadb_path
= self
._eadbpath
()
79 open(tempf
, 'w').write("empty")
81 samba
.xattr_tdb
.wrap_setxattr(eadb_path
,
82 tempf
, "user.unittests", ndr_pack(ntacl
))
87 def test_set_tdb_not_open(self
):
88 tempf
= self
._tmpfilename
()
91 open(tempf
, 'w').write("empty")
93 self
.assertRaises(IOError, samba
.xattr_tdb
.wrap_setxattr
,
94 os
.path
.join("nonexistent", "eadb.tdb"), tempf
,
95 "user.unittests", ndr_pack(ntacl
))
99 def test_set_and_get_tdb(self
):
100 tempf
= self
._tmpfilename
()
101 eadb_path
= self
._eadbpath
()
102 reftxt
= b
"this is a test"
103 open(tempf
, 'w').write("empty")
105 samba
.xattr_tdb
.wrap_setxattr(eadb_path
, tempf
, "user.unittests",
107 text
= samba
.xattr_tdb
.wrap_getxattr(eadb_path
, tempf
,
109 self
.assertEquals(text
, reftxt
)
114 def test_set_posix_eadb(self
):
115 tempf
= self
._tmpfilename
()
116 eadb_path
= self
._eadbpath
()
117 ntacl
= xattr
.NTACL()
119 open(tempf
, 'w').write("empty")
121 samba
.posix_eadb
.wrap_setxattr(eadb_path
,
122 tempf
, "user.unittests", ndr_pack(ntacl
))
127 def test_set_and_get_posix_eadb(self
):
128 tempf
= self
._tmpfilename
()
129 eadb_path
= self
._eadbpath
()
130 reftxt
= b
"this is a test"
131 open(tempf
, 'w').write("empty")
133 samba
.posix_eadb
.wrap_setxattr(eadb_path
, tempf
, "user.unittests",
135 text
= samba
.posix_eadb
.wrap_getxattr(eadb_path
, tempf
,
137 self
.assertEquals(text
, reftxt
)
143 class TestCopyTreeWithXattrs(TestCaseInTempDir
):
145 def test_simple(self
):
146 os
.chdir(self
.tempdir
)
150 f
= open('a/b/c/d', 'w')
155 copytree_with_xattrs("a", "b")