/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-13 21:34:27 UTC
  • mto: This revision was merged to the branch mainline in revision 382.
  • Revision ID: teddy@recompile.se-20190313213427-qquhadrtu7i24erp
mandos-ctl: White space changes only

* mandos-ctl: Add empty lines where appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
577
577
                    "LastApprovalRequest", "ApprovalDelay",
578
578
                    "ApprovalDuration", "Checker", "ExtendedTimeout",
579
579
                    "Expires", "LastCheckerStatus")
 
580
 
580
581
    def run(self, clients, bus=None, mandos=None):
581
582
        print(self.output(clients.values()))
 
583
 
582
584
    def output(self, clients):
583
585
        raise NotImplementedError()
584
586
 
590
592
                 for key in self.all_keywords}
591
593
                for client in clients.values()}
592
594
        return json.dumps(data, indent=4, separators=(',', ': '))
 
595
 
593
596
    @staticmethod
594
597
    def dbus_boolean_to_bool(value):
595
598
        if isinstance(value, dbus.Boolean):
696
699
 
697
700
class PropertyCmd(Command):
698
701
    """Abstract class for Actions for setting one client property"""
 
702
 
699
703
    def run_on_one_client(self, client, properties):
700
704
        """Set the Client's D-Bus property"""
701
705
        log.debug("D-Bus: %s:%s:%s.Set(%r, %r, %r)", dbus_busname,
707
711
        client.Set(client_dbus_interface, self.propname,
708
712
                   self.value_to_set,
709
713
                   dbus_interface=dbus.PROPERTIES_IFACE)
 
714
 
710
715
    @property
711
716
    def propname(self):
712
717
        raise NotImplementedError()
763
768
 
764
769
class SetSecretCmd(PropertyValueCmd):
765
770
    propname = "Secret"
 
771
 
766
772
    @property
767
773
    def value_to_set(self):
768
774
        return self._vts
 
775
 
769
776
    @value_to_set.setter
770
777
    def value_to_set(self, value):
771
778
        """When setting, read data from supplied file object"""
776
783
class MillisecondsPropertyValueArgumentCmd(PropertyValueCmd):
777
784
    """Abstract class for PropertyValueCmd taking a value argument as
778
785
a datetime.timedelta() but should store it as milliseconds."""
 
786
 
779
787
    @property
780
788
    def value_to_set(self):
781
789
        return self._vts
 
790
 
782
791
    @value_to_set.setter
783
792
    def value_to_set(self, value):
784
793
        """When setting, convert value from a datetime.timedelta"""
816
825
                         datetime.timedelta(0, 1))
817
826
        self.assertEqual(string_to_delta("PT2H"),
818
827
                         datetime.timedelta(0, 7200))
 
828
 
819
829
    def test_falls_back_to_pre_1_6_1_with_warning(self):
820
830
        # assertLogs only exists in Python 3.4
821
831
        if hasattr(self, "assertLogs"):
1173
1183
 
1174
1184
class TestCmd(unittest.TestCase):
1175
1185
    """Abstract class for tests of command classes"""
 
1186
 
1176
1187
    def setUp(self):
1177
1188
        testcase = self
1178
1189
        class MockClient(object):
1250
1261
                ("/clients/barbar", self.other_client.attributes),
1251
1262
            ])
1252
1263
        self.one_client = {"/clients/foo": self.client.attributes}
 
1264
 
1253
1265
    @property
1254
1266
    def bus(self):
1255
1267
        class Bus(object):
1269
1281
                                                      properties)
1270
1282
                            for client, properties
1271
1283
                            in self.clients.items()))
 
1284
 
1272
1285
    def test_is_enabled_run_exits_successfully(self):
1273
1286
        with self.assertRaises(SystemExit) as e:
1274
1287
            IsEnabledCmd().run(self.one_client)
1276
1289
            self.assertEqual(e.exception.code, 0)
1277
1290
        else:
1278
1291
            self.assertIsNone(e.exception.code)
 
1292
 
1279
1293
    def test_is_enabled_run_exits_with_failure(self):
1280
1294
        self.client.attributes["Enabled"] = dbus.Boolean(False)
1281
1295
        with self.assertRaises(SystemExit) as e:
1303
1317
            self.assertIn(("Approve", (False, client_dbus_interface)),
1304
1318
                          client.calls)
1305
1319
 
 
1320
 
1306
1321
class TestRemoveCmd(TestCmd):
1307
1322
    def test_remove(self):
1308
1323
        class MockMandos(object):
1372
1387
            },
1373
1388
        }
1374
1389
        return super(TestDumpJSONCmd, self).setUp()
 
1390
 
1375
1391
    def test_normal(self):
1376
1392
        json_data = json.loads(DumpJSONCmd().output(self.clients))
1377
1393
        self.assertDictEqual(json_data, self.expected_json)
 
1394
 
1378
1395
    def test_one_client(self):
1379
1396
        clients = self.one_client
1380
1397
        json_data = json.loads(DumpJSONCmd().output(clients))
1391
1408
            "barbar Yes     00:05:00 2019-02-04T00:00:00  ",
1392
1409
        ))
1393
1410
        self.assertEqual(output, expected_output)
 
1411
 
1394
1412
    def test_verbose(self):
1395
1413
        output = PrintTableCmd(verbose=True).output(
1396
1414
            self.clients.values())
1485
1503
                                            for rows in columns)
1486
1504
                                    for line in range(num_lines))
1487
1505
        self.assertEqual(output, expected_output)
 
1506
 
1488
1507
    def test_one_client(self):
1489
1508
        output = PrintTableCmd().output(self.one_client.values())
1490
1509
        expected_output = "\n".join((
1567
1586
 
1568
1587
class TestPropertyValueCmd(TestPropertyCmd):
1569
1588
    """Abstract class for tests of PropertyValueCmd classes"""
 
1589
 
1570
1590
    def runTest(self):
1571
1591
        if type(self) is TestPropertyValueCmd:
1572
1592
            return
1573
1593
        return super(TestPropertyValueCmd, self).runTest()
 
1594
 
1574
1595
    def run_command(self, value, clients):
1575
1596
        self.command(value).run(clients, self.bus)
1576
1597