81-test_cmp_cli.t: Do connections to 127.0.0.1 (e.g., Mock server) without proxy
[openssl.git] / test / recipes / 30-test_evp_fetch_prov.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2020 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 use platform;
22
23 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
24
25 my @types = ( "digest", "cipher" );
26
27 my @setups = ();
28 my @testdata = (
29     { config    => srctop_file("test", "default.cnf"),
30       providers => [ 'default' ],
31       tests  => [ { providers => [] },
32                   { },
33                   { args      => [ '-property', 'provider=default' ],
34                     message   => 'using property "provider=default"' },
35                   { args      => [ '-property', 'provider!=fips' ],
36                     message   => 'using property "provider!=fips"' },
37                   { args      => [ '-property', 'provider!=default', '-fetchfail' ],
38                     message   =>
39                         'using property "provider!=default" is expected to fail' },
40                   { args      => [ '-property', 'provider=fips', '-fetchfail' ],
41                     message   =>
42                         'using property "provider=fips" is expected to fail' } ] }
43 );
44
45 unless ($no_fips) {
46     push @setups, {
47         cmd     => app(['openssl', 'fipsinstall',
48                         '-out', bldtop_file('providers', 'fipsmodule.cnf'),
49                         '-module', bldtop_file('providers', platform->dso('fips')),
50                         '-provider_name', 'fips', '-mac_name', 'HMAC',
51                         '-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
52                         '-section_name', 'fips_sect']),
53         message => "fipsinstall"
54     };
55     push @testdata, (
56         { config    => srctop_file("test", "fips.cnf"),
57           providers => [ 'fips' ],
58           tests     => [
59               { args    => [ '-property', '' ] },
60               { args    => [ '-property', 'provider=fips' ],
61                 message => 'using property "provider=fips"' },
62               { args    => [ '-property', 'provider!=default' ],
63                 message => 'using property "provider!=default"' },
64               { args      => [ '-property', 'provider=default', '-fetchfail' ],
65                 message   =>
66                     'using property "provider=default" is expected to fail' },
67               { args      => [ '-property', 'provider!=fips', '-fetchfail' ],
68                 message   =>
69                     'using property "provider!=fips" is expected to fail' },
70               { args    => [ '-property', 'fips=yes' ],
71                 message => 'using property "fips=yes"' },
72               { args    => [ '-property', 'fips!=no' ],
73                 message => 'using property "fips!=no"' },
74               { args    => [ '-property', '-fips' ],
75                 message => 'using property "-fips"' },
76               { args    => [ '-property', 'fips=no', '-fetchfail' ],
77                 message => 'using property "fips=no is expected to fail"' },
78               { args    => [ '-property', 'fips!=yes', '-fetchfail' ],
79                 message => 'using property "fips!=yes is expected to fail"' } ] },
80         { config    => srctop_file("test", "default-and-fips.cnf"),
81           providers => [ 'default', 'fips' ],
82           tests     => [
83               { args    => [ '-property', '' ] },
84               { args      => [ '-property', 'provider!=default' ],
85                 message   => 'using property "provider!=default"' },
86               { args      => [ '-property', 'provider=default' ],
87                 message   => 'using property "provider=default"' },
88               { args      => [ '-property', 'provider!=fips' ],
89                 message   => 'using property "provider!=fips"' },
90               { args      => [ '-property', 'provider=fips' ],
91                 message   => 'using property "provider=fips"' },
92               { args    => [ '-property', 'fips=yes' ],
93                 message => 'using property "fips=yes"' },
94               { args    => [ '-property', 'fips!=no' ],
95                 message => 'using property "fips!=no"' },
96               { args    => [ '-property', '-fips' ],
97                 message => 'using property "-fips"' },
98               { args    => [ '-property', 'fips=no' ],
99                 message => 'using property "fips=no"' },
100               { args    => [ '-property', 'fips!=yes' ],
101                 message => 'using property "fips!=yes"' } ] },
102     );
103 }
104
105 my $testcount = 0;
106 foreach (@testdata) {
107     $testcount += scalar @{$_->{tests}};
108 }
109
110 plan tests => 1 + scalar @setups + $testcount * scalar(@types);
111
112 ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
113    "running evp_fetch_prov_test using the default libctx");
114
115 foreach my $setup (@setups) {
116     ok(run($setup->{cmd}), $setup->{message});
117 }
118
119 foreach my $alg (@types) {
120     foreach my $testcase (@testdata) {
121         $ENV{OPENSSL_CONF} = "";
122         foreach my $test (@{$testcase->{tests}}) {
123             my @testproviders =
124                 @{ $test->{providers} // $testcase->{providers} };
125             my $testprovstr = @testproviders
126                 ? ' and loaded providers ' . join(' & ',
127                                                   map { "'$_'" } @testproviders)
128                 : '';
129             my @testargs = @{ $test->{args} // [] };
130             my $testmsg =
131                 defined $test->{message} ? ' '.$test->{message} : '';
132
133             my $message =
134                 "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
135
136             ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
137                          "-config", "$testcase->{config}",
138                          @testargs, @testproviders])),
139                $message);
140         }
141     }
142 }