/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: 2021-02-03 23:10:42 UTC
  • Revision ID: teddy@recompile.se-20210203231042-2z3egrvpo1zt7nej
mandos-ctl: Fix bad test for command.Remove and related minor issues

The test for command.Remove removes all clients from the spy server,
and then loops over all clients, looking for the corresponding Remove
command as recorded by the spy server.  But since since there aren't
any clients left after they were removed, no assertions are made, and
the test therefore does nothing.  Fix this.

In tests for command.Approve and command.Deny, add checks that clients
were not somehow removed by the command (in which case, likewise, no
assertions are made).

Add related checks to TestPropertySetterCmd.runTest; i.e. test that a
sequence is not empty before looping over it and making assertions.

* mandos-ctl (TestBaseCommands.test_Remove): Save a copy of the
  original "clients" dict, and loop over those instead.  Add assertion
  that all clients were indeed removed.  Also fix the code which looks
  for the Remove command, which now needs to actually work.
  (TestBaseCommands.test_Approve, TestBaseCommands.test_Deny): Add
  assertion that there are still clients before looping over them.
  (TestPropertySetterCmd.runTest): Add assertion that the list of
  values to get is not empty before looping over them.  Also add check
  that there are still clients before looping over clients.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2439
2439
        busname = "se.recompile.Mandos"
2440
2440
        client_interface = "se.recompile.Mandos.Client"
2441
2441
        command.Approve().run(self.bus.clients, self.bus)
 
2442
        self.assertTrue(self.bus.clients)
2442
2443
        for clientpath in self.bus.clients:
2443
2444
            self.assertIn(("Approve", busname, clientpath,
2444
2445
                           client_interface, (True,)), self.bus.calls)
2447
2448
        busname = "se.recompile.Mandos"
2448
2449
        client_interface = "se.recompile.Mandos.Client"
2449
2450
        command.Deny().run(self.bus.clients, self.bus)
 
2451
        self.assertTrue(self.bus.clients)
2450
2452
        for clientpath in self.bus.clients:
2451
2453
            self.assertIn(("Approve", busname, clientpath,
2452
2454
                           client_interface, (False,)),
2453
2455
                          self.bus.calls)
2454
2456
 
2455
2457
    def test_Remove(self):
 
2458
        busname = "se.recompile.Mandos"
 
2459
        server_path = "/"
 
2460
        server_interface = "se.recompile.Mandos"
 
2461
        orig_clients = self.bus.clients.copy()
2456
2462
        command.Remove().run(self.bus.clients, self.bus)
2457
 
        for clientpath in self.bus.clients:
2458
 
            self.assertIn(("RemoveClient", dbus_busname,
2459
 
                           dbus_server_path, dbus_server_interface,
 
2463
        self.assertFalse(self.bus.clients)
 
2464
        for clientpath in orig_clients:
 
2465
            self.assertIn(("RemoveClient", busname,
 
2466
                           server_path, server_interface,
2460
2467
                           (clientpath,)), self.bus.calls)
2461
2468
 
2462
2469
    expected_json = {
2664
2671
        else:
2665
2672
            cmd_args = [() for x in range(len(self.values_to_get))]
2666
2673
            values_to_get = self.values_to_get
 
2674
        self.assertTrue(values_to_get)
2667
2675
        for value_to_get, cmd_arg in zip(values_to_get, cmd_args):
2668
2676
            for clientpath in self.bus.clients:
2669
2677
                self.bus.clients[clientpath][self.propname] = (
2670
2678
                    Unique())
2671
2679
            self.command(*cmd_arg).run(self.bus.clients, self.bus)
 
2680
            self.assertTrue(self.bus.clients)
2672
2681
            for clientpath in self.bus.clients:
2673
2682
                value = (self.bus.clients[clientpath]
2674
2683
                         [self.propname])