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
22 class ProvisionPasswordTestCase(SambaToolCmdTest
):
23 """Test for password validation in domain provision subcommand"""
26 super(SambaToolCmdTest
, self
).setUp()
27 self
.tempsambadir
= os
.path
.join(self
.tempdir
, "samba")
28 os
.mkdir(self
.tempsambadir
)
30 def _provision_with_password(self
, password
):
31 return self
.runsubcmd(
32 "domain", "provision", "--realm=foo.example.com", "--domain=FOO",
33 "--targetdir=%s" % self
.tempsambadir
, "--adminpass=%s" % password
,
36 def test_short_and_low_quality(self
):
37 (result
, out
, err
) = self
._provision
_with
_password
("foo")
38 self
.assertCmdFail(result
)
41 (result
, out
, err
) = self
._provision
_with
_password
("Fo0!_9")
42 self
.assertCmdFail(result
)
43 self
.assertRegexpMatches(err
, r
"minimum password length")
45 def test_low_quality(self
):
46 (result
, out
, err
) = self
._provision
_with
_password
("aaaaaaaaaaaaaaaaa")
47 self
.assertCmdFail(result
)
48 self
.assertRegexpMatches(err
, r
"quality standards")
51 (result
, out
, err
) = self
._provision
_with
_password
("Fo0!_9.")
52 self
.assertCmdSuccess(result
, out
, err
)
55 super(SambaToolCmdTest
, self
).tearDown()
56 shutil
.rmtree(self
.tempsambadir
)