611
613
"Checker", "ExtendedTimeout", "Expires",
612
614
"LastCheckerStatus")
616
def run(self, clients, bus=None, mandos=None):
617
print(self.output(clients.values()))
619
def output(self, clients):
620
raise NotImplementedError()
615
623
class DumpJSON(Output):
616
def run(self, clients, bus=None, mandos=None):
624
def output(self, clients):
617
625
data = {client["Name"]:
618
626
{key: self.dbus_boolean_to_bool(client[key])
619
627
for key in self.all_keywords}
620
for client in clients.values()}
621
print(json.dumps(data, indent=4, separators=(',', ': ')))
628
for client in clients}
629
return json.dumps(data, indent=4, separators=(',', ': '))
624
632
def dbus_boolean_to_bool(value):
745
753
raise NotImplementedError()
748
class Enable(PropertySetter):
756
class Enable(Property):
749
757
propname = "Enabled"
750
758
value_to_set = dbus.Boolean(True)
753
class Disable(PropertySetter):
761
class Disable(Property):
754
762
propname = "Enabled"
755
763
value_to_set = dbus.Boolean(False)
758
class BumpTimeout(PropertySetter):
766
class BumpTimeout(Property):
759
767
propname = "LastCheckedOK"
760
768
value_to_set = ""
763
class StartChecker(PropertySetter):
764
propname = "CheckerRunning"
765
value_to_set = dbus.Boolean(True)
768
class StopChecker(PropertySetter):
769
propname = "CheckerRunning"
770
value_to_set = dbus.Boolean(False)
773
class ApproveByDefault(PropertySetter):
774
propname = "ApprovedByDefault"
775
value_to_set = dbus.Boolean(True)
778
class DenyByDefault(PropertySetter):
779
propname = "ApprovedByDefault"
780
value_to_set = dbus.Boolean(False)
783
class PropertySetterValue(PropertySetter):
784
"""Abstract class for PropertySetter recieving a value as
785
constructor argument instead of a class attribute."""
771
class StartChecker(Property):
772
propname = "CheckerRunning"
773
value_to_set = dbus.Boolean(True)
776
class StopChecker(Property):
777
propname = "CheckerRunning"
778
value_to_set = dbus.Boolean(False)
781
class ApproveByDefault(Property):
782
propname = "ApprovedByDefault"
783
value_to_set = dbus.Boolean(True)
786
class DenyByDefault(Property):
787
propname = "ApprovedByDefault"
788
value_to_set = dbus.Boolean(False)
791
class PropertyValue(Property):
792
"Abstract class for Property recieving a value as argument"
786
793
def __init__(self, value):
787
794
self.value_to_set = value
790
class SetChecker(PropertySetterValue):
797
class SetChecker(PropertyValue):
791
798
propname = "Checker"
794
class SetHost(PropertySetterValue):
801
class SetHost(PropertyValue):
795
802
propname = "Host"
798
class SetSecret(PropertySetterValue):
805
class SetSecret(PropertyValue):
799
806
propname = "Secret"
882
888
class Test_string_to_delta(TestCaseWithAssertLogs):
883
# Just test basic RFC 3339 functionality here, the doc string for
884
# rfc3339_duration_to_delta() already has more comprehensive
885
# tests, which is run by doctest.
887
def test_rfc3339_zero_seconds(self):
888
self.assertEqual(datetime.timedelta(),
889
string_to_delta("PT0S"))
891
def test_rfc3339_zero_days(self):
892
self.assertEqual(datetime.timedelta(), string_to_delta("P0D"))
894
def test_rfc3339_one_second(self):
895
self.assertEqual(datetime.timedelta(0, 1),
896
string_to_delta("PT1S"))
898
def test_rfc3339_two_hours(self):
899
self.assertEqual(datetime.timedelta(0, 7200),
900
string_to_delta("PT2H"))
889
def test_handles_basic_rfc3339(self):
890
self.assertEqual(string_to_delta("PT0S"),
891
datetime.timedelta())
892
self.assertEqual(string_to_delta("P0D"),
893
datetime.timedelta())
894
self.assertEqual(string_to_delta("PT1S"),
895
datetime.timedelta(0, 1))
896
self.assertEqual(string_to_delta("PT2H"),
897
datetime.timedelta(0, 7200))
902
899
def test_falls_back_to_pre_1_6_1_with_warning(self):
903
900
with self.assertLogs(log, logging.WARNING):
904
901
value = string_to_delta("2h")
905
self.assertEqual(datetime.timedelta(0, 7200), value)
902
self.assertEqual(value, datetime.timedelta(0, 7200))
908
905
class Test_check_option_syntax(unittest.TestCase):
951
948
# Exit code from argparse is guaranteed to be "2". Reference:
952
949
# https://docs.python.org/3/library
953
950
# /argparse.html#exiting-methods
954
self.assertEqual(2, e.exception.code)
951
self.assertEqual(e.exception.code, 2)
957
954
@contextlib.contextmanager
958
955
def redirect_stderr_to_devnull():
959
old_stderr = sys.stderr
960
with contextlib.closing(open(os.devnull, "w")) as null:
965
sys.stderr = old_stderr
956
null = os.open(os.path.devnull, os.O_RDWR)
957
stderrcopy = os.dup(sys.stderr.fileno())
958
os.dup2(null, sys.stderr.fileno())
964
os.dup2(stderrcopy, sys.stderr.fileno())
967
967
def check_option_syntax(self, options):
968
968
check_option_syntax(self.parser, options)
1089
1089
self.assertTrue(mockbus.called)
1091
1091
def test_logs_and_exits_on_dbus_error(self):
1092
class FailingBusStub(object):
1092
class MockBusFailing(object):
1093
1093
def get_object(self, busname, dbus_path):
1094
1094
raise dbus.exceptions.DBusException("Test")
1096
1096
with self.assertLogs(log, logging.CRITICAL):
1097
1097
with self.assertRaises(SystemExit) as e:
1098
bus = get_mandos_dbus_object(bus=FailingBusStub())
1098
bus = get_mandos_dbus_object(bus=MockBusFailing())
1100
1100
if isinstance(e.exception.code, int):
1101
self.assertNotEqual(0, e.exception.code)
1101
self.assertNotEqual(e.exception.code, 0)
1103
1103
self.assertIsNotNone(e.exception.code)
1106
1106
class Test_get_managed_objects(TestCaseWithAssertLogs):
1107
1107
def test_calls_and_returns_GetManagedObjects(self):
1108
managed_objects = {"/clients/client": { "Name": "client"}}
1109
class ObjectManagerStub(object):
1108
managed_objects = {"/clients/foo": { "Name": "foo"}}
1109
class MockObjectManager(object):
1110
1110
def GetManagedObjects(self):
1111
1111
return managed_objects
1112
retval = get_managed_objects(ObjectManagerStub())
1112
retval = get_managed_objects(MockObjectManager())
1113
1113
self.assertDictEqual(managed_objects, retval)
1115
1115
def test_logs_and_exits_on_dbus_error(self):
1116
1116
dbus_logger = logging.getLogger("dbus.proxies")
1118
class ObjectManagerFailingStub(object):
1118
class MockObjectManagerFailing(object):
1119
1119
def GetManagedObjects(self):
1120
1120
dbus_logger.error("Test")
1121
1121
raise dbus.exceptions.DBusException("Test")
1133
1133
with self.assertLogs(log, logging.CRITICAL) as watcher:
1134
1134
with self.assertRaises(SystemExit) as e:
1135
get_managed_objects(ObjectManagerFailingStub())
1135
get_managed_objects(MockObjectManagerFailing())
1137
1137
dbus_logger.removeFilter(counting_handler)
1139
1139
# Make sure the dbus logger was suppressed
1140
self.assertEqual(0, counting_handler.count)
1140
self.assertEqual(counting_handler.count, 0)
1142
1142
# Test that the dbus_logger still works
1143
1143
with self.assertLogs(dbus_logger, logging.ERROR):
1144
1144
dbus_logger.error("Test")
1146
1146
if isinstance(e.exception.code, int):
1147
self.assertNotEqual(0, e.exception.code)
1147
self.assertNotEqual(e.exception.code, 0)
1149
1149
self.assertIsNotNone(e.exception.code)
1165
1165
options = self.parser.parse_args(args)
1166
1166
check_option_syntax(self.parser, options)
1167
1167
commands = commands_from_options(options)
1168
self.assertEqual(1, len(commands))
1168
self.assertEqual(len(commands), 1)
1169
1169
command = commands[0]
1170
1170
self.assertIsInstance(command, command_cls)
1171
1171
for key, value in cmd_attrs.items():
1172
self.assertEqual(value, getattr(command, key))
1172
self.assertEqual(getattr(command, key), value)
1174
1174
def test_is_enabled_short(self):
1175
self.assert_command_from_args(["-V", "client"],
1175
self.assert_command_from_args(["-V", "foo"],
1176
1176
command.IsEnabled)
1178
1178
def test_approve(self):
1179
self.assert_command_from_args(["--approve", "client"],
1179
self.assert_command_from_args(["--approve", "foo"],
1180
1180
command.Approve)
1182
1182
def test_approve_short(self):
1183
self.assert_command_from_args(["-A", "client"],
1183
self.assert_command_from_args(["-A", "foo"], command.Approve)
1186
1185
def test_deny(self):
1187
self.assert_command_from_args(["--deny", "client"],
1186
self.assert_command_from_args(["--deny", "foo"], command.Deny)
1190
1188
def test_deny_short(self):
1191
self.assert_command_from_args(["-D", "client"], command.Deny)
1189
self.assert_command_from_args(["-D", "foo"], command.Deny)
1193
1191
def test_remove(self):
1194
self.assert_command_from_args(["--remove", "client"],
1192
self.assert_command_from_args(["--remove", "foo"],
1195
1193
command.Remove)
1197
1195
def test_deny_before_remove(self):
1198
1196
options = self.parser.parse_args(["--deny", "--remove",
1200
1198
check_option_syntax(self.parser, options)
1201
1199
commands = commands_from_options(options)
1202
self.assertEqual(2, len(commands))
1200
self.assertEqual(len(commands), 2)
1203
1201
self.assertIsInstance(commands[0], command.Deny)
1204
1202
self.assertIsInstance(commands[1], command.Remove)
1209
1207
check_option_syntax(self.parser, options)
1210
1208
commands = commands_from_options(options)
1211
self.assertEqual(2, len(commands))
1209
self.assertEqual(len(commands), 2)
1212
1210
self.assertIsInstance(commands[0], command.Deny)
1213
1211
self.assertIsInstance(commands[1], command.Remove)
1215
1213
def test_remove_short(self):
1216
self.assert_command_from_args(["-r", "client"],
1214
self.assert_command_from_args(["-r", "foo"], command.Remove)
1219
1216
def test_dump_json(self):
1220
1217
self.assert_command_from_args(["--dump-json"],
1221
1218
command.DumpJSON)
1223
1220
def test_enable(self):
1224
self.assert_command_from_args(["--enable", "client"],
1221
self.assert_command_from_args(["--enable", "foo"],
1225
1222
command.Enable)
1227
1224
def test_enable_short(self):
1228
self.assert_command_from_args(["-e", "client"],
1225
self.assert_command_from_args(["-e", "foo"], command.Enable)
1231
1227
def test_disable(self):
1232
self.assert_command_from_args(["--disable", "client"],
1228
self.assert_command_from_args(["--disable", "foo"],
1233
1229
command.Disable)
1235
1231
def test_disable_short(self):
1236
self.assert_command_from_args(["-d", "client"],
1232
self.assert_command_from_args(["-d", "foo"], command.Disable)
1239
1234
def test_bump_timeout(self):
1240
self.assert_command_from_args(["--bump-timeout", "client"],
1235
self.assert_command_from_args(["--bump-timeout", "foo"],
1241
1236
command.BumpTimeout)
1243
1238
def test_bump_timeout_short(self):
1244
self.assert_command_from_args(["-b", "client"],
1239
self.assert_command_from_args(["-b", "foo"],
1245
1240
command.BumpTimeout)
1247
1242
def test_start_checker(self):
1248
self.assert_command_from_args(["--start-checker", "client"],
1243
self.assert_command_from_args(["--start-checker", "foo"],
1249
1244
command.StartChecker)
1251
1246
def test_stop_checker(self):
1252
self.assert_command_from_args(["--stop-checker", "client"],
1247
self.assert_command_from_args(["--stop-checker", "foo"],
1253
1248
command.StopChecker)
1255
1250
def test_approve_by_default(self):
1256
self.assert_command_from_args(["--approve-by-default",
1251
self.assert_command_from_args(["--approve-by-default", "foo"],
1258
1252
command.ApproveByDefault)
1260
1254
def test_deny_by_default(self):
1261
self.assert_command_from_args(["--deny-by-default", "client"],
1255
self.assert_command_from_args(["--deny-by-default", "foo"],
1262
1256
command.DenyByDefault)
1264
1258
def test_checker(self):
1265
self.assert_command_from_args(["--checker", ":", "client"],
1259
self.assert_command_from_args(["--checker", ":", "foo"],
1266
1260
command.SetChecker,
1267
1261
value_to_set=":")
1269
1263
def test_checker_empty(self):
1270
self.assert_command_from_args(["--checker", "", "client"],
1264
self.assert_command_from_args(["--checker", "", "foo"],
1271
1265
command.SetChecker,
1272
1266
value_to_set="")
1274
1268
def test_checker_short(self):
1275
self.assert_command_from_args(["-c", ":", "client"],
1269
self.assert_command_from_args(["-c", ":", "foo"],
1276
1270
command.SetChecker,
1277
1271
value_to_set=":")
1279
1273
def test_host(self):
1280
self.assert_command_from_args(
1281
["--host", "client.example.org", "client"],
1282
command.SetHost, value_to_set="client.example.org")
1274
self.assert_command_from_args(["--host", "foo.example.org",
1275
"foo"], command.SetHost,
1276
value_to_set="foo.example.org")
1284
1278
def test_host_short(self):
1285
self.assert_command_from_args(
1286
["-H", "client.example.org", "client"], command.SetHost,
1287
value_to_set="client.example.org")
1279
self.assert_command_from_args(["-H", "foo.example.org",
1280
"foo"], command.SetHost,
1281
value_to_set="foo.example.org")
1289
1283
def test_secret_devnull(self):
1290
1284
self.assert_command_from_args(["--secret", os.path.devnull,
1291
"client"], command.SetSecret,
1285
"foo"], command.SetSecret,
1292
1286
value_to_set=b"")
1294
1288
def test_secret_tempfile(self):
1311
1304
value = b"secret\0xyzzy\nbar"
1314
self.assert_command_from_args(["-s", f.name, "client"],
1307
self.assert_command_from_args(["-s", f.name, "foo"],
1315
1308
command.SetSecret,
1316
1309
value_to_set=value)
1318
1311
def test_timeout(self):
1319
self.assert_command_from_args(["--timeout", "PT5M", "client"],
1312
self.assert_command_from_args(["--timeout", "PT5M", "foo"],
1320
1313
command.SetTimeout,
1321
1314
value_to_set=300000)
1323
1316
def test_timeout_short(self):
1324
self.assert_command_from_args(["-t", "PT5M", "client"],
1317
self.assert_command_from_args(["-t", "PT5M", "foo"],
1325
1318
command.SetTimeout,
1326
1319
value_to_set=300000)
1328
1321
def test_extended_timeout(self):
1329
1322
self.assert_command_from_args(["--extended-timeout", "PT15M",
1331
1324
command.SetExtendedTimeout,
1332
1325
value_to_set=900000)
1334
1327
def test_interval(self):
1335
self.assert_command_from_args(["--interval", "PT2M",
1336
"client"], command.SetInterval,
1328
self.assert_command_from_args(["--interval", "PT2M", "foo"],
1329
command.SetInterval,
1337
1330
value_to_set=120000)
1339
1332
def test_interval_short(self):
1340
self.assert_command_from_args(["-i", "PT2M", "client"],
1333
self.assert_command_from_args(["-i", "PT2M", "foo"],
1341
1334
command.SetInterval,
1342
1335
value_to_set=120000)
1344
1337
def test_approval_delay(self):
1345
1338
self.assert_command_from_args(["--approval-delay", "PT30S",
1347
1340
command.SetApprovalDelay,
1348
1341
value_to_set=30000)
1350
1343
def test_approval_duration(self):
1351
1344
self.assert_command_from_args(["--approval-duration", "PT1S",
1353
1346
command.SetApprovalDuration,
1354
1347
value_to_set=1000)
1379
1372
self.attributes["Name"] = name
1380
1373
self.calls = []
1381
1374
def Set(self, interface, propname, value, dbus_interface):
1382
testcase.assertEqual(client_dbus_interface, interface)
1383
testcase.assertEqual(dbus.PROPERTIES_IFACE,
1375
testcase.assertEqual(interface, client_dbus_interface)
1376
testcase.assertEqual(dbus_interface,
1377
dbus.PROPERTIES_IFACE)
1385
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]
1386
1384
def Approve(self, approve, dbus_interface):
1387
testcase.assertEqual(client_dbus_interface,
1385
testcase.assertEqual(dbus_interface,
1386
client_dbus_interface)
1389
1387
self.calls.append(("Approve", (approve,
1390
1388
dbus_interface)))
1391
1389
self.client = MockClient(
1438
1436
LastCheckerStatus=-2)
1439
1437
self.clients = collections.OrderedDict(
1441
(self.client.__dbus_object_path__,
1442
self.client.attributes),
1443
(self.other_client.__dbus_object_path__,
1444
self.other_client.attributes),
1439
("/clients/foo", self.client.attributes),
1440
("/clients/barbar", self.other_client.attributes),
1446
self.one_client = {self.client.__dbus_object_path__:
1447
self.client.attributes}
1442
self.one_client = {"/clients/foo": self.client.attributes}
1451
class MockBus(object):
1453
1448
def get_object(client_bus_name, path):
1454
self.assertEqual(dbus_busname, client_bus_name)
1455
# Note: "self" here is the TestCmd instance, not the
1456
# MockBus instance, since this is a static method!
1457
if path == self.client.__dbus_object_path__:
1459
elif path == self.other_client.__dbus_object_path__:
1460
return self.other_client
1449
self.assertEqual(client_bus_name, dbus_busname)
1451
# Note: "self" here is the TestCmd instance, not
1452
# the Bus instance, since this is a static method!
1453
"/clients/foo": self.client,
1454
"/clients/barbar": self.other_client,
1464
1459
class TestBaseCommands(TestCommand):
1466
def test_IsEnabled_exits_successfully(self):
1461
def test_is_enabled(self):
1462
self.assertTrue(all(command.IsEnabled().is_enabled(client,
1464
for client, properties
1465
in self.clients.items()))
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:
1470
self.assertEqual(0, e.exception.code)
1471
self.assertEqual(e.exception.code, 0)
1472
1473
self.assertIsNone(e.exception.code)
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)
1478
1479
if isinstance(e.exception.code, int):
1479
self.assertNotEqual(0, e.exception.code)
1480
self.assertNotEqual(e.exception.code, 0)
1481
1482
self.assertIsNotNone(e.exception.code)
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)),
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)),
1497
def test_Remove(self):
1498
class MandosSpy(object):
1498
def test_remove(self):
1499
class MockMandos(object):
1499
1500
def __init__(self):
1500
1501
self.calls = []
1501
1502
def RemoveClient(self, dbus_path):
1502
1503
self.calls.append(("RemoveClient", (dbus_path,)))
1503
mandos = MandosSpy()
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,)),
1560
1562
def test_DumpJSON_normal(self):
1561
with self.capture_stdout_to_buffer() as buffer:
1562
command.DumpJSON().run(self.clients)
1563
json_data = json.loads(buffer.getvalue())
1564
self.assertDictEqual(self.expected_json, json_data)
1567
@contextlib.contextmanager
1568
def capture_stdout_to_buffer():
1569
capture_buffer = io.StringIO()
1570
old_stdout = sys.stdout
1571
sys.stdout = capture_buffer
1573
yield capture_buffer
1575
sys.stdout = old_stdout
1563
output = command.DumpJSON().output(self.clients.values())
1564
json_data = json.loads(output)
1565
self.assertDictEqual(json_data, self.expected_json)
1577
1567
def test_DumpJSON_one_client(self):
1578
with self.capture_stdout_to_buffer() as buffer:
1579
command.DumpJSON().run(self.one_client)
1580
json_data = json.loads(buffer.getvalue())
1568
output = command.DumpJSON().output(self.one_client.values())
1569
json_data = json.loads(output)
1581
1570
expected_json = {"foo": self.expected_json["foo"]}
1582
self.assertDictEqual(expected_json, json_data)
1571
self.assertDictEqual(json_data, expected_json)
1584
1573
def test_PrintTable_normal(self):
1585
with self.capture_stdout_to_buffer() as buffer:
1586
command.PrintTable().run(self.clients)
1574
output = command.PrintTable().output(self.clients.values())
1587
1575
expected_output = "\n".join((
1588
1576
"Name Enabled Timeout Last Successful Check",
1589
1577
"foo Yes 00:05:00 2019-02-03T00:00:00 ",
1590
1578
"barbar Yes 00:05:00 2019-02-04T00:00:00 ",
1592
self.assertEqual(expected_output, buffer.getvalue())
1580
self.assertEqual(output, expected_output)
1594
1582
def test_PrintTable_verbose(self):
1595
with self.capture_stdout_to_buffer() as buffer:
1596
command.PrintTable(verbose=True).run(self.clients)
1583
output = command.PrintTable(verbose=True).output(
1584
self.clients.values())
1683
1671
num_lines = max(len(rows) for rows in columns)
1684
expected_output = ("\n".join("".join(rows[line]
1685
for rows in columns)
1686
for line in range(num_lines))
1688
self.assertEqual(expected_output, buffer.getvalue())
1672
expected_output = "\n".join("".join(rows[line]
1673
for rows in columns)
1674
for line in range(num_lines))
1675
self.assertEqual(output, expected_output)
1690
1677
def test_PrintTable_one_client(self):
1691
with self.capture_stdout_to_buffer() as buffer:
1692
command.PrintTable().run(self.one_client)
1678
output = command.PrintTable().output(self.one_client.values())
1693
1679
expected_output = "\n".join((
1694
1680
"Name Enabled Timeout Last Successful Check",
1695
1681
"foo Yes 00:05:00 2019-02-03T00:00:00 ",
1697
self.assertEqual(expected_output, buffer.getvalue())
1700
class TestPropertySetterCmd(TestCommand):
1701
"""Abstract class for tests of command.PropertySetter classes"""
1683
self.assertEqual(output, expected_output)
1686
class TestPropertyCmd(TestCommand):
1687
"""Abstract class for tests of command.Property classes"""
1702
1688
def runTest(self):
1703
1689
if not hasattr(self, "command"):
1725
1712
self.command().run(clients, self.bus)
1728
class TestEnableCmd(TestPropertySetterCmd):
1715
class TestEnableCmd(TestPropertyCmd):
1729
1716
command = command.Enable
1730
1717
propname = "Enabled"
1731
1718
values_to_set = [dbus.Boolean(True)]
1734
class TestDisableCmd(TestPropertySetterCmd):
1721
class TestDisableCmd(TestPropertyCmd):
1735
1722
command = command.Disable
1736
1723
propname = "Enabled"
1737
1724
values_to_set = [dbus.Boolean(False)]
1740
class TestBumpTimeoutCmd(TestPropertySetterCmd):
1727
class TestBumpTimeoutCmd(TestPropertyCmd):
1741
1728
command = command.BumpTimeout
1742
1729
propname = "LastCheckedOK"
1743
1730
values_to_set = [""]
1746
class TestStartCheckerCmd(TestPropertySetterCmd):
1733
class TestStartCheckerCmd(TestPropertyCmd):
1747
1734
command = command.StartChecker
1748
1735
propname = "CheckerRunning"
1749
1736
values_to_set = [dbus.Boolean(True)]
1752
class TestStopCheckerCmd(TestPropertySetterCmd):
1739
class TestStopCheckerCmd(TestPropertyCmd):
1753
1740
command = command.StopChecker
1754
1741
propname = "CheckerRunning"
1755
1742
values_to_set = [dbus.Boolean(False)]
1758
class TestApproveByDefaultCmd(TestPropertySetterCmd):
1745
class TestApproveByDefaultCmd(TestPropertyCmd):
1759
1746
command = command.ApproveByDefault
1760
1747
propname = "ApprovedByDefault"
1761
1748
values_to_set = [dbus.Boolean(True)]
1764
class TestDenyByDefaultCmd(TestPropertySetterCmd):
1751
class TestDenyByDefaultCmd(TestPropertyCmd):
1765
1752
command = command.DenyByDefault
1766
1753
propname = "ApprovedByDefault"
1767
1754
values_to_set = [dbus.Boolean(False)]
1770
class TestPropertySetterValueCmd(TestPropertySetterCmd):
1771
"""Abstract class for tests of PropertySetterValueCmd classes"""
1757
class TestPropertyValueCmd(TestPropertyCmd):
1758
"""Abstract class for tests of PropertyValueCmd classes"""
1773
1760
def runTest(self):
1774
if type(self) is TestPropertySetterValueCmd:
1761
if type(self) is TestPropertyValueCmd:
1776
return super(TestPropertySetterValueCmd, self).runTest()
1763
return super(TestPropertyValueCmd, self).runTest()
1778
1765
def run_command(self, value, clients):
1779
1766
self.command(value).run(clients, self.bus)
1782
class TestSetCheckerCmd(TestPropertySetterValueCmd):
1769
class TestSetCheckerCmd(TestPropertyValueCmd):
1783
1770
command = command.SetChecker
1784
1771
propname = "Checker"
1785
1772
values_to_set = ["", ":", "fping -q -- %s"]
1788
class TestSetHostCmd(TestPropertySetterValueCmd):
1775
class TestSetHostCmd(TestPropertyValueCmd):
1789
1776
command = command.SetHost
1790
1777
propname = "Host"
1791
values_to_set = ["192.0.2.3", "client.example.org"]
1794
class TestSetSecretCmd(TestPropertySetterValueCmd):
1778
values_to_set = ["192.0.2.3", "foo.example.org"]
1781
class TestSetSecretCmd(TestPropertyValueCmd):
1795
1782
command = command.SetSecret
1796
1783
propname = "Secret"
1797
1784
values_to_set = [io.BytesIO(b""),
1798
1785
io.BytesIO(b"secret\0xyzzy\nbar")]
1799
values_to_get = [f.getvalue() for f in values_to_set]
1802
class TestSetTimeoutCmd(TestPropertySetterValueCmd):
1786
values_to_get = [b"", b"secret\0xyzzy\nbar"]
1789
class TestSetTimeoutCmd(TestPropertyValueCmd):
1803
1790
command = command.SetTimeout
1804
1791
propname = "Timeout"
1805
1792
values_to_set = [datetime.timedelta(),