Return a fatal error if application data is encountered during shutdown
[openssl.git] / test / recipes / 80-test_ca.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9
10 use strict;
11 use warnings;
12
13 use POSIX;
14 use File::Path 2.00 qw/rmtree/;
15 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file/;
16 use OpenSSL::Test::Utils;
17
18 setup("test_ca");
19
20 $ENV{OPENSSL} = cmdstr(app(["openssl"]), display => 1);
21 my $std_openssl_cnf =
22     srctop_file("apps", $^O eq "VMS" ? "openssl-vms.cnf" : "openssl.cnf");
23
24 rmtree("demoCA", { safe => 0 });
25
26 plan tests => 5;
27  SKIP: {
28      $ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "CAss.cnf").'"';
29      skip "failed creating CA structure", 4
30          if !ok(run(perlapp(["CA.pl","-newca"], stdin => undef)),
31                 'creating CA structure');
32
33      $ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "Uss.cnf").'"';
34      skip "failed creating new certificate request", 3
35          if !ok(run(perlapp(["CA.pl","-newreq"])),
36                 'creating certificate request');
37
38      $ENV{OPENSSL_CONFIG} = '-rand_serial -config "'.$std_openssl_cnf.'"';
39      skip "failed to sign certificate request", 2
40          if !is(yes(cmdstr(perlapp(["CA.pl", "-sign"]))), 0,
41                 'signing certificate request');
42
43      ok(run(perlapp(["CA.pl", "-verify", "newcert.pem"])),
44         'verifying new certificate');
45
46      skip "CT not configured, can't use -precert", 1
47          if disabled("ct");
48
49      $ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "Uss.cnf").'"';
50      ok(run(perlapp(["CA.pl", "-precert"], stderr => undef)),
51         'creating new pre-certificate');
52 }
53
54
55 rmtree("demoCA", { safe => 0 });
56 unlink "newcert.pem", "newreq.pem", "newkey.pem";
57
58
59 sub yes {
60     my $cntr = 10;
61     open(PIPE, "|-", join(" ",@_));
62     local $SIG{PIPE} = "IGNORE";
63     1 while $cntr-- > 0 && print PIPE "y\n";
64     close PIPE;
65     return 0;
66 }
67