Add config tests for including provider config files
[openssl.git] / test / recipes / 30-test_evp_fetch_prov.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
3 #
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
8
9 use strict;
10 use warnings;
11
12 use OpenSSL::Test qw(:DEFAULT bldtop_dir srctop_file srctop_dir bldtop_file);
13 use OpenSSL::Test::Utils;
14
15 BEGIN {
16 setup("test_evp_fetch_prov");
17 }
18
19 use lib srctop_dir('Configurations');
20 use lib bldtop_dir('.');
21
22 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
23
24 my @types = ( "digest", "cipher" );
25
26 my @testdata = (
27     { config    => srctop_file("test", "default.cnf"),
28       providers => [ 'default' ],
29       tests  => [ { providers => [] },
30                   { },
31                   { args      => [ '-property', 'provider=default' ],
32                     message   => 'using property "provider=default"' },
33                   { args      => [ '-property', 'provider!=fips' ],
34                     message   => 'using property "provider!=fips"' },
35                   { args      => [ '-property', 'provider!=default', '-fetchfail' ],
36                     message   =>
37                         'using property "provider!=default" is expected to fail' },
38                   { args      => [ '-property', 'provider=fips', '-fetchfail' ],
39                     message   =>
40                         'using property "provider=fips" is expected to fail' } ] }
41 );
42
43 unless ($no_fips) {
44     push @testdata, (
45         { config    => srctop_file("test", "fips.cnf"),
46           providers => [ 'fips' ],
47           tests     => [
48               { args    => [ '-property', '' ] },
49               { args    => [ '-property', 'provider=fips' ],
50                 message => 'using property "provider=fips"' },
51               { args    => [ '-property', 'provider!=default' ],
52                 message => 'using property "provider!=default"' },
53               { args      => [ '-property', 'provider=default', '-fetchfail' ],
54                 message   =>
55                     'using property "provider=default" is expected to fail' },
56               { args      => [ '-property', 'provider!=fips', '-fetchfail' ],
57                 message   =>
58                     'using property "provider!=fips" is expected to fail' },
59               { args    => [ '-property', 'fips=yes' ],
60                 message => 'using property "fips=yes"' },
61               { args    => [ '-property', 'fips!=no' ],
62                 message => 'using property "fips!=no"' },
63               { args    => [ '-property', '-fips' ],
64                 message => 'using property "-fips"' },
65               { args    => [ '-property', 'fips=no', '-fetchfail' ],
66                 message => 'using property "fips=no is expected to fail"' },
67               { args    => [ '-property', 'fips!=yes', '-fetchfail' ],
68                 message => 'using property "fips!=yes is expected to fail"' } ] },
69         { config    => srctop_file("test", "default-and-fips.cnf"),
70           providers => [ 'default', 'fips' ],
71           tests     => [
72               { args    => [ '-property', '' ] },
73               { args      => [ '-property', 'provider!=default' ],
74                 message   => 'using property "provider!=default"' },
75               { args      => [ '-property', 'provider=default' ],
76                 message   => 'using property "provider=default"' },
77               { args      => [ '-property', 'provider!=fips' ],
78                 message   => 'using property "provider!=fips"' },
79               { args      => [ '-property', 'provider=fips' ],
80                 message   => 'using property "provider=fips"' },
81               { args    => [ '-property', 'fips=yes' ],
82                 message => 'using property "fips=yes"' },
83               { args    => [ '-property', 'fips!=no' ],
84                 message => 'using property "fips!=no"' },
85               { args    => [ '-property', '-fips' ],
86                 message => 'using property "-fips"' },
87               { args    => [ '-property', 'fips=no' ],
88                 message => 'using property "fips=no"' },
89               { args    => [ '-property', 'fips!=yes' ],
90                 message => 'using property "fips!=yes"' } ] },
91     );
92 }
93
94 my $testcount = 0;
95 foreach (@testdata) {
96     $testcount += scalar @{$_->{tests}};
97 }
98
99 plan tests => 1 + $testcount * scalar(@types);
100
101 ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
102    "running evp_fetch_prov_test using the default libctx");
103
104 foreach my $alg (@types) {
105     foreach my $testcase (@testdata) {
106         $ENV{OPENSSL_CONF} = "";
107         foreach my $test (@{$testcase->{tests}}) {
108             my @testproviders =
109                 @{ $test->{providers} // $testcase->{providers} };
110             my $testprovstr = @testproviders
111                 ? ' and loaded providers ' . join(' & ',
112                                                   map { "'$_'" } @testproviders)
113                 : '';
114             my @testargs = @{ $test->{args} // [] };
115             my $testmsg =
116                 defined $test->{message} ? ' '.$test->{message} : '';
117
118             my $message =
119                 "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
120
121             ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
122                          "-config", "$testcase->{config}",
123                          @testargs, @testproviders])),
124                $message);
125         }
126     }
127 }