]> code.delx.au - gnu-emacs/blobdiff - test/automated/epg-tests.el
; Spelling fixes
[gnu-emacs] / test / automated / epg-tests.el
index d51ab23f71e3ea9c0892949b90c7de617eae2768..4a317974ef52712cf49e11ac4f539be519dc83e1 100644 (file)
   (expand-file-name "data/epg" (getenv "EMACS_TEST_DIRECTORY"))
   "Directory containing epg test data.")
 
-(defconst epg-tests-program-alist-for-passphrase-callback
-  '((OpenPGP
-     nil
-     ("gpg" . "1.4.3"))))
-
-(defun epg-tests-find-usable-gpg-configuration (&optional require-passphrase)
-  (epg-find-configuration
-   'OpenPGP
-   'no-cache
-   (if require-passphrase
-       epg-tests-program-alist-for-passphrase-callback)))
+(defun epg-tests-gpg-usable (&optional require-passphrase)
+  (and (executable-find epg-gpg-program)
+       (condition-case nil
+          (progn
+            (epg-check-configuration (epg-configuration))
+            (if require-passphrase
+                (string-match "\\`1\\."
+                              (cdr (assq 'version (epg-configuration))))
+              t))
+        (error nil))))
 
 (defun epg-tests-passphrase-callback (_c _k _d)
   ;; Need to create a copy here, since the string will be wiped out
                            &rest body)
   "Set up temporary locations and variables for testing."
   (declare (indent 1))
-  `(let ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t)))
+  `(let* ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t)))
      (unwind-protect
         (let ((context (epg-make-context 'OpenPGP)))
-           (setf (epg-context-program context)
-                 (alist-get 'program
-                            (epg-tests-find-usable-gpg-configuration
-                             ,(if require-passphrase
-                                  `'require-passphrase))))
           (setf (epg-context-home-directory context)
                 epg-tests-home-directory)
           (setenv "GPG_AGENT_INFO")
@@ -84,7 +78,7 @@
         (delete-directory epg-tests-home-directory t)))))
 
 (ert-deftest epg-decrypt-1 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
+  (skip-unless (epg-tests-gpg-usable 'require-passphrase))
   (with-epg-tests (:require-passphrase t)
     (should (equal "test"
                   (epg-decrypt-string epg-tests-context "\
@@ -96,14 +90,14 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
 -----END PGP MESSAGE-----")))))
 
 (ert-deftest epg-roundtrip-1 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
+  (skip-unless (epg-tests-gpg-usable 'require-passphrase))
   (with-epg-tests (:require-passphrase t)
     (let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil)))
       (should (equal "symmetric"
                     (epg-decrypt-string epg-tests-context cipher))))))
 
 (ert-deftest epg-roundtrip-2 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
+  (skip-unless (epg-tests-gpg-usable 'require-passphrase))
   (with-epg-tests (:require-passphrase t
                   :require-public-key t
                   :require-secret-key t)
@@ -114,7 +108,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
                     (epg-decrypt-string epg-tests-context cipher))))))
 
 (ert-deftest epg-sign-verify-1 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
+  (skip-unless (epg-tests-gpg-usable 'require-passphrase))
   (with-epg-tests (:require-passphrase t
                   :require-public-key t
                   :require-secret-key t)
@@ -128,7 +122,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
       (should (eq 'good (epg-signature-status (car verify-result)))))))
 
 (ert-deftest epg-sign-verify-2 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
+  (skip-unless (epg-tests-gpg-usable 'require-passphrase))
   (with-epg-tests (:require-passphrase t
                   :require-public-key t
                   :require-secret-key t)
@@ -144,7 +138,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
       (should (eq 'good (epg-signature-status (car verify-result)))))))
 
 (ert-deftest epg-sign-verify-3 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
+  (skip-unless (epg-tests-gpg-usable 'require-passphrase))
   (with-epg-tests (:require-passphrase t
                   :require-public-key t
                   :require-secret-key t)
@@ -159,7 +153,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
       (should (eq 'good (epg-signature-status (car verify-result)))))))
 
 (ert-deftest epg-import-1 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
+  (skip-unless (epg-tests-gpg-usable 'require-passphrase))
   (with-epg-tests (:require-passphrase nil)
     (should (= 0 (length (epg-list-keys epg-tests-context))))
     (should (= 0 (length (epg-list-keys epg-tests-context nil t)))))