Add SM2 signature and ECIES schemes
[openssl.git] / test / recipes / 15-test_out_option.t
1 #! /usr/bin/env perl
2 # Copyright 2018 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 File::Spec;
14 use OpenSSL::Test qw/:DEFAULT srctop_file/;
15 use OpenSSL::Test::Utils;
16
17 setup("test_out_option");
18
19 plan skip_all => "'-out' option tests are not available on Windows"
20     if $^O eq 'MSWin32';
21
22 plan tests => 11;
23
24 # The following patterns should be tested:
25 #
26 # path        dirname
27 # /usr/       /
28 # /           /
29 # .           .
30 # ..          .
31
32 test_illegal_path('/usr/');
33 test_illegal_path('/');
34 test_illegal_path('./');
35 test_illegal_path('../');
36
37 # Test for trying to create a file in a non-exist directory
38 my @chars = ("A".."Z", "a".."z", "0".."9");
39 my $rand_path = "";
40 $rand_path .= $chars[rand @chars] for 1..32;
41 $rand_path .= "/test.pem";
42
43 test_illegal_path($rand_path);
44 test_legal_path('test.pem');
45 unlink 'test.pem';
46
47 sub test_illegal_path {
48     my $path = File::Spec->canonpath($_[0]);
49
50     my $start = time();
51     ok(!run(app([ 'openssl', 'genrsa', '-out', $path, '16384'])), "invalid output path: $path");
52     my $end = time();
53     # The above process should exit in 2 seconds if the path is not valid
54     ok($end - $start < 2, "check time consumed");
55 }
56
57 sub test_legal_path {
58     my $path = File::Spec->canonpath($_[0]);
59
60     ok(run(app([ 'openssl', 'genrsa', '-out', $path, '2048'])), "valid output path: $path");
61 }