2 # Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
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
12 use OpenSSL::Test qw(:DEFAULT bldtop_dir srctop_file srctop_dir bldtop_file);
13 use OpenSSL::Test::Utils;
16 setup("test_evp_fetch_prov");
19 use lib srctop_dir('Configurations');
20 use lib bldtop_dir('.');
23 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
25 my @types = ( "digest", "cipher" );
29 { config => srctop_file("test", "default.cnf"),
30 providers => [ 'default' ],
31 tests => [ { providers => [] },
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' ],
39 'using property "provider!=default" is expected to fail' },
40 { args => [ '-property', 'provider=fips', '-fetchfail' ],
42 'using property "provider=fips" is expected to fail' } ] }
47 cmd => app(['openssl', 'fipsinstall',
48 '-out', bldtop_file('providers', 'fipsmodule.cnf'),
49 '-module', bldtop_file('providers', platform->dso('fips')),
50 '-provider_name', 'fips',
51 '-section_name', 'fips_sect']),
52 message => "fipsinstall"
55 { config => srctop_file("test", "fips.cnf"),
56 providers => [ 'fips' ],
58 { args => [ '-property', '' ] },
59 { args => [ '-property', 'provider=fips' ],
60 message => 'using property "provider=fips"' },
61 { args => [ '-property', 'provider!=default' ],
62 message => 'using property "provider!=default"' },
63 { args => [ '-property', 'provider=default', '-fetchfail' ],
65 'using property "provider=default" is expected to fail' },
66 { args => [ '-property', 'provider!=fips', '-fetchfail' ],
68 'using property "provider!=fips" is expected to fail' },
69 { args => [ '-property', 'fips=yes' ],
70 message => 'using property "fips=yes"' },
71 { args => [ '-property', 'fips!=no' ],
72 message => 'using property "fips!=no"' },
73 { args => [ '-property', '-fips' ],
74 message => 'using property "-fips"' },
75 { args => [ '-property', 'fips=no', '-fetchfail' ],
76 message => 'using property "fips=no is expected to fail"' },
77 { args => [ '-property', 'fips!=yes', '-fetchfail' ],
78 message => 'using property "fips!=yes is expected to fail"' } ] },
79 { config => srctop_file("test", "default-and-fips.cnf"),
80 providers => [ 'default', 'fips' ],
82 { args => [ '-property', '' ] },
83 { args => [ '-property', 'provider!=default' ],
84 message => 'using property "provider!=default"' },
85 { args => [ '-property', 'provider=default' ],
86 message => 'using property "provider=default"' },
87 { args => [ '-property', 'provider!=fips' ],
88 message => 'using property "provider!=fips"' },
89 { args => [ '-property', 'provider=fips' ],
90 message => 'using property "provider=fips"' },
91 { args => [ '-property', 'fips=yes' ],
92 message => 'using property "fips=yes"' },
93 { args => [ '-property', 'fips!=no' ],
94 message => 'using property "fips!=no"' },
95 { args => [ '-property', '-fips' ],
96 message => 'using property "-fips"' },
97 { args => [ '-property', 'fips=no' ],
98 message => 'using property "fips=no"' },
99 { args => [ '-property', 'fips!=yes' ],
100 message => 'using property "fips!=yes"' } ] },
105 foreach (@testdata) {
106 $testcount += scalar @{$_->{tests}};
109 plan tests => 1 + scalar @setups + $testcount * scalar(@types);
111 ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
112 "running evp_fetch_prov_test using the default libctx");
114 foreach my $setup (@setups) {
115 ok(run($setup->{cmd}), $setup->{message});
118 foreach my $alg (@types) {
119 foreach my $testcase (@testdata) {
120 $ENV{OPENSSL_CONF} = "";
121 foreach my $test (@{$testcase->{tests}}) {
123 @{ $test->{providers} // $testcase->{providers} };
124 my $testprovstr = @testproviders
125 ? ' and loaded providers ' . join(' & ',
126 map { "'$_'" } @testproviders)
128 my @testargs = @{ $test->{args} // [] };
130 defined $test->{message} ? ' '.$test->{message} : '';
133 "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
135 ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
136 "-config", "$testcase->{config}",
137 @testargs, @testproviders])),