612
613
"Checker", "ExtendedTimeout", "Expires",
613
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()
616
623
class DumpJSON(Output):
617
def run(self, clients, bus=None, mandos=None):
624
def output(self, clients):
618
625
data = {client["Name"]:
619
626
{key: self.dbus_boolean_to_bool(client[key])
620
627
for key in self.all_keywords}
621
for client in clients.values()}
622
print(json.dumps(data, indent=4, separators=(',', ': ')))
628
for client in clients}
629
return json.dumps(data, indent=4, separators=(',', ': '))
625
632
def dbus_boolean_to_bool(value):
746
753
raise NotImplementedError()
749
class Enable(PropertySetter):
756
class Enable(Property):
750
757
propname = "Enabled"
751
758
value_to_set = dbus.Boolean(True)
754
class Disable(PropertySetter):
761
class Disable(Property):
755
762
propname = "Enabled"
756
763
value_to_set = dbus.Boolean(False)
759
class BumpTimeout(PropertySetter):
766
class BumpTimeout(Property):
760
767
propname = "LastCheckedOK"
761
768
value_to_set = ""
764
class StartChecker(PropertySetter):
765
propname = "CheckerRunning"
766
value_to_set = dbus.Boolean(True)
769
class StopChecker(PropertySetter):
770
propname = "CheckerRunning"
771
value_to_set = dbus.Boolean(False)
774
class ApproveByDefault(PropertySetter):
775
propname = "ApprovedByDefault"
776
value_to_set = dbus.Boolean(True)
779
class DenyByDefault(PropertySetter):
780
propname = "ApprovedByDefault"
781
value_to_set = dbus.Boolean(False)
784
class PropertySetterValue(PropertySetter):
785
"""Abstract class for PropertySetter recieving a value as
786
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"
787
793
def __init__(self, value):
788
794
self.value_to_set = value
791
class SetChecker(PropertySetterValue):
797
class SetChecker(PropertyValue):
792
798
propname = "Checker"
795
class SetHost(PropertySetterValue):
801
class SetHost(PropertyValue):
796
802
propname = "Host"
799
class SetSecret(PropertySetterValue):
805
class SetSecret(PropertyValue):
800
806
propname = "Secret"
886
891
# tests, which is run by doctest.
888
893
def test_rfc3339_zero_seconds(self):
889
self.assertEqual(datetime.timedelta(),
890
string_to_delta("PT0S"))
894
self.assertEqual(string_to_delta("PT0S"),
895
datetime.timedelta())
892
897
def test_rfc3339_zero_days(self):
893
self.assertEqual(datetime.timedelta(), string_to_delta("P0D"))
898
self.assertEqual(string_to_delta("P0D"),
899
datetime.timedelta())
895
901
def test_rfc3339_one_second(self):
896
self.assertEqual(datetime.timedelta(0, 1),
897
string_to_delta("PT1S"))
902
self.assertEqual(string_to_delta("PT1S"),
903
datetime.timedelta(0, 1))
899
905
def test_rfc3339_two_hours(self):
900
self.assertEqual(datetime.timedelta(0, 7200),
901
string_to_delta("PT2H"))
906
self.assertEqual(string_to_delta("PT2H"),
907
datetime.timedelta(0, 7200))
903
909
def test_falls_back_to_pre_1_6_1_with_warning(self):
904
910
with self.assertLogs(log, logging.WARNING):
905
911
value = string_to_delta("2h")
906
self.assertEqual(datetime.timedelta(0, 7200), value)
912
self.assertEqual(value, datetime.timedelta(0, 7200))
909
915
class Test_check_option_syntax(unittest.TestCase):
952
958
# Exit code from argparse is guaranteed to be "2". Reference:
953
959
# https://docs.python.org/3/library
954
960
# /argparse.html#exiting-methods
955
self.assertEqual(2, e.exception.code)
961
self.assertEqual(e.exception.code, 2)
958
964
@contextlib.contextmanager
959
965
def redirect_stderr_to_devnull():
960
old_stderr = sys.stderr
961
with contextlib.closing(open(os.devnull, "w")) as null:
966
sys.stderr = old_stderr
966
null = os.open(os.path.devnull, os.O_RDWR)
967
stderrcopy = os.dup(sys.stderr.fileno())
968
os.dup2(null, sys.stderr.fileno())
974
os.dup2(stderrcopy, sys.stderr.fileno())
968
977
def check_option_syntax(self, options):
969
978
check_option_syntax(self.parser, options)
1090
1099
self.assertTrue(mockbus.called)
1092
1101
def test_logs_and_exits_on_dbus_error(self):
1093
class FailingBusStub(object):
1102
class MockBusFailing(object):
1094
1103
def get_object(self, busname, dbus_path):
1095
1104
raise dbus.exceptions.DBusException("Test")
1097
1106
with self.assertLogs(log, logging.CRITICAL):
1098
1107
with self.assertRaises(SystemExit) as e:
1099
bus = get_mandos_dbus_object(bus=FailingBusStub())
1108
bus = get_mandos_dbus_object(bus=MockBusFailing())
1101
1110
if isinstance(e.exception.code, int):
1102
self.assertNotEqual(0, e.exception.code)
1111
self.assertNotEqual(e.exception.code, 0)
1104
1113
self.assertIsNotNone(e.exception.code)
1107
1116
class Test_get_managed_objects(TestCaseWithAssertLogs):
1108
1117
def test_calls_and_returns_GetManagedObjects(self):
1109
managed_objects = {"/clients/client": { "Name": "client"}}
1110
class ObjectManagerStub(object):
1118
managed_objects = {"/clients/foo": { "Name": "foo"}}
1119
class MockObjectManager(object):
1111
1120
def GetManagedObjects(self):
1112
1121
return managed_objects
1113
retval = get_managed_objects(ObjectManagerStub())
1122
retval = get_managed_objects(MockObjectManager())
1114
1123
self.assertDictEqual(managed_objects, retval)
1116
1125
def test_logs_and_exits_on_dbus_error(self):
1117
1126
dbus_logger = logging.getLogger("dbus.proxies")
1119
class ObjectManagerFailingStub(object):
1128
class MockObjectManagerFailing(object):
1120
1129
def GetManagedObjects(self):
1121
1130
dbus_logger.error("Test")
1122
1131
raise dbus.exceptions.DBusException("Test")
1134
1143
with self.assertLogs(log, logging.CRITICAL) as watcher:
1135
1144
with self.assertRaises(SystemExit) as e:
1136
get_managed_objects(ObjectManagerFailingStub())
1145
get_managed_objects(MockObjectManagerFailing())
1138
1147
dbus_logger.removeFilter(counting_handler)
1140
1149
# Make sure the dbus logger was suppressed
1141
self.assertEqual(0, counting_handler.count)
1150
self.assertEqual(counting_handler.count, 0)
1143
1152
# Test that the dbus_logger still works
1144
1153
with self.assertLogs(dbus_logger, logging.ERROR):
1145
1154
dbus_logger.error("Test")
1147
1156
if isinstance(e.exception.code, int):
1148
self.assertNotEqual(0, e.exception.code)
1157
self.assertNotEqual(e.exception.code, 0)
1150
1159
self.assertIsNotNone(e.exception.code)
1166
1175
options = self.parser.parse_args(args)
1167
1176
check_option_syntax(self.parser, options)
1168
1177
commands = commands_from_options(options)
1169
self.assertEqual(1, len(commands))
1178
self.assertEqual(len(commands), 1)
1170
1179
command = commands[0]
1171
1180
self.assertIsInstance(command, command_cls)
1172
1181
for key, value in cmd_attrs.items():
1173
self.assertEqual(value, getattr(command, key))
1182
self.assertEqual(getattr(command, key), value)
1175
1184
def test_is_enabled_short(self):
1176
self.assert_command_from_args(["-V", "client"],
1185
self.assert_command_from_args(["-V", "foo"],
1177
1186
command.IsEnabled)
1179
1188
def test_approve(self):
1180
self.assert_command_from_args(["--approve", "client"],
1189
self.assert_command_from_args(["--approve", "foo"],
1181
1190
command.Approve)
1183
1192
def test_approve_short(self):
1184
self.assert_command_from_args(["-A", "client"],
1193
self.assert_command_from_args(["-A", "foo"], command.Approve)
1187
1195
def test_deny(self):
1188
self.assert_command_from_args(["--deny", "client"],
1196
self.assert_command_from_args(["--deny", "foo"], command.Deny)
1191
1198
def test_deny_short(self):
1192
self.assert_command_from_args(["-D", "client"], command.Deny)
1199
self.assert_command_from_args(["-D", "foo"], command.Deny)
1194
1201
def test_remove(self):
1195
self.assert_command_from_args(["--remove", "client"],
1202
self.assert_command_from_args(["--remove", "foo"],
1196
1203
command.Remove)
1198
1205
def test_deny_before_remove(self):
1199
1206
options = self.parser.parse_args(["--deny", "--remove",
1201
1208
check_option_syntax(self.parser, options)
1202
1209
commands = commands_from_options(options)
1203
self.assertEqual(2, len(commands))
1210
self.assertEqual(len(commands), 2)
1204
1211
self.assertIsInstance(commands[0], command.Deny)
1205
1212
self.assertIsInstance(commands[1], command.Remove)
1210
1217
check_option_syntax(self.parser, options)
1211
1218
commands = commands_from_options(options)
1212
self.assertEqual(2, len(commands))
1219
self.assertEqual(len(commands), 2)
1213
1220
self.assertIsInstance(commands[0], command.Deny)
1214
1221
self.assertIsInstance(commands[1], command.Remove)
1216
1223
def test_remove_short(self):
1217
self.assert_command_from_args(["-r", "client"],
1224
self.assert_command_from_args(["-r", "foo"], command.Remove)
1220
1226
def test_dump_json(self):
1221
1227
self.assert_command_from_args(["--dump-json"],
1222
1228
command.DumpJSON)
1224
1230
def test_enable(self):
1225
self.assert_command_from_args(["--enable", "client"],
1231
self.assert_command_from_args(["--enable", "foo"],
1226
1232
command.Enable)
1228
1234
def test_enable_short(self):
1229
self.assert_command_from_args(["-e", "client"],
1235
self.assert_command_from_args(["-e", "foo"], command.Enable)
1232
1237
def test_disable(self):
1233
self.assert_command_from_args(["--disable", "client"],
1238
self.assert_command_from_args(["--disable", "foo"],
1234
1239
command.Disable)
1236
1241
def test_disable_short(self):
1237
self.assert_command_from_args(["-d", "client"],
1242
self.assert_command_from_args(["-d", "foo"], command.Disable)
1240
1244
def test_bump_timeout(self):
1241
self.assert_command_from_args(["--bump-timeout", "client"],
1245
self.assert_command_from_args(["--bump-timeout", "foo"],
1242
1246
command.BumpTimeout)
1244
1248
def test_bump_timeout_short(self):
1245
self.assert_command_from_args(["-b", "client"],
1249
self.assert_command_from_args(["-b", "foo"],
1246
1250
command.BumpTimeout)
1248
1252
def test_start_checker(self):
1249
self.assert_command_from_args(["--start-checker", "client"],
1253
self.assert_command_from_args(["--start-checker", "foo"],
1250
1254
command.StartChecker)
1252
1256
def test_stop_checker(self):
1253
self.assert_command_from_args(["--stop-checker", "client"],
1257
self.assert_command_from_args(["--stop-checker", "foo"],
1254
1258
command.StopChecker)
1256
1260
def test_approve_by_default(self):
1257
self.assert_command_from_args(["--approve-by-default",
1261
self.assert_command_from_args(["--approve-by-default", "foo"],
1259
1262
command.ApproveByDefault)
1261
1264
def test_deny_by_default(self):
1262
self.assert_command_from_args(["--deny-by-default", "client"],
1265
self.assert_command_from_args(["--deny-by-default", "foo"],
1263
1266
command.DenyByDefault)
1265
1268
def test_checker(self):
1266
self.assert_command_from_args(["--checker", ":", "client"],
1269
self.assert_command_from_args(["--checker", ":", "foo"],
1267
1270
command.SetChecker,
1268
1271
value_to_set=":")
1270
1273
def test_checker_empty(self):
1271
self.assert_command_from_args(["--checker", "", "client"],
1274
self.assert_command_from_args(["--checker", "", "foo"],
1272
1275
command.SetChecker,
1273
1276
value_to_set="")
1275
1278
def test_checker_short(self):
1276
self.assert_command_from_args(["-c", ":", "client"],
1279
self.assert_command_from_args(["-c", ":", "foo"],
1277
1280
command.SetChecker,
1278
1281
value_to_set=":")
1280
1283
def test_host(self):
1281
self.assert_command_from_args(
1282
["--host", "client.example.org", "client"],
1283
command.SetHost, value_to_set="client.example.org")
1284
self.assert_command_from_args(["--host", "foo.example.org",
1285
"foo"], command.SetHost,
1286
value_to_set="foo.example.org")
1285
1288
def test_host_short(self):
1286
self.assert_command_from_args(
1287
["-H", "client.example.org", "client"], command.SetHost,
1288
value_to_set="client.example.org")
1289
self.assert_command_from_args(["-H", "foo.example.org",
1290
"foo"], command.SetHost,
1291
value_to_set="foo.example.org")
1290
1293
def test_secret_devnull(self):
1291
1294
self.assert_command_from_args(["--secret", os.path.devnull,
1292
"client"], command.SetSecret,
1295
"foo"], command.SetSecret,
1293
1296
value_to_set=b"")
1295
1298
def test_secret_tempfile(self):
1312
1314
value = b"secret\0xyzzy\nbar"
1315
self.assert_command_from_args(["-s", f.name, "client"],
1317
self.assert_command_from_args(["-s", f.name, "foo"],
1316
1318
command.SetSecret,
1317
1319
value_to_set=value)
1319
1321
def test_timeout(self):
1320
self.assert_command_from_args(["--timeout", "PT5M", "client"],
1322
self.assert_command_from_args(["--timeout", "PT5M", "foo"],
1321
1323
command.SetTimeout,
1322
1324
value_to_set=300000)
1324
1326
def test_timeout_short(self):
1325
self.assert_command_from_args(["-t", "PT5M", "client"],
1327
self.assert_command_from_args(["-t", "PT5M", "foo"],
1326
1328
command.SetTimeout,
1327
1329
value_to_set=300000)
1329
1331
def test_extended_timeout(self):
1330
1332
self.assert_command_from_args(["--extended-timeout", "PT15M",
1332
1334
command.SetExtendedTimeout,
1333
1335
value_to_set=900000)
1335
1337
def test_interval(self):
1336
self.assert_command_from_args(["--interval", "PT2M",
1337
"client"], command.SetInterval,
1338
self.assert_command_from_args(["--interval", "PT2M", "foo"],
1339
command.SetInterval,
1338
1340
value_to_set=120000)
1340
1342
def test_interval_short(self):
1341
self.assert_command_from_args(["-i", "PT2M", "client"],
1343
self.assert_command_from_args(["-i", "PT2M", "foo"],
1342
1344
command.SetInterval,
1343
1345
value_to_set=120000)
1345
1347
def test_approval_delay(self):
1346
1348
self.assert_command_from_args(["--approval-delay", "PT30S",
1348
1350
command.SetApprovalDelay,
1349
1351
value_to_set=30000)
1351
1353
def test_approval_duration(self):
1352
1354
self.assert_command_from_args(["--approval-duration", "PT1S",
1354
1356
command.SetApprovalDuration,
1355
1357
value_to_set=1000)
1380
1382
self.attributes["Name"] = name
1381
1383
self.calls = []
1382
1384
def Set(self, interface, propname, value, dbus_interface):
1383
testcase.assertEqual(client_dbus_interface, interface)
1384
testcase.assertEqual(dbus.PROPERTIES_IFACE,
1385
testcase.assertEqual(interface, client_dbus_interface)
1386
testcase.assertEqual(dbus_interface,
1387
dbus.PROPERTIES_IFACE)
1386
1388
self.attributes[propname] = value
1387
1389
def Approve(self, approve, dbus_interface):
1388
testcase.assertEqual(client_dbus_interface,
1390
testcase.assertEqual(dbus_interface,
1391
client_dbus_interface)
1390
1392
self.calls.append(("Approve", (approve,
1391
1393
dbus_interface)))
1392
1394
self.client = MockClient(
1439
1441
LastCheckerStatus=-2)
1440
1442
self.clients = collections.OrderedDict(
1442
(self.client.__dbus_object_path__,
1443
self.client.attributes),
1444
(self.other_client.__dbus_object_path__,
1445
self.other_client.attributes),
1444
("/clients/foo", self.client.attributes),
1445
("/clients/barbar", self.other_client.attributes),
1447
self.one_client = {self.client.__dbus_object_path__:
1448
self.client.attributes}
1447
self.one_client = {"/clients/foo": self.client.attributes}
1452
class MockBus(object):
1454
1453
def get_object(client_bus_name, path):
1455
self.assertEqual(dbus_busname, client_bus_name)
1456
# Note: "self" here is the TestCmd instance, not the
1457
# MockBus instance, since this is a static method!
1458
if path == self.client.__dbus_object_path__:
1460
elif path == self.other_client.__dbus_object_path__:
1461
return self.other_client
1454
self.assertEqual(client_bus_name, dbus_busname)
1456
# Note: "self" here is the TestCmd instance, not
1457
# the Bus instance, since this is a static method!
1458
"/clients/foo": self.client,
1459
"/clients/barbar": self.other_client,
1465
1464
class TestBaseCommands(TestCommand):
1467
def test_IsEnabled_exits_successfully(self):
1466
def test_IsEnabled(self):
1467
self.assertTrue(all(command.IsEnabled().is_enabled(client,
1469
for client, properties
1470
in self.clients.items()))
1472
def test_IsEnabled_run_exits_successfully(self):
1468
1473
with self.assertRaises(SystemExit) as e:
1469
1474
command.IsEnabled().run(self.one_client)
1470
1475
if e.exception.code is not None:
1471
self.assertEqual(0, e.exception.code)
1476
self.assertEqual(e.exception.code, 0)
1473
1478
self.assertIsNone(e.exception.code)
1475
def test_IsEnabled_exits_with_failure(self):
1480
def test_IsEnabled_run_exits_with_failure(self):
1476
1481
self.client.attributes["Enabled"] = dbus.Boolean(False)
1477
1482
with self.assertRaises(SystemExit) as e:
1478
1483
command.IsEnabled().run(self.one_client)
1479
1484
if isinstance(e.exception.code, int):
1480
self.assertNotEqual(0, e.exception.code)
1485
self.assertNotEqual(e.exception.code, 0)
1482
1487
self.assertIsNotNone(e.exception.code)
1561
1566
def test_DumpJSON_normal(self):
1562
with self.capture_stdout_to_buffer() as buffer:
1563
command.DumpJSON().run(self.clients)
1564
json_data = json.loads(buffer.getvalue())
1565
self.assertDictEqual(self.expected_json, json_data)
1568
@contextlib.contextmanager
1569
def capture_stdout_to_buffer():
1570
capture_buffer = io.StringIO()
1571
old_stdout = sys.stdout
1572
sys.stdout = capture_buffer
1574
yield capture_buffer
1576
sys.stdout = old_stdout
1567
output = command.DumpJSON().output(self.clients.values())
1568
json_data = json.loads(output)
1569
self.assertDictEqual(json_data, self.expected_json)
1578
1571
def test_DumpJSON_one_client(self):
1579
with self.capture_stdout_to_buffer() as buffer:
1580
command.DumpJSON().run(self.one_client)
1581
json_data = json.loads(buffer.getvalue())
1572
output = command.DumpJSON().output(self.one_client.values())
1573
json_data = json.loads(output)
1582
1574
expected_json = {"foo": self.expected_json["foo"]}
1583
self.assertDictEqual(expected_json, json_data)
1575
self.assertDictEqual(json_data, expected_json)
1585
1577
def test_PrintTable_normal(self):
1586
with self.capture_stdout_to_buffer() as buffer:
1587
command.PrintTable().run(self.clients)
1578
output = command.PrintTable().output(self.clients.values())
1588
1579
expected_output = "\n".join((
1589
1580
"Name Enabled Timeout Last Successful Check",
1590
1581
"foo Yes 00:05:00 2019-02-03T00:00:00 ",
1591
1582
"barbar Yes 00:05:00 2019-02-04T00:00:00 ",
1593
self.assertEqual(expected_output, buffer.getvalue())
1584
self.assertEqual(output, expected_output)
1595
1586
def test_PrintTable_verbose(self):
1596
with self.capture_stdout_to_buffer() as buffer:
1597
command.PrintTable(verbose=True).run(self.clients)
1587
output = command.PrintTable(verbose=True).output(
1588
self.clients.values())
1684
1675
num_lines = max(len(rows) for rows in columns)
1685
expected_output = ("\n".join("".join(rows[line]
1686
for rows in columns)
1687
for line in range(num_lines))
1689
self.assertEqual(expected_output, buffer.getvalue())
1676
expected_output = "\n".join("".join(rows[line]
1677
for rows in columns)
1678
for line in range(num_lines))
1679
self.assertEqual(output, expected_output)
1691
1681
def test_PrintTable_one_client(self):
1692
with self.capture_stdout_to_buffer() as buffer:
1693
command.PrintTable().run(self.one_client)
1682
output = command.PrintTable().output(self.one_client.values())
1694
1683
expected_output = "\n".join((
1695
1684
"Name Enabled Timeout Last Successful Check",
1696
1685
"foo Yes 00:05:00 2019-02-03T00:00:00 ",
1698
self.assertEqual(expected_output, buffer.getvalue())
1701
class TestPropertySetterCmd(TestCommand):
1702
"""Abstract class for tests of command.PropertySetter classes"""
1687
self.assertEqual(output, expected_output)
1690
class TestPropertyCmd(TestCommand):
1691
"""Abstract class for tests of command.Property classes"""
1703
1692
def runTest(self):
1704
1693
if not hasattr(self, "command"):
1726
1715
self.command().run(clients, self.bus)
1729
class TestEnableCmd(TestPropertySetterCmd):
1718
class TestEnableCmd(TestPropertyCmd):
1730
1719
command = command.Enable
1731
1720
propname = "Enabled"
1732
1721
values_to_set = [dbus.Boolean(True)]
1735
class TestDisableCmd(TestPropertySetterCmd):
1724
class TestDisableCmd(TestPropertyCmd):
1736
1725
command = command.Disable
1737
1726
propname = "Enabled"
1738
1727
values_to_set = [dbus.Boolean(False)]
1741
class TestBumpTimeoutCmd(TestPropertySetterCmd):
1730
class TestBumpTimeoutCmd(TestPropertyCmd):
1742
1731
command = command.BumpTimeout
1743
1732
propname = "LastCheckedOK"
1744
1733
values_to_set = [""]
1747
class TestStartCheckerCmd(TestPropertySetterCmd):
1736
class TestStartCheckerCmd(TestPropertyCmd):
1748
1737
command = command.StartChecker
1749
1738
propname = "CheckerRunning"
1750
1739
values_to_set = [dbus.Boolean(True)]
1753
class TestStopCheckerCmd(TestPropertySetterCmd):
1742
class TestStopCheckerCmd(TestPropertyCmd):
1754
1743
command = command.StopChecker
1755
1744
propname = "CheckerRunning"
1756
1745
values_to_set = [dbus.Boolean(False)]
1759
class TestApproveByDefaultCmd(TestPropertySetterCmd):
1748
class TestApproveByDefaultCmd(TestPropertyCmd):
1760
1749
command = command.ApproveByDefault
1761
1750
propname = "ApprovedByDefault"
1762
1751
values_to_set = [dbus.Boolean(True)]
1765
class TestDenyByDefaultCmd(TestPropertySetterCmd):
1754
class TestDenyByDefaultCmd(TestPropertyCmd):
1766
1755
command = command.DenyByDefault
1767
1756
propname = "ApprovedByDefault"
1768
1757
values_to_set = [dbus.Boolean(False)]
1771
class TestPropertySetterValueCmd(TestPropertySetterCmd):
1772
"""Abstract class for tests of PropertySetterValueCmd classes"""
1760
class TestPropertyValueCmd(TestPropertyCmd):
1761
"""Abstract class for tests of PropertyValueCmd classes"""
1774
1763
def runTest(self):
1775
if type(self) is TestPropertySetterValueCmd:
1764
if type(self) is TestPropertyValueCmd:
1777
return super(TestPropertySetterValueCmd, self).runTest()
1766
return super(TestPropertyValueCmd, self).runTest()
1779
1768
def run_command(self, value, clients):
1780
1769
self.command(value).run(clients, self.bus)
1783
class TestSetCheckerCmd(TestPropertySetterValueCmd):
1772
class TestSetCheckerCmd(TestPropertyValueCmd):
1784
1773
command = command.SetChecker
1785
1774
propname = "Checker"
1786
1775
values_to_set = ["", ":", "fping -q -- %s"]
1789
class TestSetHostCmd(TestPropertySetterValueCmd):
1778
class TestSetHostCmd(TestPropertyValueCmd):
1790
1779
command = command.SetHost
1791
1780
propname = "Host"
1792
values_to_set = ["192.0.2.3", "client.example.org"]
1795
class TestSetSecretCmd(TestPropertySetterValueCmd):
1781
values_to_set = ["192.0.2.3", "foo.example.org"]
1784
class TestSetSecretCmd(TestPropertyValueCmd):
1796
1785
command = command.SetSecret
1797
1786
propname = "Secret"
1798
1787
values_to_set = [io.BytesIO(b""),
1799
1788
io.BytesIO(b"secret\0xyzzy\nbar")]
1800
values_to_get = [f.getvalue() for f in values_to_set]
1803
class TestSetTimeoutCmd(TestPropertySetterValueCmd):
1789
values_to_get = [b"", b"secret\0xyzzy\nbar"]
1792
class TestSetTimeoutCmd(TestPropertyValueCmd):
1804
1793
command = command.SetTimeout
1805
1794
propname = "Timeout"
1806
1795
values_to_set = [datetime.timedelta(),