/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 dracut-module/password-agent.c

  • 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
 
/* -*- coding: utf-8; lexical-binding: t -*- */
 
1
/* -*- mode: c; coding: utf-8; after-save-hook: (lambda () (let* ((find-build-directory (lambda (try-directory &optional base-directory) (let ((base-directory (or base-directory try-directory))) (cond ((equal try-directory "/") base-directory) ((file-readable-p (concat (file-name-as-directory try-directory) "Makefile")) try-directory) ((funcall find-build-directory (directory-file-name (file-name-directory try-directory)) base-directory)))))) (build-directory (funcall find-build-directory (buffer-file-name))) (local-build-directory (if (fboundp 'file-local-name) (file-local-name build-directory) (or (file-remote-p build-directory 'localname) build-directory))) (command (file-relative-name (file-name-sans-extension (buffer-file-name)) build-directory))) (pcase (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (let ((qbdir (shell-quote-argument local-build-directory)) (qcmd (shell-quote-argument command))) (format "cd %s && CFLAGS=-Werror make --silent %s && %s --test --verbose" qbdir qcmd qcmd)) nil "*Test*")) (0 (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w)))) (_ (with-current-buffer "*Test*" (compilation-mode) (cd-absolute build-directory)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); -*- */
2
2
/*
3
3
 * Mandos password agent - Simple password agent to run Mandos client
4
4
 *
5
 
 * Copyright © 2019-2022 Teddy Hogeborn
6
 
 * Copyright © 2019-2022 Björn Påhlsson
 
5
 * Copyright © 2019-2021 Teddy Hogeborn
 
6
 * Copyright © 2019-2021 Björn Påhlsson
7
7
 * 
8
8
 * This file is part of Mandos.
9
9
 * 
6005
6005
    if(ssret < 0){
6006
6006
      if(saved_errno != EMSGSIZE) {
6007
6007
        g_test_skip("Skipping EMSGSIZE test");
6008
 
        g_test_message("Error on send(%" PRIuMAX " bytes): %s",
6009
 
                       (uintmax_t)message_size,
6010
 
                       strerror(saved_errno));
 
6008
        g_test_message("Error on send(): %s", strerror(saved_errno));
6011
6009
        return;
6012
6010
      }
6013
6011
      break;
8195
8193
  g_option_context_free(context);
8196
8194
  return should_run_tests != FALSE;
8197
8195
}
8198
 
 
8199
 
/*
8200
 
Local Variables:
8201
 
run-tests:
8202
 
(lambda ()
8203
 
  (if (not (funcall run-tests-in-test-buffer default-directory))
8204
 
      (funcall show-test-buffer-in-test-window)
8205
 
    (funcall remove-test-window)))
8206
 
run-tests-in-test-buffer:
8207
 
(lambda (dir)
8208
 
  (with-current-buffer (get-buffer-create "*Test*")
8209
 
    (setq buffer-read-only nil
8210
 
          default-directory dir)
8211
 
    (erase-buffer)
8212
 
    (compilation-mode))
8213
 
  (let ((process-result
8214
 
         (let ((inhibit-read-only t))
8215
 
           (process-file-shell-command
8216
 
            (funcall get-command-line) nil "*Test*"))))
8217
 
    (and (numberp process-result)
8218
 
         (= process-result 0))))
8219
 
get-command-line:
8220
 
(lambda ()
8221
 
  (let*
8222
 
      ((build-directory
8223
 
        (funcall find-build-directory (buffer-file-name)))
8224
 
       (local-build-directory
8225
 
        (if (fboundp 'file-local-name)
8226
 
            (file-local-name build-directory)
8227
 
          (or (file-remote-p build-directory 'localname)
8228
 
              build-directory)))
8229
 
       (command
8230
 
        (file-relative-name (file-name-sans-extension
8231
 
                             (buffer-file-name)) build-directory))
8232
 
       (qbdir (shell-quote-argument local-build-directory))
8233
 
       (qcmd (shell-quote-argument command)))
8234
 
    (format (concat "cd %s && CFLAGS=-Werror make --silent %s"
8235
 
             " && %s --test --verbose") qbdir qcmd qcmd)))
8236
 
find-build-directory:
8237
 
(lambda (try-directory &optional base-directory)
8238
 
  (let ((base-directory (or base-directory try-directory)))
8239
 
    (cond ((equal try-directory "/") base-directory)
8240
 
          ((file-readable-p
8241
 
            (concat (file-name-as-directory try-directory)
8242
 
                    "Makefile")) try-directory)
8243
 
          ((funcall find-build-directory
8244
 
                    (directory-file-name (file-name-directory
8245
 
                                          try-directory))
8246
 
                    base-directory)))))
8247
 
show-test-buffer-in-test-window:
8248
 
(lambda ()
8249
 
  (when (not (get-buffer-window-list "*Test*"))
8250
 
    (setq next-error-last-buffer (get-buffer "*Test*"))
8251
 
    (let* ((side (if (>= (window-width) 146) 'right 'bottom))
8252
 
           (display-buffer-overriding-action
8253
 
            `((display-buffer-in-side-window) (side . ,side)
8254
 
              (window-height . fit-window-to-buffer)
8255
 
              (window-width . fit-window-to-buffer))))
8256
 
      (display-buffer "*Test*"))))
8257
 
remove-test-window:
8258
 
(lambda ()
8259
 
  (let ((test-window (get-buffer-window "*Test*")))
8260
 
    (if test-window (delete-window test-window))))
8261
 
eval: (add-hook 'after-save-hook run-tests 90 t)
8262
 
End:
8263
 
*/