2 # Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
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
14 use OpenSSL::Test qw/:DEFAULT srctop_file/;
15 use OpenSSL::Test::Utils;
17 setup("test_out_option");
19 plan skip_all => "'-out' option tests are not available on Windows"
24 # The following patterns should be tested:
32 test_illegal_path('/usr/');
33 test_illegal_path('/');
34 test_illegal_path('./');
35 test_illegal_path('../');
37 # Test for trying to create a file in a non-exist directory
38 my @chars = ("A".."Z", "a".."z", "0".."9");
40 $rand_path .= $chars[rand @chars] for 1..32;
41 $rand_path .= "/test.pem";
43 test_illegal_path($rand_path);
44 test_legal_path('test.pem');
47 sub test_illegal_path {
48 my $path = File::Spec->canonpath($_[0]);
51 ok(!run(app([ 'openssl', 'genrsa', '-out', $path, '16384'])), "invalid output path: $path");
53 # The above process should exit in 2 seconds if the path is not valid
54 ok($end - $start < 2, "check time consumed");
58 my $path = File::Spec->canonpath($_[0]);
60 ok(run(app([ 'openssl', 'genrsa', '-out', $path, '2048'])), "valid output path: $path");