aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDaiki Ueno2016-05-19 18:05:19 +0900
committerDaiki Ueno2016-05-20 16:29:04 +0900
commit65e38569e5eca8e4e8a0e38391c07e3862e78cb7 (patch)
tree5360e3d251365b68281a7c7e06263de892113b6a /test
parent970074470d7bc332fc36fd30feee93e1d6130177 (diff)
downloademacs-65e38569e5eca8e4e8a0e38391c07e3862e78cb7.tar.gz
emacs-65e38569e5eca8e4e8a0e38391c07e3862e78cb7.zip
epg: Add a way to detect gpg1 executable for tests
Fixes bug#23561. * test/automated/epg-tests.el (epg-tests-program-alist-for-passphrase-callback): New constant. (epg-tests-find-usable-gpg-configuration): New function, renamed from `epg-tests-gpg-usable'. All callers changed. (epg-tests-gpg-usable): Remove. * lisp/epg-config.el (epg-config--program-alist): Factor out constructor element to... (epg-config--configuration-constructor-alist): ...here. (epg-find-configuration): Rename FORCE argument to NO-CACHE, and add PROGRAM-ALIST argument.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/epg-tests.el42
1 files changed, 24 insertions, 18 deletions
diff --git a/test/lisp/epg-tests.el b/test/lisp/epg-tests.el
index 4a317974ef5..d51ab23f71e 100644
--- a/test/lisp/epg-tests.el
+++ b/test/lisp/epg-tests.el
@@ -30,16 +30,17 @@
30 (expand-file-name "data/epg" (getenv "EMACS_TEST_DIRECTORY")) 30 (expand-file-name "data/epg" (getenv "EMACS_TEST_DIRECTORY"))
31 "Directory containing epg test data.") 31 "Directory containing epg test data.")
32 32
33(defun epg-tests-gpg-usable (&optional require-passphrase) 33(defconst epg-tests-program-alist-for-passphrase-callback
34 (and (executable-find epg-gpg-program) 34 '((OpenPGP
35 (condition-case nil 35 nil
36 (progn 36 ("gpg" . "1.4.3"))))
37 (epg-check-configuration (epg-configuration)) 37
38 (if require-passphrase 38(defun epg-tests-find-usable-gpg-configuration (&optional require-passphrase)
39 (string-match "\\`1\\." 39 (epg-find-configuration
40 (cdr (assq 'version (epg-configuration)))) 40 'OpenPGP
41 t)) 41 'no-cache
42 (error nil)))) 42 (if require-passphrase
43 epg-tests-program-alist-for-passphrase-callback)))
43 44
44(defun epg-tests-passphrase-callback (_c _k _d) 45(defun epg-tests-passphrase-callback (_c _k _d)
45 ;; Need to create a copy here, since the string will be wiped out 46 ;; Need to create a copy here, since the string will be wiped out
@@ -52,9 +53,14 @@
52 &rest body) 53 &rest body)
53 "Set up temporary locations and variables for testing." 54 "Set up temporary locations and variables for testing."
54 (declare (indent 1)) 55 (declare (indent 1))
55 `(let* ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t))) 56 `(let ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t)))
56 (unwind-protect 57 (unwind-protect
57 (let ((context (epg-make-context 'OpenPGP))) 58 (let ((context (epg-make-context 'OpenPGP)))
59 (setf (epg-context-program context)
60 (alist-get 'program
61 (epg-tests-find-usable-gpg-configuration
62 ,(if require-passphrase
63 `'require-passphrase))))
58 (setf (epg-context-home-directory context) 64 (setf (epg-context-home-directory context)
59 epg-tests-home-directory) 65 epg-tests-home-directory)
60 (setenv "GPG_AGENT_INFO") 66 (setenv "GPG_AGENT_INFO")
@@ -78,7 +84,7 @@
78 (delete-directory epg-tests-home-directory t))))) 84 (delete-directory epg-tests-home-directory t)))))
79 85
80(ert-deftest epg-decrypt-1 () 86(ert-deftest epg-decrypt-1 ()
81 (skip-unless (epg-tests-gpg-usable 'require-passphrase)) 87 (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
82 (with-epg-tests (:require-passphrase t) 88 (with-epg-tests (:require-passphrase t)
83 (should (equal "test" 89 (should (equal "test"
84 (epg-decrypt-string epg-tests-context "\ 90 (epg-decrypt-string epg-tests-context "\
@@ -90,14 +96,14 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
90-----END PGP MESSAGE-----"))))) 96-----END PGP MESSAGE-----")))))
91 97
92(ert-deftest epg-roundtrip-1 () 98(ert-deftest epg-roundtrip-1 ()
93 (skip-unless (epg-tests-gpg-usable 'require-passphrase)) 99 (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
94 (with-epg-tests (:require-passphrase t) 100 (with-epg-tests (:require-passphrase t)
95 (let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil))) 101 (let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil)))
96 (should (equal "symmetric" 102 (should (equal "symmetric"
97 (epg-decrypt-string epg-tests-context cipher)))))) 103 (epg-decrypt-string epg-tests-context cipher))))))
98 104
99(ert-deftest epg-roundtrip-2 () 105(ert-deftest epg-roundtrip-2 ()
100 (skip-unless (epg-tests-gpg-usable 'require-passphrase)) 106 (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
101 (with-epg-tests (:require-passphrase t 107 (with-epg-tests (:require-passphrase t
102 :require-public-key t 108 :require-public-key t
103 :require-secret-key t) 109 :require-secret-key t)
@@ -108,7 +114,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
108 (epg-decrypt-string epg-tests-context cipher)))))) 114 (epg-decrypt-string epg-tests-context cipher))))))
109 115
110(ert-deftest epg-sign-verify-1 () 116(ert-deftest epg-sign-verify-1 ()
111 (skip-unless (epg-tests-gpg-usable 'require-passphrase)) 117 (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
112 (with-epg-tests (:require-passphrase t 118 (with-epg-tests (:require-passphrase t
113 :require-public-key t 119 :require-public-key t
114 :require-secret-key t) 120 :require-secret-key t)
@@ -122,7 +128,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
122 (should (eq 'good (epg-signature-status (car verify-result))))))) 128 (should (eq 'good (epg-signature-status (car verify-result)))))))
123 129
124(ert-deftest epg-sign-verify-2 () 130(ert-deftest epg-sign-verify-2 ()
125 (skip-unless (epg-tests-gpg-usable 'require-passphrase)) 131 (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
126 (with-epg-tests (:require-passphrase t 132 (with-epg-tests (:require-passphrase t
127 :require-public-key t 133 :require-public-key t
128 :require-secret-key t) 134 :require-secret-key t)
@@ -138,7 +144,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
138 (should (eq 'good (epg-signature-status (car verify-result))))))) 144 (should (eq 'good (epg-signature-status (car verify-result)))))))
139 145
140(ert-deftest epg-sign-verify-3 () 146(ert-deftest epg-sign-verify-3 ()
141 (skip-unless (epg-tests-gpg-usable 'require-passphrase)) 147 (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
142 (with-epg-tests (:require-passphrase t 148 (with-epg-tests (:require-passphrase t
143 :require-public-key t 149 :require-public-key t
144 :require-secret-key t) 150 :require-secret-key t)
@@ -153,7 +159,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
153 (should (eq 'good (epg-signature-status (car verify-result))))))) 159 (should (eq 'good (epg-signature-status (car verify-result)))))))
154 160
155(ert-deftest epg-import-1 () 161(ert-deftest epg-import-1 ()
156 (skip-unless (epg-tests-gpg-usable 'require-passphrase)) 162 (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
157 (with-epg-tests (:require-passphrase nil) 163 (with-epg-tests (:require-passphrase nil)
158 (should (= 0 (length (epg-list-keys epg-tests-context)))) 164 (should (= 0 (length (epg-list-keys epg-tests-context))))
159 (should (= 0 (length (epg-list-keys epg-tests-context nil t))))) 165 (should (= 0 (length (epg-list-keys epg-tests-context nil t)))))