Adapt some test recipes to the newer cmdstr()
[openssl.git] / test / recipes / 80-test_ca.t
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use POSIX;
7 use File::Path 2.00 qw/rmtree/;
8 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file/;
9
10 setup("test_ca");
11
12 $ENV{OPENSSL} = cmdstr(app(["openssl"]), display => 1);
13 my $std_openssl_cnf =
14     srctop_file("apps", $^O eq "VMS" ? "openssl-vms.cnf" : "openssl.cnf");
15
16 rmtree("demoCA", { safe => 0 });
17
18 plan tests => 4;
19  SKIP: {
20      $ENV{OPENSSL_CONFIG} = "-config ".srctop_file("test", "CAss.cnf");
21      skip "failed creating CA structure", 3
22          if !ok(run(perlapp(["CA.pl","-newca"], stdin => undef)),
23                 'creating CA structure');
24
25      $ENV{OPENSSL_CONFIG} = "-config ".srctop_file("test", "Uss.cnf");
26      skip "failed creating new certificate request", 2
27          if !ok(run(perlapp(["CA.pl","-newreq"])),
28                 'creating CA structure');
29
30      $ENV{OPENSSL_CONFIG} = "-config ".$std_openssl_cnf;
31      skip "failed to sign certificate request", 1
32          if !is(yes(cmdstr(perlapp(["CA.pl", "-sign"]))), 0,
33                 'signing certificate request');
34
35      ok(run(perlapp(["CA.pl", "-verify", "newcert.pem"])),
36         'verifying new certificate');
37 }
38
39
40 rmtree("demoCA", { safe => 0 });
41 unlink "newcert.pem", "newreq.pem";
42
43
44 sub yes {
45     my $cntr = 10;
46     open(PIPE, "|-", join(" ",@_));
47     local $SIG{PIPE} = "IGNORE";
48     1 while $cntr-- > 0 && print PIPE "y\n";
49     close PIPE;
50     return 0;
51 }
52