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 testtools
import TestCase
, TestSkipped
27 class XattrTests(TestCase
):
29 def test_set_xattr_native(self
):
30 if not samba
.xattr_native
.is_xattr_supported():
33 path
= os
.environ
['SELFTEST_PREFIX']
34 tempf
= os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
37 open(tempf
, 'w').write("empty")
39 samba
.xattr_native
.wrap_setxattr(tempf
, "user.unittests",
42 raise TestSkipped("the filesystem where the tests are runned do not support XATTR")
45 def test_set_and_get_native(self
):
46 if not samba
.xattr_native
.is_xattr_supported():
49 path
= os
.environ
['SELFTEST_PREFIX']
50 tempf
= os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
51 reftxt
= "this is a test"
52 open(tempf
, 'w').write("empty")
54 samba
.xattr_native
.wrap_setxattr(tempf
, "user.unittests", reftxt
)
55 text
= samba
.xattr_native
.wrap_getxattr(tempf
, "user.unittests")
56 self
.assertEquals(text
, reftxt
)
58 raise TestSkipped("the filesystem where the tests are runned do not support XATTR")
61 def test_set_xattr_tdb(self
):
62 path
= os
.environ
['SELFTEST_PREFIX']
64 tempf
= os
.path
.join(path
, "pytests"+str(int(100000*random
.random())))
67 open(tempf
, 'w').write("empty")
69 samba
.xattr_tdb
.wrap_setxattr(os
.path
.join(path
, "eadb.tdb"),
70 tempf
, "user.unittests", ndr_pack(ntacl
))
73 os
.unlink(os
.path
.join(path
, "eadb.tdb"))
75 def test_set_tdb_not_open(self
):
76 path
= os
.environ
['SELFTEST_PREFIX']
78 tempf
= os
.path
.join(path
, "pytests"+str(int(100000*random
.random())))
81 open(tempf
, 'w').write("empty")
83 self
.assertRaises(IOError, samba
.xattr_tdb
.wrap_setxattr
,
84 os
.path
.join(path
, "nonexistent","eadb.tdb"), tempf
,
85 "user.unittests", ndr_pack(ntacl
))
89 def test_set_and_get_tdb(self
):
90 path
= os
.environ
['SELFTEST_PREFIX']
92 tempf
= os
.path
.join(path
, "pytests"+str(int(100000*random
.random())))
93 reftxt
= "this is a test"
94 open(tempf
, 'w').write("empty")
96 samba
.xattr_tdb
.wrap_setxattr(os
.path
.join(path
, "eadb.tdb"),
97 tempf
, "user.unittests", reftxt
)
98 text
= samba
.xattr_tdb
.wrap_getxattr(
99 os
.path
.join(path
, "eadb.tdb"), tempf
, "user.unittests")
100 self
.assertEquals(text
, reftxt
)
103 os
.unlink(os
.path
.join(path
, "eadb.tdb"))