diff options
| author | Noam Postavsky | 2018-07-14 23:45:27 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2018-07-14 23:45:27 -0400 |
| commit | 10a7e91956ebc5d808c88aecffb9d71a568d0233 (patch) | |
| tree | ae1156a4dc789a9f8e6e0f7ec02b5952b7efab05 /test | |
| parent | 4d42d1d351fbdd236a11ae86f7d0796337e629b3 (diff) | |
| download | emacs-10a7e91956ebc5d808c88aecffb9d71a568d0233.tar.gz emacs-10a7e91956ebc5d808c88aecffb9d71a568d0233.zip | |
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'.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/package-tests.el | 16 | ||||
| -rw-r--r-- | 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." | |||
| 467 | 467 | ||
| 468 | (ert-deftest package-test-signed () | 468 | (ert-deftest package-test-signed () |
| 469 | "Test verifying package signature." | 469 | "Test verifying package signature." |
| 470 | (skip-unless (ignore-errors | 470 | (skip-unless (let ((homedir (make-temp-file "package-test" t))) |
| 471 | (let ((homedir (make-temp-file "package-test" t))) | 471 | (unwind-protect |
| 472 | (unwind-protect | 472 | (let ((process-environment |
| 473 | (let ((process-environment | 473 | (cons (concat "HOME=" homedir) |
| 474 | (cons (format "HOME=%s" homedir) | 474 | process-environment))) |
| 475 | process-environment))) | 475 | (epg-find-configuration 'OpenPGP)) |
| 476 | (epg-check-configuration | 476 | (delete-directory homedir t)))) |
| 477 | (epg-find-configuration 'OpenPGP))) | ||
| 478 | (delete-directory homedir t))))) | ||
| 479 | (let* ((keyring (expand-file-name "key.pub" package-test-data-dir)) | 477 | (let* ((keyring (expand-file-name "key.pub" package-test-data-dir)) |
| 480 | (package-test-data-dir | 478 | (package-test-data-dir |
| 481 | (expand-file-name "package-resources/signed" package-test-file-dir))) | 479 | (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 @@ | |||
| 43 | prog-alist)) | 43 | prog-alist)) |
| 44 | 44 | ||
| 45 | (defun epg-tests-find-usable-gpg-configuration (&optional _require-passphrase) | 45 | (defun epg-tests-find-usable-gpg-configuration (&optional _require-passphrase) |
| 46 | ;; Tracing for Bug#23561, but only do it once per run. | 46 | (epg-find-configuration 'OpenPGP 'no-cache epg-tests--config-program-alist)) |
| 47 | (if (get-buffer "*trace-output*") | ||
| 48 | (epg-find-configuration 'OpenPGP 'no-cache epg-tests--config-program-alist) | ||
| 49 | (dolist (fun '(epg-find-configuration | ||
| 50 | executable-find | ||
| 51 | epg-check-configuration | ||
| 52 | epg-config--make-gpg-configuration)) | ||
| 53 | (trace-function-background fun)) | ||
| 54 | (prog1 (unwind-protect | ||
| 55 | (epg-find-configuration 'OpenPGP 'no-cache epg-tests--config-program-alist) | ||
| 56 | (untrace-all)) | ||
| 57 | (princ (with-current-buffer "*trace-output*" (buffer-string)) | ||
| 58 | #'external-debugging-output)))) | ||
| 59 | 47 | ||
| 60 | (defun epg-tests-passphrase-callback (_c _k _d) | 48 | (defun epg-tests-passphrase-callback (_c _k _d) |
| 61 | ;; Need to create a copy here, since the string will be wiped out | 49 | ;; Need to create a copy here, since the string will be wiped out |
| @@ -75,12 +63,16 @@ | |||
| 75 | (format "GNUPGHOME=%s" epg-tests-home-directory)) | 63 | (format "GNUPGHOME=%s" epg-tests-home-directory)) |
| 76 | process-environment))) | 64 | process-environment))) |
| 77 | (unwind-protect | 65 | (unwind-protect |
| 78 | (let ((context (epg-make-context 'OpenPGP))) | 66 | (let ((context (epg-make-context 'OpenPGP)) |
| 67 | (epg-config (epg-tests-find-usable-gpg-configuration | ||
| 68 | ,(if require-passphrase | ||
| 69 | `'require-passphrase)))) | ||
| 70 | ;; GNUPGHOME is needed to find a usable gpg, so we can't | ||
| 71 | ;; check whether to skip any earlier (Bug#23561). | ||
| 72 | (unless epg-config | ||
| 73 | (ert-skip "No usable gpg config")) | ||
| 79 | (setf (epg-context-program context) | 74 | (setf (epg-context-program context) |
| 80 | (alist-get 'program | 75 | (alist-get 'program epg-config)) |
| 81 | (epg-tests-find-usable-gpg-configuration | ||
| 82 | ,(if require-passphrase | ||
| 83 | `'require-passphrase)))) | ||
| 84 | (setf (epg-context-home-directory context) | 76 | (setf (epg-context-home-directory context) |
| 85 | epg-tests-home-directory) | 77 | epg-tests-home-directory) |
| 86 | ,(if require-passphrase | 78 | ,(if require-passphrase |
| @@ -109,7 +101,6 @@ | |||
| 109 | (delete-directory epg-tests-home-directory t))))) | 101 | (delete-directory epg-tests-home-directory t))))) |
| 110 | 102 | ||
| 111 | (ert-deftest epg-decrypt-1 () | 103 | (ert-deftest epg-decrypt-1 () |
| 112 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | ||
| 113 | (with-epg-tests (:require-passphrase t) | 104 | (with-epg-tests (:require-passphrase t) |
| 114 | (should (equal "test" | 105 | (should (equal "test" |
| 115 | (epg-decrypt-string epg-tests-context "\ | 106 | (epg-decrypt-string epg-tests-context "\ |
| @@ -121,14 +112,12 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 121 | -----END PGP MESSAGE-----"))))) | 112 | -----END PGP MESSAGE-----"))))) |
| 122 | 113 | ||
| 123 | (ert-deftest epg-roundtrip-1 () | 114 | (ert-deftest epg-roundtrip-1 () |
| 124 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | ||
| 125 | (with-epg-tests (:require-passphrase t) | 115 | (with-epg-tests (:require-passphrase t) |
| 126 | (let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil))) | 116 | (let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil))) |
| 127 | (should (equal "symmetric" | 117 | (should (equal "symmetric" |
| 128 | (epg-decrypt-string epg-tests-context cipher)))))) | 118 | (epg-decrypt-string epg-tests-context cipher)))))) |
| 129 | 119 | ||
| 130 | (ert-deftest epg-roundtrip-2 () | 120 | (ert-deftest epg-roundtrip-2 () |
| 131 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | ||
| 132 | (with-epg-tests (:require-passphrase t | 121 | (with-epg-tests (:require-passphrase t |
| 133 | :require-public-key t | 122 | :require-public-key t |
| 134 | :require-secret-key t) | 123 | :require-secret-key t) |
| @@ -139,7 +128,6 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 139 | (epg-decrypt-string epg-tests-context cipher)))))) | 128 | (epg-decrypt-string epg-tests-context cipher)))))) |
| 140 | 129 | ||
| 141 | (ert-deftest epg-sign-verify-1 () | 130 | (ert-deftest epg-sign-verify-1 () |
| 142 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | ||
| 143 | (with-epg-tests (:require-passphrase t | 131 | (with-epg-tests (:require-passphrase t |
| 144 | :require-public-key t | 132 | :require-public-key t |
| 145 | :require-secret-key t) | 133 | :require-secret-key t) |
| @@ -153,7 +141,6 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 153 | (should (eq 'good (epg-signature-status (car verify-result))))))) | 141 | (should (eq 'good (epg-signature-status (car verify-result))))))) |
| 154 | 142 | ||
| 155 | (ert-deftest epg-sign-verify-2 () | 143 | (ert-deftest epg-sign-verify-2 () |
| 156 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | ||
| 157 | (with-epg-tests (:require-passphrase t | 144 | (with-epg-tests (:require-passphrase t |
| 158 | :require-public-key t | 145 | :require-public-key t |
| 159 | :require-secret-key t) | 146 | :require-secret-key t) |
| @@ -169,7 +156,6 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 169 | (should (eq 'good (epg-signature-status (car verify-result))))))) | 156 | (should (eq 'good (epg-signature-status (car verify-result))))))) |
| 170 | 157 | ||
| 171 | (ert-deftest epg-sign-verify-3 () | 158 | (ert-deftest epg-sign-verify-3 () |
| 172 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | ||
| 173 | (with-epg-tests (:require-passphrase t | 159 | (with-epg-tests (:require-passphrase t |
| 174 | :require-public-key t | 160 | :require-public-key t |
| 175 | :require-secret-key t) | 161 | :require-secret-key t) |
| @@ -184,7 +170,6 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 184 | (should (eq 'good (epg-signature-status (car verify-result))))))) | 170 | (should (eq 'good (epg-signature-status (car verify-result))))))) |
| 185 | 171 | ||
| 186 | (ert-deftest epg-import-1 () | 172 | (ert-deftest epg-import-1 () |
| 187 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | ||
| 188 | (with-epg-tests (:require-passphrase nil) | 173 | (with-epg-tests (:require-passphrase nil) |
| 189 | (should (= 0 (length (epg-list-keys epg-tests-context)))) | 174 | (should (= 0 (length (epg-list-keys epg-tests-context)))) |
| 190 | (should (= 0 (length (epg-list-keys epg-tests-context nil t))))) | 175 | (should (= 0 (length (epg-list-keys epg-tests-context nil t))))) |