1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Catalyst IT Ltd 2017.
4 # Originally written by Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from samba
.tests
.samba_tool
.base
import SambaToolCmdTest
22 from samba
.tests
import BlackboxProcessError
23 from samba
.tests
import check_help_consistency
24 from samba
.common
import get_string
27 class HelpTestCase(SambaToolCmdTest
):
28 """Tests for samba-tool help and --help
30 We test for consistency and lack of crashes."""
32 def _find_sub_commands(self
, args
):
35 def test_help_tree(self
):
36 # we call actual subprocesses, because we are probing the
37 # actual help output where there is no sub-command. Don't copy
38 # this if you have an actual command: for that use
39 # self.runcmd() or self.runsubcmd().
45 for c
in known_commands
:
46 line
= ' '.join(['samba-tool'] + c
+ ['--help'])
48 output
= self
.check_output(line
)
49 except BlackboxProcessError
as e
:
51 failed_commands
.append(c
)
52 output
= get_string(output
)
53 tail
= output
.partition('Available subcommands:')[2]
54 subcommands
= re
.findall(r
'^\s*([\w-]+)\s+-', tail
,
57 new_commands
.append(c
+ [s
])
59 # check that `samba-tool help X Y` == `samba-tool X Y --help`
60 line
= ' '.join(['samba-tool', 'help'] + c
)
62 output2
= self
.check_output(line
)
63 except BlackboxProcessError
as e
:
65 failed_commands
.append(c
)
67 output2
= get_string(output2
)
68 self
.assertEqual(output
, output2
)
70 err
= check_help_consistency(output
,
71 options_start
='Options:',
72 options_end
='Available subcommands:')
74 self
.fail("consistency error with %s:\n%s" % (line
, err
))
79 known_commands
= new_commands
81 self
.assertEqual(failed_commands
, [])
83 def test_bad_password_option(self
):
84 """Do we get a warning with an invalid --pass option?"""
85 (result
, out
, err
) = self
.run_command(["samba-tool",
87 "--pass-the-salt-please",
89 self
.assertIn("if '--pass-the-salt-please' is not misspelt", err
)
90 self
.assertIn("the appropriate list in is_password_option", err
)