/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-17 11:10:21 UTC
  • Revision ID: teddy@recompile.se-20190317111021-chyektrlb42h6l0j
mandos-ctl: Refactor

* mandos-ctl (TestBaseCommands.test_remove): Remove superfluous
                                             super() call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
886
886
 
887
887
 
888
888
class Test_string_to_delta(TestCaseWithAssertLogs):
889
 
    # Just test basic RFC 3339 functionality here, the doc string for
890
 
    # rfc3339_duration_to_delta() already has more comprehensive
891
 
    # tests, which is run by doctest.
892
 
 
893
 
    def test_rfc3339_zero_seconds(self):
 
889
    def test_handles_basic_rfc3339(self):
894
890
        self.assertEqual(string_to_delta("PT0S"),
895
891
                         datetime.timedelta())
896
 
 
897
 
    def test_rfc3339_zero_days(self):
898
892
        self.assertEqual(string_to_delta("P0D"),
899
893
                         datetime.timedelta())
900
 
 
901
 
    def test_rfc3339_one_second(self):
902
894
        self.assertEqual(string_to_delta("PT1S"),
903
895
                         datetime.timedelta(0, 1))
904
 
 
905
 
    def test_rfc3339_two_hours(self):
906
896
        self.assertEqual(string_to_delta("PT2H"),
907
897
                         datetime.timedelta(0, 7200))
908
898
 
1386
1376
                testcase.assertEqual(dbus_interface,
1387
1377
                                     dbus.PROPERTIES_IFACE)
1388
1378
                self.attributes[propname] = value
 
1379
            def Get(self, interface, propname, dbus_interface):
 
1380
                testcase.assertEqual(interface, client_dbus_interface)
 
1381
                testcase.assertEqual(dbus_interface,
 
1382
                                     dbus.PROPERTIES_IFACE)
 
1383
                return self.attributes[propname]
1389
1384
            def Approve(self, approve, dbus_interface):
1390
1385
                testcase.assertEqual(dbus_interface,
1391
1386
                                     client_dbus_interface)
1463
1458
 
1464
1459
class TestBaseCommands(TestCommand):
1465
1460
 
1466
 
    def test_IsEnabled_exits_successfully(self):
 
1461
    def test_is_enabled(self):
 
1462
        self.assertTrue(all(command.IsEnabled().is_enabled(client,
 
1463
                                                      properties)
 
1464
                            for client, properties
 
1465
                            in self.clients.items()))
 
1466
 
 
1467
    def test_is_enabled_run_exits_successfully(self):
1467
1468
        with self.assertRaises(SystemExit) as e:
1468
1469
            command.IsEnabled().run(self.one_client)
1469
1470
        if e.exception.code is not None:
1471
1472
        else:
1472
1473
            self.assertIsNone(e.exception.code)
1473
1474
 
1474
 
    def test_IsEnabled_exits_with_failure(self):
 
1475
    def test_is_enabled_run_exits_with_failure(self):
1475
1476
        self.client.attributes["Enabled"] = dbus.Boolean(False)
1476
1477
        with self.assertRaises(SystemExit) as e:
1477
1478
            command.IsEnabled().run(self.one_client)
1480
1481
        else:
1481
1482
            self.assertIsNotNone(e.exception.code)
1482
1483
 
1483
 
    def test_Approve(self):
 
1484
    def test_approve(self):
1484
1485
        command.Approve().run(self.clients, self.bus)
1485
1486
        for clientpath in self.clients:
1486
1487
            client = self.bus.get_object(dbus_busname, clientpath)
1487
1488
            self.assertIn(("Approve", (True, client_dbus_interface)),
1488
1489
                          client.calls)
1489
1490
 
1490
 
    def test_Deny(self):
 
1491
    def test_deny(self):
1491
1492
        command.Deny().run(self.clients, self.bus)
1492
1493
        for clientpath in self.clients:
1493
1494
            client = self.bus.get_object(dbus_busname, clientpath)
1494
1495
            self.assertIn(("Approve", (False, client_dbus_interface)),
1495
1496
                          client.calls)
1496
1497
 
1497
 
    def test_Remove(self):
 
1498
    def test_remove(self):
1498
1499
        class MockMandos(object):
1499
1500
            def __init__(self):
1500
1501
                self.calls = []
1502
1503
                self.calls.append(("RemoveClient", (dbus_path,)))
1503
1504
        mandos = MockMandos()
1504
1505
        command.Remove().run(self.clients, self.bus, mandos)
 
1506
        self.assertEqual(len(mandos.calls), 2)
1505
1507
        for clientpath in self.clients:
1506
1508
            self.assertIn(("RemoveClient", (clientpath,)),
1507
1509
                          mandos.calls)
1693
1695
            for clientpath in self.clients:
1694
1696
                client = self.bus.get_object(dbus_busname, clientpath)
1695
1697
                old_value = client.attributes[self.propname]
 
1698
                self.assertNotIsInstance(old_value, self.Unique)
1696
1699
                client.attributes[self.propname] = self.Unique()
1697
1700
            self.run_command(value_to_set, self.clients)
1698
1701
            for clientpath in self.clients: