Revert "epg: Add a way to detect gpg1 executable for tests"
This reverts commit d4ae6d7033
.
This commit is contained in:
parent
e41a5cbae9
commit
dadfc30dae
2 changed files with 52 additions and 70 deletions
|
@ -81,53 +81,43 @@ Note that the buffer name starts with a space."
|
||||||
(defconst epg-config--program-alist
|
(defconst epg-config--program-alist
|
||||||
'((OpenPGP
|
'((OpenPGP
|
||||||
epg-gpg-program
|
epg-gpg-program
|
||||||
|
epg-config--make-gpg-configuration
|
||||||
("gpg2" . "2.1.6") ("gpg" . "1.4.3"))
|
("gpg2" . "2.1.6") ("gpg" . "1.4.3"))
|
||||||
(CMS
|
(CMS
|
||||||
epg-gpgsm-program
|
epg-gpgsm-program
|
||||||
|
epg-config--make-gpgsm-configuration
|
||||||
("gpgsm" . "2.0.4")))
|
("gpgsm" . "2.0.4")))
|
||||||
"Alist used to obtain the usable configuration of executables.
|
"Alist used to obtain the usable configuration of executables.
|
||||||
The first element of each entry is protocol symbol, which is
|
The first element of each entry is protocol symbol, which is
|
||||||
either `OpenPGP' or `CMS'. The second element is a symbol where
|
either `OpenPGP' or `CMS'. The second element is a symbol where
|
||||||
the executable name is remembered. The rest of the entry is an
|
the executable name is remembered. The third element is a
|
||||||
alist mapping executable names to the minimum required version
|
function which constructs a configuration object (actually a
|
||||||
suitable for the use with Emacs.")
|
plist). The rest of the entry is an alist mapping executable
|
||||||
|
names to the minimum required version suitable for the use with
|
||||||
(defconst epg-config--configuration-constructor-alist
|
Emacs.")
|
||||||
'((OpenPGP . epg-config--make-gpg-configuration)
|
|
||||||
(CMS . epg-config--make-gpgsm-configuration))
|
|
||||||
"Alist used to obtain the usable configuration of executables.
|
|
||||||
The first element of each entry is protocol symbol, which is
|
|
||||||
either `OpenPGP' or `CMS'. The second element is a function
|
|
||||||
which constructs a configuration object (actually a plist).")
|
|
||||||
|
|
||||||
(defvar epg--configurations nil)
|
(defvar epg--configurations nil)
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun epg-find-configuration (protocol &optional no-cache program-alist)
|
(defun epg-find-configuration (protocol &optional force)
|
||||||
"Find or create a usable configuration to handle PROTOCOL.
|
"Find or create a usable configuration to handle PROTOCOL.
|
||||||
This function first looks at the existing configuration found by
|
This function first looks at the existing configuration found by
|
||||||
the previous invocation of this function, unless NO-CACHE is non-nil.
|
the previous invocation of this function, unless FORCE is non-nil.
|
||||||
|
|
||||||
Then it walks through PROGRAM-ALIST or
|
Then it walks through `epg-config--program-alist'. If
|
||||||
`epg-config--program-alist'. If `epg-gpg-program' or
|
`epg-gpg-program' or `epg-gpgsm-program' is already set with
|
||||||
`epg-gpgsm-program' is already set with custom, use it.
|
custom, use it. Otherwise, it tries the programs listed in the
|
||||||
Otherwise, it tries the programs listed in the entry until the
|
entry until the version requirement is met."
|
||||||
version requirement is met."
|
(let ((entry (assq protocol epg-config--program-alist)))
|
||||||
(unless program-alist
|
|
||||||
(setq program-alist epg-config--program-alist))
|
|
||||||
(let ((entry (assq protocol program-alist)))
|
|
||||||
(unless entry
|
(unless entry
|
||||||
(error "Unknown protocol %S" protocol))
|
(error "Unknown protocol %S" protocol))
|
||||||
(cl-destructuring-bind (symbol . alist)
|
(cl-destructuring-bind (symbol constructor . alist)
|
||||||
(cdr entry)
|
(cdr entry)
|
||||||
(let ((constructor
|
(or (and (not force) (alist-get protocol epg--configurations))
|
||||||
(alist-get protocol epg-config--configuration-constructor-alist)))
|
|
||||||
(or (and (not no-cache) (alist-get protocol epg--configurations))
|
|
||||||
;; If the executable value is already set with M-x
|
;; If the executable value is already set with M-x
|
||||||
;; customize, use it without checking.
|
;; customize, use it without checking.
|
||||||
(if (and symbol (get symbol 'saved-value))
|
(if (get symbol 'saved-value)
|
||||||
(let ((configuration
|
(let ((configuration (funcall constructor (symbol-value symbol))))
|
||||||
(funcall constructor (symbol-value symbol))))
|
|
||||||
(push (cons protocol configuration) epg--configurations)
|
(push (cons protocol configuration) epg--configurations)
|
||||||
configuration)
|
configuration)
|
||||||
(catch 'found
|
(catch 'found
|
||||||
|
@ -140,10 +130,8 @@ version requirement is met."
|
||||||
(epg-check-configuration configuration
|
(epg-check-configuration configuration
|
||||||
(cdr program-version))
|
(cdr program-version))
|
||||||
t)
|
t)
|
||||||
(unless no-cache
|
(push (cons protocol configuration) epg--configurations)
|
||||||
(push (cons protocol configuration)
|
(throw 'found configuration))))))))))))
|
||||||
epg--configurations))
|
|
||||||
(throw 'found configuration)))))))))))))
|
|
||||||
|
|
||||||
;; Create an `epg-configuration' object for `gpg', using PROGRAM.
|
;; Create an `epg-configuration' object for `gpg', using PROGRAM.
|
||||||
(defun epg-config--make-gpg-configuration (program)
|
(defun epg-config--make-gpg-configuration (program)
|
||||||
|
|
|
@ -30,17 +30,16 @@
|
||||||
(expand-file-name "data/epg" (getenv "EMACS_TEST_DIRECTORY"))
|
(expand-file-name "data/epg" (getenv "EMACS_TEST_DIRECTORY"))
|
||||||
"Directory containing epg test data.")
|
"Directory containing epg test data.")
|
||||||
|
|
||||||
(defconst epg-tests-program-alist-for-passphrase-callback
|
(defun epg-tests-gpg-usable (&optional require-passphrase)
|
||||||
'((OpenPGP
|
(and (executable-find epg-gpg-program)
|
||||||
nil
|
(condition-case nil
|
||||||
("gpg" . "1.4.3"))))
|
(progn
|
||||||
|
(epg-check-configuration (epg-configuration))
|
||||||
(defun epg-tests-find-usable-gpg-configuration (&optional require-passphrase)
|
|
||||||
(epg-find-configuration
|
|
||||||
'OpenPGP
|
|
||||||
'no-cache
|
|
||||||
(if require-passphrase
|
(if require-passphrase
|
||||||
epg-tests-program-alist-for-passphrase-callback)))
|
(string-match "\\`1\\."
|
||||||
|
(cdr (assq 'version (epg-configuration))))
|
||||||
|
t))
|
||||||
|
(error nil))))
|
||||||
|
|
||||||
(defun epg-tests-passphrase-callback (_c _k _d)
|
(defun epg-tests-passphrase-callback (_c _k _d)
|
||||||
;; Need to create a copy here, since the string will be wiped out
|
;; Need to create a copy here, since the string will be wiped out
|
||||||
|
@ -53,14 +52,9 @@
|
||||||
&rest body)
|
&rest body)
|
||||||
"Set up temporary locations and variables for testing."
|
"Set up temporary locations and variables for testing."
|
||||||
(declare (indent 1))
|
(declare (indent 1))
|
||||||
`(let ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t)))
|
`(let* ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t)))
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(let ((context (epg-make-context 'OpenPGP)))
|
(let ((context (epg-make-context 'OpenPGP)))
|
||||||
(setf (epg-context-program context)
|
|
||||||
(alist-get 'program
|
|
||||||
(epg-tests-find-usable-gpg-configuration
|
|
||||||
,(if require-passphrase
|
|
||||||
`'require-passphrase))))
|
|
||||||
(setf (epg-context-home-directory context)
|
(setf (epg-context-home-directory context)
|
||||||
epg-tests-home-directory)
|
epg-tests-home-directory)
|
||||||
(setenv "GPG_AGENT_INFO")
|
(setenv "GPG_AGENT_INFO")
|
||||||
|
@ -84,7 +78,7 @@
|
||||||
(delete-directory epg-tests-home-directory t)))))
|
(delete-directory epg-tests-home-directory t)))))
|
||||||
|
|
||||||
(ert-deftest epg-decrypt-1 ()
|
(ert-deftest epg-decrypt-1 ()
|
||||||
(skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
|
(skip-unless (epg-tests-gpg-usable 'require-passphrase))
|
||||||
(with-epg-tests (:require-passphrase t)
|
(with-epg-tests (:require-passphrase t)
|
||||||
(should (equal "test"
|
(should (equal "test"
|
||||||
(epg-decrypt-string epg-tests-context "\
|
(epg-decrypt-string epg-tests-context "\
|
||||||
|
@ -96,14 +90,14 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
|
||||||
-----END PGP MESSAGE-----")))))
|
-----END PGP MESSAGE-----")))))
|
||||||
|
|
||||||
(ert-deftest epg-roundtrip-1 ()
|
(ert-deftest epg-roundtrip-1 ()
|
||||||
(skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
|
(skip-unless (epg-tests-gpg-usable 'require-passphrase))
|
||||||
(with-epg-tests (:require-passphrase t)
|
(with-epg-tests (:require-passphrase t)
|
||||||
(let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil)))
|
(let ((cipher (epg-encrypt-string epg-tests-context "symmetric" nil)))
|
||||||
(should (equal "symmetric"
|
(should (equal "symmetric"
|
||||||
(epg-decrypt-string epg-tests-context cipher))))))
|
(epg-decrypt-string epg-tests-context cipher))))))
|
||||||
|
|
||||||
(ert-deftest epg-roundtrip-2 ()
|
(ert-deftest epg-roundtrip-2 ()
|
||||||
(skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
|
(skip-unless (epg-tests-gpg-usable 'require-passphrase))
|
||||||
(with-epg-tests (:require-passphrase t
|
(with-epg-tests (:require-passphrase t
|
||||||
:require-public-key t
|
:require-public-key t
|
||||||
:require-secret-key t)
|
:require-secret-key t)
|
||||||
|
@ -114,7 +108,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
|
||||||
(epg-decrypt-string epg-tests-context cipher))))))
|
(epg-decrypt-string epg-tests-context cipher))))))
|
||||||
|
|
||||||
(ert-deftest epg-sign-verify-1 ()
|
(ert-deftest epg-sign-verify-1 ()
|
||||||
(skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
|
(skip-unless (epg-tests-gpg-usable 'require-passphrase))
|
||||||
(with-epg-tests (:require-passphrase t
|
(with-epg-tests (:require-passphrase t
|
||||||
:require-public-key t
|
:require-public-key t
|
||||||
:require-secret-key t)
|
:require-secret-key t)
|
||||||
|
@ -128,7 +122,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
|
||||||
(should (eq 'good (epg-signature-status (car verify-result)))))))
|
(should (eq 'good (epg-signature-status (car verify-result)))))))
|
||||||
|
|
||||||
(ert-deftest epg-sign-verify-2 ()
|
(ert-deftest epg-sign-verify-2 ()
|
||||||
(skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
|
(skip-unless (epg-tests-gpg-usable 'require-passphrase))
|
||||||
(with-epg-tests (:require-passphrase t
|
(with-epg-tests (:require-passphrase t
|
||||||
:require-public-key t
|
:require-public-key t
|
||||||
:require-secret-key t)
|
:require-secret-key t)
|
||||||
|
@ -144,7 +138,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
|
||||||
(should (eq 'good (epg-signature-status (car verify-result)))))))
|
(should (eq 'good (epg-signature-status (car verify-result)))))))
|
||||||
|
|
||||||
(ert-deftest epg-sign-verify-3 ()
|
(ert-deftest epg-sign-verify-3 ()
|
||||||
(skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
|
(skip-unless (epg-tests-gpg-usable 'require-passphrase))
|
||||||
(with-epg-tests (:require-passphrase t
|
(with-epg-tests (:require-passphrase t
|
||||||
:require-public-key t
|
:require-public-key t
|
||||||
:require-secret-key t)
|
:require-secret-key t)
|
||||||
|
@ -159,7 +153,7 @@ jA0EAwMCE19JBLTvvmhgyRrGGglRbnKkK9PJG8fDwO5ccjysrR7IcdNcnA==
|
||||||
(should (eq 'good (epg-signature-status (car verify-result)))))))
|
(should (eq 'good (epg-signature-status (car verify-result)))))))
|
||||||
|
|
||||||
(ert-deftest epg-import-1 ()
|
(ert-deftest epg-import-1 ()
|
||||||
(skip-unless (epg-tests-find-usable-gpg-configuration 'require-passphrase))
|
(skip-unless (epg-tests-gpg-usable 'require-passphrase))
|
||||||
(with-epg-tests (:require-passphrase nil)
|
(with-epg-tests (:require-passphrase nil)
|
||||||
(should (= 0 (length (epg-list-keys epg-tests-context))))
|
(should (= 0 (length (epg-list-keys epg-tests-context))))
|
||||||
(should (= 0 (length (epg-list-keys epg-tests-context nil t)))))
|
(should (= 0 (length (epg-list-keys epg-tests-context nil t)))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue