From 10a7e91956ebc5d808c88aecffb9d71a568d0233 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 14 Jul 2018 23:45:27 -0400 Subject: [PATCH] Fix gpg detection for tests (Bug#23561) * 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 | 16 ++++++------ test/lisp/epg-tests.el | 35 ++++++++------------------- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el index db6d103a2ef..db8e1ae37e6 100644 --- a/test/lisp/emacs-lisp/package-tests.el +++ b/test/lisp/emacs-lisp/package-tests.el @@ -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))) diff --git a/test/lisp/epg-tests.el b/test/lisp/epg-tests.el index 361ba8fc0c2..c34e589a4ac 100644 --- a/test/lisp/epg-tests.el +++ b/test/lisp/epg-tests.el @@ -43,19 +43,7 @@ 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 @@ -75,12 +63,16 @@ (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 @@ -109,7 +101,6 @@ (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))))) -- 2.39.2