[PATCH consfigurator v2 6/6] add tests for pass data source.

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


Test the several cases of transforming (IDEN1 IDEN2) to a filesystem
location. Tricky cases include an illegal hostname in IDEN1 and shadowing of
an entry by one prefixed with "_".
---
 consfigurator.asd    |  1 +
 tests/data/pass.lisp | 86 ++++++++++++++++++++++++++++++++++++++++++++
 tests/runner.lisp    |  2 ++
 3 files changed, 89 insertions(+)
 create mode 100644 tests/data/pass.lisp

diff --git a/consfigurator.asd b/consfigurator.asd
index 5a275a0..689b33a 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -112,6 +112,7 @@
   :components ((:file "tests/package")
                (:file "tests/gnupg")
                (:file "tests/runner")
+               (:file "tests/data/pass")
                (:file "tests/data/util")
                (:file "tests/util")
                (:file "tests/property/file"))
diff --git a/tests/data/pass.lisp b/tests/data/pass.lisp
new file mode 100644
index 0000000..2853935
--- /dev/null
+++ b/tests/data/pass.lisp
@@ -0,0 +1,86 @@
+;;; 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)
+(in-consfig "consfigurator/tests")
+
+(defun pass (home args &key input)
+  (run-program `("env" ,#?"GNUPGHOME=${*gnupghome*}"
+                       ,#?"PASSWORD_STORE_DIR=${home}" "pass"
+                       , at args)
+               :input (if input (make-string-input-stream input) nil)
+               :output :string :error-output :output))
+
+(defun pass-setup (test-home)
+  "Set up pass(1) store for test suite in TEST-HOME."
+  (let ((dir #?"${test-home}/password-store"))
+    (pass dir `("init" ,+gpg-fingerprint+))
+    (pass dir '("insert" "-m" "server.example.org/account") :input "hunter2")
+    (pass dir '("insert" "-m" "_foo/bar/baz") :input "OK")
+    (pass dir '("insert" "-m" "foo/bar/baz") :input "illegal")
+    (pass dir '("insert" "-m" "valid/file") :input "shadowed")
+    (pass dir '("insert" "-m" "_valid/file") :input "visible")
+    (pass dir '("insert" "-m" "toplevel") :input "sekrit")
+    (pass dir '("insert" "-m" "server.example.org/etc/foo.conf")
+          :input "[section]
+key=value")
+    (try-register-data-source :pass :location dir)))
+
+(deftest pass-host.1
+    (with-gnupghome
+        (get-data-string "server.example.org" "account"))
+  "hunter2")
+
+(deftest pass-host.2
+    (with-gnupghome
+        (get-data-string "--user-passwd-server.example.org" "account"))
+  "hunter2")
+
+(deftest pass-host.3
+    (with-gnupghome
+        (get-data-string "server.example.org" "/etc/foo.conf")) "[section]
+key=value")
+
+(deftest pass-host.4
+    (handler-case
+        (with-gnupghome
+            (get-data-string "a.example.com" "/etc/foo.conf"))
+      (error (c)
+        (format nil "~a" c)))
+  "Could not provide prerequisite data \"a.example.com\" | \"/etc/foo.conf\"")
+
+(deftest pass-underscore.1
+    (with-gnupghome (get-data-string "_server.example.org" "account"))
+  "hunter2")
+
+(deftest pass-underscore.2
+    (with-gnupghome (get-data-string "_foo/bar" "baz")) "OK")
+
+(deftest pass-underscore.3
+    (handler-case
+        (with-gnupghome (get-data-string "foo/bar" "baz"))
+      (error (c)
+        (format nil "~a" c)))
+  "Could not provide prerequisite data \"foo/bar\" | \"baz\"")
+
+(deftest pass-underscore.4
+    (with-gnupghome (get-data-string "_valid" "file")) "visible")
+
+(deftest pass-underscore.5
+    (with-gnupghome (get-data-string "_" "toplevel")) "sekrit")
+
diff --git a/tests/runner.lisp b/tests/runner.lisp
index a4d720d..47ddcf0 100644
--- a/tests/runner.lisp
+++ b/tests/runner.lisp
@@ -4,6 +4,8 @@
 (defun runner ()
   "Run tests via (sb-)rt, with setup and teardown"
   (with-local-temporary-directory (test-home)
+    (reset-data-sources)
     (gpg-setup test-home)
+    (pass-setup test-home)
     (do-tests)
     (gpg-cleanup)))
-- 
2.34.1




More information about the sgo-software-discuss mailing list