From: Matt Caswell Date: Fri, 7 May 2021 16:13:05 +0000 (+0100) Subject: Add a test for converting a property list to a string X-Git-Tag: openssl-3.0.0-alpha17~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ad8570a8b6b4ec27e92013653d4d36b0c1b36991;p=thirdparty%2Fopenssl.git Add a test for converting a property list to a string Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15242) --- diff --git a/test/property_test.c b/test/property_test.c index 3682474bd21..94540bc7769 100644 --- a/test/property_test.c +++ b/test/property_test.c @@ -435,6 +435,61 @@ err: return ret; } +static int test_property_list_to_string(void) +{ + OSSL_PROPERTY_LIST *pl = NULL; + int ret = 0; + struct props_list_str { + const char *in; + const char *out; + } props[] = { + { "fips=yes", "fips=yes" }, + { "fips!=yes", "fips!=yes" }, + { "fips = yes", "fips=yes" }, + { "fips", "fips=yes" }, + { "fips=no", "fips=no" }, + { "-fips", "-fips" }, + { "?fips=yes", "?fips=yes" }, + { "fips=yes,provider=fips", "fips=yes,provider=fips" }, + { "fips = yes , provider = fips", "fips=yes,provider=fips" }, + { "fips=yes,provider!=fips", "fips=yes,provider!=fips" }, + { "fips=yes,?provider=fips", "fips=yes,?provider=fips" }, + { "fips=yes,-provider", "fips=yes,-provider" }, + /* foo is an unknown internal name */ + { "foo=yes,fips=yes", "fips=yes"}, + { "", "" }, + { NULL, "" } + }; + size_t i, bufsize; + char *buf = NULL; + + for (i = 0; i < OSSL_NELEM(props); i++) { + if (props[i].in != NULL + && !TEST_ptr(pl = ossl_parse_query(NULL, props[i].in, 1))) + goto err; + bufsize = ossl_property_list_to_string(NULL, pl, NULL, 0); + if (!TEST_size_t_gt(bufsize, 0)) + goto err; + buf = OPENSSL_malloc(bufsize); + if (!TEST_ptr(buf) + || !TEST_size_t_eq(ossl_property_list_to_string(NULL, pl, buf, + bufsize), + bufsize) + || !TEST_str_eq(props[i].out, buf) + || !TEST_size_t_eq(bufsize, strlen(props[i].out) + 1)) + goto err; + OPENSSL_free(buf); + buf = NULL; + ossl_property_free(pl); + pl = NULL; + } + + ret = 1; + err: + OPENSSL_free(buf); + ossl_property_free(pl); + return ret; +} int setup_tests(void) { @@ -448,5 +503,6 @@ int setup_tests(void) ADD_TEST(test_property); ADD_TEST(test_query_cache_stochastic); ADD_TEST(test_fips_mode); + ADD_TEST(test_property_list_to_string); return 1; }