diff options
author | David Bremner <david@tethera.net> | 2022-05-05 08:29:26 -0300 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-05-05 12:34:24 -0700 |
commit | 23e304277c6ab46995fc68d5c4574fc58a9a57b4 (patch) | |
tree | 3c4bd21d7e6f87e149fac7dad4a2c36153331a90 /tests | |
parent | 4315b429f8f39772bef5fc2175859a55ae513714 (diff) | |
download | consfigurator-23e304277c6ab46995fc68d5c4574fc58a9a57b4.tar.gz |
add tests for pass(1) data source
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@tethera.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/pass.lisp | 52 | ||||
-rw-r--r-- | tests/runner.lisp | 26 |
2 files changed, 77 insertions, 1 deletions
diff --git a/tests/data/pass.lisp b/tests/data/pass.lisp new file mode 100644 index 0000000..5852809 --- /dev/null +++ b/tests/data/pass.lisp @@ -0,0 +1,52 @@ +(in-package :consfigurator/tests) +(named-readtables:in-readtable :consfigurator) +(in-consfig "consfigurator/tests") + +(defun populate-data-pass () + "Invoked by test runner before data source is registered." + (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")) + +(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") + (simple-program-error (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 d43456d..aafeafa 100644 --- a/tests/runner.lisp +++ b/tests/runner.lisp @@ -67,13 +67,35 @@ registered and populated." (error "Test setup failure for pgp file ~a" *test-pgp-file*))) ,@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" + ,@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* (merge-pathnames #P"password-store/" ,test-home))) + (pass (list "init" *test-gnupg-fingerprint*)) + (populate-data-pass) + (handler-case + (try-register-data-source :pass :location *test-pass-dir*) + (missing-data-source () + (error "Test setup failure for pass directory ~a" *test-pass-dir*))) + ,@body)) + (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))))))) ;;;; tests for test runner machinery @@ -88,3 +110,5 @@ registered and populated." (deftest runner.2 (not *test-gnupg-fingerprint*) nil) (deftest runner.3 (not *test-pgp-file*) nil) + +(deftest runner.4 (nth-value 2 (pass '("list"))) 0) |