build: Change bin/default/python -> bin/python symlink to bin/default/python_modules
[Samba.git] / source4 / scripting / python / samba / tests / samba_tool / ntacl.py
blob2a329fe7d403802b8c21b7d081fead7fceeb7602
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Andrew Bartlett 2012
4 # Based on user.py:
5 # Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import os
22 import time
23 import ldb
24 from samba.tests.samba_tool.base import SambaToolCmdTest
25 import random
27 class NtACLCmdSysvolTestCase(SambaToolCmdTest):
28 """Tests for samba-tool ntacl sysvol* subcommands"""
31 def test_ntvfs(self):
32 (result, out, err) = self.runsubcmd("ntacl", "sysvolreset",
33 "--use-ntvfs")
34 self.assertCmdSuccess(result)
35 self.assertEquals(out,"","Shouldn't be any output messages")
36 self.assertIn("Please note that POSIX permissions have NOT been changed, only the stored NT ACL", err)
38 def test_s3fs(self):
39 (result, out, err) = self.runsubcmd("ntacl", "sysvolreset",
40 "--use-s3fs")
42 self.assertCmdSuccess(result)
43 self.assertEquals(err,"","Shouldn't be any error messages")
44 self.assertEquals(out,"","Shouldn't be any output messages")
46 def test_ntvfs_check(self):
47 (result, out, err) = self.runsubcmd("ntacl", "sysvolreset",
48 "--use-ntvfs")
49 self.assertCmdSuccess(result)
50 self.assertEquals(out,"","Shouldn't be any output messages")
51 self.assertIn("Please note that POSIX permissions have NOT been changed, only the stored NT ACL", err)
52 # Now check they were set correctly
53 (result, out, err) = self.runsubcmd("ntacl", "sysvolcheck")
54 self.assertCmdSuccess(result)
55 self.assertEquals(err,"","Shouldn't be any error messages")
56 self.assertEquals(out,"","Shouldn't be any output messages")
58 def test_s3fs_check(self):
59 (result, out, err) = self.runsubcmd("ntacl", "sysvolreset",
60 "--use-s3fs")
62 self.assertCmdSuccess(result)
63 self.assertEquals(err,"","Shouldn't be any error messages")
64 self.assertEquals(out,"","Shouldn't be any output messages")
66 # Now check they were set correctly
67 (result, out, err) = self.runsubcmd("ntacl", "sysvolcheck")
68 self.assertCmdSuccess(result)
69 self.assertEquals(err,"","Shouldn't be any error messages")
70 self.assertEquals(out,"","Shouldn't be any output messages")
72 class NtACLCmdGetSetTestCase(SambaToolCmdTest):
73 """Tests for samba-tool ntacl get/set subcommands"""
75 acl = "O:DAG:DUD:P(A;OICI;0x001f01ff;;;DA)(A;OICI;0x001f01ff;;;EA)(A;OICIIO;0x001f01ff;;;CO)(A;OICI;0x001f01ff;;;DA)(A;OICI;0x001f01ff;;;SY)(A;OICI;0x001200a9;;;AU)(A;OICI;0x001200a9;;;ED)S:AI(OU;CIIDSA;WP;f30e3bbe-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)(OU;CIIDSA;WP;f30e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)"
78 def test_ntvfs(self):
79 path = os.environ['SELFTEST_PREFIX']
80 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
81 open(tempf, 'w').write("empty")
83 (result, out, err) = self.runsubcmd("ntacl", "set", self.acl, tempf,
84 "--use-ntvfs")
85 self.assertCmdSuccess(result)
86 self.assertEquals(out,"","Shouldn't be any output messages")
87 self.assertIn("Please note that POSIX permissions have NOT been changed, only the stored NT ACL", err)
89 def test_s3fs(self):
90 path = os.environ['SELFTEST_PREFIX']
91 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
92 open(tempf, 'w').write("empty")
94 (result, out, err) = self.runsubcmd("ntacl", "set", self.acl, tempf,
95 "--use-s3fs")
97 self.assertCmdSuccess(result)
98 self.assertEquals(err,"","Shouldn't be any error messages")
99 self.assertEquals(out,"","Shouldn't be any output messages")
101 def test_ntvfs_check(self):
102 path = os.environ['SELFTEST_PREFIX']
103 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
104 open(tempf, 'w').write("empty")
106 (result, out, err) = self.runsubcmd("ntacl", "set", self.acl, tempf,
107 "--use-ntvfs")
108 self.assertCmdSuccess(result)
109 self.assertEquals(out,"","Shouldn't be any output messages")
110 self.assertIn("Please note that POSIX permissions have NOT been changed, only the stored NT ACL", err)
112 # Now check they were set correctly
113 (result, out, err) = self.runsubcmd("ntacl", "get", tempf,
114 "--use-ntvfs", "--as-sddl")
115 self.assertCmdSuccess(result)
116 self.assertEquals(err,"","Shouldn't be any error messages")
117 self.assertEquals(self.acl+"\n", out, "Output should be the ACL")
119 def test_s3fs_check(self):
120 path = os.environ['SELFTEST_PREFIX']
121 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
122 open(tempf, 'w').write("empty")
124 (result, out, err) = self.runsubcmd("ntacl", "set", self.acl, tempf,
125 "--use-s3fs")
126 self.assertCmdSuccess(result)
127 self.assertEquals(out,"","Shouldn't be any output messages")
128 self.assertEquals(err,"","Shouldn't be any error messages")
130 # Now check they were set correctly
131 (result, out, err) = self.runsubcmd("ntacl", "get", tempf,
132 "--use-s3fs", "--as-sddl")
133 self.assertCmdSuccess(result)
134 self.assertEquals(err,"","Shouldn't be any error messages")
135 self.assertEquals(self.acl+"\n", out,"Output should be the ACL")