summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2018-04-20 08:36:18 +0200
committerRichard Levitte <levitte@openssl.org>2018-04-25 11:44:25 +0200
commit39e32be1ccc527036e0a52c3cf64a40faf28ab9d (patch)
treef0302ea1916ecfe745bbd8811be23a53cb7fde3b
parent22f0c72b928604cc42c16bf59b9d31f92e4c4be9 (diff)
test/recipes/15-test_out_option.t: refine tests
Test writing to the null device. This should be successful. Also, refactor so the planned number of tests is calculated. Reviewed-by: Andy Polyakov <appro@openssl.org> (Merged from https://github.com/openssl/openssl/pull/6033)
-rw-r--r--test/recipes/15-test_out_option.t71
1 files changed, 37 insertions, 34 deletions
diff --git a/test/recipes/15-test_out_option.t b/test/recipes/15-test_out_option.t
index f50001d48b..e1129ccce8 100644
--- a/test/recipes/15-test_out_option.t
+++ b/test/recipes/15-test_out_option.t
@@ -16,46 +16,49 @@ use OpenSSL::Test::Utils;
setup("test_out_option");
-plan skip_all => "'-out' option tests are not available on Windows"
- if $^O eq 'MSWin32';
-
-plan tests => 11;
-
-# The following patterns should be tested:
-#
-# path dirname
-# /usr/ /
-# / /
-# . .
-# .. .
-
-test_illegal_path('/usr/');
-test_illegal_path('/');
-test_illegal_path('./');
-test_illegal_path('../');
+# Paths that should generate failure when trying to write to them.
+# Directories are a safe bet for failure on all platforms.
+# Note that directories must end with a slash here, because of how
+# File::Spec massages them into directory specs on some platforms.
+my @failure_paths = (
+ './',
+ );
+my @success_paths = (
+ 'randomname.bin'
+ );
# Test for trying to create a file in a non-exist directory
-my @chars = ("A".."Z", "a".."z", "0".."9");
my $rand_path = "";
-$rand_path .= $chars[rand @chars] for 1..32;
-$rand_path .= "/test.pem";
+do {
+ my @chars = ("A".."Z", "a".."z", "0".."9");
+ $rand_path .= $chars[rand @chars] for 1..32;
+} while (-d File::Spec->catdir('.', $rand_path));
+$rand_path .= "/randomname.bin";
-test_illegal_path($rand_path);
-test_legal_path('test.pem');
-unlink 'test.pem';
+push @failure_paths, $rand_path;
-sub test_illegal_path {
- my $path = File::Spec->canonpath($_[0]);
-
- my $start = time();
- ok(!run(app([ 'openssl', 'genrsa', '-out', $path, '16384'])), "invalid output path: $path");
- my $end = time();
- # The above process should exit in 2 seconds if the path is not valid
- ok($end - $start < 2, "check time consumed");
+# All explicit cross compilations run a risk of failing this, because the
+# null device provided by perl might not match what the cross compiled
+# application expects to see as a null device. Therefore, we skip the check
+# of outputing to the null device if the cross compile prefix is set.
+if ((config('CROSS_COMPILE') // '') eq '') {
+ # Check that we can write to the NULL device
+ push @success_paths, File::Spec->devnull();
}
-sub test_legal_path {
- my $path = File::Spec->canonpath($_[0]);
+plan tests => scalar @failure_paths + scalar @success_paths;
+
+foreach (@failure_paths) {
+ my $path = File::Spec->canonpath($_);
+ ok(!run(app([ 'openssl', 'rand', '-out', $path, '1'])),
+ "invalid output path: $path");
+}
+foreach (@success_paths) {
+ my $path = File::Spec->canonpath($_);
+ ok(run(app([ 'openssl', 'rand', '-out', $path, '1'])),
+ "valid output path: $path");
+}
- ok(run(app([ 'openssl', 'genrsa', '-out', $path, '2048'])), "valid output path: $path");
+END {
+ unlink 'randomname.bin' if -f 'randomname.bin';
}