]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/40-test_rehash.t
Add a simple test for the new rehash command
[thirdparty/openssl.git] / test / recipes / 40-test_rehash.t
CommitLineData
84d90cf3
RL
1#! /usr/bin/perl
2
3use strict;
4use warnings;
5
6use File::Spec::Functions;
7use File::Copy;
8use File::Basename;
9use OpenSSL::Test qw/:DEFAULT top_file/;
10
11setup("test_rehash");
12
13plan tests => 4;
14
15indir "rehash.$$" => sub {
16 prepare();
17 ok(run(app(["openssl", "rehash", curdir()])),
18 'Testing normal rehash operations');
19}, create => 1, cleanup => 1;
20
21indir "rehash.$$" => sub {
22 prepare(sub { chmod 400, $_ foreach (@_); });
23 ok(run(app(["openssl", "rehash", curdir()])),
24 'Testing rehash operations on readonly files');
25}, create => 1, cleanup => 1;
26
27indir "rehash.$$" => sub {
28 ok(run(app(["openssl", "rehash", curdir()])),
29 'Testing rehash operations on empty directory');
30}, create => 1, cleanup => 1;
31
32indir "rehash.$$" => sub {
33 prepare();
34 chmod 0500, curdir();
35 isnt(run(app(["openssl", "rehash", curdir()])), 1,
36 'Testing rehash operations on readonly directory');
37 chmod 0700, curdir(); # make it writable again, so cleanup works
38}, create => 1, cleanup => 1;
39
40sub prepare {
41 my @sourcefiles =
42 sort map { glob(top_file('certs', 'demo', "*.$_")) } ('pem',
43 'crt',
44 'cer',
45 'crl');
46 my @destfiles = ();
47 foreach (@sourcefiles) {
48 copy($_, curdir());
49 push @destfiles, catfile(curdir(), basename($_));
50 }
51 foreach (@_) {
52 die "Internal error, argument is not CODE"
53 unless (ref($_) eq 'CODE');
54 $_->(@destfiles);
55 }
56}