xref: /freebsd/crypto/openssl/test/recipes/30-test_evp_fetch_prov.t (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert#! /usr/bin/env perl
2*e0c4386eSCy Schubert# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert#
4*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License").  You may not use
5*e0c4386eSCy Schubert# this file except in compliance with the License.  You can obtain a copy
6*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert
9*e0c4386eSCy Schubertuse strict;
10*e0c4386eSCy Schubertuse warnings;
11*e0c4386eSCy Schubert
12*e0c4386eSCy Schubertuse OpenSSL::Test qw(:DEFAULT bldtop_dir srctop_file srctop_dir bldtop_file);
13*e0c4386eSCy Schubertuse OpenSSL::Test::Utils;
14*e0c4386eSCy Schubert
15*e0c4386eSCy SchubertBEGIN {
16*e0c4386eSCy Schubertsetup("test_evp_fetch_prov");
17*e0c4386eSCy Schubert}
18*e0c4386eSCy Schubert
19*e0c4386eSCy Schubertuse lib srctop_dir('Configurations');
20*e0c4386eSCy Schubertuse lib bldtop_dir('.');
21*e0c4386eSCy Schubert
22*e0c4386eSCy Schubertmy $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
23*e0c4386eSCy Schubert
24*e0c4386eSCy Schubertmy @types = ( "digest", "cipher" );
25*e0c4386eSCy Schubert
26*e0c4386eSCy Schubertmy @testdata = (
27*e0c4386eSCy Schubert    { config    => srctop_file("test", "default.cnf"),
28*e0c4386eSCy Schubert      providers => [ 'default' ],
29*e0c4386eSCy Schubert      tests  => [ { providers => [] },
30*e0c4386eSCy Schubert                  { },
31*e0c4386eSCy Schubert                  { args      => [ '-property', 'provider=default' ],
32*e0c4386eSCy Schubert                    message   => 'using property "provider=default"' },
33*e0c4386eSCy Schubert                  { args      => [ '-property', 'provider!=fips' ],
34*e0c4386eSCy Schubert                    message   => 'using property "provider!=fips"' },
35*e0c4386eSCy Schubert                  { args      => [ '-property', 'provider!=default', '-fetchfail' ],
36*e0c4386eSCy Schubert                    message   =>
37*e0c4386eSCy Schubert                        'using property "provider!=default" is expected to fail' },
38*e0c4386eSCy Schubert                  { args      => [ '-property', 'provider=fips', '-fetchfail' ],
39*e0c4386eSCy Schubert                    message   =>
40*e0c4386eSCy Schubert                        'using property "provider=fips" is expected to fail' } ] }
41*e0c4386eSCy Schubert);
42*e0c4386eSCy Schubert
43*e0c4386eSCy Schubertunless ($no_fips) {
44*e0c4386eSCy Schubert    push @testdata, (
45*e0c4386eSCy Schubert        { config    => srctop_file("test", "fips.cnf"),
46*e0c4386eSCy Schubert          providers => [ 'fips' ],
47*e0c4386eSCy Schubert          tests     => [
48*e0c4386eSCy Schubert              { args    => [ '-property', '' ] },
49*e0c4386eSCy Schubert              { args    => [ '-property', 'provider=fips' ],
50*e0c4386eSCy Schubert                message => 'using property "provider=fips"' },
51*e0c4386eSCy Schubert              { args    => [ '-property', 'provider!=default' ],
52*e0c4386eSCy Schubert                message => 'using property "provider!=default"' },
53*e0c4386eSCy Schubert              { args      => [ '-property', 'provider=default', '-fetchfail' ],
54*e0c4386eSCy Schubert                message   =>
55*e0c4386eSCy Schubert                    'using property "provider=default" is expected to fail' },
56*e0c4386eSCy Schubert              { args      => [ '-property', 'provider!=fips', '-fetchfail' ],
57*e0c4386eSCy Schubert                message   =>
58*e0c4386eSCy Schubert                    'using property "provider!=fips" is expected to fail' },
59*e0c4386eSCy Schubert              { args    => [ '-property', 'fips=yes' ],
60*e0c4386eSCy Schubert                message => 'using property "fips=yes"' },
61*e0c4386eSCy Schubert              { args    => [ '-property', 'fips!=no' ],
62*e0c4386eSCy Schubert                message => 'using property "fips!=no"' },
63*e0c4386eSCy Schubert              { args    => [ '-property', '-fips' ],
64*e0c4386eSCy Schubert                message => 'using property "-fips"' },
65*e0c4386eSCy Schubert              { args    => [ '-property', 'fips=no', '-fetchfail' ],
66*e0c4386eSCy Schubert                message => 'using property "fips=no is expected to fail"' },
67*e0c4386eSCy Schubert              { args    => [ '-property', 'fips!=yes', '-fetchfail' ],
68*e0c4386eSCy Schubert                message => 'using property "fips!=yes is expected to fail"' } ] },
69*e0c4386eSCy Schubert        { config    => srctop_file("test", "default-and-fips.cnf"),
70*e0c4386eSCy Schubert          providers => [ 'default', 'fips' ],
71*e0c4386eSCy Schubert          tests     => [
72*e0c4386eSCy Schubert              { args    => [ '-property', '' ] },
73*e0c4386eSCy Schubert              { args      => [ '-property', 'provider!=default' ],
74*e0c4386eSCy Schubert                message   => 'using property "provider!=default"' },
75*e0c4386eSCy Schubert              { args      => [ '-property', 'provider=default' ],
76*e0c4386eSCy Schubert                message   => 'using property "provider=default"' },
77*e0c4386eSCy Schubert              { args      => [ '-property', 'provider!=fips' ],
78*e0c4386eSCy Schubert                message   => 'using property "provider!=fips"' },
79*e0c4386eSCy Schubert              { args      => [ '-property', 'provider=fips' ],
80*e0c4386eSCy Schubert                message   => 'using property "provider=fips"' },
81*e0c4386eSCy Schubert              { args    => [ '-property', 'fips=yes' ],
82*e0c4386eSCy Schubert                message => 'using property "fips=yes"' },
83*e0c4386eSCy Schubert              { args    => [ '-property', 'fips!=no' ],
84*e0c4386eSCy Schubert                message => 'using property "fips!=no"' },
85*e0c4386eSCy Schubert              { args    => [ '-property', '-fips' ],
86*e0c4386eSCy Schubert                message => 'using property "-fips"' },
87*e0c4386eSCy Schubert              { args    => [ '-property', 'fips=no' ],
88*e0c4386eSCy Schubert                message => 'using property "fips=no"' },
89*e0c4386eSCy Schubert              { args    => [ '-property', 'fips!=yes' ],
90*e0c4386eSCy Schubert                message => 'using property "fips!=yes"' } ] },
91*e0c4386eSCy Schubert    );
92*e0c4386eSCy Schubert}
93*e0c4386eSCy Schubert
94*e0c4386eSCy Schubertmy $testcount = 0;
95*e0c4386eSCy Schubertforeach (@testdata) {
96*e0c4386eSCy Schubert    $testcount += scalar @{$_->{tests}};
97*e0c4386eSCy Schubert}
98*e0c4386eSCy Schubert
99*e0c4386eSCy Schubertplan tests => 1 + $testcount * scalar(@types);
100*e0c4386eSCy Schubert
101*e0c4386eSCy Schubertok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
102*e0c4386eSCy Schubert   "running evp_fetch_prov_test using the default libctx");
103*e0c4386eSCy Schubert
104*e0c4386eSCy Schubertforeach my $alg (@types) {
105*e0c4386eSCy Schubert    foreach my $testcase (@testdata) {
106*e0c4386eSCy Schubert        $ENV{OPENSSL_CONF} = "";
107*e0c4386eSCy Schubert        foreach my $test (@{$testcase->{tests}}) {
108*e0c4386eSCy Schubert            my @testproviders =
109*e0c4386eSCy Schubert                @{ $test->{providers} // $testcase->{providers} };
110*e0c4386eSCy Schubert            my $testprovstr = @testproviders
111*e0c4386eSCy Schubert                ? ' and loaded providers ' . join(' & ',
112*e0c4386eSCy Schubert                                                  map { "'$_'" } @testproviders)
113*e0c4386eSCy Schubert                : '';
114*e0c4386eSCy Schubert            my @testargs = @{ $test->{args} // [] };
115*e0c4386eSCy Schubert            my $testmsg =
116*e0c4386eSCy Schubert                defined $test->{message} ? ' '.$test->{message} : '';
117*e0c4386eSCy Schubert
118*e0c4386eSCy Schubert            my $message =
119*e0c4386eSCy Schubert                "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
120*e0c4386eSCy Schubert
121*e0c4386eSCy Schubert            ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
122*e0c4386eSCy Schubert                         "-config", "$testcase->{config}",
123*e0c4386eSCy Schubert                         @testargs, @testproviders])),
124*e0c4386eSCy Schubert               $message);
125*e0c4386eSCy Schubert        }
126*e0c4386eSCy Schubert    }
127*e0c4386eSCy Schubert}
128