/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-03-12 18:11:55 UTC
  • Revision ID: teddy@recompile.se-20190312181155-q8q3moo97u7ta2za
mandos-ctl: White space and other non-semantic changes only

* mandos-ctl: Break long lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
342
342
        self.verbose = verbose
343
343
 
344
344
    def output(self, clients):
345
 
        default_keywords = ("Name", "Enabled", "Timeout", "LastCheckedOK")
 
345
        default_keywords = ("Name", "Enabled", "Timeout",
 
346
                            "LastCheckedOK")
346
347
        keywords = default_keywords
347
348
        if self.verbose:
348
349
            keywords = self.all_keywords
924
925
class TestPrintTableCmd(TestCmd):
925
926
    def test_normal(self):
926
927
        output = PrintTableCmd().output(self.clients.values())
927
 
        expected_output = """
928
 
Name   Enabled Timeout  Last Successful Check
929
 
foo    Yes     00:05:00 2019-02-03T00:00:00  
930
 
barbar Yes     00:05:00 2019-02-04T00:00:00  
931
 
"""[1:-1]
 
928
        expected_output = "\n".join((
 
929
            "Name   Enabled Timeout  Last Successful Check",
 
930
            "foo    Yes     00:05:00 2019-02-03T00:00:00  ",
 
931
            "barbar Yes     00:05:00 2019-02-04T00:00:00  ",
 
932
        ))
932
933
        self.assertEqual(output, expected_output)
933
934
    def test_verbose(self):
934
935
        output = PrintTableCmd(verbose=True).output(
935
936
            self.clients.values())
936
 
        expected_output = """
937
 
Name   Enabled Timeout  Last Successful Check Created             Interval Host            Key ID                                                           Fingerprint                              Check Is Running Last Enabled        Approval Is Pending Approved By Default Last Approval Request Approval Delay Approval Duration Checker              Extended Timeout Expires             Last Checker Status
938
 
foo    Yes     00:05:00 2019-02-03T00:00:00   2019-01-02T00:00:00 00:02:00 foo.example.org 92ed150794387c03ce684574b1139a6594a34f895daaaf09fd8ea90a27cddb12 778827225BA7DE539C5A7CFA59CFF7CDBD9A5920 No               2019-01-03T00:00:00 No                  Yes                                       00:00:00       00:00:01          fping -q -- %(host)s 00:15:00         2019-02-04T00:00:00 0                  
939
 
barbar Yes     00:05:00 2019-02-04T00:00:00   2019-01-03T00:00:00 00:02:00 192.0.2.3       0558568eedd67d622f5c83b35a115f796ab612cff5ad227247e46c2b020f441c 3E393AEAEFB84C7E89E2F547B3A107558FCA3A27 Yes              2019-01-04T00:00:00 No                  No                  2019-01-03T00:00:00   00:00:30       00:00:01          :                    00:15:00         2019-02-05T00:00:00 -2                 
940
 
"""[1:-1]
 
937
        expected_output = "\n".join((
 
938
            # First line (headers)
 
939
            "Name   Enabled Timeout  Last Successful Check Created   "
 
940
            "          Interval Host            Key ID               "
 
941
            "                                            Fingerprint "
 
942
            "                             Check Is Running Last Enabl"
 
943
            "ed        Approval Is Pending Approved By Default Last A"
 
944
            "pproval Request Approval Delay Approval Duration Checker"
 
945
            "              Extended Timeout Expires             Last "
 
946
            "Checker Status",
 
947
            # Second line (client "foo")
 
948
            "foo    Yes     00:05:00 2019-02-03T00:00:00   2019-01-02"
 
949
            "T00:00:00 00:02:00 foo.example.org 92ed150794387c03ce684"
 
950
            "574b1139a6594a34f895daaaf09fd8ea90a27cddb12 778827225BA7"
 
951
            "DE539C5A7CFA59CFF7CDBD9A5920 No               2019-01-03"
 
952
            "T00:00:00 No                  Yes                       "
 
953
            "                00:00:00       00:00:01          fping -"
 
954
            "q -- %(host)s 00:15:00         2019-02-04T00:00:00 0    "
 
955
            "              ",
 
956
            # Third line (client "barbar")
 
957
            "barbar Yes     00:05:00 2019-02-04T00:00:00   2019-01-03"
 
958
            "T00:00:00 00:02:00 192.0.2.3       0558568eedd67d622f5c8"
 
959
            "3b35a115f796ab612cff5ad227247e46c2b020f441c 3E393AEAEFB8"
 
960
            "4C7E89E2F547B3A107558FCA3A27 Yes              2019-01-04"
 
961
            "T00:00:00 No                  No                  2019-0"
 
962
            "1-03T00:00:00   00:00:30       00:00:01          :      "
 
963
            "              00:15:00         2019-02-05T00:00:00 -2   "
 
964
            "              ",
 
965
        ))
941
966
        self.assertEqual(output, expected_output)
942
967
    def test_one_client(self):
943
968
        output = PrintTableCmd().output(self.one_client.values())
1011
1036
 
1012
1037
class TestIsEnabledCmd(TestCmd):
1013
1038
    def test_is_enabled(self):
1014
 
        self.assertTrue(all(IsEnabledCmd().is_enabled(client, properties)
1015
 
                            for client, properties in self.clients.items()))
 
1039
        self.assertTrue(all(IsEnabledCmd().is_enabled(client,
 
1040
                                                      properties)
 
1041
                            for client, properties
 
1042
                            in self.clients.items()))
1016
1043
    def test_is_enabled_run_exits_successfully(self):
1017
1044
        with self.assertRaises(SystemExit) as e:
1018
1045
            IsEnabledCmd().run(self.one_client)
1211
1238
    def setUp(self):
1212
1239
        self.parser = argparse.ArgumentParser()
1213
1240
        add_command_line_options(self.parser)
1214
 
    def assert_command_from_args(self, args, command_cls, **cmd_attrs):
 
1241
    def assert_command_from_args(self, args, command_cls,
 
1242
                                 **cmd_attrs):
1215
1243
        """Assert that parsing ARGS should result in an instance of
1216
1244
COMMAND_CLS with (optionally) all supplied attributes (CMD_ATTRS)."""
1217
1245
        options = self.parser.parse_args(args)
1386
1414
        self.assert_command_from_args(["-V", "foo"], IsEnabledCmd)
1387
1415
 
1388
1416
    def test_deny_before_remove(self):
1389
 
        options = self.parser.parse_args(["--deny", "--remove", "foo"])
 
1417
        options = self.parser.parse_args(["--deny", "--remove",
 
1418
                                          "foo"])
1390
1419
        check_option_syntax(self.parser, options)
1391
1420
        commands = commands_from_options(options)
1392
1421
        self.assertEqual(len(commands), 2)
1394
1423
        self.assertIsInstance(commands[1], RemoveCmd)
1395
1424
 
1396
1425
    def test_deny_before_remove_reversed(self):
1397
 
        options = self.parser.parse_args(["--remove", "--deny", "--all"])
 
1426
        options = self.parser.parse_args(["--remove", "--deny",
 
1427
                                          "--all"])
1398
1428
        check_option_syntax(self.parser, options)
1399
1429
        commands = commands_from_options(options)
1400
1430
        self.assertEqual(len(commands), 2)
1439
1469
            with self.temporarily_suppress_stderr():
1440
1470
                yield
1441
1471
        # Exit code from argparse is guaranteed to be "2".  Reference:
1442
 
        # https://docs.python.org/3/library/argparse.html#exiting-methods
 
1472
        # https://docs.python.org/3/library
 
1473
        # /argparse.html#exiting-methods
1443
1474
        self.assertEqual(e.exception.code, 2)
1444
1475
 
1445
1476
    @staticmethod