Skip to content
Snippets Groups Projects
Commit 19772971 authored by Daniel Kahn Gillmor's avatar Daniel Kahn Gillmor
Browse files

Use temporary, short-path GNUPGHOME for test suites (Closes: #861591)

parent 2caa7ce8
No related branches found
No related tags found
No related merge requests found
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Date: Thu, 25 May 2017 16:07:45 -0400
Subject: Kill any GnuPG agent before and after the test suite.
This helps to ensure that the test suite daemon is started fresh at
every test suite run. And it also avoids leaving a daemon running
after the test suite, assuming the test suite manages to reach the
end.
This is considered a reasonable practice by upstream.
---
t/000_setup.t | 3 +++
t/zzz_cleanup.t | 2 ++
2 files changed, 5 insertions(+)
diff --git a/t/000_setup.t b/t/000_setup.t
index b183241..4dc4329 100644
--- a/t/000_setup.t
+++ b/t/000_setup.t
@@ -17,6 +17,9 @@ TEST
$agentconf->write("pinentry-program " . getcwd() . "/test/fake-pinentry.pl\n");
$agentconf->close();
copy('test/gpg.conf', 'test/gnupghome/gpg.conf');
+ # reset the state of any long-lived gpg-agent, ignoring errors:
+ system('gpgconf', '--homedir=test/gnupghome', '--quiet', '--kill', 'gpg-agent');
+
reset_handles();
my $pid = $gnupg->import_keys(command_args => [ 'test/public_keys.pgp', 'test/secret_keys.pgp', 'test/new_secret.pgp' ],
diff --git a/t/zzz_cleanup.t b/t/zzz_cleanup.t
index 5c03a72..eea3a48 100644
--- a/t/zzz_cleanup.t
+++ b/t/zzz_cleanup.t
@@ -12,6 +12,8 @@ use File::Path qw (remove_tree);
TEST
{
my $err = [];
+ # kill off any long-lived gpg-agent, ignoring errors:
+ system('gpgconf', '--homedir=test/gnupghome', '--quiet', '--kill', 'gpg-agent');
remove_tree('test/gnupghome', {error => \$err});
return ! @$err;
};
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Date: Fri, 26 May 2017 09:51:40 -0400
Subject: Use a short temporary homedir during the test suite
This avoids problems with the length of the path to the homedir as
compared to the size limits of sockaddr_un.sun_path, particularly on
systems where /run/user/$(id -u) is not present or available (such as
many minimalist build environments).
---
t/000_setup.t | 9 +++++----
t/MyTestSpecific.pm | 18 +++++++++++++++++-
t/list_secret_keys.t | 3 ++-
t/zzz_cleanup.t | 6 ++++--
4 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/t/000_setup.t b/t/000_setup.t
index 4dc4329..82d7005 100644
--- a/t/000_setup.t
+++ b/t/000_setup.t
@@ -12,13 +12,14 @@ use File::Copy;
TEST
{
- make_path('test/gnupghome', { mode => 0700 });
- my $agentconf = IO::File->new( "> test/gnupghome/gpg-agent.conf" );
+ my $homedir = $gnupg->options->homedir();
+ make_path($homedir, { mode => 0700 });
+ my $agentconf = IO::File->new( "> " . $homedir . "/gpg-agent.conf" );
$agentconf->write("pinentry-program " . getcwd() . "/test/fake-pinentry.pl\n");
$agentconf->close();
- copy('test/gpg.conf', 'test/gnupghome/gpg.conf');
+ copy('test/gpg.conf', $homedir . '/gpg.conf');
# reset the state of any long-lived gpg-agent, ignoring errors:
- system('gpgconf', '--homedir=test/gnupghome', '--quiet', '--kill', 'gpg-agent');
+ system('gpgconf', '--homedir', $homedir, '--quiet', '--kill', 'gpg-agent');
reset_handles();
diff --git a/t/MyTestSpecific.pm b/t/MyTestSpecific.pm
index e513c25..809d55c 100644
--- a/t/MyTestSpecific.pm
+++ b/t/MyTestSpecific.pm
@@ -22,6 +22,7 @@ use IO::Seekable;
use File::Compare;
use Exporter;
use Class::Struct;
+use File::Temp qw (tempdir);
use GnuPG::Interface;
use GnuPG::Handles;
@@ -40,10 +41,25 @@ use vars qw( @ISA @EXPORT
$gnupg = GnuPG::Interface->new( passphrase => 'test' );
+
+my $homedir;
+if (-f "test/gnupghome") {
+ my $record = IO::File->new( "< test/gnupghome" );
+ $homedir = <$record>;
+ $record->close();
+} else {
+ $homedir = tempdir( DIR => '/tmp');
+ my $record = IO::File->new( "> test/gnupghome" );
+ $record->write($homedir);
+ $record->close();
+}
+
my @version = split('\.', $gnupg->version());
$gpg_is_modern = ($version[0] > 2 || ($version[0] == 2 && $version[1] >= 1));
-$gnupg->options->hash_init( homedir => 'test/gnupghome',
+
+
+$gnupg->options->hash_init( homedir => $homedir,
armor => 1,
meta_interactive => 0,
meta_signing_key_id => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C',
diff --git a/t/list_secret_keys.t b/t/list_secret_keys.t
index 7040c38..d1e3f30 100644
--- a/t/list_secret_keys.t
+++ b/t/list_secret_keys.t
@@ -23,8 +23,9 @@ TEST
$outfile = 'test/secret-keys/1.out';
my $out = IO::File->new( "> $outfile" )
or die "cannot open $outfile for writing: $ERRNO";
+ my $modern_pubring_line = $gnupg->options->homedir() . "/pubring.kbx\n";
while (<$stdout>) {
- if ($gpg_is_modern && /^\/.*\/test\/gnupghome\/pubring.kbx$/) {
+ if ($gpg_is_modern && ($_ eq $modern_pubring_line)) {
$out->print("test/gnupghome/pubring.kbx\n");
} elsif ($gpg_is_modern && /^--*$/) {
$out->print("--------------------------\n");
diff --git a/t/zzz_cleanup.t b/t/zzz_cleanup.t
index eea3a48..c3ec16f 100644
--- a/t/zzz_cleanup.t
+++ b/t/zzz_cleanup.t
@@ -11,9 +11,11 @@ use File::Path qw (remove_tree);
# this is actually no test, just cleanup.
TEST
{
+ my $homedir = $gnupg->options->homedir();
my $err = [];
# kill off any long-lived gpg-agent, ignoring errors:
- system('gpgconf', '--homedir=test/gnupghome', '--quiet', '--kill', 'gpg-agent');
- remove_tree('test/gnupghome', {error => \$err});
+ system('gpgconf', '--homedir', $homedir, '--quiet', '--kill', 'gpg-agent');
+ remove_tree($homedir, {error => \$err});
+ unlink('test/gnupghome');
return ! @$err;
};
......@@ -14,3 +14,5 @@
0014-fix-spelling-s-convience-convenience.patch
0015-added-new-secret-key-with-different-passphrase.patch
0016-Test-use-of-gpg-without-explicit-passphrase-agent-pi.patch
0017-Kill-any-GnuPG-agent-before-and-after-the-test-suite.patch
0018-Use-a-short-temporary-homedir-during-the-test-suite.patch
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment