]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix gpg detection for tests (Bug#23561)
authorNoam Postavsky <npostavs@gmail.com>
Sun, 15 Jul 2018 03:45:27 +0000 (23:45 -0400)
committerNoam Postavsky <npostavs@gmail.com>
Sun, 15 Jul 2018 03:45:27 +0000 (23:45 -0400)
* test/lisp/emacs-lisp/package-tests.el (package-test-signed): Stop
using epg-check-configuration and ignore-errors, they're redundant
because epg-find-configuration already does all that.
* test/lisp/epg-tests.el (epg-tests-find-usable-gpg-configuration):
Remove tracing.
(with-epg-tests): Skip test if no gpg config is found.
(epg-decrypt-1 epg-roundtrip-1, epg-sign-verify-1, epg-sign-verify-2)
(epg-import-1): Don't check gpg configuration at top-level, rely on
`with-epg-tests' instead.  Checking the gpg configuration requires a
valid HOME (or GNUPGHOME), which is provided by `with-epg-tests'.

test/lisp/emacs-lisp/package-tests.el
test/lisp/epg-tests.el

index db6d103a2efe1e63012af6aea07b239c5267b5e0..db8e1ae37e61a984a949ff16d473a5a895aea8be 100644 (file)
@@ -467,15 +467,13 @@ Must called from within a `tar-mode' buffer."
 
 (ert-deftest package-test-signed ()
   "Test verifying package signature."
-  (skip-unless (ignore-errors
-                (let ((homedir (make-temp-file "package-test" t)))
-                  (unwind-protect
-                      (let ((process-environment
-                             (cons (format "HOME=%s" homedir)
-                                   process-environment)))
-                        (epg-check-configuration
-                          (epg-find-configuration 'OpenPGP)))
-                    (delete-directory homedir t)))))
+  (skip-unless (let ((homedir (make-temp-file "package-test" t)))
+                (unwind-protect
+                    (let ((process-environment
+                           (cons (concat "HOME=" homedir)
+                                 process-environment)))
+                      (epg-find-configuration 'OpenPGP))
+                  (delete-directory homedir t))))
   (let* ((keyring (expand-file-name "key.pub" package-test-data-dir))
         (package-test-data-dir
           (expand-file-name "package-resources/signed" package-test-file-dir)))
index 361ba8fc0c24470643ee84b775a4442a73fca6ef..c34e589a4ac793c6b254c4b210977d9437384df5 100644 (file)
     prog-alist))
 
 (defun epg-tests-find-usable-gpg-configuration (&optional _require-passphrase)
-  ;; Tracing for Bug#23561, but only do it once per run.
-  (if (get-buffer "*trace-output*")
-      (epg-find-configuration 'OpenPGP 'no-cache epg-tests--config-program-alist)
-    (dolist (fun '(epg-find-configuration
-                   executable-find
-                   epg-check-configuration
-                   epg-config--make-gpg-configuration))
-      (trace-function-background fun))
-    (prog1 (unwind-protect
-               (epg-find-configuration 'OpenPGP 'no-cache epg-tests--config-program-alist)
-             (untrace-all))
-      (princ (with-current-buffer "*trace-output*" (buffer-string))
-             #'external-debugging-output))))
+  (epg-find-configuration 'OpenPGP 'no-cache epg-tests--config-program-alist))
 
 (defun epg-tests-passphrase-callback (_c _k _d)
   ;; Need to create a copy here, since the string will be wiped out
                  (format "GNUPGHOME=%s" epg-tests-home-directory))
            process-environment)))
      (unwind-protect
-        (let ((context (epg-make-context 'OpenPGP)))
+         (let ((context (epg-make-context 'OpenPGP))
+               (epg-config (epg-tests-find-usable-gpg-configuration
+                            ,(if require-passphrase
+                                 `'require-passphrase))))
+           ;; GNUPGHOME is needed to find a usable gpg, so we can't
+           ;; check whether to skip any earlier (Bug#23561).
+           (unless epg-config
+             (ert-skip "No usable gpg config"))
            (setf (epg-context-program context)
-                 (alist-get 'program
-                            (epg-tests-find-usable-gpg-configuration
-                             ,(if require-passphrase
-                                  `'require-passphrase))))
+                 (alist-get 'program epg-config))
           (setf (epg-context-home-directory context)
                 epg-tests-home-directory)
           ,(if require-passphrase
         (delete-directory epg-tests-home-directory t)))))
 
 (ert-deftest epg-decrypt-1 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
   (with-epg-tests (:require-passphrase t)
     (should (equal "test"
                   (epg-decrypt-string epg-tests-context "\
@@ -121,14 +112,12 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
 -----END PGP MESSAGE-----")))))
 
 (ert-deftest epg-roundtrip-1 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration '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))
   (with-epg-tests (:require-passphrase t
                   :require-public-key t
                   :require-secret-key t)
@@ -139,7 +128,6 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
                     (epg-decrypt-string epg-tests-context cipher))))))
 
 (ert-deftest epg-sign-verify-1 ()
-  (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
   (with-epg-tests (:require-passphrase t
                   :require-public-key t
                   :require-secret-key t)
@@ -153,7 +141,6 @@ 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))
   (with-epg-tests (:require-passphrase t
                   :require-public-key t
                   :require-secret-key t)
@@ -169,7 +156,6 @@ 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))
   (with-epg-tests (:require-passphrase t
                   :require-public-key t
                   :require-secret-key t)
@@ -184,7 +170,6 @@ 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))
   (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)))))