[PATCH consfigurator v2 5/6] add gnupg scaffolding for test suite

David Bremner david at tethera.net
Thu Mar 10 00:28:59 GMT 2022


This is ported from the bash function add_gpg_home in the notmuch test suite.

Provide a new entry point #'runner to run tests with setup and teardown of
whatever is needed (and too inconvenient or expensive to do on a per-test
basis).
---
 consfigurator.asd          |  4 ++-
 tests/gnupg-secret-key.asc | 58 +++++++++++++++++++++++++++++++++++
 tests/gnupg.lisp           | 63 ++++++++++++++++++++++++++++++++++++++
 tests/package.lisp         |  2 +-
 tests/runner.lisp          |  9 ++++++
 5 files changed, 134 insertions(+), 2 deletions(-)
 create mode 100644 tests/gnupg-secret-key.asc
 create mode 100644 tests/gnupg.lisp
 create mode 100644 tests/runner.lisp

diff --git a/consfigurator.asd b/consfigurator.asd
index e9e9ee4..5a275a0 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -110,7 +110,9 @@
                (:feature :sbcl (:require #:sb-rt))
                (:feature (:not :sbcl) #:rt))
   :components ((:file "tests/package")
+               (:file "tests/gnupg")
+               (:file "tests/runner")
                (:file "tests/data/util")
                (:file "tests/util")
                (:file "tests/property/file"))
-  :perform (test-op (o c) (symbol-call :consfigurator/tests '#:do-tests)))
+  :perform (test-op (o c) (symbol-call :consfigurator/tests '#:runner)))
diff --git a/tests/gnupg-secret-key.asc b/tests/gnupg-secret-key.asc
new file mode 100644
index 0000000..744361b
--- /dev/null
+++ b/tests/gnupg-secret-key.asc
@@ -0,0 +1,58 @@
+-----BEGIN PGP PRIVATE KEY BLOCK-----
+
+lQOYBGIl6x0BCAC9OB9xE8eO9zASZ7/J5q62IXs55ZfwHuYT2dKCAsBrWfBHG5sn
+0183AM13KP81DeUgqgq9o0JJVbzo6L2BVQf3wMOz9/onIJP7stHXK405RdyMotD8
+mwZEng0b8LtW85hTMqdooaqyCBPCJFr8bKDG8kPTjjec/ko2x3BcotcUvkMskIYO
+Y8G2V9eRyZ1BUa5c7gGZRuxT/MNmoA5oruZzdW/P7Pws2V+PX+b1ysV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cjh9RL/bRb03So6WCQBSWgfNbxH5zUf/edyIapzIrcLn0
+Jp5jqHK84FMH3+g=
+=24jV
+-----END PGP PRIVATE KEY BLOCK-----
diff --git a/tests/gnupg.lisp b/tests/gnupg.lisp
new file mode 100644
index 0000000..9ed9eed
--- /dev/null
+++ b/tests/gnupg.lisp
@@ -0,0 +1,63 @@
+;;; Consfigurator -- Lisp declarative configuration management system
+
+;;; Copyright (C) 2022  David Bremner <david at tethera.net>
+
+;;; This file is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3, or (at your option)
+;;; any later version.
+
+;;; This file is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+(in-package :consfigurator/tests)
+(named-readtables:in-readtable :consfigurator)
+
+(defvar *gnupghome* nil
+  "Home directory for gnupg tests. Because gnupg uses Unix domain sockets
+  internally, this path should be short enough to avoid the 108 chars limit on
+  socket paths.")
+
+(define-constant +keyfile+
+    (asdf:system-relative-pathname 'consfigurator/tests
+                                   "tests/gnupg-secret-key.asc")
+  :test #'equal)
+
+;; this needs to be kept in sync with the shipped key
+(define-constant +gpg-fingerprint+ "F6B568B783D69267DA6FBE4B2C52E016026B271C"
+  :test #'equal)
+
+(defmacro with-gnupghome (&rest body)
+  "Run BODY with GNUPGHOME to test suite value set in environment"
+  `(let ((val nil))
+     (setf (osicat:environment-variable "GNUPGHOME") (namestring *gnupghome*))
+     (setq val (progn , at body))
+     (osicat:makunbound-environment-variable "GNUPGHOME")
+     val))
+
+(defun gpg (args &key input)
+  "run gpg on the test suite gnupg home directory"
+  (run-program  `("gpg" "--homedir" ,(namestring *gnupghome*) , at args)
+                :input input
+                :output :string :error-output :output))
+
+(defun gpg-setup (test-home)
+  "Set up gnupg homedir for test suite in TEST-HOME."
+  (setf *gnupghome* (ensure-directory-pathname #?"${test-home}/gnupg"))
+  (ensure-directories-exist *gnupghome* :mode #o700)
+  (gpg '("--no-tty" "--import") :input +keyfile+)
+  (with-open-file (stream #?"${*gnupghome*}/gpg.conf" :direction :output)
+    (format stream "debug-quick-random~%no-emit-version~%"))
+  (let ((str (format nil "~a:6:~%" +gpg-fingerprint+)))
+    (gpg '("--quiet" "--batch" "--no-tty" "--import-ownertrust")
+         :input (make-string-input-stream str))))
+
+(defun gpg-cleanup ()
+  "Clean up any test suite gnupg related processes. Caller is responsible for
+actually removing the *GNUPGHOME* directory"
+  (run-program "gpgconf" "--homedir" *gnupghome* "--kill" "all"))
diff --git a/tests/package.lisp b/tests/package.lisp
index 161bad7..4487d67 100644
--- a/tests/package.lisp
+++ b/tests/package.lisp
@@ -1,6 +1,6 @@
 (in-package :cl-user)
 
 (defpackage :consfigurator/tests
-  (:use #:cl #:consfigurator #+sbcl :sb-rt #-sbcl :rtest)
+  (:use #:cl #:consfigurator #:alexandria #+sbcl :sb-rt #-sbcl :rtest)
   (:local-nicknames (#:file       #:consfigurator.property.file)
                     (#:data-util  #:consfigurator.data.util)))
diff --git a/tests/runner.lisp b/tests/runner.lisp
new file mode 100644
index 0000000..a4d720d
--- /dev/null
+++ b/tests/runner.lisp
@@ -0,0 +1,9 @@
+(in-package :consfigurator/tests)
+(named-readtables:in-readtable :consfigurator)
+
+(defun runner ()
+  "Run tests via (sb-)rt, with setup and teardown"
+  (with-local-temporary-directory (test-home)
+    (gpg-setup test-home)
+    (do-tests)
+    (gpg-cleanup)))
-- 
2.34.1




More information about the sgo-software-discuss mailing list