summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2021-04-26 16:00:04 +0100
committerMatt Caswell <matt@openssl.org>2021-05-11 14:59:43 +0100
commit3b85bcfa14988cb383d94e5dee16645ce1ad39ed (patch)
tree11c993c25d7bc40b4bcbe262e3acac7aa398fefe
parent7b88c184b66c0d7cfb1f76422448af6a636eea8c (diff)
Add a test to check that child provider callbacks are working
Write a test to confirm that if a provider is unloaded/loaded into a libctx then it is similarly unloaded/loaded from any child libctxs. Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14991)
-rw-r--r--test/provider_test.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/test/provider_test.c b/test/provider_test.c
index 0abf55e33d..b2236e3a36 100644
--- a/test/provider_test.c
+++ b/test/provider_test.c
@@ -34,6 +34,7 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
char expected_greeting[256];
int ok = 0;
long err;
+ int dolegacycheck = (legacy != NULL);
BIO_snprintf(expected_greeting, sizeof(expected_greeting),
"Hello OpenSSL %.20s, greetings from %s!",
@@ -41,7 +42,7 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
if (!TEST_ptr(prov = OSSL_PROVIDER_load(*libctx, name)))
goto err;
- if (legacy != NULL) {
+ if (dolegacycheck) {
if (!TEST_true(OSSL_PROVIDER_get_params(prov, digest_check))
|| !TEST_true(digestsuccess))
goto err;
@@ -49,14 +50,40 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
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, expected_greeting)
- || !TEST_true(OSSL_PROVIDER_unload(prov)))
+ || !TEST_str_eq(greeting, expected_greeting))
+ 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;
- prov = NULL;
OSSL_PROVIDER_unload(legacy);
legacy = NULL;
+ if (dolegacycheck) {
+ /* Legacy provider should also be unloaded from child libctx */
+ if (!TEST_true(OSSL_PROVIDER_get_params(prov, digest_check))
+ || !TEST_false(digestsuccess))
+ goto err;
+ /*
+ * Loading the legacy provider again should make it available again in
+ * the child libctx.
+ */
+ legacy = OSSL_PROVIDER_load(*libctx, "legacy");
+ if (!TEST_ptr(legacy)
+ || !TEST_true(OSSL_PROVIDER_get_params(prov, digest_check))
+ || !TEST_true(digestsuccess))
+ goto err;
+ OSSL_PROVIDER_unload(legacy);
+ legacy = NULL;
+ }
+
+ 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
@@ -64,12 +91,6 @@ static int test_provider(OSSL_LIB_CTX **libctx, const char *name,
OSSL_LIB_CTX_free(*libctx);
*libctx = NULL;
- /* 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;
-
/* We print out all the data to make sure it can still be accessed */
ERR_print_errors_fp(stderr);
ok = 1;