30-test_evp_fetch_prov.t 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2020 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. use strict;
  9. use warnings;
  10. use OpenSSL::Test qw(:DEFAULT bldtop_dir srctop_file srctop_dir bldtop_file);
  11. use OpenSSL::Test::Utils;
  12. BEGIN {
  13. setup("test_evp_fetch_prov");
  14. }
  15. use lib srctop_dir('Configurations');
  16. use lib bldtop_dir('.');
  17. use platform;
  18. my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
  19. my $infile = bldtop_file('providers', platform->dso('fips'));
  20. my @types = ( "digest", "cipher" );
  21. my @setups = ();
  22. my @testdata = (
  23. { config => srctop_file("test", "default.cnf"),
  24. providers => [ 'default' ],
  25. tests => [ { providers => [] },
  26. { },
  27. { args => [ '-property', 'provider=default' ],
  28. message => 'using property "provider=default"' },
  29. { args => [ '-property', 'provider!=fips' ],
  30. message => 'using property "provider!=fips"' },
  31. { args => [ '-property', 'provider!=default', '-fetchfail' ],
  32. message =>
  33. 'using property "provider!=default" is expected to fail' },
  34. { args => [ '-property', 'provider=fips', '-fetchfail' ],
  35. message =>
  36. 'using property "provider=fips" is expected to fail' } ] }
  37. );
  38. unless ($no_fips) {
  39. push @setups, {
  40. cmd => app(['openssl', 'fipsinstall',
  41. '-out', bldtop_file('providers', 'fipsmodule.cnf'),
  42. '-module', $infile]),
  43. message => "fipsinstall"
  44. };
  45. push @testdata, (
  46. { config => srctop_file("test", "fips.cnf"),
  47. providers => [ 'fips' ],
  48. tests => [
  49. { args => [ '-property', '' ] },
  50. { args => [ '-property', 'provider=fips' ],
  51. message => 'using property "provider=fips"' },
  52. { args => [ '-property', 'provider!=default' ],
  53. message => 'using property "provider!=default"' },
  54. { args => [ '-property', 'provider=default', '-fetchfail' ],
  55. message =>
  56. 'using property "provider=default" is expected to fail' },
  57. { args => [ '-property', 'provider!=fips', '-fetchfail' ],
  58. message =>
  59. 'using property "provider!=fips" is expected to fail' },
  60. { args => [ '-property', 'fips=yes' ],
  61. message => 'using property "fips=yes"' },
  62. { args => [ '-property', 'fips!=no' ],
  63. message => 'using property "fips!=no"' },
  64. { args => [ '-property', '-fips' ],
  65. message => 'using property "-fips"' },
  66. { args => [ '-property', 'fips=no', '-fetchfail' ],
  67. message => 'using property "fips=no is expected to fail"' },
  68. { args => [ '-property', 'fips!=yes', '-fetchfail' ],
  69. message => 'using property "fips!=yes is expected to fail"' } ] },
  70. { config => srctop_file("test", "default-and-fips.cnf"),
  71. providers => [ 'default', 'fips' ],
  72. tests => [
  73. { args => [ '-property', '' ] },
  74. { args => [ '-property', 'provider!=default' ],
  75. message => 'using property "provider!=default"' },
  76. { args => [ '-property', 'provider=default' ],
  77. message => 'using property "provider=default"' },
  78. { args => [ '-property', 'provider!=fips' ],
  79. message => 'using property "provider!=fips"' },
  80. { args => [ '-property', 'provider=fips' ],
  81. message => 'using property "provider=fips"' },
  82. { args => [ '-property', 'fips=yes' ],
  83. message => 'using property "fips=yes"' },
  84. { args => [ '-property', 'fips!=no' ],
  85. message => 'using property "fips!=no"' },
  86. { args => [ '-property', '-fips' ],
  87. message => 'using property "-fips"' },
  88. { args => [ '-property', 'fips=no' ],
  89. message => 'using property "fips=no"' },
  90. { args => [ '-property', 'fips!=yes' ],
  91. message => 'using property "fips!=yes"' } ] },
  92. );
  93. }
  94. my $testcount = 0;
  95. foreach (@testdata) {
  96. $testcount += scalar @{$_->{tests}};
  97. }
  98. plan tests => 1 + scalar @setups + $testcount * scalar(@types);
  99. ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
  100. "running evp_fetch_prov_test using the default libctx");
  101. foreach my $setup (@setups) {
  102. ok(run($setup->{cmd}), $setup->{message});
  103. }
  104. foreach my $alg (@types) {
  105. foreach my $testcase (@testdata) {
  106. $ENV{OPENSSL_CONF} = "";
  107. foreach my $test (@{$testcase->{tests}}) {
  108. my @testproviders =
  109. @{ $test->{providers} // $testcase->{providers} };
  110. my $testprovstr = @testproviders
  111. ? ' and loaded providers ' . join(' & ',
  112. map { "'$_'" } @testproviders)
  113. : '';
  114. my @testargs = @{ $test->{args} // [] };
  115. my $testmsg =
  116. defined $test->{message} ? ' '.$test->{message} : '';
  117. my $message =
  118. "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
  119. ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
  120. "-config", "$testcase->{config}",
  121. @testargs, @testproviders])),
  122. $message);
  123. }
  124. }
  125. }