]>
Commit | Line | Data |
---|---|---|
7bb82f92 | 1 | #! /usr/bin/env perl |
33388b44 | 2 | # Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. |
7bb82f92 SL |
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 | ||
e0d952fc | 23 | my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0); |
5744dacb | 24 | my $infile = bldtop_file('providers', platform->dso('fips')); |
7bb82f92 | 25 | |
e0d952fc | 26 | my @types = ( "digest", "cipher" ); |
7bb82f92 | 27 | |
e0d952fc RL |
28 | my @setups = (); |
29 | my @testdata = ( | |
30 | { config => srctop_file("test", "default.cnf"), | |
31 | providers => [ 'default' ], | |
32 | tests => [ { providers => [] }, | |
33 | { }, | |
745fc918 MC |
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' ], | |
e0d952fc | 39 | message => |
745fc918 MC |
40 | 'using property "provider!=default" is expected to fail' }, |
41 | { args => [ '-property', 'provider=fips', '-fetchfail' ], | |
e0d952fc | 42 | message => |
745fc918 | 43 | 'using property "provider=fips" is expected to fail' } ] } |
e0d952fc RL |
44 | ); |
45 | ||
46 | unless ($no_fips) { | |
47 | push @setups, { | |
1e78a50f | 48 | cmd => app(['openssl', 'fipsinstall', |
1cd2c1f8 | 49 | '-out', bldtop_file('providers', 'fipsmodule.cnf'), |
5744dacb | 50 | '-module', $infile]), |
be3acd79 | 51 | message => "fipsinstall" |
e0d952fc RL |
52 | }; |
53 | push @testdata, ( | |
54 | { config => srctop_file("test", "fips.cnf"), | |
55 | providers => [ 'fips' ], | |
56 | tests => [ | |
57 | { args => [ '-property', '' ] }, | |
745fc918 MC |
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' ], | |
e0d952fc | 63 | message => |
745fc918 MC |
64 | 'using property "provider=default" is expected to fail' }, |
65 | { args => [ '-property', 'provider!=fips', '-fetchfail' ], | |
e0d952fc | 66 | message => |
745fc918 MC |
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"' } ] }, | |
e0d952fc RL |
78 | { config => srctop_file("test", "default-and-fips.cnf"), |
79 | providers => [ 'default', 'fips' ], | |
80 | tests => [ | |
81 | { args => [ '-property', '' ] }, | |
745fc918 MC |
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"' } ] }, | |
e0d952fc RL |
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); | |
7bb82f92 | 109 | |
7bb82f92 | 110 | ok(run(test(["evp_fetch_prov_test", "-defaultctx"])), |
e0d952fc RL |
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) { | |
22e27978 | 119 | $ENV{OPENSSL_CONF} = ""; |
e0d952fc RL |
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", | |
22e27978 | 135 | "-config", "$testcase->{config}", |
e0d952fc RL |
136 | @testargs, @testproviders])), |
137 | $message); | |
138 | } | |
139 | } | |
140 | } |