2 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include <openssl/evp.h>
12 #include <openssl/conf.h>
15 static char *configfile
= NULL
;
16 static char *recurseconfigfile
= NULL
;
17 static char *pathedconfig
= NULL
;
20 * Test to make sure there are no leaks or failures from loading the config
23 static int test_double_config(void)
25 OSSL_LIB_CTX
*ctx
= OSSL_LIB_CTX_new();
27 EVP_MD
*sha256
= NULL
;
29 if (!TEST_ptr(configfile
))
34 if (!TEST_true(OSSL_LIB_CTX_load_config(ctx
, configfile
)))
36 if (!TEST_true(OSSL_LIB_CTX_load_config(ctx
, configfile
)))
39 /* Check we can actually fetch something */
40 sha256
= EVP_MD_fetch(ctx
, "SHA2-256", NULL
);
41 if (!TEST_ptr(sha256
))
47 OSSL_LIB_CTX_free(ctx
);
51 static int test_recursive_config(void)
53 OSSL_LIB_CTX
*ctx
= OSSL_LIB_CTX_new();
57 if (!TEST_ptr(recurseconfigfile
))
63 if (!TEST_false(OSSL_LIB_CTX_load_config(ctx
, recurseconfigfile
)))
66 err
= ERR_peek_error();
67 /* We expect to get a recursion error here */
68 if (ERR_GET_REASON(err
) == CONF_R_RECURSIVE_SECTION_REFERENCE
)
71 OSSL_LIB_CTX_free(ctx
);
75 #define P_TEST_PATH "/../test/p_test.so"
76 static int test_path_config(void)
78 OSSL_LIB_CTX
*ctx
= NULL
;
82 char *module_path
= getenv("OPENSSL_MODULES");
83 char *full_path
= NULL
;
86 if (!TEST_ptr(module_path
))
89 full_path
= OPENSSL_zalloc(strlen(module_path
) + strlen(P_TEST_PATH
) + 1);
90 if (!TEST_ptr(full_path
))
93 strcpy(full_path
, module_path
);
94 full_path
= strcat(full_path
, P_TEST_PATH
);
95 TEST_info("full path is %s", full_path
);
96 rc
= stat(full_path
, &sbuf
);
97 OPENSSL_free(full_path
);
99 return TEST_skip("Skipping modulepath test as provider not present");
101 if (!TEST_ptr(pathedconfig
))
104 ctx
= OSSL_LIB_CTX_new();
108 if (!TEST_true(OSSL_LIB_CTX_load_config(ctx
, pathedconfig
)))
111 /* attempt to manually load the test provider */
112 if (!TEST_ptr(prov
= OSSL_PROVIDER_load(ctx
, "test")))
115 OSSL_PROVIDER_unload(prov
);
119 OSSL_LIB_CTX_free(ctx
);
123 OPT_TEST_DECLARE_USAGE("configfile\n")
125 int setup_tests(void)
127 if (!test_skip_common_options()) {
128 TEST_error("Error parsing test options\n");
132 if (!TEST_ptr(configfile
= test_get_argument(0)))
135 if (!TEST_ptr(recurseconfigfile
= test_get_argument(1)))
138 if (!TEST_ptr(pathedconfig
= test_get_argument(2)))
141 ADD_TEST(test_recursive_config
);
142 ADD_TEST(test_double_config
);
143 ADD_TEST(test_path_config
);