/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-monitor

  • 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:
1
 
#!/usr/bin/python3 -bb
 
1
#!/usr/bin/python3 -bbI
2
2
# -*- mode: python; coding: utf-8 -*-
3
3
#
4
4
# Mandos Monitor - Control and monitor the Mandos server
35
35
import os
36
36
import warnings
37
37
import datetime
 
38
import locale
 
39
import logging
38
40
 
39
41
import urwid.curses_display
40
42
import urwid
44
46
 
45
47
import dbus
46
48
 
47
 
import locale
48
 
 
49
 
import logging
50
 
 
51
49
if sys.version_info.major == 2:
 
50
    __metaclass__ = type
52
51
    str = unicode
53
52
 
54
53
log = logging.getLogger(os.path.basename(sys.argv[0]))
57
56
 
58
57
logging.captureWarnings(True)   # Show warnings via the logging system
59
58
 
60
 
locale.setlocale(locale.LC_ALL, '')
 
59
locale.setlocale(locale.LC_ALL, "")
61
60
 
62
 
logging.getLogger('dbus.proxies').setLevel(logging.CRITICAL)
 
61
logging.getLogger("dbus.proxies").setLevel(logging.CRITICAL)
63
62
 
64
63
# Some useful constants
65
 
domain = 'se.recompile'
66
 
server_interface = domain + '.Mandos'
67
 
client_interface = domain + '.Mandos.Client'
68
 
version = "1.8.9"
 
64
domain = "se.recompile"
 
65
server_interface = domain + ".Mandos"
 
66
client_interface = domain + ".Mandos.Client"
 
67
version = "1.8.14"
69
68
 
70
69
try:
71
70
    dbus.OBJECT_MANAGER_IFACE
90
89
                             int(fraction*1000000))  # Microseconds
91
90
 
92
91
 
93
 
class MandosClientPropertyCache(object):
 
92
class MandosClientPropertyCache:
94
93
    """This wraps a Mandos Client D-Bus proxy object, caches the
95
94
    properties and calls a hook function when any of them are
96
95
    changed.
167
166
                                         self.rejected,
168
167
                                         client_interface,
169
168
                                         byte_arrays=True))
170
 
        log.debug('Created client %s', self.properties["Name"])
 
169
        log.debug("Created client %s", self.properties["Name"])
171
170
 
172
171
    def using_timer(self, flag):
173
172
        """Call this method with True or False when timer should be
185
184
    def checker_completed(self, exitstatus, condition, command):
186
185
        if exitstatus == 0:
187
186
            log.debug('Checker for client %s (command "%s")'
188
 
                      ' succeeded', self.properties["Name"], command)
 
187
                      " succeeded", self.properties["Name"], command)
189
188
            self.update()
190
189
            return
191
190
        # Checker failed
192
191
        if os.WIFEXITED(condition):
193
192
            log.info('Checker for client %s (command "%s") failed'
194
 
                     ' with exit code %d', self.properties["Name"],
 
193
                     " with exit code %d", self.properties["Name"],
195
194
                     command, os.WEXITSTATUS(condition))
196
195
        elif os.WIFSIGNALED(condition):
197
196
            log.info('Checker for client %s (command "%s") was'
198
 
                     ' killed by signal %d', self.properties["Name"],
 
197
                     " killed by signal %d", self.properties["Name"],
199
198
                     command, os.WTERMSIG(condition))
200
199
        self.update()
201
200
 
249
248
        # Rebuild focus and non-focus widgets using current properties
250
249
 
251
250
        # Base part of a client. Name!
252
 
        base = '{name}: '.format(name=self.properties["Name"])
 
251
        base = "{name}: ".format(name=self.properties["Name"])
253
252
        if not self.properties["Enabled"]:
254
253
            message = "DISABLED"
255
254
            self.using_timer(False)
277
276
                timer = datetime.timedelta(0)
278
277
            else:
279
278
                expires = (datetime.datetime.strptime
280
 
                           (expires, '%Y-%m-%dT%H:%M:%S.%f'))
 
279
                           (expires, "%Y-%m-%dT%H:%M:%S.%f"))
281
280
                timer = max(expires - datetime.datetime.utcnow(),
282
281
                            datetime.timedelta())
283
 
            message = ('A checker has failed! Time until client'
284
 
                       ' gets disabled: {}'
 
282
            message = ("A checker has failed! Time until client"
 
283
                       " gets disabled: {}"
285
284
                       .format(str(timer).rsplit(".", 1)[0]))
286
285
            self.using_timer(True)
287
286
        else:
408
407
        return ret
409
408
 
410
409
 
411
 
class UserInterface(object):
 
410
class UserInterface:
412
411
    """This is the entire user interface - the whole screen
413
412
    with boxes, lists of client widgets, etc.
414
413
    """
471
470
                           "Mandos Monitor version " + version))
472
471
        self.add_log_line(("bold", "q: Quit  ?: Help"))
473
472
 
474
 
        self.busname = domain + '.Mandos'
 
473
        self.busname = domain + ".Mandos"
475
474
        self.main_loop = GLib.MainLoop()
476
475
 
477
476
    def client_not_found(self, key_id, address):