Ensure we test fetching encoder/decoder/store loader with a query string
authorMatt Caswell <matt@openssl.org>
Mon, 10 Jan 2022 14:46:46 +0000 (14:46 +0000)
committerPauli <pauli@openssl.org>
Wed, 12 Jan 2022 00:00:33 +0000 (11:00 +1100)
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)

test/provfetchtest.c

index 95ae87910e6189ea3dffc954de5ca6212d17542c..aae9b4005790714a2373385641494ba170e98718 100644 (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;
 }