30-test_evp_fetch_prov.t 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2021 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. my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
  18. my @types = ( "digest", "cipher" );
  19. my @testdata = (
  20. { config => srctop_file("test", "default.cnf"),
  21. providers => [ 'default' ],
  22. tests => [ { providers => [] },
  23. { },
  24. { args => [ '-property', 'provider=default' ],
  25. message => 'using property "provider=default"' },
  26. { args => [ '-property', 'provider!=fips' ],
  27. message => 'using property "provider!=fips"' },
  28. { args => [ '-property', 'provider!=default', '-fetchfail' ],
  29. message =>
  30. 'using property "provider!=default" is expected to fail' },
  31. { args => [ '-property', 'provider=fips', '-fetchfail' ],
  32. message =>
  33. 'using property "provider=fips" is expected to fail' } ] }
  34. );
  35. unless ($no_fips) {
  36. push @testdata, (
  37. { config => srctop_file("test", "fips.cnf"),
  38. providers => [ 'fips' ],
  39. tests => [
  40. { args => [ '-property', '' ] },
  41. { args => [ '-property', 'provider=fips' ],
  42. message => 'using property "provider=fips"' },
  43. { args => [ '-property', 'provider!=default' ],
  44. message => 'using property "provider!=default"' },
  45. { args => [ '-property', 'provider=default', '-fetchfail' ],
  46. message =>
  47. 'using property "provider=default" is expected to fail' },
  48. { args => [ '-property', 'provider!=fips', '-fetchfail' ],
  49. message =>
  50. 'using property "provider!=fips" is expected to fail' },
  51. { args => [ '-property', 'fips=yes' ],
  52. message => 'using property "fips=yes"' },
  53. { args => [ '-property', 'fips!=no' ],
  54. message => 'using property "fips!=no"' },
  55. { args => [ '-property', '-fips' ],
  56. message => 'using property "-fips"' },
  57. { args => [ '-property', 'fips=no', '-fetchfail' ],
  58. message => 'using property "fips=no is expected to fail"' },
  59. { args => [ '-property', 'fips!=yes', '-fetchfail' ],
  60. message => 'using property "fips!=yes is expected to fail"' } ] },
  61. { config => srctop_file("test", "default-and-fips.cnf"),
  62. providers => [ 'default', 'fips' ],
  63. tests => [
  64. { args => [ '-property', '' ] },
  65. { args => [ '-property', 'provider!=default' ],
  66. message => 'using property "provider!=default"' },
  67. { args => [ '-property', 'provider=default' ],
  68. message => 'using property "provider=default"' },
  69. { args => [ '-property', 'provider!=fips' ],
  70. message => 'using property "provider!=fips"' },
  71. { args => [ '-property', 'provider=fips' ],
  72. message => 'using property "provider=fips"' },
  73. { args => [ '-property', 'fips=yes' ],
  74. message => 'using property "fips=yes"' },
  75. { args => [ '-property', 'fips!=no' ],
  76. message => 'using property "fips!=no"' },
  77. { args => [ '-property', '-fips' ],
  78. message => 'using property "-fips"' },
  79. { args => [ '-property', 'fips=no' ],
  80. message => 'using property "fips=no"' },
  81. { args => [ '-property', 'fips!=yes' ],
  82. message => 'using property "fips!=yes"' } ] },
  83. );
  84. }
  85. my $testcount = 0;
  86. foreach (@testdata) {
  87. $testcount += scalar @{$_->{tests}};
  88. }
  89. plan tests => 1 + $testcount * scalar(@types);
  90. ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
  91. "running evp_fetch_prov_test using the default libctx");
  92. foreach my $alg (@types) {
  93. foreach my $testcase (@testdata) {
  94. $ENV{OPENSSL_CONF} = "";
  95. foreach my $test (@{$testcase->{tests}}) {
  96. my @testproviders =
  97. @{ $test->{providers} // $testcase->{providers} };
  98. my $testprovstr = @testproviders
  99. ? ' and loaded providers ' . join(' & ',
  100. map { "'$_'" } @testproviders)
  101. : '';
  102. my @testargs = @{ $test->{args} // [] };
  103. my $testmsg =
  104. defined $test->{message} ? ' '.$test->{message} : '';
  105. my $message =
  106. "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
  107. ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
  108. "-config", "$testcase->{config}",
  109. @testargs, @testproviders])),
  110. $message);
  111. }
  112. }
  113. }