Sanitize tests environment.
authorDamien Goutte-Gattat <dgouttegattat@incenp.org>
Wed, 12 Jul 2017 07:48:19 +0000 (09:48 +0200)
committerDamien Goutte-Gattat <dgouttegattat@incenp.org>
Wed, 12 Jul 2017 07:48:19 +0000 (09:48 +0200)
* tests/Makefile.am (clean-local): New target.
(TESTS_ENVIRONMENT): New variable.
(EXTRA_DIST): New variable.
* tests/clean-socketdir: New file.
--

We should avoid using the current user's GNUPGHOME directory
(and any pre-existing agent) when running the tests.

Then, since running the tests imply spawning an agent, we should
wipe out the corresponding socket directory upon 'make clean'.
This will also terminate the agent.

GnuPG-bug-id: 3274
Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
tests/Makefile.am
tests/clean-socketdir [new file with mode: 0755]

index 6c19071..311303d 100644 (file)
@@ -37,5 +37,12 @@ TESTS = t-link t-getfunctionlist t-initialize t-getinfo t-getslotlist \
 
 noinst_PROGRAMS = $(TESTS)
 
+EXTRA_DIST = clean-socketdir
+
+TESTS_ENVIRONMENT = GNUPGHOME=`/bin/pwd` GPG_AGENT_INFO= LC_ALL=C
+
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src
 LDADD = ../src/scute.la
+
+clean-local:
+       $(TESTS_ENVIRONMENT) $(srcdir)/clean-socketdir
diff --git a/tests/clean-socketdir b/tests/clean-socketdir
new file mode 100755 (executable)
index 0000000..32ffdc6
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# We do the clean-up only when the tests are run with GNUPGHOME
+# set to the tests directory (which is the default). If the user
+# saw fit to override TESTS_ENVIRONMENT to use another home, we
+# must assume she knows what she is doing.
+if [ "$GNUPGHOME" = "`/bin/pwd`" ]; then
+    socketdir=`gpgconf --list-dirs socketdir`
+    if [ -d "$socketdir" ]; then
+        rm -f $socketdir/S.*
+        rmdir $socketdir || true
+    fi
+
+    if [ -d private-keys-v1.d ]; then
+        rmdir private-keys-v1.d
+    fi
+fi