mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
tests: Harmonize temporary and socket directory handling.
* tests/gpgscm/tests.scm (mkdtemp): Do not magically obey the environment variable 'TMP', make sure to always return an absolute path. * tests/gpgme/Makefile.am (TMP): Drop variable. (TESTS_ENVIRONMENT): Drop 'TMP'. * tests/gpgme/gpgme-defs.scm (create-gpgmehome): Start the agent. Do not create private key store, the agent does that for us. * tests/gpgsm/Makefile.am (TMP): Drop variable. (TESTS_ENVIRONMENT): Drop 'TMP'. * tests/gpgme/gpgme-defs.scm (create-gpgsmhome): Start the agent. Do not create private key store, the agent does that for us. * tests/migrations/Makefile.am (TMP): Drop variable. (TESTS_ENVIRONMENT): Drop 'TMP'. * tests/migrations/common.scm (gpgconf): New variable. (run-test): Create and remove socket directory. * tests/migrations/extended-pkf.scm (src-tarball): Remove variable. (setup): Remove function. (trigger-migration): Likewise. Use 'run-test' to execute the test. * tests/migrations/from-classic.scm (src-tarball): Remove variable. (setup): Remove function. Use 'run-test' to execute the tests. * tests/openpgp/Makefile.am (TMP): Drop variable. (TESTS_ENVIRONMENT): Drop 'TMP'. * tests/openpgp/README: Do not mention 'TMP'. * tests/openpgp/defs.scm (with-home-directory): New macro. (create-legacy-gpghome): Do not create private key store, the agent does that for us. (start-agent): Make sure to terminate the right agent with 'atexit'. -- Previously, the test suite relied upon creating home directories in '/tmp'. This has been problematic in some build environments, although POSIX mandates that '/tmp' must be available. We now rely on 'gpgconf --create-socketdir' to create a suitable socket directory for us. This allows us to get rid of some cruft. It also aligns the environment the tests are run in closer with the environment that we intend that GnuPG runs in. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
171e4314eb
commit
7e19786a5d
@ -28,12 +28,9 @@ include $(top_srcdir)/am/cmacros.am
|
|||||||
|
|
||||||
AM_CFLAGS =
|
AM_CFLAGS =
|
||||||
|
|
||||||
TMP ?= /tmp
|
|
||||||
|
|
||||||
TESTS_ENVIRONMENT = LC_ALL=C \
|
TESTS_ENVIRONMENT = LC_ALL=C \
|
||||||
EXEEXT=$(EXEEXT) \
|
EXEEXT=$(EXEEXT) \
|
||||||
PATH=../gpgscm:$(PATH) \
|
PATH=../gpgscm:$(PATH) \
|
||||||
TMP=$(TMP) \
|
|
||||||
srcdir=$(abs_srcdir) \
|
srcdir=$(abs_srcdir) \
|
||||||
objdir=$(abs_top_builddir) \
|
objdir=$(abs_top_builddir) \
|
||||||
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp:$(abs_top_srcdir)/tests/gpgme
|
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp:$(abs_top_srcdir)/tests/gpgme
|
||||||
|
@ -54,7 +54,8 @@
|
|||||||
(create-file
|
(create-file
|
||||||
"gpg-agent.conf"
|
"gpg-agent.conf"
|
||||||
(string-append "pinentry-program " (tool 'pinentry)))
|
(string-append "pinentry-program " (tool 'pinentry)))
|
||||||
(mkdir "private-keys-v1.d" "-rwx")
|
|
||||||
|
(start-agent)
|
||||||
|
|
||||||
(log "Storing private keys")
|
(log "Storing private keys")
|
||||||
(for-each
|
(for-each
|
||||||
|
@ -268,14 +268,13 @@
|
|||||||
;; Make a temporary directory. If arguments are given, they are
|
;; Make a temporary directory. If arguments are given, they are
|
||||||
;; joined using path-join, and must end in a component ending in
|
;; joined using path-join, and must end in a component ending in
|
||||||
;; "XXXXXX". If no arguments are given, a suitable location and
|
;; "XXXXXX". If no arguments are given, a suitable location and
|
||||||
;; generic name is used.
|
;; generic name is used. Returns an absolute path.
|
||||||
(define (mkdtemp . components)
|
(define (mkdtemp . components)
|
||||||
(_mkdtemp (if (null? components)
|
(canonical-path (_mkdtemp (if (null? components)
|
||||||
(path-join (getenv "TMP")
|
(string-append "gpgscm-" (get-isotime) "-"
|
||||||
(string-append "gpgscm-" (get-isotime) "-"
|
(basename-suffix *scriptname* ".scm")
|
||||||
(basename-suffix *scriptname* ".scm")
|
"-XXXXXX")
|
||||||
"-XXXXXX"))
|
(apply path-join components)))))
|
||||||
(apply path-join components))))
|
|
||||||
|
|
||||||
(define-macro (with-temporary-working-directory . expressions)
|
(define-macro (with-temporary-working-directory . expressions)
|
||||||
(let ((tmp-sym (gensym)))
|
(let ((tmp-sym (gensym)))
|
||||||
|
@ -28,12 +28,9 @@ include $(top_srcdir)/am/cmacros.am
|
|||||||
|
|
||||||
AM_CFLAGS =
|
AM_CFLAGS =
|
||||||
|
|
||||||
TMP ?= /tmp
|
|
||||||
|
|
||||||
TESTS_ENVIRONMENT = LC_ALL=C \
|
TESTS_ENVIRONMENT = LC_ALL=C \
|
||||||
EXEEXT=$(EXEEXT) \
|
EXEEXT=$(EXEEXT) \
|
||||||
PATH=../gpgscm:$(PATH) \
|
PATH=../gpgscm:$(PATH) \
|
||||||
TMP=$(TMP) \
|
|
||||||
srcdir=$(abs_srcdir) \
|
srcdir=$(abs_srcdir) \
|
||||||
objdir=$(abs_top_builddir) \
|
objdir=$(abs_top_builddir) \
|
||||||
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp:$(abs_top_srcdir)/tests/gpgsm
|
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp:$(abs_top_srcdir)/tests/gpgsm
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
"faked-system-time 1008241200")
|
"faked-system-time 1008241200")
|
||||||
(create-file "gpg-agent.conf"
|
(create-file "gpg-agent.conf"
|
||||||
(string-append "pinentry-program " (tool 'pinentry)))
|
(string-append "pinentry-program " (tool 'pinentry)))
|
||||||
|
(start-agent)
|
||||||
(create-file
|
(create-file
|
||||||
"trustlist.txt"
|
"trustlist.txt"
|
||||||
"32100C27173EF6E9C4E9A25D3D69F86D37A4F939"
|
"32100C27173EF6E9C4E9A25D3D69F86D37A4F939"
|
||||||
@ -80,7 +81,6 @@
|
|||||||
"3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E S")
|
"3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E S")
|
||||||
|
|
||||||
(log "Storing private keys")
|
(log "Storing private keys")
|
||||||
(mkdir "private-keys-v1.d" "-rwx")
|
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (name)
|
(lambda (name)
|
||||||
(file-copy (in-srcdir name)
|
(file-copy (in-srcdir name)
|
||||||
|
@ -28,12 +28,9 @@ include $(top_srcdir)/am/cmacros.am
|
|||||||
|
|
||||||
AM_CFLAGS =
|
AM_CFLAGS =
|
||||||
|
|
||||||
TMP ?= /tmp
|
|
||||||
|
|
||||||
TESTS_ENVIRONMENT = GPG_AGENT_INFO= LC_ALL=C \
|
TESTS_ENVIRONMENT = GPG_AGENT_INFO= LC_ALL=C \
|
||||||
EXEEXT=$(EXEEXT) \
|
EXEEXT=$(EXEEXT) \
|
||||||
PATH=../gpgscm:$(PATH) \
|
PATH=../gpgscm:$(PATH) \
|
||||||
TMP=$(TMP) \
|
|
||||||
srcdir=$(abs_srcdir) \
|
srcdir=$(abs_srcdir) \
|
||||||
objdir=$(abs_top_builddir) \
|
objdir=$(abs_top_builddir) \
|
||||||
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/migrations
|
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/migrations
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
(string-append executable (getenv "EXEEXT")))
|
(string-append executable (getenv "EXEEXT")))
|
||||||
|
|
||||||
;; We may not use a relative name for gpg-agent.
|
;; We may not use a relative name for gpg-agent.
|
||||||
|
(define gpgconf (path-join (getenv "objdir") "tools" (qualify "gpgconf")))
|
||||||
(define GPG-AGENT (path-join (getenv "objdir") "agent" (qualify "gpg-agent")))
|
(define GPG-AGENT (path-join (getenv "objdir") "agent" (qualify "gpg-agent")))
|
||||||
(define GPG `(,(path-join (getenv "objdir") "g10" (qualify "gpg"))
|
(define GPG `(,(path-join (getenv "objdir") "g10" (qualify "gpg"))
|
||||||
--no-permission-warning --no-greeting
|
--no-permission-warning --no-greeting
|
||||||
@ -51,4 +52,9 @@
|
|||||||
(info message)
|
(info message)
|
||||||
(untar-armored src-tarball)
|
(untar-armored src-tarball)
|
||||||
(setenv "GNUPGHOME" (getcwd) #t)
|
(setenv "GNUPGHOME" (getcwd) #t)
|
||||||
(test (getcwd))))
|
|
||||||
|
(catch (log "Warning: Creating socket directory failed:" (car *error*))
|
||||||
|
(call-popen `(,gpgconf --create-socketdir) ""))
|
||||||
|
(test (getcwd))
|
||||||
|
(catch (log "Warning: Removing socket directory failed.")
|
||||||
|
(call-popen `(,gpgconf --remove-socketdir) ""))))
|
||||||
|
@ -22,15 +22,6 @@
|
|||||||
(catch (skip "gpgtar not built")
|
(catch (skip "gpgtar not built")
|
||||||
(call-check `(,GPGTAR --help)))
|
(call-check `(,GPGTAR --help)))
|
||||||
|
|
||||||
(define src-tarball (in-srcdir "extended-pkf.tar.asc"))
|
|
||||||
|
|
||||||
(define (setup)
|
|
||||||
(untar-armored src-tarball)
|
|
||||||
(setenv "GNUPGHOME" (getcwd) #t))
|
|
||||||
|
|
||||||
(define (trigger-migration)
|
|
||||||
(call-check `(,@GPG --list-secret-keys)))
|
|
||||||
|
|
||||||
(define (assert-keys-usable)
|
(define (assert-keys-usable)
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (keyid)
|
(lambda (keyid)
|
||||||
@ -38,9 +29,10 @@
|
|||||||
(call-check `(,@GPG --list-secret-keys ,keyid))))
|
(call-check `(,@GPG --list-secret-keys ,keyid))))
|
||||||
'("C40FDECF" "ECABF51D")))
|
'("C40FDECF" "ECABF51D")))
|
||||||
|
|
||||||
(info "Testing the extended private key format ...")
|
(run-test
|
||||||
(with-temporary-working-directory
|
"Testing the extended private key format ..."
|
||||||
(setup)
|
(in-srcdir "extended-pkf.tar.asc")
|
||||||
(assert-keys-usable))
|
(lambda (gpghome)
|
||||||
|
(assert-keys-usable)))
|
||||||
|
|
||||||
;; XXX try changing a key, and check that the format is not changed.
|
;; XXX try changing a key, and check that the format is not changed.
|
||||||
|
@ -22,12 +22,6 @@
|
|||||||
(catch (skip "gpgtar not built")
|
(catch (skip "gpgtar not built")
|
||||||
(call-check `(,GPGTAR --help)))
|
(call-check `(,GPGTAR --help)))
|
||||||
|
|
||||||
(define src-tarball (in-srcdir "from-classic.tar.asc"))
|
|
||||||
|
|
||||||
(define (setup)
|
|
||||||
(untar-armored src-tarball)
|
|
||||||
(setenv "GNUPGHOME" (getcwd) #t))
|
|
||||||
|
|
||||||
(define (trigger-migration)
|
(define (trigger-migration)
|
||||||
(call-check `(,@GPG --list-secret-keys)))
|
(call-check `(,@GPG --list-secret-keys)))
|
||||||
|
|
||||||
@ -41,24 +35,27 @@
|
|||||||
(call-check `(,@GPG --list-secret-keys ,keyid))))
|
(call-check `(,@GPG --list-secret-keys ,keyid))))
|
||||||
'("D74C5F22" "C40FDECF" "ECABF51D")))
|
'("D74C5F22" "C40FDECF" "ECABF51D")))
|
||||||
|
|
||||||
(info "Testing a clean migration ...")
|
(run-test
|
||||||
(with-temporary-working-directory
|
"Testing a clean migration ..."
|
||||||
(setup)
|
(in-srcdir "from-classic.tar.asc")
|
||||||
(trigger-migration)
|
(lambda (gpghome)
|
||||||
(assert-migrated))
|
(trigger-migration)
|
||||||
|
(assert-migrated)))
|
||||||
|
|
||||||
(info "Testing a migration with existing private-keys-v1.d ...")
|
(run-test
|
||||||
(with-temporary-working-directory
|
"Testing a migration with existing private-keys-v1.d ..."
|
||||||
(setup)
|
(in-srcdir "from-classic.tar.asc")
|
||||||
(mkdir "private-keys-v1.d" "-rwx")
|
(lambda (gpghome)
|
||||||
(trigger-migration)
|
(mkdir "private-keys-v1.d" "-rwx")
|
||||||
(assert-migrated))
|
(trigger-migration)
|
||||||
|
(assert-migrated)))
|
||||||
|
|
||||||
(info "Testing a migration with existing but weird private-keys-v1.d ...")
|
(run-test
|
||||||
(with-temporary-working-directory
|
"Testing a migration with existing but weird private-keys-v1.d ..."
|
||||||
(setup)
|
(in-srcdir "from-classic.tar.asc")
|
||||||
(mkdir "private-keys-v1.d" "")
|
(lambda (gpghome)
|
||||||
(trigger-migration)
|
(mkdir "private-keys-v1.d" "")
|
||||||
(assert-migrated))
|
(trigger-migration)
|
||||||
|
(assert-migrated)))
|
||||||
|
|
||||||
;; XXX Check a case where the migration fails.
|
;; XXX Check a case where the migration fails.
|
||||||
|
@ -33,12 +33,9 @@ noinst_PROGRAMS = fake-pinentry
|
|||||||
|
|
||||||
fake_pinentry_SOURCES = fake-pinentry.c
|
fake_pinentry_SOURCES = fake-pinentry.c
|
||||||
|
|
||||||
TMP ?= /tmp
|
|
||||||
|
|
||||||
TESTS_ENVIRONMENT = LC_ALL=C \
|
TESTS_ENVIRONMENT = LC_ALL=C \
|
||||||
EXEEXT=$(EXEEXT) \
|
EXEEXT=$(EXEEXT) \
|
||||||
PATH=../gpgscm:$(PATH) \
|
PATH=../gpgscm:$(PATH) \
|
||||||
TMP=$(TMP) \
|
|
||||||
srcdir=$(abs_srcdir) \
|
srcdir=$(abs_srcdir) \
|
||||||
objdir=$(abs_top_builddir) \
|
objdir=$(abs_top_builddir) \
|
||||||
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp
|
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp
|
||||||
|
@ -30,7 +30,7 @@ This is a bit tricky because one needs to manually set some
|
|||||||
environment variables. We should make that easier. See discussion
|
environment variables. We should make that easier. See discussion
|
||||||
below. From your build directory, do:
|
below. From your build directory, do:
|
||||||
|
|
||||||
obj $ TMP=/tmp srcdir=<path to>/tests/openpgp \
|
obj $ srcdir=<path to>/tests/openpgp \
|
||||||
GPGSCM_PATH=<path to>/tests/gpgscm:<path to>/tests/openpgp \
|
GPGSCM_PATH=<path to>/tests/gpgscm:<path to>/tests/openpgp \
|
||||||
$(pwd)/tests/gpgscm/gpgscm [gpgscm args] \
|
$(pwd)/tests/gpgscm/gpgscm [gpgscm args] \
|
||||||
run-tests.scm [test suite runner args]
|
run-tests.scm [test suite runner args]
|
||||||
|
@ -278,6 +278,15 @@
|
|||||||
;; GnuPG helper.
|
;; GnuPG helper.
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
;; Evaluate a sequence of expressions with the given home directory.
|
||||||
|
(define-macro (with-home-directory gnupghome . expressions)
|
||||||
|
(let ((original-home-directory (gensym)))
|
||||||
|
`(let ((,original-home-directory (getenv "GNUPGHOME")))
|
||||||
|
(dynamic-wind
|
||||||
|
(lambda () (setenv "GNUPGHOME" ,gnupghome #t))
|
||||||
|
(lambda () ,@expressions)
|
||||||
|
(lambda () (setenv "GNUPGHOME" ,original-home-directory #t))))))
|
||||||
|
|
||||||
;; Evaluate a sequence of expressions with an ephemeral home
|
;; Evaluate a sequence of expressions with an ephemeral home
|
||||||
;; directory.
|
;; directory.
|
||||||
(define-macro (with-ephemeral-home-directory . expressions)
|
(define-macro (with-ephemeral-home-directory . expressions)
|
||||||
@ -364,7 +373,6 @@
|
|||||||
|
|
||||||
(define (create-legacy-gpghome)
|
(define (create-legacy-gpghome)
|
||||||
(create-sample-files)
|
(create-sample-files)
|
||||||
(mkdir "private-keys-v1.d" "-rwx")
|
|
||||||
|
|
||||||
(log "Storing private keys")
|
(log "Storing private keys")
|
||||||
(for-each
|
(for-each
|
||||||
@ -434,7 +442,10 @@
|
|||||||
;; Create the socket dir and start the agent.
|
;; Create the socket dir and start the agent.
|
||||||
(define (start-agent)
|
(define (start-agent)
|
||||||
(log "Starting gpg-agent...")
|
(log "Starting gpg-agent...")
|
||||||
(atexit stop-agent)
|
(let ((gnupghome (getenv "GNUPGHOME")))
|
||||||
|
(atexit (lambda ()
|
||||||
|
(with-home-directory gnupghome
|
||||||
|
(stop-agent)))))
|
||||||
(catch (log "Warning: Creating socket directory failed:" (car *error*))
|
(catch (log "Warning: Creating socket directory failed:" (car *error*))
|
||||||
(call-popen `(,(tool 'gpgconf) --create-socketdir) ""))
|
(call-popen `(,(tool 'gpgconf) --create-socketdir) ""))
|
||||||
(call-check `(,(tool 'gpg-connect-agent) --verbose
|
(call-check `(,(tool 'gpg-connect-agent) --verbose
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
(with-ephemeral-home-directory
|
(with-ephemeral-home-directory
|
||||||
(chdir (getenv "GNUPGHOME"))
|
(chdir (getenv "GNUPGHOME"))
|
||||||
(create-gpghome)
|
(create-gpghome)
|
||||||
|
(start-agent)
|
||||||
(create-legacy-gpghome)
|
(create-legacy-gpghome)
|
||||||
(stop-agent)
|
(stop-agent)
|
||||||
(call-check `(,(tool 'gpgtar) --create --output ,(cadr *args*) ".")))
|
(call-check `(,(tool 'gpgtar) --create --output ,(cadr *args*) ".")))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user