/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-07-15 01:59:36 UTC
  • Revision ID: teddy@recompile.se-20190715015936-09xieyg8ogdxvoi2
Debian package change: Add autopkgtest support

* Makefile (check): Run a few more superficial tests.
  (debian/control/[Source: mandos]/Testsuite): New; set to
                                               "autopkgtest".
  (debian/tests/control): New.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
 
# -*- mode: python; coding: utf-8; after-save-hook: (lambda () (let ((command (if (and (boundp 'tramp-file-name-structure) (string-match (car tramp-file-name-structure) (buffer-file-name))) (tramp-file-name-localname (tramp-dissect-file-name (buffer-file-name))) (buffer-file-name)))) (if (= (shell-command (format "%s --check" (shell-quote-argument command)) "*Test*") 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w)) (kill-buffer "*Test*")) (display-buffer "*Test*")))); -*-
 
2
# -*- after-save-hook: (lambda () (let ((command (if (fboundp 'file-local-name) (file-local-name (buffer-file-name)) (or (file-remote-p (buffer-file-name) 'localname) (buffer-file-name))))) (if (= (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (format "%s --test" (shell-quote-argument command)) nil "*Test*")) 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w))) (progn (with-current-buffer "*Test*" (compilation-mode)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); coding: utf-8 -*-
3
3
#
4
4
# Mandos Monitor - Control and monitor the Mandos server
5
5
#
1780
1780
        self.assert_command_from_args(["--is-enabled", "client"],
1781
1781
                                      command.IsEnabled)
1782
1782
 
1783
 
    def assert_command_from_args(self, args, command_cls,
1784
 
                                 **cmd_attrs):
 
1783
    def assert_command_from_args(self, args, command_cls, length=1,
 
1784
                                 clients=None, **cmd_attrs):
1785
1785
        """Assert that parsing ARGS should result in an instance of
1786
1786
COMMAND_CLS with (optionally) all supplied attributes (CMD_ATTRS)."""
1787
1787
        options = self.parser.parse_args(args)
1788
1788
        check_option_syntax(self.parser, options)
1789
1789
        commands = commands_from_options(options)
1790
 
        self.assertEqual(1, len(commands))
1791
 
        command = commands[0]
1792
 
        self.assertIsInstance(command, command_cls)
 
1790
        self.assertEqual(length, len(commands))
 
1791
        for command in commands:
 
1792
            if isinstance(command, command_cls):
 
1793
                break
 
1794
        else:
 
1795
            self.assertIsInstance(command, command_cls)
 
1796
        if clients is not None:
 
1797
            self.assertEqual(clients, options.client)
1793
1798
        for key, value in cmd_attrs.items():
1794
1799
            self.assertEqual(value, getattr(command, key))
1795
1800
 
 
1801
    def assert_commands_from_args(self, args, commands, clients=None):
 
1802
        for cmd in commands:
 
1803
            self.assert_command_from_args(args, cmd,
 
1804
                                          length=len(commands),
 
1805
                                          clients=clients)
 
1806
 
1796
1807
    def test_is_enabled_short(self):
1797
1808
        self.assert_command_from_args(["-V", "client"],
1798
1809
                                      command.IsEnabled)
1989
2000
                                      verbose=True)
1990
2001
 
1991
2002
 
 
2003
    def test_manual_page_example_1(self):
 
2004
        self.assert_command_from_args("--verbose".split(),
 
2005
                                      command.PrintTable,
 
2006
                                      clients=[],
 
2007
                                      verbose=True)
 
2008
 
 
2009
    def test_manual_page_example_2(self):
 
2010
        self.assert_command_from_args(
 
2011
            "--verbose foo1.example.org foo2.example.org".split(),
 
2012
            command.PrintTable, clients=["foo1.example.org",
 
2013
                                         "foo2.example.org"],
 
2014
            verbose=True)
 
2015
 
 
2016
    def test_manual_page_example_3(self):
 
2017
        self.assert_command_from_args("--enable --all".split(),
 
2018
                                      command.Enable,
 
2019
                                      clients=[])
 
2020
 
 
2021
    def test_manual_page_example_4(self):
 
2022
        self.assert_commands_from_args(
 
2023
            ("--timeout=PT5M --interval=PT1M foo1.example.org"
 
2024
             " foo2.example.org").split(),
 
2025
            [command.SetTimeout, command.SetInterval],
 
2026
            clients=["foo1.example.org", "foo2.example.org"])
 
2027
 
 
2028
    def test_manual_page_example_5(self):
 
2029
        self.assert_command_from_args("--approve --all".split(),
 
2030
                                      command.Approve,
 
2031
                                      clients=[])
 
2032
 
 
2033
 
1992
2034
class TestCommand(unittest.TestCase):
1993
2035
    """Abstract class for tests of command classes"""
1994
2036