Skip to content

Commit 83529e1

Browse files
author
NIIBE Yutaka
committed
tests: Fix no gpg-agent upon removal of GNUPGHOME.
* 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 <[email protected]>
1 parent cb1731c commit 83529e1

File tree

7 files changed

+28
-13
lines changed

7 files changed

+28
-13
lines changed

tests/gpgscm/gnupg.scm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,22 @@
2828

2929
;; Evaluate a sequence of expressions with an ephemeral home
3030
;; directory.
31-
(define-macro (with-ephemeral-home-directory setup-fn . expressions)
31+
(define-macro (with-ephemeral-home-directory setup-fn teardown-fn . expressions)
3232
(let ((original-home-directory (gensym))
3333
(ephemeral-home-directory (gensym))
34-
(setup (gensym)))
34+
(setup (gensym))
35+
(teardown (gensym)))
3536
`(let ((,original-home-directory (getenv "GNUPGHOME"))
3637
(,ephemeral-home-directory (mkdtemp))
37-
(,setup (delay (,setup-fn))))
38+
(,setup (delay (,setup-fn)))
39+
(,teardown (delay (,teardown-fn))))
3840
(finally (unlink-recursively ,ephemeral-home-directory)
3941
(dynamic-wind
4042
(lambda ()
4143
(setenv "GNUPGHOME" ,ephemeral-home-directory #t)
4244
(with-working-directory ,ephemeral-home-directory (force ,setup)))
4345
(lambda () ,@expressions)
44-
(lambda () (setenv "GNUPGHOME" ,original-home-directory #t)))))))
46+
(lambda ()
47+
(setenv "GNUPGHOME" ,ephemeral-home-directory #t)
48+
(with-working-directory ,ephemeral-home-directory (force ,teardown))
49+
(setenv "GNUPGHOME" ,original-home-directory #t)))))))

tests/gpgsm/export.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
(lambda (cert)
2626
(lettmp (exported)
2727
(call-check `(,@gpgsm --output ,exported --export ,cert::uid::CN))
28-
(with-ephemeral-home-directory setup-gpgsm-environment
28+
(with-ephemeral-home-directory setup-gpgsm-environment-no-atexit stop-agent
2929
(call-check `(,@gpgsm --import ,exported))
3030
(assert (sm-have-public-key? cert)))))
3131
(lambda (cert) cert::uid::CN)

tests/gpgsm/gpgsm-defs.scm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,9 @@
9999
(call-check `(,(tool 'gpgtar) --extract --directory=. ,(cadr *args*)))
100100
(create-gpgsm-gpghome))
101101
(start-agent))
102+
103+
(define (setup-gpgsm-environment-no-atexit)
104+
(if (member "--unpack-tarball" *args*)
105+
(call-check `(,(tool 'gpgtar) --extract --directory=. ,(cadr *args*)))
106+
(create-gpgsm-gpghome))
107+
(start-agent #t))

tests/migrations/common.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
(define GPGTAR (path-join (getenv "objdir") "tools" (qualify "gpgtar")))
4040

4141
(define (untar-armored source-name)
42-
(with-ephemeral-home-directory (lambda ())
42+
(with-ephemeral-home-directory (lambda ()) (lambda ())
4343
(pipe:do
4444
(pipe:open source-name (logior O_RDONLY O_BINARY))
4545
(pipe:spawn `(,@GPG --dearmor))

tests/openpgp/decrypt-session-key.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
(lambda (name)
3838
(let* ((source (in-srcdir "tests" "openpgp" (string-append name ".asc")))
3939
(key (get-session-key source)))
40-
(with-ephemeral-home-directory setup-environment
40+
(with-ephemeral-home-directory setup-environment-no-atexit stop-agent
4141
(tr:do
4242
(tr:open source)
4343
(tr:gpg "" `(--yes --decrypt --override-session-key ,key))

tests/openpgp/decrypt-unwrap-verify.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
;; Then, verify the signature with a clean working directory
3737
;; containing only Steve's public key.
38-
(with-ephemeral-home-directory setup-environment
38+
(with-ephemeral-home-directory setup-environment-no-atexit stop-agent
3939
(call-check `(,@gpg --import ,steve's-key))
4040
(call-check `(,@gpg --verify ,unwrapped)))))
4141
'("encsig-2-keys-3" "encsig-2-keys-4")))

tests/openpgp/defs.scm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201

202202
(define have-opt-always-trust
203203
(catch #f
204-
(with-ephemeral-home-directory (lambda ())
204+
(with-ephemeral-home-directory (lambda ()) (lambda ())
205205
(call-check `(,(tool 'gpg) --gpgconf-test --always-trust)))
206206
#t))
207207

@@ -365,6 +365,10 @@
365365
(create-gpghome)
366366
(start-agent))
367367

368+
(define (setup-environment-no-atexit)
369+
(create-gpghome)
370+
(start-agent #t))
371+
368372
(define (create-sample-files)
369373
(log "Creating sample data files")
370374
(for-each
@@ -448,12 +452,12 @@
448452
(preset-passphrases))
449453

450454
;; Create the socket dir and start the agent.
451-
(define (start-agent)
455+
(define (start-agent . args)
452456
(log "Starting gpg-agent...")
453457
(let ((gnupghome (getenv "GNUPGHOME")))
454-
(atexit (lambda ()
455-
(with-home-directory gnupghome
456-
(stop-agent)))))
458+
(if (null? args)
459+
(atexit (lambda ()
460+
(with-home-directory gnupghome (stop-agent))))))
457461
(catch (log "Warning: Creating socket directory failed:" (car *error*))
458462
(gpg-conf '--create-socketdir))
459463
(call-check `(,(tool 'gpg-connect-agent) --verbose

0 commit comments

Comments
 (0)