1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Catalyst IT Ltd. 2017
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 from samba.tests.samba_tool.base import SambaToolCmdTest
23 class ProvisionPasswordTestCase(SambaToolCmdTest):
24 """Test for password validation in domain provision subcommand"""
27 super(SambaToolCmdTest, self).setUp()
28 self.tempsambadir = os.path.join(self.tempdir, "samba")
29 os.mkdir(self.tempsambadir)
31 def _provision_with_password(self, password):
32 return self.runsubcmd(
33 "domain", "provision", "--realm=foo.example.com", "--domain=FOO",
34 "--targetdir=%s" % self.tempsambadir, "--adminpass=%s" % password,
37 def test_short_and_low_quality(self):
38 (result, out, err) = self._provision_with_password("foo")
39 self.assertCmdFail(result)
42 (result, out, err) = self._provision_with_password("Fo0!_9")
43 self.assertCmdFail(result)
44 self.assertRegexpMatches(err, r"minimum password length")
46 def test_low_quality(self):
47 (result, out, err) = self._provision_with_password("aaaaaaaaaaaaaaaaa")
48 self.assertCmdFail(result)
49 self.assertRegexpMatches(err, r"quality standards")
52 (result, out, err) = self._provision_with_password("Fo0!_9.")
53 self.assertCmdSuccess(result, out, err)
56 super(SambaToolCmdTest, self).tearDown()
57 shutil.rmtree(self.tempsambadir)