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