]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/30-test_evp_fetch_prov.t
TEST: Modify test/recipes/25-test_x509.t to leave artifacts behind
[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', 'default=yes' ],
37 message => 'using property "default=yes"' },
38 { args => [ '-property', 'fips=no' ],
39 message => 'using property "fips=no"' },
40 { args => [ '-property', 'default=no', '-fetchfail' ],
41 message =>
42 'using property "default=no" is expected to fail' },
43 { args => [ '-property', 'fips=yes', '-fetchfail' ],
44 message =>
45 'using property "fips=yes" is expected to fail' } ] }
46 );
47
48 unless ($no_fips) {
49 push @setups, {
50 cmd => app(['openssl', 'fipsinstall',
51 '-out', bldtop_file('providers', 'fipsinstall.conf'),
52 '-module', bldtop_file('providers', platform->dso('fips')),
53 '-provider_name', 'fips', '-mac_name', 'HMAC',
54 '-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
55 '-section_name', 'fips_sect']),
56 message => "fipsinstall"
57 };
58 push @testdata, (
59 { config => srctop_file("test", "fips.cnf"),
60 providers => [ 'fips' ],
61 tests => [
62 { args => [ '-property', '' ] },
63 { args => [ '-property', 'fips=yes' ],
64 message => 'using property "fips=yes"' },
65 { args => [ '-property', 'default=no' ],
66 message => 'using property "default = no"' },
67 { args => [ '-property', 'default=yes', '-fetchfail' ],
68 message =>
69 'using property "default=yes" is expected to fail' },
70 { args => [ '-property', 'fips=no', '-fetchfail' ],
71 message =>
72 'using property "fips=no" is expected to fail' } ] },
73 { config => srctop_file("test", "default-and-fips.cnf"),
74 providers => [ 'default', 'fips' ],
75 tests => [
76 { args => [ '-property', '' ] },
77 { args => [ '-property', 'default=no' ],
78 message => 'using property "default=no"' },
79 { args => [ '-property', 'default=yes' ],
80 message => 'using property "default=yes"' },
81 { args => [ '-property', 'fips=no' ],
82 message => 'using property "fips=no"' },
83 { args => [ '-property', 'fips=yes' ],
84 message => 'using property "fips=yes"' } ] }
85 );
86 }
87
88 my $testcount = 0;
89 foreach (@testdata) {
90 $testcount += scalar @{$_->{tests}};
91 }
92
93 plan tests => 1 + scalar @setups + $testcount * scalar(@types);
94
95 ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
96 "running evp_fetch_prov_test using the default libctx");
97
98 foreach my $setup (@setups) {
99 ok(run($setup->{cmd}), $setup->{message});
100 }
101
102 foreach my $alg (@types) {
103 foreach my $testcase (@testdata) {
104 $ENV{OPENSSL_CONF} = $testcase->{config};
105 foreach my $test (@{$testcase->{tests}}) {
106 my @testproviders =
107 @{ $test->{providers} // $testcase->{providers} };
108 my $testprovstr = @testproviders
109 ? ' and loaded providers ' . join(' & ',
110 map { "'$_'" } @testproviders)
111 : '';
112 my @testargs = @{ $test->{args} // [] };
113 my $testmsg =
114 defined $test->{message} ? ' '.$test->{message} : '';
115
116 my $message =
117 "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
118
119 ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
120 @testargs, @testproviders])),
121 $message);
122 }
123 }
124 }