/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-09 00:35:00 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 382.
  • Revision ID: teddy@recompile.se-20190309003500-t0pdqxwy5g8jrfax
mandos-ctl: Make --deny always apply before --remove

* mandos-ctl (commands_from_options): Move options.remove clause to
                                      after options.deny.
  (Test_command_from_options.test_deny_before_remove): New.
  (Test_command_from_options.test_deny_before_remove_reversed): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
611
611
    if options.is_enabled:
612
612
        commands.append(IsEnabledCmd())
613
613
 
614
 
    if options.remove:
615
 
        commands.append(RemoveCmd())
616
 
 
617
614
    if options.checker is not None:
618
615
        commands.append(SetCheckerCmd(options.checker))
619
616
 
652
649
    if options.deny:
653
650
        commands.append(DenyCmd())
654
651
 
 
652
    if options.remove:
 
653
        commands.append(RemoveCmd())
 
654
 
655
655
    # If no command option has been given, show table of clients,
656
656
    # optionally verbosely
657
657
    if not commands:
1355
1355
    def test_is_enabled_short(self):
1356
1356
        self.assert_command_from_args(["-V", "foo"], IsEnabledCmd)
1357
1357
 
 
1358
    def test_deny_before_remove(self):
 
1359
        options = self.parser.parse_args(["--deny", "--remove", "foo"])
 
1360
        check_option_syntax(self.parser, options)
 
1361
        commands = commands_from_options(options)
 
1362
        self.assertEqual(len(commands), 2)
 
1363
        self.assertIsInstance(commands[0], DenyCmd)
 
1364
        self.assertIsInstance(commands[1], RemoveCmd)
 
1365
 
 
1366
    def test_deny_before_remove_reversed(self):
 
1367
        options = self.parser.parse_args(["--remove", "--deny", "--all"])
 
1368
        check_option_syntax(self.parser, options)
 
1369
        commands = commands_from_options(options)
 
1370
        self.assertEqual(len(commands), 2)
 
1371
        self.assertIsInstance(commands[0], DenyCmd)
 
1372
        self.assertIsInstance(commands[1], RemoveCmd)
 
1373
 
1358
1374
 
1359
1375
class Test_check_option_syntax(unittest.TestCase):
1360
1376
    # This mostly corresponds to the definition from has_actions() in