]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/30-test_evp_fetch_prov.t
Add DRBG self tests
[thirdparty/openssl.git] / test / recipes / 30-test_evp_fetch_prov.t
CommitLineData
7bb82f92
SL
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
9use strict;
10use warnings;
11
12use OpenSSL::Test qw(:DEFAULT bldtop_dir srctop_file srctop_dir bldtop_file);
13use OpenSSL::Test::Utils;
14
15BEGIN {
16setup("test_evp_fetch_prov");
17}
18
19use lib srctop_dir('Configurations');
20use lib bldtop_dir('.');
21use platform;
22
e0d952fc 23my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
7bb82f92 24
e0d952fc 25my @types = ( "digest", "cipher" );
7bb82f92
SL
26
27$ENV{OPENSSL_MODULES} = bldtop_dir("providers");
28$ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers");
29
e0d952fc
RL
30my @setups = ();
31my @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
48unless ($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']),
be3acd79 56 message => "fipsinstall"
e0d952fc
RL
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
88my $testcount = 0;
89foreach (@testdata) {
90 $testcount += scalar @{$_->{tests}};
91}
92
93plan tests => 1 + scalar @setups + $testcount * scalar(@types);
7bb82f92 94
7bb82f92 95ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
e0d952fc
RL
96 "running evp_fetch_prov_test using the default libctx");
97
98foreach my $setup (@setups) {
99 ok(run($setup->{cmd}), $setup->{message});
100}
101
102foreach 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}