1
0
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:
Justus Winter 2017-03-06 17:16:41 +01:00
parent 171e4314eb
commit 7e19786a5d
No known key found for this signature in database
GPG Key ID: DD1A52F9DA8C9020
13 changed files with 56 additions and 61 deletions

View File

@ -28,12 +28,9 @@ include $(top_srcdir)/am/cmacros.am
AM_CFLAGS =
TMP ?= /tmp
TESTS_ENVIRONMENT = LC_ALL=C \
EXEEXT=$(EXEEXT) \
PATH=../gpgscm:$(PATH) \
TMP=$(TMP) \
srcdir=$(abs_srcdir) \
objdir=$(abs_top_builddir) \
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp:$(abs_top_srcdir)/tests/gpgme

View File

@ -54,7 +54,8 @@
(create-file
"gpg-agent.conf"
(string-append "pinentry-program " (tool 'pinentry)))
(mkdir "private-keys-v1.d" "-rwx")
(start-agent)
(log "Storing private keys")
(for-each

View File

@ -268,14 +268,13 @@
;; Make a temporary directory. If arguments are given, they are
;; joined using path-join, and must end in a component ending in
;; "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)
(_mkdtemp (if (null? components)
(path-join (getenv "TMP")
(string-append "gpgscm-" (get-isotime) "-"
(basename-suffix *scriptname* ".scm")
"-XXXXXX"))
(apply path-join components))))
(canonical-path (_mkdtemp (if (null? components)
(string-append "gpgscm-" (get-isotime) "-"
(basename-suffix *scriptname* ".scm")
"-XXXXXX")
(apply path-join components)))))
(define-macro (with-temporary-working-directory . expressions)
(let ((tmp-sym (gensym)))

View File

@ -28,12 +28,9 @@ include $(top_srcdir)/am/cmacros.am
AM_CFLAGS =
TMP ?= /tmp
TESTS_ENVIRONMENT = LC_ALL=C \
EXEEXT=$(EXEEXT) \
PATH=../gpgscm:$(PATH) \
TMP=$(TMP) \
srcdir=$(abs_srcdir) \
objdir=$(abs_top_builddir) \
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp:$(abs_top_srcdir)/tests/gpgsm

View File

@ -73,6 +73,7 @@
"faked-system-time 1008241200")
(create-file "gpg-agent.conf"
(string-append "pinentry-program " (tool 'pinentry)))
(start-agent)
(create-file
"trustlist.txt"
"32100C27173EF6E9C4E9A25D3D69F86D37A4F939"
@ -80,7 +81,6 @@
"3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E S")
(log "Storing private keys")
(mkdir "private-keys-v1.d" "-rwx")
(for-each
(lambda (name)
(file-copy (in-srcdir name)

View File

@ -28,12 +28,9 @@ include $(top_srcdir)/am/cmacros.am
AM_CFLAGS =
TMP ?= /tmp
TESTS_ENVIRONMENT = GPG_AGENT_INFO= LC_ALL=C \
EXEEXT=$(EXEEXT) \
PATH=../gpgscm:$(PATH) \
TMP=$(TMP) \
srcdir=$(abs_srcdir) \
objdir=$(abs_top_builddir) \
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/migrations

View File

@ -26,6 +26,7 @@
(string-append executable (getenv "EXEEXT")))
;; 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 `(,(path-join (getenv "objdir") "g10" (qualify "gpg"))
--no-permission-warning --no-greeting
@ -51,4 +52,9 @@
(info message)
(untar-armored src-tarball)
(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) ""))))

View File

@ -22,15 +22,6 @@
(catch (skip "gpgtar not built")
(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)
(for-each
(lambda (keyid)
@ -38,9 +29,10 @@
(call-check `(,@GPG --list-secret-keys ,keyid))))
'("C40FDECF" "ECABF51D")))
(info "Testing the extended private key format ...")
(with-temporary-working-directory
(setup)
(assert-keys-usable))
(run-test
"Testing the extended private key format ..."
(in-srcdir "extended-pkf.tar.asc")
(lambda (gpghome)
(assert-keys-usable)))
;; XXX try changing a key, and check that the format is not changed.

View File

@ -22,12 +22,6 @@
(catch (skip "gpgtar not built")
(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)
(call-check `(,@GPG --list-secret-keys)))
@ -41,24 +35,27 @@
(call-check `(,@GPG --list-secret-keys ,keyid))))
'("D74C5F22" "C40FDECF" "ECABF51D")))
(info "Testing a clean migration ...")
(with-temporary-working-directory
(setup)
(trigger-migration)
(assert-migrated))
(run-test
"Testing a clean migration ..."
(in-srcdir "from-classic.tar.asc")
(lambda (gpghome)
(trigger-migration)
(assert-migrated)))
(info "Testing a migration with existing private-keys-v1.d ...")
(with-temporary-working-directory
(setup)
(mkdir "private-keys-v1.d" "-rwx")
(trigger-migration)
(assert-migrated))
(run-test
"Testing a migration with existing private-keys-v1.d ..."
(in-srcdir "from-classic.tar.asc")
(lambda (gpghome)
(mkdir "private-keys-v1.d" "-rwx")
(trigger-migration)
(assert-migrated)))
(info "Testing a migration with existing but weird private-keys-v1.d ...")
(with-temporary-working-directory
(setup)
(mkdir "private-keys-v1.d" "")
(trigger-migration)
(assert-migrated))
(run-test
"Testing a migration with existing but weird private-keys-v1.d ..."
(in-srcdir "from-classic.tar.asc")
(lambda (gpghome)
(mkdir "private-keys-v1.d" "")
(trigger-migration)
(assert-migrated)))
;; XXX Check a case where the migration fails.

View File

@ -33,12 +33,9 @@ noinst_PROGRAMS = fake-pinentry
fake_pinentry_SOURCES = fake-pinentry.c
TMP ?= /tmp
TESTS_ENVIRONMENT = LC_ALL=C \
EXEEXT=$(EXEEXT) \
PATH=../gpgscm:$(PATH) \
TMP=$(TMP) \
srcdir=$(abs_srcdir) \
objdir=$(abs_top_builddir) \
GPGSCM_PATH=$(abs_top_srcdir)/tests/gpgscm:$(abs_top_srcdir)/tests/openpgp

View File

@ -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
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 \
$(pwd)/tests/gpgscm/gpgscm [gpgscm args] \
run-tests.scm [test suite runner args]

View File

@ -278,6 +278,15 @@
;; 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
;; directory.
(define-macro (with-ephemeral-home-directory . expressions)
@ -364,7 +373,6 @@
(define (create-legacy-gpghome)
(create-sample-files)
(mkdir "private-keys-v1.d" "-rwx")
(log "Storing private keys")
(for-each
@ -434,7 +442,10 @@
;; Create the socket dir and start the agent.
(define (start-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*))
(call-popen `(,(tool 'gpgconf) --create-socketdir) ""))
(call-check `(,(tool 'gpg-connect-agent) --verbose

View File

@ -25,6 +25,7 @@
(with-ephemeral-home-directory
(chdir (getenv "GNUPGHOME"))
(create-gpghome)
(start-agent)
(create-legacy-gpghome)
(stop-agent)
(call-check `(,(tool 'gpgtar) --create --output ,(cadr *args*) ".")))