2 # Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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 OpenSSL
::Test qw
/:DEFAULT data_file/;
16 setup
('test_ca_internals');
18 my @updatedb_tests = (
20 description
=> 'updatedb called before the first certificate expires',
21 filename
=> 'index.txt',
23 testdate
=> '990101000000Z',
28 description
=> 'updatedb called before Y2k',
29 filename
=> 'index.txt',
31 testdate
=> '991201000000Z',
33 expirelist
=> [ '1000' ]
36 description
=> 'updatedb called after year 2020',
37 filename
=> 'index.txt',
39 testdate
=> '211201000000Z',
41 expirelist
=> [ '1001' ]
44 description
=> 'updatedb called in year 2049 (last year with 2 digits)',
45 filename
=> 'index.txt',
47 testdate
=> '491201000000Z',
49 expirelist
=> [ '1002' ]
52 description
=> 'updatedb called in year 2050 (first year with 4 digits) before the last certificate expires',
53 filename
=> 'index.txt',
55 testdate
=> '20500101000000Z',
60 description
=> 'updatedb called after the last certificate expired',
61 filename
=> 'index.txt',
63 testdate
=> '20501201000000Z',
65 expirelist
=> [ '1003' ]
68 description
=> 'updatedb called for the first time after the last certificate expired',
69 filename
=> 'index.txt',
71 testdate
=> '20501201000000Z',
73 expirelist
=> [ '1000',
80 my @unsupported_commands = (
82 command
=> 'unsupported'
86 # every "test_updatedb" makes 3 checks
87 plan tests
=> 3 * scalar(@updatedb_tests) +
88 1 * scalar(@unsupported_commands);
91 foreach my $test (@updatedb_tests) {
94 foreach my $test (@unsupported_commands) {
95 test_unsupported_commands
($test);
99 ################### subs to do tests per supported command ################
101 sub test_unsupported_commands
{
105 test
(['ca_internals_test',
109 statusvar
=> \
my $exit
112 is
($exit, 0, "command '".$opts->{command
}."' completed without an error");
117 my $amtexpectedexpired = scalar(@
{$opts->{expirelist
}});
119 my $expirelistcorrect = 1;
124 if ($opts->{copydb
}) {
125 copy
(data_file
('index.txt'), 'index.txt');
129 test
(['ca_internals_test',
136 statusvar
=> \
my $exit
139 foreach my $tmp (@output) {
140 ($cert) = $tmp =~ /^[\x20\x23]*[^0-9A-Fa-f]*([0-9A-Fa-f]+)=Expired/;
141 if ($tmp =~ /^[\x20\x23]*skipping test/) {
144 if (defined($cert) && (length($cert) > 0)) {
147 foreach my $expire (@
{$opts->{expirelist
}}) {
148 if ($expire eq $cert) {
152 if ($expirefound != 1) {
153 $expirelistcorrect = 0;
159 $amtexpired = $amtexpectedexpired;
160 $expirelistcorrect = 1;
162 is
($exit, 1, "ca_internals_test: returned EXIT_FAILURE (".$opts->{description
}.")");
163 is
($amtexpired, $amtexpectedexpired, "ca_internals_test: amount of expired certificates differs from expected amount (".$opts->{description
}.")");
164 is
($expirelistcorrect, 1, "ca_internals_test: list of expired certificates differs from expected list (".$opts->{description
}.")");