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
, ndr_unpack
23 from unittest
import TestCase
29 class XattrTests(TestCase
):
31 def test_set_xattr_native(self
):
32 if samba
.xattr_native
.is_xattr_supported():
36 path
=os
.environ
['SELFTEST_PREFIX']
38 self
.assertTrue(path
!=None, "SELFTEST_PREFIX env not set")
40 path
=os
.environ
['SELFTEST_PREFIX']
41 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
44 open(tempf
, 'w').write("empty")
46 samba
.xattr_native
.wrap_setxattr(tempf
,"user.unittests",ndr_pack(ntacl
))
48 print >>sys
.stderr
, "WARNING: the filesystem where the tests are runned do not support XATTR, tests SKIPED"
51 print >>sys
.stderr
, "WARNING: the filesystem where the tests are runned do not support XATTR, tests SKIPED"
54 def test_set_and_get_native(self
):
55 if samba
.xattr_native
.is_xattr_supported():
59 path
=os
.environ
['SELFTEST_PREFIX']
61 self
.assertTrue(path
!=None, "SELFTEST_PREFIX env not set")
63 path
=os
.environ
['SELFTEST_PREFIX']
64 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
65 reftxt
="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
.assertEquals(text
,reftxt
)
72 print >>sys
.stderr
,"WARNING: the filesystem where the tests are runned do not support XATTR, tests SKIPED"
75 print >>sys
.stderr
,"WARNING: the filesystem where the tests are runned do not support XATTR, tests SKIPED"
77 def test_set_xattr_tdb(self
):
80 path
=os
.environ
['SELFTEST_PREFIX']
82 self
.assertTrue(path
!=None, "SELFTEST_PREFIX env not set")
84 eadb
=tdb
.Tdb(os
.path
.join(path
,"eadb.tdb"), 50000, tdb
.DEFAULT
, os
.O_CREAT|os
.O_RDWR
)
86 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
89 open(tempf
, 'w').write("empty")
90 samba
.xattr_tdb
.wrap_setxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests",ndr_pack(ntacl
))
92 os
.unlink(os
.path
.join(path
,"eadb.tdb"))
94 def test_set_tdb_not_open(self
):
97 path
=os
.environ
['SELFTEST_PREFIX']
99 self
.assertTrue(path
!=None, "SELFTEST_PREFIX env not set")
101 eadb
=tdb
.Tdb(os
.path
.join(path
,"eadb.tdb"), 50000, tdb
.DEFAULT
, os
.O_CREAT|os
.O_RDWR
)
103 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
106 open(tempf
, 'w').write("empty")
107 self
.assertRaises(IOError,samba
.xattr_tdb
.wrap_setxattr
,os
.path
.join(path
,os
.path
.join("nonexistent","eadb.tdb")),tempf
,"user.unittests",ndr_pack(ntacl
))
110 def test_set_and_get_tdb(self
):
113 path
=os
.environ
['SELFTEST_PREFIX']
115 self
.assertTrue(path
!=None, "SELFTEST_PREFIX env not set")
118 tempf
=os
.path
.join(path
,"pytests"+str(int(100000*random
.random())))
119 reftxt
="this is a test"
120 open(tempf
, 'w').write("empty")
121 samba
.xattr_tdb
.wrap_setxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests",reftxt
)
122 text
= samba
.xattr_tdb
.wrap_getxattr(os
.path
.join(path
,"eadb.tdb"),tempf
,"user.unittests")
123 self
.assertEquals(text
,reftxt
)
125 os
.unlink(os
.path
.join(path
,"eadb.tdb"))