summaryrefslogtreecommitdiff
path: root/python/samba/tests/samba_tool/provision_password_check.py
blob: a8fb8578ecc6c98ba0248c82aaaddb387aeebfde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Unix SMB/CIFS implementation.
# Copyright (C) Catalyst IT Ltd. 2017
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from samba.tests.samba_tool.base import SambaToolCmdTest
import os
import shutil


class ProvisionPasswordTestCase(SambaToolCmdTest):
    """Test for password validation in domain provision subcommand"""

    def setUp(self):
        super(ProvisionPasswordTestCase, self).setUp()
        self.tempsambadir = os.path.join(self.tempdir, "samba")
        os.mkdir(self.tempsambadir)

    def _provision_with_password(self, password):
        return self.runsubcmd(
            "domain", "provision", "--realm=foo.example.com", "--domain=FOO",
            "--targetdir=%s" % self.tempsambadir, "--adminpass=%s" % password,
            "--use-ntvfs")

    def test_short_and_low_quality(self):
        (result, out, err) = self._provision_with_password("foo")
        self.assertCmdFail(result)

    def test_short(self):
        (result, out, err) = self._provision_with_password("Fo0!_9")
        self.assertCmdFail(result)
        self.assertRegexpMatches(err, r"minimum password length")

    def test_low_quality(self):
        (result, out, err) = self._provision_with_password("aaaaaaaaaaaaaaaaa")
        self.assertCmdFail(result)
        self.assertRegexpMatches(err, r"quality standards")

    def test_good(self):
        (result, out, err) = self._provision_with_password("Fo0!_9.")
        self.assertCmdSuccess(result, out, err)

    def tearDown(self):
        super(ProvisionPasswordTestCase, self).tearDown()
        shutil.rmtree(self.tempsambadir)