GH753: More spelling fix
[openssl.git] / test / recipes / 40-test_rehash.t
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use File::Spec::Functions;
7 use File::Copy;
8 use File::Basename;
9 use OpenSSL::Test qw/:DEFAULT bldtop_file/;
10
11 setup("test_rehash");
12
13 #If "openssl rehash -help" fails it's most likely because we're on a platform
14 #that doesn't support the rehash command (e.g. Windows)
15 plan skip_all => "test_rehash is not available on this platform"
16     unless run(app(["openssl", "rehash", "-help"]));
17
18 plan tests => 5;
19
20 indir "rehash.$$" => sub {
21     prepare();
22     ok(run(app(["openssl", "rehash", curdir()])),
23        'Testing normal rehash operations');
24 }, create => 1, cleanup => 1;
25
26 indir "rehash.$$" => sub {
27     prepare(sub { chmod 400, $_ foreach (@_); });
28     ok(run(app(["openssl", "rehash", curdir()])),
29        'Testing rehash operations on readonly files');
30 }, create => 1, cleanup => 1;
31
32 indir "rehash.$$" => sub {
33     ok(run(app(["openssl", "rehash", curdir()])),
34        'Testing rehash operations on empty directory');
35 }, create => 1, cleanup => 1;
36
37 indir "rehash.$$" => sub {
38     prepare();
39     chmod 0500, curdir();
40   SKIP: {
41       if (!ok(!open(FOO, ">unwritable.txt"),
42               "Testing that we aren't running as a privileged user, such as root")) {
43           close FOO;
44           skip "It's pointless to run the next test as root", 1;
45       }
46       isnt(run(app(["openssl", "rehash", curdir()])), 1,
47            'Testing rehash operations on readonly directory');
48     }
49     chmod 0700, curdir();       # make it writable again, so cleanup works
50 }, create => 1, cleanup => 1;
51
52 sub prepare {
53     my @sourcefiles =
54         sort map { glob(bldtop_file('certs', 'demo', "*.$_")) } ('pem',
55                                                               'crt',
56                                                               'cer',
57                                                               'crl');
58     my @destfiles = ();
59     foreach (@sourcefiles) {
60         copy($_, curdir());
61         push @destfiles, catfile(curdir(), basename($_));
62     }
63     foreach (@_) {
64         die "Internal error, argument is not CODE"
65             unless (ref($_) eq 'CODE');
66         $_->(@destfiles);
67     }
68 }