Skip to content

Commit

Permalink
Add include test for legacy provider
Browse files Browse the repository at this point in the history
  • Loading branch information
xhanulik committed Oct 19, 2023
1 parent 17f63aa commit d443600
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
23 changes: 19 additions & 4 deletions test/provider_include_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
#include <stddef.h>
#include <string.h>
#include <openssl/provider.h>
#include <openssl/params.h>
#include <openssl/core_names.h>
#include <openssl/self_test.h>
#include <openssl/evp.h>
#include <openssl/crypto.h>
#include "testutil.h"

#ifdef _WIN32
Expand Down Expand Up @@ -43,6 +40,7 @@ typedef enum OPTION_choice {
OPT_ERR = -1,
OPT_EOF = 0,
OPT_FAIL,
OPT_LEGACY,
OPT_TEST_ENUM
} OPTION_CHOICE;

Expand Down Expand Up @@ -95,11 +93,22 @@ static int test_include_default_provider(void)
return 1;
}

static int test_include_legacy_provider(void)
{
if (OSSL_PROVIDER_available(libctx, "legacy") != 1) {
opt_printf_stderr("Legacy provider is missing\n");
return 0;
}
return 1;
}

const OPTIONS *test_get_options(void)
{
static const OPTIONS test_options[] = {
OPT_TEST_OPTIONS_WITH_EXTRA_USAGE("config_file\n"),
{ "f", OPT_FAIL, '-', "A failure is expected" },
{ "legacy", OPT_LEGACY, '-',
"Test availability of legacy provider" },
{ NULL }
};
return test_options;
Expand All @@ -109,12 +118,16 @@ int setup_tests(void)
{
OPTION_CHOICE o;
char *config_file = NULL;
int legacy_enabled = 0;

while ((o = opt_next()) != OPT_EOF) {
switch (o) {
case OPT_FAIL:
expect_failure = 1;
break;
case OPT_LEGACY:
legacy_enabled = 1;
break;
case OPT_TEST_CASES:
break;
default:
Expand Down Expand Up @@ -144,6 +157,8 @@ int setup_tests(void)
OPENSSL_free(config_file);

ADD_TEST(test_include_default_provider);
if (legacy_enabled)
ADD_TEST(test_include_legacy_provider);
return 1;
}

Expand Down
19 changes: 15 additions & 4 deletions test/recipes/30-test_provider_include.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

use strict;
use warnings;
use OpenSSL::Test qw/:DEFAULT data_file/;
use OpenSSL::Test qw/:DEFAULT data_file bldtop_dir/;
use OpenSSL::Test::Utils;
use Cwd qw(abs_path);

setup("test_provider_include");

Expand All @@ -18,7 +19,17 @@ plan skip_all => "test_provider_include doesn't work without posix-io"

delete $ENV{OPENSSL_CONF_INCLUDE};

plan tests => 2;
plan tests => 3;

ok(run(test(["provider_include_test", data_file("null-default.cnf")])), "test null and default provider availability");
ok(run(test(["provider_include_test", "-f", data_file("null.cnf")])), "test default provider unavailability");
$ENV{OPENSSL_MODULES} = abs_path(bldtop_dir("providers"));

ok(run(test(["provider_include_test", data_file("null-default.cnf")])),
"test null and default provider availability");
ok(run(test(["provider_include_test", "-f", data_file("null.cnf")])),
"test default provider unavailability");
SKIP: {
skip "Skipping legacy test", 1
if disabled("legacy");
ok(run(test(["provider_include_test", "-legacy", data_file("null-default-legacy.cnf")])),
"test null, default and legacy provider availability");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[provider_sect]
legacy = legacy_sect

[legacy_sect]
activate = 1
12 changes: 12 additions & 0 deletions test/recipes/30-test_provider_include_data/null-default-legacy.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
openssl_conf = openssl_init

[openssl_init]
providers = provider_sect

[provider_sect]
null = null_sect

[null_sect]
activate = 1

.include includes-dir
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ null = null_sect
[null_sect]
activate = 1

.include default-dir
.include includes-dir

0 comments on commit d443600

Please sign in to comment.