Add libctx/provider support to cmp_server_test

Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/11808)
This commit is contained in:
Shane Lontis 2020-05-14 12:32:44 +10:00 committed by Dr. David von Oheimb
parent 97e00da902
commit ab28b59064
2 changed files with 40 additions and 8 deletions

View File

@ -18,6 +18,8 @@ typedef struct test_fixture {
OSSL_CMP_MSG *req;
} CMP_SRV_TEST_FIXTURE;
static OPENSSL_CTX *libctx = NULL;
static OSSL_PROVIDER *default_null_provider = NULL, *provider = NULL;
static OSSL_CMP_MSG *request = NULL;
static void tear_down(CMP_SRV_TEST_FIXTURE *fixture)
@ -33,7 +35,7 @@ static CMP_SRV_TEST_FIXTURE *set_up(const char *const test_case_name)
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
return NULL;
fixture->test_case_name = test_case_name;
if (!TEST_ptr(fixture->srv_ctx = OSSL_CMP_SRV_CTX_new(NULL, NULL)))
if (!TEST_ptr(fixture->srv_ctx = OSSL_CMP_SRV_CTX_new(libctx, NULL)))
goto err;
return fixture;
@ -67,7 +69,7 @@ static int execute_test_handle_request(CMP_SRV_TEST_FIXTURE *fixture)
OSSL_CMP_ERRORMSGCONTENT *errorContent;
int res = 0;
if (!TEST_ptr(client_ctx = OSSL_CMP_CTX_new(NULL, NULL))
if (!TEST_ptr(client_ctx = OSSL_CMP_CTX_new(libctx, NULL))
|| !TEST_true(OSSL_CMP_CTX_set_transfer_cb_arg(client_ctx, ctx)))
goto end;
@ -119,9 +121,16 @@ static int test_handle_request(void)
void cleanup_tests(void)
{
OSSL_CMP_MSG_free(request);
OSSL_PROVIDER_unload(default_null_provider);
OSSL_PROVIDER_unload(provider);
OPENSSL_CTX_free(libctx);
return;
}
#define USAGE \
"CR_protected_PBM_1234.der module_name [module_conf_file]\n"
OPT_TEST_DECLARE_USAGE(USAGE)
int setup_tests(void)
{
const char *request_f;
@ -132,10 +141,13 @@ int setup_tests(void)
}
if (!TEST_ptr(request_f = test_get_argument(0))) {
TEST_error("usage: cmp_server_test CR_protected_PBM_1234.der\n");
TEST_error("usage: cmp_server_test %s", USAGE);
return 0;
}
if (!test_get_libctx(&libctx, &default_null_provider, &provider, 1, USAGE))
return 0;
if (!TEST_ptr(request = load_pkimsg(request_f))) {
cleanup_tests();
return 0;

View File

@ -9,10 +9,18 @@
# https://www.openssl.org/source/license.html
use strict;
use OpenSSL::Test qw/:DEFAULT data_file/;
use OpenSSL::Test qw/:DEFAULT data_file srctop_file srctop_dir bldtop_file bldtop_dir/;
use OpenSSL::Test::Utils;
setup("test_cmp_server");
BEGIN {
setup("test_cmp_server");
}
use lib srctop_dir('Configurations');
use lib bldtop_dir('.');
use platform;
my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
plan skip_all => "This test is not supported in a no-cmp build"
if disabled("cmp");
@ -20,7 +28,19 @@ plan skip_all => "This test is not supported in a no-cmp build"
plan skip_all => "This test is not supported in a no-ec build"
if disabled("ec");
plan tests => 1;
plan tests => 2 + ($no_fips ? 0 : 2); #fips install + fips test
ok(run(test(["cmp_server_test",
data_file("CR_protected_PBM_1234.der")])));
my @basic_cmd = ("cmp_server_test", data_file("CR_protected_PBM_1234.der"));
ok(run(test([@basic_cmd, "none"])));
ok(run(test([@basic_cmd, "default", srctop_file("test", "default.cnf")])));
unless ($no_fips) {
ok(run(app(['openssl', 'fipsinstall',
'-out', bldtop_file('providers', 'fipsmodule.cnf'),
'-module', bldtop_file('providers', platform->dso('fips'))])),
"fipsinstall");
ok(run(test([@basic_cmd, "fips", srctop_file("test", "fips.cnf")])));
}