]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/30-test_evp_fetch_prov.t
TEST: make and use a fipsinstall script
[thirdparty/openssl.git] / test / recipes / 30-test_evp_fetch_prov.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 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
25 my @types = ( "digest", "cipher" );
26
27 $ENV{OPENSSL_MODULES} = bldtop_dir("providers");
28 $ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers");
29
30 my @setups = ();
31 my @testdata = (
32 { config => srctop_file("test", "default.cnf"),
33 providers => [ 'default' ],
34 tests => [ { providers => [] },
35 { },
36 { args => [ '-property', 'provider=default' ],
37 message => 'using property "provider=default"' },
38 { args => [ '-property', 'provider!=fips' ],
39 message => 'using property "provider!=fips"' },
40 { args => [ '-property', 'provider!=default', '-fetchfail' ],
41 message =>
42 'using property "provider!=default" is expected to fail' },
43 { args => [ '-property', 'provider=fips', '-fetchfail' ],
44 message =>
45 'using property "provider=fips" is expected to fail' } ] }
46 );
47
48 unless ($no_fips) {
49 push @setups, {
50 cmd => perltest(['fipsinstall.pl', bldtop_dir()]),
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 }