diff options
| author | Daiki Ueno | 2016-05-20 19:34:06 +0900 |
|---|---|---|
| committer | Daiki Ueno | 2016-05-20 19:34:06 +0900 |
| commit | dadfc30dae9529282a05720155d4aa1c5bd749b1 (patch) | |
| tree | 89df0bbe7ab1346d6998ff122549deb647beb144 | |
| parent | e41a5cbae9d208a191884e634f77ab6ccc990e64 (diff) | |
| download | emacs-dadfc30dae9529282a05720155d4aa1c5bd749b1.tar.gz emacs-dadfc30dae9529282a05720155d4aa1c5bd749b1.zip | |
Revert "epg: Add a way to detect gpg1 executable for tests"
This reverts commit d4ae6d7033b34e8b75c59aaf1584131e439ef2d5.
| -rw-r--r-- | lisp/epg-config.el | 82 | ||||
| -rw-r--r-- | test/automated/epg-tests.el | 42 |
2 files changed, 53 insertions, 71 deletions
diff --git a/lisp/epg-config.el b/lisp/epg-config.el index 9179e04dcc1..8a208044cba 100644 --- a/lisp/epg-config.el +++ b/lisp/epg-config.el | |||
| @@ -81,69 +81,57 @@ Note that the buffer name starts with a space." | |||
| 81 | (defconst epg-config--program-alist | 81 | (defconst epg-config--program-alist |
| 82 | '((OpenPGP | 82 | '((OpenPGP |
| 83 | epg-gpg-program | 83 | epg-gpg-program |
| 84 | epg-config--make-gpg-configuration | ||
| 84 | ("gpg2" . "2.1.6") ("gpg" . "1.4.3")) | 85 | ("gpg2" . "2.1.6") ("gpg" . "1.4.3")) |
| 85 | (CMS | 86 | (CMS |
| 86 | epg-gpgsm-program | 87 | epg-gpgsm-program |
| 88 | epg-config--make-gpgsm-configuration | ||
| 87 | ("gpgsm" . "2.0.4"))) | 89 | ("gpgsm" . "2.0.4"))) |
| 88 | "Alist used to obtain the usable configuration of executables. | 90 | "Alist used to obtain the usable configuration of executables. |
| 89 | The first element of each entry is protocol symbol, which is | 91 | The first element of each entry is protocol symbol, which is |
| 90 | either `OpenPGP' or `CMS'. The second element is a symbol where | 92 | either `OpenPGP' or `CMS'. The second element is a symbol where |
| 91 | the executable name is remembered. The rest of the entry is an | 93 | the executable name is remembered. The third element is a |
| 92 | alist mapping executable names to the minimum required version | 94 | function which constructs a configuration object (actually a |
| 93 | suitable for the use with Emacs.") | 95 | plist). The rest of the entry is an alist mapping executable |
| 94 | 96 | names to the minimum required version suitable for the use with | |
| 95 | (defconst epg-config--configuration-constructor-alist | 97 | Emacs.") |
| 96 | '((OpenPGP . epg-config--make-gpg-configuration) | ||
| 97 | (CMS . epg-config--make-gpgsm-configuration)) | ||
| 98 | "Alist used to obtain the usable configuration of executables. | ||
| 99 | The first element of each entry is protocol symbol, which is | ||
| 100 | either `OpenPGP' or `CMS'. The second element is a function | ||
| 101 | which constructs a configuration object (actually a plist).") | ||
| 102 | 98 | ||
| 103 | (defvar epg--configurations nil) | 99 | (defvar epg--configurations nil) |
| 104 | 100 | ||
| 105 | ;;;###autoload | 101 | ;;;###autoload |
| 106 | (defun epg-find-configuration (protocol &optional no-cache program-alist) | 102 | (defun epg-find-configuration (protocol &optional force) |
| 107 | "Find or create a usable configuration to handle PROTOCOL. | 103 | "Find or create a usable configuration to handle PROTOCOL. |
| 108 | This function first looks at the existing configuration found by | 104 | This function first looks at the existing configuration found by |
| 109 | the previous invocation of this function, unless NO-CACHE is non-nil. | 105 | the previous invocation of this function, unless FORCE is non-nil. |
| 110 | 106 | ||
| 111 | Then it walks through PROGRAM-ALIST or | 107 | Then it walks through `epg-config--program-alist'. If |
| 112 | `epg-config--program-alist'. If `epg-gpg-program' or | 108 | `epg-gpg-program' or `epg-gpgsm-program' is already set with |
| 113 | `epg-gpgsm-program' is already set with custom, use it. | 109 | custom, use it. Otherwise, it tries the programs listed in the |
| 114 | Otherwise, it tries the programs listed in the entry until the | 110 | entry until the version requirement is met." |
| 115 | version requirement is met." | 111 | (let ((entry (assq protocol epg-config--program-alist))) |
| 116 | (unless program-alist | ||
| 117 | (setq program-alist epg-config--program-alist)) | ||
| 118 | (let ((entry (assq protocol program-alist))) | ||
| 119 | (unless entry | 112 | (unless entry |
| 120 | (error "Unknown protocol %S" protocol)) | 113 | (error "Unknown protocol %S" protocol)) |
| 121 | (cl-destructuring-bind (symbol . alist) | 114 | (cl-destructuring-bind (symbol constructor . alist) |
| 122 | (cdr entry) | 115 | (cdr entry) |
| 123 | (let ((constructor | 116 | (or (and (not force) (alist-get protocol epg--configurations)) |
| 124 | (alist-get protocol epg-config--configuration-constructor-alist))) | 117 | ;; If the executable value is already set with M-x |
| 125 | (or (and (not no-cache) (alist-get protocol epg--configurations)) | 118 | ;; customize, use it without checking. |
| 126 | ;; If the executable value is already set with M-x | 119 | (if (get symbol 'saved-value) |
| 127 | ;; customize, use it without checking. | 120 | (let ((configuration (funcall constructor (symbol-value symbol)))) |
| 128 | (if (and symbol (get symbol 'saved-value)) | 121 | (push (cons protocol configuration) epg--configurations) |
| 129 | (let ((configuration | 122 | configuration) |
| 130 | (funcall constructor (symbol-value symbol)))) | 123 | (catch 'found |
| 131 | (push (cons protocol configuration) epg--configurations) | 124 | (dolist (program-version alist) |
| 132 | configuration) | 125 | (let ((executable (executable-find (car program-version)))) |
| 133 | (catch 'found | 126 | (when executable |
| 134 | (dolist (program-version alist) | 127 | (let ((configuration |
| 135 | (let ((executable (executable-find (car program-version)))) | 128 | (funcall constructor executable))) |
| 136 | (when executable | 129 | (when (ignore-errors |
| 137 | (let ((configuration | 130 | (epg-check-configuration configuration |
| 138 | (funcall constructor executable))) | 131 | (cdr program-version)) |
| 139 | (when (ignore-errors | 132 | t) |
| 140 | (epg-check-configuration configuration | 133 | (push (cons protocol configuration) epg--configurations) |
| 141 | (cdr program-version)) | 134 | (throw 'found configuration)))))))))))) |
| 142 | t) | ||
| 143 | (unless no-cache | ||
| 144 | (push (cons protocol configuration) | ||
| 145 | epg--configurations)) | ||
| 146 | (throw 'found configuration))))))))))))) | ||
| 147 | 135 | ||
| 148 | ;; Create an `epg-configuration' object for `gpg', using PROGRAM. | 136 | ;; Create an `epg-configuration' object for `gpg', using PROGRAM. |
| 149 | (defun epg-config--make-gpg-configuration (program) | 137 | (defun epg-config--make-gpg-configuration (program) |
diff --git a/test/automated/epg-tests.el b/test/automated/epg-tests.el index d51ab23f71e..4a317974ef5 100644 --- a/test/automated/epg-tests.el +++ b/test/automated/epg-tests.el | |||
| @@ -30,17 +30,16 @@ | |||
| 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 | (defconst epg-tests-program-alist-for-passphrase-callback | 33 | (defun epg-tests-gpg-usable (&optional require-passphrase) |
| 34 | '((OpenPGP | 34 | (and (executable-find epg-gpg-program) |
| 35 | nil | 35 | (condition-case nil |
| 36 | ("gpg" . "1.4.3")))) | 36 | (progn |
| 37 | 37 | (epg-check-configuration (epg-configuration)) | |
| 38 | (defun epg-tests-find-usable-gpg-configuration (&optional require-passphrase) | 38 | (if require-passphrase |
| 39 | (epg-find-configuration | 39 | (string-match "\\`1\\." |
| 40 | 'OpenPGP | 40 | (cdr (assq 'version (epg-configuration)))) |
| 41 | 'no-cache | 41 | t)) |
| 42 | (if require-passphrase | 42 | (error nil)))) |
| 43 | epg-tests-program-alist-for-passphrase-callback))) | ||
| 44 | 43 | ||
| 45 | (defun epg-tests-passphrase-callback (_c _k _d) | 44 | (defun epg-tests-passphrase-callback (_c _k _d) |
| 46 | ;; Need to create a copy here, since the string will be wiped out | 45 | ;; Need to create a copy here, since the string will be wiped out |
| @@ -53,14 +52,9 @@ | |||
| 53 | &rest body) | 52 | &rest body) |
| 54 | "Set up temporary locations and variables for testing." | 53 | "Set up temporary locations and variables for testing." |
| 55 | (declare (indent 1)) | 54 | (declare (indent 1)) |
| 56 | `(let ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t))) | 55 | `(let* ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t))) |
| 57 | (unwind-protect | 56 | (unwind-protect |
| 58 | (let ((context (epg-make-context 'OpenPGP))) | 57 | (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)))) | ||
| 64 | (setf (epg-context-home-directory context) | 58 | (setf (epg-context-home-directory context) |
| 65 | epg-tests-home-directory) | 59 | epg-tests-home-directory) |
| 66 | (setenv "GPG_AGENT_INFO") | 60 | (setenv "GPG_AGENT_INFO") |
| @@ -84,7 +78,7 @@ | |||
| 84 | (delete-directory epg-tests-home-directory t))))) | 78 | (delete-directory epg-tests-home-directory t))))) |
| 85 | 79 | ||
| 86 | (ert-deftest epg-decrypt-1 () | 80 | (ert-deftest epg-decrypt-1 () |
| 87 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | 81 | (skip-unless (epg-tests-gpg-usable 'require-passphrase)) |
| 88 | (with-epg-tests (:require-passphrase t) | 82 | (with-epg-tests (:require-passphrase t) |
| 89 | (should (equal "test" | 83 | (should (equal "test" |
| 90 | (epg-decrypt-string epg-tests-context "\ | 84 | (epg-decrypt-string epg-tests-context "\ |
| @@ -96,14 +90,14 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 96 | -----END PGP MESSAGE-----"))))) | 90 | -----END PGP MESSAGE-----"))))) |
| 97 | 91 | ||
| 98 | (ert-deftest epg-roundtrip-1 () | 92 | (ert-deftest epg-roundtrip-1 () |
| 99 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | 93 | (skip-unless (epg-tests-gpg-usable 'require-passphrase)) |
| 100 | (with-epg-tests (:require-passphrase t) | 94 | (with-epg-tests (:require-passphrase t) |
| 101 | (let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil))) | 95 | (let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil))) |
| 102 | (should (equal "symmetric" | 96 | (should (equal "symmetric" |
| 103 | (epg-decrypt-string epg-tests-context cipher)))))) | 97 | (epg-decrypt-string epg-tests-context cipher)))))) |
| 104 | 98 | ||
| 105 | (ert-deftest epg-roundtrip-2 () | 99 | (ert-deftest epg-roundtrip-2 () |
| 106 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | 100 | (skip-unless (epg-tests-gpg-usable 'require-passphrase)) |
| 107 | (with-epg-tests (:require-passphrase t | 101 | (with-epg-tests (:require-passphrase t |
| 108 | :require-public-key t | 102 | :require-public-key t |
| 109 | :require-secret-key t) | 103 | :require-secret-key t) |
| @@ -114,7 +108,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 114 | (epg-decrypt-string epg-tests-context cipher)))))) | 108 | (epg-decrypt-string epg-tests-context cipher)))))) |
| 115 | 109 | ||
| 116 | (ert-deftest epg-sign-verify-1 () | 110 | (ert-deftest epg-sign-verify-1 () |
| 117 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | 111 | (skip-unless (epg-tests-gpg-usable 'require-passphrase)) |
| 118 | (with-epg-tests (:require-passphrase t | 112 | (with-epg-tests (:require-passphrase t |
| 119 | :require-public-key t | 113 | :require-public-key t |
| 120 | :require-secret-key t) | 114 | :require-secret-key t) |
| @@ -128,7 +122,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 128 | (should (eq 'good (epg-signature-status (car verify-result))))))) | 122 | (should (eq 'good (epg-signature-status (car verify-result))))))) |
| 129 | 123 | ||
| 130 | (ert-deftest epg-sign-verify-2 () | 124 | (ert-deftest epg-sign-verify-2 () |
| 131 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | 125 | (skip-unless (epg-tests-gpg-usable 'require-passphrase)) |
| 132 | (with-epg-tests (:require-passphrase t | 126 | (with-epg-tests (:require-passphrase t |
| 133 | :require-public-key t | 127 | :require-public-key t |
| 134 | :require-secret-key t) | 128 | :require-secret-key t) |
| @@ -144,7 +138,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 144 | (should (eq 'good (epg-signature-status (car verify-result))))))) | 138 | (should (eq 'good (epg-signature-status (car verify-result))))))) |
| 145 | 139 | ||
| 146 | (ert-deftest epg-sign-verify-3 () | 140 | (ert-deftest epg-sign-verify-3 () |
| 147 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | 141 | (skip-unless (epg-tests-gpg-usable 'require-passphrase)) |
| 148 | (with-epg-tests (:require-passphrase t | 142 | (with-epg-tests (:require-passphrase t |
| 149 | :require-public-key t | 143 | :require-public-key t |
| 150 | :require-secret-key t) | 144 | :require-secret-key t) |
| @@ -159,7 +153,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA== | |||
| 159 | (should (eq 'good (epg-signature-status (car verify-result))))))) | 153 | (should (eq 'good (epg-signature-status (car verify-result))))))) |
| 160 | 154 | ||
| 161 | (ert-deftest epg-import-1 () | 155 | (ert-deftest epg-import-1 () |
| 162 | (skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase)) | 156 | (skip-unless (epg-tests-gpg-usable 'require-passphrase)) |
| 163 | (with-epg-tests (:require-passphrase nil) | 157 | (with-epg-tests (:require-passphrase nil) |
| 164 | (should (= 0 (length (epg-list-keys epg-tests-context)))) | 158 | (should (= 0 (length (epg-list-keys epg-tests-context)))) |
| 165 | (should (= 0 (length (epg-list-keys epg-tests-context nil t))))) | 159 | (should (= 0 (length (epg-list-keys epg-tests-context nil t))))) |