summaryrefslogtreecommitdiffstats
path: root/test/property_test.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2021-10-04 15:33:37 +0200
committerRichard Levitte <levitte@openssl.org>2021-10-27 12:41:15 +0200
commitdc010ca6ec01d313a84c3c4b040232655a1772ad (patch)
treeb925e2db5fad6f5c06e5bbac180fe15c223ae8b7 /test/property_test.c
parent433e13455ede1a39d415b690b8a564b4f36b8dee (diff)
CORE: Encure that cached fetches can be done per provider
This mostly entails passing around a provider pointer, and handling queries that includes a pointer to a provider, where NULL means "any". This also means that there's a need to pass the provider pointer, not just down to the cache functions, but also be able to get it from ossl_method_store_fetch(). To this end, that function's OSSL_PROVIDER pointer argument is modified to be a pointer reference, so the function can answer back what provider the method comes from. Test added. Fixes #16614 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16725)
Diffstat (limited to 'test/property_test.c')
-rw-r--r--test/property_test.c146
1 files changed, 118 insertions, 28 deletions
diff --git a/test/property_test.c b/test/property_test.c
index c23ddb0f99..ad44cf1513 100644
--- a/test/property_test.c
+++ b/test/property_test.c
@@ -15,6 +15,16 @@
#include "internal/property.h"
#include "../crypto/property/property_local.h"
+/*
+ * We make our OSSL_PROVIDER for testing purposes. All we really need is
+ * a pointer. We know that as long as we don't try to use the method
+ * cache flush functions, the provider pointer is merely a pointer being
+ * passed around, and used as a tag of sorts.
+ */
+struct ossl_provider_st {
+ int x;
+};
+
static int add_property_names(const char *n, ...)
{
va_list args;
@@ -313,13 +323,14 @@ static int test_register_deregister(void)
size_t i;
int ret = 0;
OSSL_METHOD_STORE *store;
+ OSSL_PROVIDER prov = { 1 };
if (!TEST_ptr(store = ossl_method_store_new(NULL))
|| !add_property_names("position", NULL))
goto err;
for (i = 0; i < OSSL_NELEM(impls); i++)
- if (!TEST_true(ossl_method_store_add(store, NULL, impls[i].nid,
+ if (!TEST_true(ossl_method_store_add(store, &prov, impls[i].nid,
impls[i].prop, impls[i].impl,
&up_ref, &down_ref))) {
TEST_note("iteration %zd", i + 1);
@@ -348,34 +359,40 @@ err:
static int test_property(void)
{
+ static OSSL_PROVIDER fake_provider1 = { 1 };
+ static OSSL_PROVIDER fake_provider2 = { 2 };
+ static const OSSL_PROVIDER *fake_prov1 = &fake_provider1;
+ static const OSSL_PROVIDER *fake_prov2 = &fake_provider2;
static const struct {
+ const OSSL_PROVIDER **prov;
int nid;
const char *prop;
char *impl;
} impls[] = {
- { 1, "fast=no, colour=green", "a" },
- { 1, "fast, colour=blue", "b" },
- { 1, "", "-" },
- { 9, "sky=blue, furry", "c" },
- { 3, NULL, "d" },
- { 6, "sky.colour=blue, sky=green, old.data", "e" },
+ { &fake_prov1, 1, "fast=no, colour=green", "a" },
+ { &fake_prov1, 1, "fast, colour=blue", "b" },
+ { &fake_prov1, 1, "", "-" },
+ { &fake_prov2, 9, "sky=blue, furry", "c" },
+ { &fake_prov2, 3, NULL, "d" },
+ { &fake_prov2, 6, "sky.colour=blue, sky=green, old.data", "e" },
};
static struct {
+ const OSSL_PROVIDER **prov;
int nid;
const char *prop;
char *expected;
} queries[] = {
- { 1, "fast", "b" },
- { 1, "fast=yes", "b" },
- { 1, "fast=no, colour=green", "a" },
- { 1, "colour=blue, fast", "b" },
- { 1, "colour=blue", "b" },
- { 9, "furry", "c" },
- { 6, "sky.colour=blue", "e" },
- { 6, "old.data", "e" },
- { 9, "furry=yes, sky=blue", "c" },
- { 1, "", "a" },
- { 3, "", "d" },
+ { &fake_prov1, 1, "fast", "b" },
+ { &fake_prov1, 1, "fast=yes", "b" },
+ { &fake_prov1, 1, "fast=no, colour=green", "a" },
+ { &fake_prov1, 1, "colour=blue, fast", "b" },
+ { &fake_prov1, 1, "colour=blue", "b" },
+ { &fake_prov2, 9, "furry", "c" },
+ { &fake_prov2, 6, "sky.colour=blue", "e" },
+ { &fake_prov2, 6, "old.data", "e" },
+ { &fake_prov2, 9, "furry=yes, sky=blue", "c" },
+ { &fake_prov1, 1, "", "a" },
+ { &fake_prov2, 3, "", "d" },
};
OSSL_METHOD_STORE *store;
size_t i;
@@ -387,17 +404,24 @@ static int test_property(void)
goto err;
for (i = 0; i < OSSL_NELEM(impls); i++)
- if (!TEST_true(ossl_method_store_add(store, NULL, impls[i].nid,
- impls[i].prop, impls[i].impl,
+ if (!TEST_true(ossl_method_store_add(store, *impls[i].prov,
+ impls[i].nid, impls[i].prop,
+ impls[i].impl,
&up_ref, &down_ref))) {
TEST_note("iteration %zd", i + 1);
goto err;
}
+ /*
+ * The first check of queries is with NULL given as provider. All
+ * queries are expected to succeed.
+ */
for (i = 0; i < OSSL_NELEM(queries); i++) {
+ const OSSL_PROVIDER *nullprov = NULL;
OSSL_PROPERTY_LIST *pq = NULL;
- if (!TEST_true(ossl_method_store_fetch(store, queries[i].nid,
- queries[i].prop, &result))
+ if (!TEST_true(ossl_method_store_fetch(store,
+ queries[i].nid, queries[i].prop,
+ &nullprov, &result))
|| !TEST_str_eq((char *)result, queries[i].expected)) {
TEST_note("iteration %zd", i + 1);
ossl_property_free(pq);
@@ -405,6 +429,70 @@ static int test_property(void)
}
ossl_property_free(pq);
}
+ /*
+ * The second check of queries is with &address1 given as provider.
+ */
+ for (i = 0; i < OSSL_NELEM(queries); i++) {
+ OSSL_PROPERTY_LIST *pq = NULL;
+
+ result = NULL;
+ if (queries[i].prov == &fake_prov1) {
+ if (!TEST_true(ossl_method_store_fetch(store,
+ queries[i].nid,
+ queries[i].prop,
+ &fake_prov1, &result))
+ || !TEST_ptr_eq(fake_prov1, &fake_provider1)
+ || !TEST_str_eq((char *)result, queries[i].expected)) {
+ TEST_note("iteration %zd", i + 1);
+ ossl_property_free(pq);
+ goto err;
+ }
+ } else {
+ if (!TEST_false(ossl_method_store_fetch(store,
+ queries[i].nid,
+ queries[i].prop,
+ &fake_prov1, &result))
+ || !TEST_ptr_eq(fake_prov1, &fake_provider1)
+ || !TEST_ptr_null(result)) {
+ TEST_note("iteration %zd", i + 1);
+ ossl_property_free(pq);
+ goto err;
+ }
+ }
+ ossl_property_free(pq);
+ }
+ /*
+ * The third check of queries is with &address2 given as provider.
+ */
+ for (i = 0; i < OSSL_NELEM(queries); i++) {
+ OSSL_PROPERTY_LIST *pq = NULL;
+
+ result = NULL;
+ if (queries[i].prov == &fake_prov2) {
+ if (!TEST_true(ossl_method_store_fetch(store,
+ queries[i].nid,
+ queries[i].prop,
+ &fake_prov2, &result))
+ || !TEST_ptr_eq(fake_prov2, &fake_provider2)
+ || !TEST_str_eq((char *)result, queries[i].expected)) {
+ TEST_note("iteration %zd", i + 1);
+ ossl_property_free(pq);
+ goto err;
+ }
+ } else {
+ if (!TEST_false(ossl_method_store_fetch(store,
+ queries[i].nid,
+ queries[i].prop,
+ &fake_prov2, &result))
+ || !TEST_ptr_eq(fake_prov2, &fake_provider2)
+ || !TEST_ptr_null(result)) {
+ TEST_note("iteration %zd", i + 1);
+ ossl_property_free(pq);
+ goto err;
+ }
+ }
+ ossl_property_free(pq);
+ }
ret = 1;
err:
ossl_method_store_free(store);
@@ -420,6 +508,7 @@ static int test_query_cache_stochastic(void)
void *result;
int errors = 0;
int v[10001];
+ OSSL_PROVIDER prov = { 1 };
if (!TEST_ptr(store = ossl_method_store_new(NULL))
|| !add_property_names("n", NULL))
@@ -428,20 +517,21 @@ static int test_query_cache_stochastic(void)
for (i = 1; i <= max; i++) {
v[i] = 2 * i;
BIO_snprintf(buf, sizeof(buf), "n=%d\n", i);
- if (!TEST_true(ossl_method_store_add(store, NULL, i, buf, "abc",
+ if (!TEST_true(ossl_method_store_add(store, &prov, i, buf, "abc",
&up_ref, &down_ref))
- || !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i,
+ || !TEST_true(ossl_method_store_cache_set(store, &prov, i,
+ buf, v + i,
&up_ref, &down_ref))
- || !TEST_true(ossl_method_store_cache_set(store, i, "n=1234",
- "miss", &up_ref,
- &down_ref))) {
+ || !TEST_true(ossl_method_store_cache_set(store, &prov, i,
+ "n=1234", "miss",
+ &up_ref, &down_ref))) {
TEST_note("iteration %d", i);
goto err;
}
}
for (i = 1; i <= max; i++) {
BIO_snprintf(buf, sizeof(buf), "n=%d\n", i);
- if (!ossl_method_store_cache_get(store, i, buf, &result)
+ if (!ossl_method_store_cache_get(store, NULL, i, buf, &result)
|| result != v + i)
errors++;
}