ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / tests / samba_tool / schema.py
blob5c4ac78ef53349c9ec8401cca6e70f2ba0e647ca
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) William Brown <william@blackhats.net.au> 2018
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import os
19 import ldb
20 from samba.tests.samba_tool.base import SambaToolCmdTest
23 class SchemaCmdTestCase(SambaToolCmdTest):
24 """Tests for samba-tool dsacl subcommands"""
25 samdb = None
27 def setUp(self):
28 super().setUp()
29 self.samdb = self.getSamDB("-H", "ldap://%s" % os.environ["DC_SERVER"],
30 "-U%s%%%s" % (os.environ["DC_USERNAME"], os.environ["DC_PASSWORD"]))
32 def test_display_attribute(self):
33 """Tests that we can display schema attributes"""
34 (result, out, err) = self.runsublevelcmd("schema", ("attribute",
35 "show"), "uid",
36 "-H", "ldap://%s" % os.environ["DC_SERVER"],
37 "-U%s%%%s" % (os.environ["DC_USERNAME"],
38 os.environ["DC_PASSWORD"]))
40 self.assertCmdSuccess(result, out, err)
41 self.assertEqual(err, "", "Shouldn't be any error messages")
42 self.assertIn("dn: CN=uid,CN=Schema,CN=Configuration,", out)
44 def test_modify_attribute_searchflags(self):
45 """Tests that we can modify searchFlags of an attribute"""
46 (result, out, err) = self.runsublevelcmd("schema", ("attribute",
47 "modify"), "uid", "--searchflags=9",
48 "-H", "ldap://%s" % os.environ["DC_SERVER"],
49 "-U%s%%%s" % (os.environ["DC_USERNAME"],
50 os.environ["DC_PASSWORD"]))
52 self.assertCmdFail(result, 'Unknown flag 9, please see --help')
54 (result, out, err) = self.runsublevelcmd("schema", ("attribute",
55 "modify"), "uid", "--searchflags=fATTINDEX",
56 "-H", "ldap://%s" % os.environ["DC_SERVER"],
57 "-U%s%%%s" % (os.environ["DC_USERNAME"],
58 os.environ["DC_PASSWORD"]))
60 self.assertCmdSuccess(result, out, err)
61 self.assertEqual(err, "", "Shouldn't be any error messages")
62 self.assertIn("modified cn=uid,CN=Schema,CN=Configuration,", out)
64 (result, out, err) = self.runsublevelcmd("schema", ("attribute",
65 "modify"), "uid",
66 "--searchflags=fATTINDEX,fSUBTREEATTINDEX",
67 "-H", "ldap://%s" % os.environ["DC_SERVER"],
68 "-U%s%%%s" % (os.environ["DC_USERNAME"],
69 os.environ["DC_PASSWORD"]))
71 self.assertCmdSuccess(result, out, err)
72 self.assertEqual(err, "", "Shouldn't be any error messages")
73 self.assertIn("modified cn=uid,CN=Schema,CN=Configuration,", out)
75 (result, out, err) = self.runsublevelcmd("schema", ("attribute",
76 "modify"), "uid",
77 "--searchflags=fAtTiNdEx,fPRESERVEONDELETE",
78 "-H", "ldap://%s" % os.environ["DC_SERVER"],
79 "-U%s%%%s" % (os.environ["DC_USERNAME"],
80 os.environ["DC_PASSWORD"]))
82 self.assertCmdSuccess(result, out, err)
83 self.assertEqual(err, "", "Shouldn't be any error messages")
84 self.assertIn("modified cn=uid,CN=Schema,CN=Configuration,", out)
86 def test_show_oc_attribute(self):
87 """Tests that we can modify searchFlags of an attribute"""
88 (result, out, err) = self.runsublevelcmd("schema", ("attribute",
89 "show_oc"), "cn",
90 "-H", "ldap://%s" % os.environ["DC_SERVER"],
91 "-U%s%%%s" % (os.environ["DC_USERNAME"],
92 os.environ["DC_PASSWORD"]))
94 self.assertCmdSuccess(result, out, err)
95 self.assertEqual(err, "", "Shouldn't be any error messages")
96 self.assertIn("--- MAY contain ---", out)
97 self.assertIn("--- MUST contain ---", out)
99 def test_display_objectclass(self):
100 """Tests that we can display schema objectclasses"""
101 (result, out, err) = self.runsublevelcmd("schema", ("objectclass",
102 "show"), "person",
103 "-H", "ldap://%s" % os.environ["DC_SERVER"],
104 "-U%s%%%s" % (os.environ["DC_USERNAME"],
105 os.environ["DC_PASSWORD"]))
107 self.assertCmdSuccess(result, out, err)
108 self.assertEqual(err, "", "Shouldn't be any error messages")
109 self.assertIn("dn: CN=Person,CN=Schema,CN=Configuration,", out)