PEP8: fix E225: missing whitespace around operator
[nivanova/samba-autobuild/.git] / python / samba / tests / ntacls.py
1 # Unix SMB/CIFS implementation. Tests for ntacls manipulation
2 # Copyright (C) Matthieu Patou <mat@matws.net> 2009-2010
3 # Copyright (C) Andrew Bartlett 2012
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 """Tests for samba.ntacls."""
20
21 import os
22
23 from samba.ntacls import setntacl, getntacl, XattrBackendError
24 from samba.param import LoadParm
25 from samba.dcerpc import security
26 from samba.tests import TestCaseInTempDir, SkipTest
27
28 NTACL_SDDL = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;OICI;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512)"
29 DOMAIN_SID = "S-1-5-21-2212615479-2695158682-2101375467"
30
31
32 class NtaclsTests(TestCaseInTempDir):
33
34     def setUp(self):
35         super(NtaclsTests, self).setUp()
36         self.tempf = os.path.join(self.tempdir, "test")
37         open(self.tempf, 'w').write("empty")
38
39     def tearDown(self):
40         os.unlink(self.tempf)
41         super(NtaclsTests, self).tearDown()
42
43     def test_setntacl(self):
44         lp = LoadParm()
45         open(self.tempf, 'w').write("empty")
46         lp.set("posix:eadb", os.path.join(self.tempdir, "eadbtest.tdb"))
47         setntacl(lp, self.tempf, NTACL_SDDL, DOMAIN_SID)
48         os.unlink(os.path.join(self.tempdir, "eadbtest.tdb"))
49
50     def test_setntacl_getntacl(self):
51         lp = LoadParm()
52         open(self.tempf, 'w').write("empty")
53         lp.set("posix:eadb", os.path.join(self.tempdir, "eadbtest.tdb"))
54         setntacl(lp, self.tempf, NTACL_SDDL, DOMAIN_SID)
55         facl = getntacl(lp, self.tempf)
56         anysid = security.dom_sid(security.SID_NT_SELF)
57         self.assertEquals(facl.as_sddl(anysid), NTACL_SDDL)
58         os.unlink(os.path.join(self.tempdir, "eadbtest.tdb"))
59
60     def test_setntacl_getntacl_param(self):
61         lp = LoadParm()
62         open(self.tempf, 'w').write("empty")
63         setntacl(lp, self.tempf, NTACL_SDDL, DOMAIN_SID, "tdb",
64                  os.path.join(self.tempdir, "eadbtest.tdb"))
65         facl = getntacl(lp, self.tempf, "tdb", os.path.join(
66             self.tempdir, "eadbtest.tdb"))
67         domsid = security.dom_sid(security.SID_NT_SELF)
68         self.assertEquals(facl.as_sddl(domsid), NTACL_SDDL)
69         os.unlink(os.path.join(self.tempdir, "eadbtest.tdb"))
70
71     def test_setntacl_invalidbackend(self):
72         lp = LoadParm()
73         open(self.tempf, 'w').write("empty")
74         self.assertRaises(XattrBackendError, setntacl, lp, self.tempf,
75                           NTACL_SDDL, DOMAIN_SID, "ttdb",
76                           os.path.join(self.tempdir, "eadbtest.tdb"))
77
78     def test_setntacl_forcenative(self):
79         if os.getuid() == 0:
80             raise SkipTest("Running test as root, test skipped")
81         lp = LoadParm()
82         open(self.tempf, 'w').write("empty")
83         lp.set("posix:eadb", os.path.join(self.tempdir, "eadbtest.tdb"))
84         self.assertRaises(Exception, setntacl, lp, self.tempf, NTACL_SDDL,
85                           DOMAIN_SID, "native")