summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Horman <nhorman@openssl.org>2024-04-03 15:18:33 -0400
committerTomas Mraz <tomas@openssl.org>2024-04-26 14:06:30 +0200
commit74f551e90c3415bd391add232a93d433fb052b55 (patch)
treecd0231e6b42f3c0a5213c0ad4f020badb849497e
parentb6456af5c043397998997a4f91348fb0aeca2625 (diff)
Add test for OSSL_PROVIDER_load with module path set
Ensure that, with the modulepath setting set in a config field, that we are able to load a provider from the path relative to OPENSSL_MODULES Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (cherry picked from commit 91a77cbf66c575345cf1eab31717e8edafcd1633) (Merged from https://github.com/openssl/openssl/pull/24198) (cherry picked from commit db163245097bc813235403c234795721d4e5c4eb)
-rw-r--r--test/build.info1
-rw-r--r--test/pathed.cnf22
-rw-r--r--test/prov_config_test.c42
-rw-r--r--test/recipes/30-test_prov_config.t6
4 files changed, 69 insertions, 2 deletions
diff --git a/test/build.info b/test/build.info
index 416c227077..25ab0430b7 100644
--- a/test/build.info
+++ b/test/build.info
@@ -874,6 +874,7 @@ IF[{- !$disabled{tests} -}]
ENDIF
IF[{- $disabled{module} || !$target{dso_scheme} -}]
DEFINE[provider_test]=NO_PROVIDER_MODULE
+ DEFINE[prov_config_test]=NO_PROVIDER_MODULE
DEFINE[provider_internal_test]=NO_PROVIDER_MODULE
ENDIF
DEPEND[]=provider_internal_test.cnf
diff --git a/test/pathed.cnf b/test/pathed.cnf
new file mode 100644
index 0000000000..07bdc1fdb2
--- /dev/null
+++ b/test/pathed.cnf
@@ -0,0 +1,22 @@
+openssl_conf = openssl_init
+
+# Comment out the next line to ignore configuration errors
+config_diagnostics = 1
+
+[openssl_init]
+providers = provider_sect
+
+[provider_sect]
+default = default_sect
+legacy = legacy_sect
+test = test_sect
+
+[test_sect]
+module = ../test/p_test.so
+activate = false
+
+[default_sect]
+activate = true
+
+[legacy_sect]
+activate = false
diff --git a/test/prov_config_test.c b/test/prov_config_test.c
index b44ec78d8d..d59a954667 100644
--- a/test/prov_config_test.c
+++ b/test/prov_config_test.c
@@ -13,6 +13,7 @@
static char *configfile = NULL;
static char *recurseconfigfile = NULL;
+static char *pathedconfig = NULL;
/*
* Test to make sure there are no leaks or failures from loading the config
@@ -70,6 +71,34 @@ static int test_recursive_config(void)
return testresult;
}
+#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACOSX) && !defined(NO_PROVIDER_MODULE)
+static int test_path_config(void)
+{
+ OSSL_LIB_CTX *ctx = OSSL_LIB_CTX_new();
+ OSSL_PROVIDER *prov;
+ int testresult = 0;
+
+ if (!TEST_ptr(pathedconfig))
+ return 0;
+ if (!TEST_ptr(ctx))
+ return 0;
+
+ if (!TEST_true(OSSL_LIB_CTX_load_config(ctx, pathedconfig)))
+ goto err;
+
+ /* attempt to manually load the test provider */
+ if (!TEST_ptr(prov = OSSL_PROVIDER_load(ctx, "test")))
+ goto err;
+
+ OSSL_PROVIDER_unload(prov);
+
+ testresult = 1;
+ err:
+ OSSL_LIB_CTX_free(ctx);
+ return testresult;
+}
+#endif
+
OPT_TEST_DECLARE_USAGE("configfile\n")
int setup_tests(void)
@@ -85,7 +114,20 @@ int setup_tests(void)
if (!TEST_ptr(recurseconfigfile = test_get_argument(1)))
return 0;
+ if (!TEST_ptr(pathedconfig = test_get_argument(2)))
+ return 0;
+
ADD_TEST(test_recursive_config);
ADD_TEST(test_double_config);
+#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACOSX) && !defined(NO_PROVIDER_MODULE)
+ /*
+ * This test has to specify a module path to a file
+ * Which is setup as ../test/p_test.so
+ * Since windows/macos doesn't build with that extension
+ * just skip the test here
+ * Additionally skip it if we're not building provider modules
+ */
+ ADD_TEST(test_path_config);
+#endif
return 1;
}
diff --git a/test/recipes/30-test_prov_config.t b/test/recipes/30-test_prov_config.t
index 7f6350fd84..8884d07f3a 100644
--- a/test/recipes/30-test_prov_config.t
+++ b/test/recipes/30-test_prov_config.t
@@ -23,13 +23,15 @@ my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
plan tests => 2;
ok(run(test(["prov_config_test", srctop_file("test", "default.cnf"),
- srctop_file("test", "recursive.cnf")])),
+ srctop_file("test", "recursive.cnf"),
+ srctop_file("test", "pathed.cnf")])),
"running prov_config_test default.cnf");
SKIP: {
skip "Skipping FIPS test in this build", 1 if $no_fips;
ok(run(test(["prov_config_test", srctop_file("test", "fips.cnf"),
- srctop_file("test", "recursive.cnf")])),
+ srctop_file("test", "recursive.cnf"),
+ srctop_file("test", "pathed.cnf")])),
"running prov_config_test fips.cnf");
}