summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDmitry Belyavskiy <beldmit@gmail.com>2023-08-03 13:20:33 +0200
committerDmitry Belyavskiy <beldmit@gmail.com>2023-08-30 21:55:47 +0200
commit4f3e3d9d3cb9632a8263cfe27ff11f342bf93351 (patch)
treec0d2ad236bb062d41b057befb031c79fd72f0776 /test
parent9d2f7e1f611f03e65f25adf08b76e08821b315da (diff)
OSSL_PROVIDER_load_ex tests
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tim Hudson <tjh@openssl.org> (Merged from https://github.com/openssl/openssl/pull/21604)
Diffstat (limited to 'test')
-rw-r--r--test/provider_internal_test.c4
-rw-r--r--test/provider_test.c67
2 files changed, 68 insertions, 3 deletions
diff --git a/test/provider_internal_test.c b/test/provider_internal_test.c
index bccce7159e..6c333f85db 100644
--- a/test/provider_internal_test.c
+++ b/test/provider_internal_test.c
@@ -64,7 +64,7 @@ static int test_builtin_provider(void)
ret =
TEST_ptr(prov =
- ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME, 0))
+ ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME, NULL, 0))
&& test_provider(prov, expected_greeting1(name));
EVP_set_default_properties(NULL, "");
@@ -79,7 +79,7 @@ static int test_loaded_provider(void)
OSSL_PROVIDER *prov = NULL;
return
- TEST_ptr(prov = ossl_provider_new(NULL, name, NULL, 0))
+ TEST_ptr(prov = ossl_provider_new(NULL, name, NULL, NULL, 0))
&& test_provider(prov, expected_greeting1(name));
}
diff --git a/test/provider_test.c b/test/provider_test.c
index b2e0a5da71..d1fe71f46d 100644
--- a/test/provider_test.c
+++ b/test/provider_test.c
@@ -9,6 +9,7 @@
#include <stddef.h>
#include <openssl/provider.h>
+#include <openssl/param_build.h>
#include "testutil.h"
extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME;
@@ -157,6 +158,60 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
return ok;
}
+#ifndef NO_PROVIDER_MODULE
+static int test_provider_ex(OSSL_LIB_CTX **libctx, const char *name)
+{
+ OSSL_PROVIDER *prov = NULL;
+ const char *greeting = NULL;
+ int ok = 0;
+ long err;
+ const char custom_buf[] = "Custom greeting";
+ OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
+ OSSL_PARAM *params = NULL;
+
+ OSSL_PARAM_BLD_push_utf8_string(bld, "greeting", custom_buf, strlen(custom_buf));
+ params = OSSL_PARAM_BLD_to_param(bld);
+
+ OSSL_PARAM_BLD_free(bld);
+
+ if (!TEST_ptr(prov = OSSL_PROVIDER_load_ex(*libctx, name, params)))
+ goto err;
+
+ if (!TEST_true(OSSL_PROVIDER_get_params(prov, greeting_request))
+ || !TEST_ptr(greeting = greeting_request[0].data)
+ || !TEST_size_t_gt(greeting_request[0].data_size, 0)
+ || !TEST_str_eq(greeting, custom_buf))
+ goto err;
+
+ /* Make sure we got the error we were expecting */
+ err = ERR_peek_last_error();
+ if (!TEST_int_gt(err, 0)
+ || !TEST_int_eq(ERR_GET_REASON(err), 1))
+ goto err;
+
+ if (!TEST_true(OSSL_PROVIDER_unload(prov)))
+ goto err;
+ prov = NULL;
+
+ /*
+ * We must free the libctx to force the provider to really be unloaded from
+ * memory
+ */
+ OSSL_LIB_CTX_free(*libctx);
+ *libctx = NULL;
+
+ /* We print out all the data to make sure it can still be accessed */
+ ERR_print_errors_fp(stderr);
+ ok = 1;
+ err:
+ OSSL_PARAM_free(params);
+ OSSL_PROVIDER_unload(prov);
+ OSSL_LIB_CTX_free(*libctx);
+ *libctx = NULL;
+ return ok;
+}
+#endif
+
static int test_builtin_provider(void)
{
OSSL_LIB_CTX *libctx = OSSL_LIB_CTX_new();
@@ -211,12 +266,22 @@ static int test_loaded_provider(void)
{
OSSL_LIB_CTX *libctx = OSSL_LIB_CTX_new();
const char *name = "p_test";
+ int res = 0;
if (!TEST_ptr(libctx))
return 0;
/* test_provider will free libctx as part of the test */
- return test_provider(&libctx, name, NULL);
+ res = test_provider(&libctx, name, NULL);
+
+ libctx = OSSL_LIB_CTX_new();
+ if (!TEST_ptr(libctx))
+ return 0;
+
+ /* test_provider_ex will free libctx as part of the test */
+ res = res && test_provider_ex(&libctx, name);
+
+ return res;
}
#endif