]>
Commit | Line | Data |
---|---|---|
c7702e07 PY |
1 | #! /usr/bin/env perl |
2 | # Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. | |
3 | # | |
909f1a2e | 4 | # Licensed under the Apache License 2.0 (the "License"). You may not use |
c7702e07 PY |
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 | ||
6fb7b089 | 19 | plan tests => 4; |
c7702e07 | 20 | |
6fb7b089 RL |
21 | # Test 1 |
22 | SKIP: { | |
23 | # Paths that should generate failure when trying to write to them. | |
24 | # Directories are a safe bet for failure on most platforms. | |
25 | # Notably, this isn't true on OpenVMS, as a default file name is | |
26 | # appended under the hood when trying to "write" to a directory spec. | |
27 | # From observation, that file is '.' (i.e. a file with no file name | |
28 | # and no extension), so '[]' gets translated to '[].' | |
29 | skip 'Directories become writable files on OpenVMS', 1 if $^O eq 'VMS'; | |
c7702e07 | 30 | |
6fb7b089 RL |
31 | # Note that directories must end with a slash here, because of how |
32 | # File::Spec massages them into directory specs on some platforms. | |
33 | my $path = File::Spec->canonpath('./'); | |
34 | ok(!run(app([ 'openssl', 'rand', '-out', $path, '1'])), | |
35 | "invalid output path: $path"); | |
36 | } | |
c7702e07 | 37 | |
6fb7b089 RL |
38 | # Test 2 |
39 | { | |
40 | my $path = File::Spec->canonpath('randomname.bin'); | |
41 | ok(run(app([ 'openssl', 'rand', '-out', $path, '1'])), | |
42 | "valid output path: $path"); | |
c7702e07 PY |
43 | } |
44 | ||
6fb7b089 RL |
45 | # Test 3 |
46 | { | |
47 | # Test for trying to create a file in a non-exist directory | |
48 | my $rand_path = ""; | |
49 | do { | |
50 | my @chars = ("A".."Z", "a".."z", "0".."9"); | |
51 | $rand_path .= $chars[rand @chars] for 1..32; | |
52 | } while (-d File::Spec->catdir('.', $rand_path)); | |
53 | $rand_path .= "/randomname.bin"; | |
39e32be1 | 54 | |
6fb7b089 | 55 | my $path = File::Spec->canonpath($rand_path); |
39e32be1 RL |
56 | ok(!run(app([ 'openssl', 'rand', '-out', $path, '1'])), |
57 | "invalid output path: $path"); | |
58 | } | |
6fb7b089 RL |
59 | |
60 | # Test 4 | |
61 | SKIP: { | |
62 | skip "It's not safe to use perl's idea of the NULL device in an explicitly cross compiled build", 1 | |
63 | unless (config('CROSS_COMPILE') // '') eq ''; | |
64 | ||
65 | my $path = File::Spec->canonpath(File::Spec->devnull()); | |
39e32be1 RL |
66 | ok(run(app([ 'openssl', 'rand', '-out', $path, '1'])), |
67 | "valid output path: $path"); | |
68 | } | |
c7702e07 | 69 | |
6fb7b089 | 70 | # Cleanup |
39e32be1 RL |
71 | END { |
72 | unlink 'randomname.bin' if -f 'randomname.bin'; | |
c7702e07 | 73 | } |