2 # Copyright 2015-2016 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
13 use File::Spec::Functions;
17 use OpenSSL::Test qw/:DEFAULT srctop_file/;
21 #If "openssl rehash -help" fails it's most likely because we're on a platform
22 #that doesn't support the rehash command (e.g. Windows)
23 plan skip_all => "test_rehash is not available on this platform"
24 unless run(app(["openssl", "rehash", "-help"]));
28 indir "rehash.$$" => sub {
30 ok(run(app(["openssl", "rehash", curdir()])),
31 'Testing normal rehash operations');
32 }, create => 1, cleanup => 1;
34 indir "rehash.$$" => sub {
35 prepare(sub { chmod 400, $_ foreach (@_); });
36 ok(run(app(["openssl", "rehash", curdir()])),
37 'Testing rehash operations on readonly files');
38 }, create => 1, cleanup => 1;
40 indir "rehash.$$" => sub {
41 ok(run(app(["openssl", "rehash", curdir()])),
42 'Testing rehash operations on empty directory');
43 }, create => 1, cleanup => 1;
45 indir "rehash.$$" => sub {
49 if (!ok(!open(FOO, ">unwritable.txt"),
50 "Testing that we aren't running as a privileged user, such as root")) {
52 skip "It's pointless to run the next test as root", 1;
54 isnt(run(app(["openssl", "rehash", curdir()])), 1,
55 'Testing rehash operations on readonly directory');
57 chmod 0700, curdir(); # make it writable again, so cleanup works
58 }, create => 1, cleanup => 1;
61 my @pemsourcefiles = sort glob(srctop_file('test', "*.pem"));
64 die "There are no source files\n" if scalar @pemsourcefiles == 0;
67 foreach (@pemsourcefiles) {
68 my $basename = basename($_, ".pem");
71 open PEM, $_ or die "Can't read $_: $!\n";
72 while (my $line = <PEM>) {
73 if ($line =~ m{^-----BEGIN (?:CERTIFICATE|X509 CRL)-----}) {
74 die "New start in a PEM blob?\n" if $writing;
78 $basename . sprintf("-%02d", $cnt) . ".pem");
79 push @destfiles, $destfile;
80 open OUT, '>', $destfile
81 or die "Can't write $destfile\n";
84 print OUT $line if $writing;
85 if ($line =~ m|^-----END |) {
86 close OUT if $writing;
90 die "No end marker in $basename\n" if $writing;
92 die "No test PEM files produced\n" if $cnt == 0;
95 die "Internal error, argument is not CODE"
96 unless (ref($_) eq 'CODE');