Skip to content

Commit

Permalink
tests: Fix no gpg-agent upon removal of GNUPGHOME.
Browse files Browse the repository at this point in the history
* tests/gpgscm/gnupg.scm (with-ephemeral-home-directory): Add
teadown-fn.
* tests/gpgsm/export.scm: Use -no-atexit version and stop-agent.
* tests/openpgp/decrypt-session-key.scm: Likewise.
* tests/openpgp/decrypt-unwrap-verify.scm: Likewise.
* tests/openpgp/defs.scm (have-opt-always-trust): Likewise.
(setup-environment-no-atexit): New.
(start-agent): Support no use of atexit.
* tests/gpgsm/gpgsm-defs.scm (setup-gpgsm-environment-no-atexit): New.
* tests/migrations/common.scm (untar-armored): Follow the change
of with-ephemeral-home-directory.

--

When gpg-agent detects homedir removal, it will automatically exit.
Then, call of 'gpgconf --kill all' will fail.  So, stop-agent should
be called before the removal of homedir.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
  • Loading branch information
NIIBE Yutaka committed Apr 4, 2018
1 parent cb1731c commit 83529e1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
13 changes: 9 additions & 4 deletions tests/gpgscm/gnupg.scm
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@

;; Evaluate a sequence of expressions with an ephemeral home
;; directory.
(define-macro (with-ephemeral-home-directory setup-fn . expressions)
(define-macro (with-ephemeral-home-directory setup-fn teardown-fn . expressions)
(let ((original-home-directory (gensym))
(ephemeral-home-directory (gensym))
(setup (gensym)))
(setup (gensym))
(teardown (gensym)))
`(let ((,original-home-directory (getenv "GNUPGHOME"))
(,ephemeral-home-directory (mkdtemp))
(,setup (delay (,setup-fn))))
(,setup (delay (,setup-fn)))
(,teardown (delay (,teardown-fn))))
(finally (unlink-recursively ,ephemeral-home-directory)
(dynamic-wind
(lambda ()
(setenv "GNUPGHOME" ,ephemeral-home-directory #t)
(with-working-directory ,ephemeral-home-directory (force ,setup)))
(lambda () ,@expressions)
(lambda () (setenv "GNUPGHOME" ,original-home-directory #t)))))))
(lambda ()
(setenv "GNUPGHOME" ,ephemeral-home-directory #t)
(with-working-directory ,ephemeral-home-directory (force ,teardown))
(setenv "GNUPGHOME" ,original-home-directory #t)))))))
2 changes: 1 addition & 1 deletion tests/gpgsm/export.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(lambda (cert)
(lettmp (exported)
(call-check `(,@gpgsm --output ,exported --export ,cert::uid::CN))
(with-ephemeral-home-directory setup-gpgsm-environment
(with-ephemeral-home-directory setup-gpgsm-environment-no-atexit stop-agent
(call-check `(,@gpgsm --import ,exported))
(assert (sm-have-public-key? cert)))))
(lambda (cert) cert::uid::CN)
Expand Down
6 changes: 6 additions & 0 deletions tests/gpgsm/gpgsm-defs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@
(call-check `(,(tool 'gpgtar) --extract --directory=. ,(cadr *args*)))
(create-gpgsm-gpghome))
(start-agent))

(define (setup-gpgsm-environment-no-atexit)
(if (member "--unpack-tarball" *args*)
(call-check `(,(tool 'gpgtar) --extract --directory=. ,(cadr *args*)))
(create-gpgsm-gpghome))
(start-agent #t))
2 changes: 1 addition & 1 deletion tests/migrations/common.scm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
(define GPGTAR (path-join (getenv "objdir") "tools" (qualify "gpgtar")))

(define (untar-armored source-name)
(with-ephemeral-home-directory (lambda ())
(with-ephemeral-home-directory (lambda ()) (lambda ())
(pipe:do
(pipe:open source-name (logior O_RDONLY O_BINARY))
(pipe:spawn `(,@GPG --dearmor))
Expand Down
2 changes: 1 addition & 1 deletion tests/openpgp/decrypt-session-key.scm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
(lambda (name)
(let* ((source (in-srcdir "tests" "openpgp" (string-append name ".asc")))
(key (get-session-key source)))
(with-ephemeral-home-directory setup-environment
(with-ephemeral-home-directory setup-environment-no-atexit stop-agent
(tr:do
(tr:open source)
(tr:gpg "" `(--yes --decrypt --override-session-key ,key))
Expand Down
2 changes: 1 addition & 1 deletion tests/openpgp/decrypt-unwrap-verify.scm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

;; Then, verify the signature with a clean working directory
;; containing only Steve's public key.
(with-ephemeral-home-directory setup-environment
(with-ephemeral-home-directory setup-environment-no-atexit stop-agent
(call-check `(,@gpg --import ,steve's-key))
(call-check `(,@gpg --verify ,unwrapped)))))
'("encsig-2-keys-3" "encsig-2-keys-4")))
14 changes: 9 additions & 5 deletions tests/openpgp/defs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@

(define have-opt-always-trust
(catch #f
(with-ephemeral-home-directory (lambda ())
(with-ephemeral-home-directory (lambda ()) (lambda ())
(call-check `(,(tool 'gpg) --gpgconf-test --always-trust)))
#t))

Expand Down Expand Up @@ -365,6 +365,10 @@
(create-gpghome)
(start-agent))

(define (setup-environment-no-atexit)
(create-gpghome)
(start-agent #t))

(define (create-sample-files)
(log "Creating sample data files")
(for-each
Expand Down Expand Up @@ -448,12 +452,12 @@
(preset-passphrases))

;; Create the socket dir and start the agent.
(define (start-agent)
(define (start-agent . args)
(log "Starting gpg-agent...")
(let ((gnupghome (getenv "GNUPGHOME")))
(atexit (lambda ()
(with-home-directory gnupghome
(stop-agent)))))
(if (null? args)
(atexit (lambda ()
(with-home-directory gnupghome (stop-agent))))))
(catch (log "Warning: Creating socket directory failed:" (car *error*))
(gpg-conf '--create-socketdir))
(call-check `(,(tool 'gpg-connect-agent) --verbose
Expand Down

0 comments on commit 83529e1

Please sign in to comment.