1 # Test 'samba-tool domain passwordsettings' sub-commands
3 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
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.
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.
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/>.
21 from samba.tests.samba_tool.base import SambaToolCmdTest
23 class PwdSettingsCmdTestCase(SambaToolCmdTest):
24 """Tests for 'samba-tool domain passwordsettings' subcommands"""
27 super(PwdSettingsCmdTestCase, self).setUp()
28 self.server = "ldap://%s" % os.environ["DC_SERVER"]
29 self.user_auth = "-U%s%%%s" % (os.environ["DC_USERNAME"],
30 os.environ["DC_PASSWORD"])
31 self.ldb = self.getSamDB("-H", self.server, self.user_auth)
34 super(PwdSettingsCmdTestCase, self).tearDown()
36 def test_domain_passwordsettings(self):
37 """Checks the 'set/show' commands for the domain settings (non-PSO)"""
39 # check the 'show' cmd for the domain settings
40 (result, out, err) = self.runsublevelcmd("domain", ("passwordsettings",
41 "show"), "-H", self.server,
43 self.assertCmdSuccess(result, out, err)
44 self.assertEquals(err,"","Shouldn't be any error messages")
46 # check an arbitrary setting is displayed correctly
47 min_pwd_len = self.ldb.get_minPwdLength()
48 self.assertIn("Minimum password length: %s" % min_pwd_len, out)
50 # check we can change the domain setting
51 self.addCleanup(self.ldb.set_minPwdLength, min_pwd_len)
52 new_len = int(min_pwd_len) + 3
53 (result, out, err) = self.runsublevelcmd("domain", ("passwordsettings",
55 "--min-pwd-length=%u" % new_len,
58 self.assertCmdSuccess(result, out, err)
59 self.assertEquals(err,"","Shouldn't be any error messages")
60 self.assertIn("successful", out)
61 self.assertEquals(str(new_len), self.ldb.get_minPwdLength())
63 # check the updated value is now displayed
64 (result, out, err) = self.runsublevelcmd("domain", ("passwordsettings",
65 "show"), "-H", self.server,
67 self.assertCmdSuccess(result, out, err)
68 self.assertEquals(err,"","Shouldn't be any error messages")
69 self.assertIn("Minimum password length: %u" % new_len, out)