Add test for the provider configuration module
We reuse test/provider_internal_test.c and test/p_test.c, and get it loaded one more time via the configuration file test/provider_internal_test.conf To support different platform standards regarding module extensions, we generate test/provider_internal_test.conf Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/8549)
This commit is contained in:
parent
abbc2c4083
commit
6d872a838d
6 changed files with 67 additions and 18 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -60,6 +60,8 @@ Makefile
|
|||
/test/versions
|
||||
/test/ossl_shim/ossl_shim
|
||||
/test/rsa_complex
|
||||
# Other generated files in test/
|
||||
/test/provider_internal_test.conf
|
||||
|
||||
# Certain files that get created by tests on the fly
|
||||
/test/test-runs
|
||||
|
|
|
@ -616,6 +616,8 @@ IF[{- !$disabled{tests} -}]
|
|||
DEFINE[provider_test]=OPENSSL_NO_MODULE
|
||||
DEFINE[provider_internal_test]=OPENSSL_NO_MODULE
|
||||
ENDIF
|
||||
DEPEND[]=provider_internal_test.conf
|
||||
GENERATE[provider_internal_test.conf]=provider_internal_test.conf.in
|
||||
|
||||
PROGRAMS{noinst}=params_test
|
||||
SOURCE[params_test]=params_test.c
|
||||
|
|
|
@ -52,21 +52,33 @@ static int p_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
|
|||
if (strcmp(p->key, "greeting") == 0) {
|
||||
static char *opensslv = NULL;
|
||||
static char *provname = NULL;
|
||||
static char *greeting = NULL;
|
||||
static OSSL_PARAM counter_request[] = {
|
||||
/* Known libcrypto provided parameters */
|
||||
{ "openssl-version", OSSL_PARAM_UTF8_PTR,
|
||||
&opensslv, sizeof(&opensslv), NULL },
|
||||
{ "provider-name", OSSL_PARAM_UTF8_PTR,
|
||||
&provname, sizeof(&provname), NULL},
|
||||
|
||||
/* This might be present, if there's such a configuration */
|
||||
{ "greeting", OSSL_PARAM_UTF8_PTR,
|
||||
&greeting, sizeof(&greeting), NULL },
|
||||
|
||||
{ NULL, 0, NULL, 0, NULL }
|
||||
};
|
||||
char buf[256];
|
||||
size_t buf_l;
|
||||
|
||||
if (c_get_params(prov, counter_request)) {
|
||||
if (greeting) {
|
||||
strcpy(buf, greeting);
|
||||
} else {
|
||||
const char *versionp = *(void **)counter_request[0].data;
|
||||
const char *namep = *(void **)counter_request[1].data;
|
||||
|
||||
sprintf(buf, "Hello OpenSSL %.20s, greetings from %s!",
|
||||
versionp, namep);
|
||||
}
|
||||
} else {
|
||||
sprintf(buf, "Howdy stranger...");
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "internal/provider.h"
|
||||
#include "testutil.h"
|
||||
|
||||
|
@ -20,20 +21,11 @@ static OSSL_PARAM greeting_request[] = {
|
|||
{ NULL, 0, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
static int test_provider(OSSL_PROVIDER *prov)
|
||||
static int test_provider(OSSL_PROVIDER *prov, const char *expected_greeting)
|
||||
{
|
||||
const char *name = NULL;
|
||||
const char *greeting = NULL;
|
||||
char expected_greeting[256];
|
||||
int ret = 0;
|
||||
|
||||
if (!TEST_ptr(name = ossl_provider_name(prov)))
|
||||
return 0;
|
||||
|
||||
BIO_snprintf(expected_greeting, sizeof(expected_greeting),
|
||||
"Hello OpenSSL %.20s, greetings from %s!",
|
||||
OPENSSL_VERSION_STR, name);
|
||||
|
||||
ret =
|
||||
TEST_true(ossl_provider_activate(prov))
|
||||
&& TEST_true(ossl_provider_get_params(prov, greeting_request))
|
||||
|
@ -41,10 +33,22 @@ static int test_provider(OSSL_PROVIDER *prov)
|
|||
&& TEST_size_t_gt(greeting_request[0].data_size, 0)
|
||||
&& TEST_str_eq(greeting, expected_greeting);
|
||||
|
||||
TEST_info("Got this greeting: %s\n", greeting);
|
||||
ossl_provider_free(prov);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char *expected_greeting1(const char *name)
|
||||
{
|
||||
static char expected_greeting[256] = "";
|
||||
|
||||
snprintf(expected_greeting, sizeof(expected_greeting),
|
||||
"Hello OpenSSL %.20s, greetings from %s!",
|
||||
OPENSSL_VERSION_STR, name);
|
||||
|
||||
return expected_greeting;
|
||||
}
|
||||
|
||||
static int test_builtin_provider(void)
|
||||
{
|
||||
const char *name = "p_test_builtin";
|
||||
|
@ -53,7 +57,7 @@ static int test_builtin_provider(void)
|
|||
return
|
||||
TEST_ptr(prov =
|
||||
ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME))
|
||||
&& test_provider(prov);
|
||||
&& test_provider(prov, expected_greeting1(name));
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_MODULE
|
||||
|
@ -64,7 +68,21 @@ static int test_loaded_provider(void)
|
|||
|
||||
return
|
||||
TEST_ptr(prov = ossl_provider_new(NULL, name, NULL))
|
||||
&& test_provider(prov);
|
||||
&& test_provider(prov, expected_greeting1(name));
|
||||
}
|
||||
|
||||
static int test_configured_provider(void)
|
||||
{
|
||||
const char *name = "p_test_configured";
|
||||
OSSL_PROVIDER *prov = NULL;
|
||||
/* This MUST match the config file */
|
||||
const char *expected_greeting =
|
||||
"Hello OpenSSL, greetings from Test Provider";
|
||||
|
||||
return
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL)
|
||||
&& TEST_ptr(prov = ossl_provider_find(NULL, name))
|
||||
&& test_provider(prov, expected_greeting);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -73,6 +91,7 @@ int setup_tests(void)
|
|||
ADD_TEST(test_builtin_provider);
|
||||
#ifndef OPENSSL_NO_MODULE
|
||||
ADD_TEST(test_loaded_provider);
|
||||
ADD_TEST(test_configured_provider);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
|
13
test/provider_internal_test.conf.in
Normal file
13
test/provider_internal_test.conf.in
Normal file
|
@ -0,0 +1,13 @@
|
|||
{- use platform -}
|
||||
openssl_conf = openssl_init
|
||||
|
||||
[openssl_init]
|
||||
providers = providers
|
||||
|
||||
[providers]
|
||||
p_test_configured = p_test_configured
|
||||
|
||||
[p_test_configured]
|
||||
module = {- platform->dso('p_test') -}
|
||||
activate = 1
|
||||
greeting = Hello OpenSSL, greetings from Test Provider
|
|
@ -7,12 +7,13 @@
|
|||
# https://www.openssl.org/source/license.html
|
||||
|
||||
use strict;
|
||||
use OpenSSL::Test qw(:DEFAULT bldtop_dir);
|
||||
use OpenSSL::Test qw(:DEFAULT bldtop_dir bldtop_file);
|
||||
use OpenSSL::Test::Simple;
|
||||
use OpenSSL::Test::Utils;
|
||||
|
||||
setup("test_internal_provider");
|
||||
|
||||
$ENV{"OPENSSL_MODULES"} = bldtop_dir("test");
|
||||
$ENV{OPENSSL_MODULES} = bldtop_dir("test");
|
||||
$ENV{OPENSSL_CONF} = bldtop_file("test", "provider_internal_test.conf");
|
||||
|
||||
simple_test("test_internal_provider", "provider_internal_test");
|
||||
|
|
Loading…
Reference in a new issue