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