[PATCH consfigurator v3 8/8] add tests for pass data source.

David Bremner david at tethera.net
Sun Mar 13 14:40:11 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 "_".

Signed-off-by: David Bremner <david at tethera.net>
---
 consfigurator.asd    |  1 +
 src/package.lisp     |  1 +
 tests/data/pass.lisp | 41 +++++++++++++++++++++++++++++++++++++++++
 tests/runner.lisp    | 34 ++++++++++++++++++++++++++++++++--
 4 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 tests/data/pass.lisp

diff --git a/consfigurator.asd b/consfigurator.asd
index 62834aa..8395202 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -111,6 +111,7 @@
                (:feature (:not :sbcl) #:rt))
   :components ((:file "tests/package")
                (:file "tests/runner")
+               (:file "tests/data/pass")
                (:file "tests/data/pgp")
                (:file "tests/data/util")
                (:file "tests/util")
diff --git a/src/package.lisp b/src/package.lisp
index f7e02e6..b2969cd 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -326,6 +326,7 @@
            #:get-data-protected-string
            #:*data-source-gnupghome*
            #:with-reset-data-sources
+           #:missing-data
 
            ;; image.lisp
            #:eval-in-grandchild
diff --git a/tests/data/pass.lisp b/tests/data/pass.lisp
new file mode 100644
index 0000000..4f4d279
--- /dev/null
+++ b/tests/data/pass.lisp
@@ -0,0 +1,41 @@
+(in-package :consfigurator/tests)
+(named-readtables:in-readtable :consfigurator)
+(in-consfig "consfigurator/tests")
+
+(deftest pass-host.1
+    (get-data-string "server.example.org" "account")
+  "hunter2")
+
+(deftest pass-host.2
+    (get-data-string "--user-passwd-server.example.org" "account")
+  "hunter2")
+
+(deftest pass-host.3
+    (get-data-string "server.example.org" "/etc/foo.conf") "[section]
+key=value")
+
+(deftest pass-host.4
+    (handler-case
+        (get-data-string "a.example.com" "/etc/foo.conf")
+      (missing-data (c) "fail"))
+  "fail")
+
+(deftest pass-underscore.1
+    (get-data-string "_server.example.org" "account")
+  "hunter2")
+
+(deftest pass-underscore.2
+    (get-data-string "_foo/bar" "baz") "OK")
+
+(deftest pass-underscore.3
+    (handler-case
+        (get-data-string "foo/bar" "baz")
+      (missing-data (c) "fail"))
+  "fail")
+
+(deftest pass-underscore.4
+    (get-data-string "_valid" "file") "visible")
+
+(deftest pass-underscore.5
+    (get-data-string "_" "toplevel") "sekrit")
+
diff --git a/tests/runner.lisp b/tests/runner.lisp
index 6615683..7be865e 100644
--- a/tests/runner.lisp
+++ b/tests/runner.lisp
@@ -65,6 +65,32 @@ registered and populated."
      (try-register-data-source :pgp :location *test-pgp-file*)
      , at body))
 
+(defparameter *test-pass-dir* nil
+  "pass(1) store for use in test suite.")
+
+(defun pass (args &key input)
+  (run-program `("env" ,#?"GNUPGHOME=${*data-source-gnupghome*}"
+                       ,#?"PASSWORD_STORE_DIR=${*test-pass-dir*}" "pass"
+                       , at args)
+               :input (if input (make-string-input-stream input) nil)
+               :output :string :error-output :output))
+
+(defmacro with-test-pass-source (test-home &rest body)
+  "Run BODY with pass(1) data source in TEST-HOME populated and registed."
+  `(let ((*test-pass-dir* (strcat (namestring ,test-home) "/password-store")))
+     (pass (list "init" *test-gnupg-fingerprint*))
+     (pass '("insert" "-m" "server.example.org/account") :input "hunter2")
+     (pass '("insert" "-m" "_foo/bar/baz") :input "OK")
+     (pass '("insert" "-m" "foo/bar/baz") :input "illegal")
+     (pass '("insert" "-m" "valid/file") :input "shadowed")
+     (pass '("insert" "-m" "_valid/file") :input "visible")
+     (pass '("insert" "-m" "toplevel") :input "sekrit")
+     (pass '("insert" "-m" "server.example.org/etc/foo.conf")
+           :input "[section]
+key=value")
+     (try-register-data-source :pass :location *test-pass-dir*)
+     , at body))
+
 ;; tests for test runner machinery
 (deftest runner.0 (not *data-source-gnupghome*) nil)
 
@@ -78,11 +104,15 @@ registered and populated."
 
 (deftest runner.3 (not *test-pgp-file*) nil)
 
+(deftest runner.4
+     (nth-value 0 (pass '("show" "toplevel")))
+  "sekrit")
+
 (defun runner ()
   "Run tests via (sb-)rt, with setup and teardown"
   (with-local-temporary-directory (test-home)
     (with-test-gnupg-home test-home
       (with-reset-data-sources
         (with-test-pgp-source test-home
-          (do-tests))))))
-
+          (with-test-pass-source test-home
+            (do-tests)))))))
-- 
2.35.1




More information about the sgo-software-discuss mailing list