s4-drs: Add DRSUAPI_DRS_NONGC_RO_REP bit to DRS_OPTIONS
[Samba/fernandojvsilva.git] / source4 / scripting / python / samba / tests / xattr.py
blob9bfe52c67e3a7ef1f7debfc16bc66a4a982b162e
1 #!/usr/bin/python
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.testcase import TestCase, TestSkipped
24 import random
25 import os
27 class XattrTests(TestCase):
29 def _tmpfilename(self):
30 random.seed()
31 path = os.environ['SELFTEST_PREFIX']
32 return os.path.join(path, "pytests"+str(int(100000*random.random())))
34 def _eadbpath(self):
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():
39 raise TestSkipped()
40 ntacl = xattr.NTACL()
41 ntacl.version = 1
42 tempf = self._tmpfilename()
43 open(tempf, 'w').write("empty")
44 try:
45 samba.xattr_native.wrap_setxattr(tempf, "user.unittests",
46 ndr_pack(ntacl))
47 except IOError:
48 raise TestSkipped("the filesystem where the tests are runned do not support XATTR")
49 os.unlink(tempf)
51 def test_set_and_get_native(self):
52 if not samba.xattr_native.is_xattr_supported():
53 raise TestSkipped()
54 tempf = self._tmpfilename()
55 reftxt = "this is a test"
56 open(tempf, 'w').write("empty")
57 try:
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)
61 except IOError:
62 raise TestSkipped("the filesystem where the tests are runned do not support XATTR")
63 os.unlink(tempf)
65 def test_set_xattr_tdb(self):
66 tempf = self._tmpfilename()
67 eadb_path = self._eadbpath()
68 ntacl = xattr.NTACL()
69 ntacl.version = 1
70 open(tempf, 'w').write("empty")
71 try:
72 samba.xattr_tdb.wrap_setxattr(eadb_path,
73 tempf, "user.unittests", ndr_pack(ntacl))
74 finally:
75 os.unlink(tempf)
76 os.unlink(eadb_path)
78 def test_set_tdb_not_open(self):
79 tempf = self._tmpfilename()
80 ntacl = xattr.NTACL()
81 ntacl.version = 1
82 open(tempf, 'w').write("empty")
83 try:
84 self.assertRaises(IOError, samba.xattr_tdb.wrap_setxattr,
85 os.path.join("nonexistent", "eadb.tdb"), tempf,
86 "user.unittests", ndr_pack(ntacl))
87 finally:
88 os.unlink(tempf)
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")
95 try:
96 samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests",
97 reftxt)
98 text = samba.xattr_tdb.wrap_getxattr(eadb_path, tempf,
99 "user.unittests")
100 self.assertEquals(text, reftxt)
101 finally:
102 os.unlink(tempf)
103 os.unlink(eadb_path)