VMS perl doesn't implement fork(), so don't run the TLSProxy tests there
[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::Spec::Functions qw/splitdir curdir catfile devnull/;
8 use File::Path 2.00 qw/remove_tree/;
9 use OpenSSL::Test qw/:DEFAULT cmdstr top_file quotify/;
10
11 setup("test_ca");
12
13 my $perl = $^X;
14 $ENV{OPENSSL} = cmdstr(app(["openssl"]));
15 my $CA_pl = top_file("apps", "CA.pl");
16 my $std_openssl_cnf = $^O eq "VMS"
17     ? top_file("apps", "openssl-vms.cnf") : top_file("apps", "openssl.cnf");
18
19 ($perl) = quotify($perl) unless $^O eq "VMS"; # never quotify a command on VMS. Ever!
20
21 remove_tree("demoCA", { safe => 0 });
22
23 plan tests => 4;
24  SKIP: {
25      $ENV{OPENSSL_CONFIG} = "-config ".top_file("test", "CAss.cnf");
26      skip "failed creating CA structure", 3
27          if !is(system("$perl ".$CA_pl." -newca < ".devnull()." 2>&1"), 0,
28                 'creating CA structure');
29
30      $ENV{OPENSSL_CONFIG} = "-config ".top_file("test", "Uss.cnf");
31      skip "failed creating new certificate request", 2
32          if !is(system("$perl ".$CA_pl." -newreq 2>&1"), 0,
33                 'creating new certificate request');
34
35      $ENV{OPENSSL_CONFIG} = "-config ".$std_openssl_cnf;
36      skip "failed to sign certificate request", 1
37          if !is(yes("$perl ".$CA_pl." -sign 2>&1"), 0,
38                 'signing certificate request');
39
40      is(system("$perl ".$CA_pl." -verify newcert.pem 2>&1"), 0,
41         'verifying new certificate');
42 }
43
44
45 remove_tree("demoCA", { safe => 0 });
46 unlink "newcert.pem", "newreq.pem";
47
48
49 sub yes {
50     my $cntr = 10;
51     open(PIPE, "|-", join(" ",@_));
52     local $SIG{PIPE} = "IGNORE";
53     1 while $cntr-- > 0 && print PIPE "y\n";
54     close PIPE;
55     return 0;
56 }