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
25 from samba
import version
28 class HelpTestCase(SambaToolCmdTest
):
29 """Tests for samba-tool help and --help
31 We test for consistency and lack of crashes."""
33 def _find_sub_commands(self
, args
):
36 def test_help_tree(self
):
37 # we call actual subprocesses, because we are probing the
38 # actual help output where there is no sub-command. Don't copy
39 # this if you have an actual command: for that use
40 # self.runcmd() or self.runsubcmd().
46 for c
in known_commands
:
47 line
= ' '.join(['samba-tool'] + c
+ ['--help'])
49 output
= self
.check_output(line
)
50 except BlackboxProcessError
as e
:
52 failed_commands
.append(c
)
53 output
= get_string(output
)
54 tail
= output
.partition('Available subcommands:')[2]
55 subcommands
= re
.findall(r
'^\s*([\w-]+)\s+-', tail
,
58 new_commands
.append(c
+ [s
])
60 # check that `samba-tool help X Y` == `samba-tool X Y --help`
61 line
= ' '.join(['samba-tool', 'help'] + c
)
63 output2
= self
.check_output(line
)
64 except BlackboxProcessError
as e
:
66 failed_commands
.append(c
)
68 output2
= get_string(output2
)
69 self
.assertEqual(output
, output2
)
71 err
= check_help_consistency(output
,
72 options_start
='Options:',
73 options_end
='Available subcommands:')
75 self
.fail("consistency error with %s:\n%s" % (line
, err
))
80 known_commands
= new_commands
82 self
.assertEqual(failed_commands
, [])
84 def test_bad_password_option(self
):
85 """Do we get a warning with an invalid --pass option?"""
86 (result
, out
, err
) = self
.run_command(["samba-tool",
88 "--pass-the-salt-please",
90 self
.assertIn("if '--pass-the-salt-please' is not misspelt", err
)
91 self
.assertIn("the appropriate list in is_password_option", err
)
93 def test_version(self
):
94 """Does --version work?"""
95 (result
, out
, err
) = self
.run_command(["samba-tool", "--version"])
96 self
.assertEqual(version
, out
.strip())
98 def test_sub_command_version(self
):
99 """Does --version work in a sub-command?"""
100 (result
, out
, err
) = self
.run_command(["samba-tool", "spn", "--version"])
101 self
.assertEqual(version
, out
.strip())
103 def test_leaf_command_version(self
):
104 """Does --version work in a leaf command?"""
105 (result
, out
, err
) = self
.run_command(["samba-tool", "contact", "edit",
107 self
.assertEqual(version
, out
.strip())
109 def test_help_version(self
):
110 """Is version mentioned in --help?"""
111 (result
, out
, err
) = self
.run_command(["samba-tool", "spn", "--help"])
112 self
.assertIn(version
, out
)
114 def test_version_beats_help(self
):
115 """Does samba-tool --help --version print version?"""
116 (result
, out
, err
) = self
.run_command(["samba-tool", "spn", "--help", "-V"])
117 self
.assertEqual(version
, out
.strip())
118 (result
, out
, err
) = self
.run_command(["samba-tool", "--help", "-V"])
119 self
.assertEqual(version
, out
.strip())
120 (result
, out
, err
) = self
.run_command(["samba-tool", "dns", "-V", "--help"])
121 self
.assertEqual(version
, out
.strip())