Ensure we test fetching encoder/decoder/store loader with a query string

Although we had a test for fetching an encoder/decoder/store loader it
did not use a query string. The issue highlighted by #17456 only occurs
if a query string is used.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17459)
This commit is contained in:
Matt Caswell 2022-01-10 14:46:46 +00:00 committed by Pauli
parent cd1981a0dc
commit f5e97b3702

View File

@ -225,6 +225,7 @@ static int dummy_provider_init(const OSSL_CORE_HANDLE *handle,
* Test 1: Encoder
* Test 2: Store loader
* Test 3: EVP_RAND
* Test 4-7: As above, but additionally with a query string
*/
static int fetch_test(int tst)
{
@ -236,6 +237,7 @@ static int fetch_test(int tst)
OSSL_STORE_LOADER *loader = NULL;
int testresult = 0;
unsigned char buf[32];
int query = tst > 3;
if (!TEST_ptr(libctx))
goto err;
@ -246,24 +248,29 @@ static int fetch_test(int tst)
|| !TEST_ptr(dummyprov = OSSL_PROVIDER_load(libctx, "dummy-prov")))
goto err;
switch (tst) {
switch (tst % 4) {
case 0:
decoder = OSSL_DECODER_fetch(libctx, "DUMMY", NULL);
decoder = OSSL_DECODER_fetch(libctx, "DUMMY",
query ? "provider=dummy" : NULL);
if (!TEST_ptr(decoder))
goto err;
break;
case 1:
encoder = OSSL_ENCODER_fetch(libctx, "DUMMY", NULL);
encoder = OSSL_ENCODER_fetch(libctx, "DUMMY",
query ? "provider=dummy" : NULL);
if (!TEST_ptr(encoder))
goto err;
break;
case 2:
loader = OSSL_STORE_LOADER_fetch(libctx, "DUMMY", NULL);
loader = OSSL_STORE_LOADER_fetch(libctx, "DUMMY",
query ? "provider=dummy" : NULL);
if (!TEST_ptr(loader))
goto err;
break;
case 3:
if (!TEST_true(RAND_set_DRBG_type(libctx, "DUMMY", NULL, NULL, NULL))
if (!TEST_true(RAND_set_DRBG_type(libctx, "DUMMY",
query ? "provider=dummy" : NULL,
NULL, NULL))
|| !TEST_int_ge(RAND_bytes_ex(libctx, buf, sizeof(buf), 0), 1))
goto err;
break;
@ -284,7 +291,7 @@ static int fetch_test(int tst)
int setup_tests(void)
{
ADD_ALL_TESTS(fetch_test, 4);
ADD_ALL_TESTS(fetch_test, 8);
return 1;
}