summaryrefslogtreecommitdiff
path: root/t/000_setup.t
blob: 8e3235a88d01863abcbefd6d15d609a3510b3b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl -w

use strict;
use English qw( -no_match_vars );

use lib './t';
use MyTest;
use MyTestSpecific;
use Cwd;
use File::Path qw (make_path);
use File::Copy;

TEST
{
    my $homedir = $gnupg->options->homedir();
    make_path($homedir, { mode => 0700 });

    copy('test/gpg.conf', $homedir . '/gpg.conf');

    if ($gnupg->cmp_version($gnupg->version, '2.2') >= 0) {
        my $agentconf = IO::File->new( "> " . $homedir . "/gpg-agent.conf" );
        # Classic gpg can't use loopback pinentry programs like fake-pinentry.pl.
        $agentconf->write(
            "allow-preset-passphrase\n".
                "allow-loopback-pinentry\n".
                "pinentry-program " . getcwd() . "/test/fake-pinentry.pl\n"
            );
        $agentconf->close();

        my $error = system("gpg-connect-agent", "--homedir", "$homedir", '/bye');
        if ($error) {
            warn "gpg-connect-agent returned error : $error";
        }

        $error = system('gpg-connect-agent', "--homedir", "$homedir", 'reloadagent', '/bye');
        if ($error) {
            warn "gpg-connect-agent returned error : $error";
        }

        $error = system("gpg-agent", '--homedir', "$homedir");
        if ($error) {
            warn "gpg-agent returned error : $error";
        }

    }
    reset_handles();

    my $pid = $gnupg->import_keys(command_args => [ 'test/public_keys.pgp', 'test/secret_keys.pgp', 'test/new_secret.pgp' ],
                                  options => [ 'batch'],
                                  handles => $handles);
    waitpid $pid, 0;

    return $CHILD_ERROR == 0;
};