1*e7be843bSPierre Pronchery /* 2*e7be843bSPierre Pronchery * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved. 3*e7be843bSPierre Pronchery * 4*e7be843bSPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use 5*e7be843bSPierre Pronchery * this file except in compliance with the License. You can obtain a copy 6*e7be843bSPierre Pronchery * in the file LICENSE in the source distribution or at 7*e7be843bSPierre Pronchery * https://www.openssl.org/source/license.html 8*e7be843bSPierre Pronchery */ 9*e7be843bSPierre Pronchery 10*e7be843bSPierre Pronchery #include <stddef.h> 11*e7be843bSPierre Pronchery #include <openssl/provider.h> 12*e7be843bSPierre Pronchery #include "testutil.h" 13*e7be843bSPierre Pronchery test_default_libctx(void)14*e7be843bSPierre Proncherystatic int test_default_libctx(void) 15*e7be843bSPierre Pronchery { 16*e7be843bSPierre Pronchery OSSL_LIB_CTX *ctx = NULL; 17*e7be843bSPierre Pronchery char *path = "./some/path"; 18*e7be843bSPierre Pronchery const char *retrieved_path = NULL; 19*e7be843bSPierre Pronchery int ok; 20*e7be843bSPierre Pronchery 21*e7be843bSPierre Pronchery ok = TEST_true(OSSL_PROVIDER_set_default_search_path(ctx, path)) 22*e7be843bSPierre Pronchery && TEST_ptr(retrieved_path = OSSL_PROVIDER_get0_default_search_path(ctx)) 23*e7be843bSPierre Pronchery && TEST_str_eq(path, retrieved_path); 24*e7be843bSPierre Pronchery 25*e7be843bSPierre Pronchery return ok; 26*e7be843bSPierre Pronchery } 27*e7be843bSPierre Pronchery test_explicit_libctx(void)28*e7be843bSPierre Proncherystatic int test_explicit_libctx(void) 29*e7be843bSPierre Pronchery { 30*e7be843bSPierre Pronchery OSSL_LIB_CTX *ctx = NULL; 31*e7be843bSPierre Pronchery char *def_libctx_path = "./some/path"; 32*e7be843bSPierre Pronchery char *path = "./another/location"; 33*e7be843bSPierre Pronchery const char *retrieved_defctx_path = NULL; 34*e7be843bSPierre Pronchery const char *retrieved_path = NULL; 35*e7be843bSPierre Pronchery int ok; 36*e7be843bSPierre Pronchery 37*e7be843bSPierre Pronchery /* Set search path for default context, then create a new context and set 38*e7be843bSPierre Pronchery another path for it. Finally, get both paths and make sure they are 39*e7be843bSPierre Pronchery still what we set and are separate. */ 40*e7be843bSPierre Pronchery ok = TEST_true(OSSL_PROVIDER_set_default_search_path(NULL, def_libctx_path)) 41*e7be843bSPierre Pronchery && TEST_ptr(ctx = OSSL_LIB_CTX_new()) 42*e7be843bSPierre Pronchery && TEST_true(OSSL_PROVIDER_set_default_search_path(ctx, path)) 43*e7be843bSPierre Pronchery && TEST_ptr(retrieved_defctx_path = OSSL_PROVIDER_get0_default_search_path(NULL)) 44*e7be843bSPierre Pronchery && TEST_str_eq(def_libctx_path, retrieved_defctx_path) 45*e7be843bSPierre Pronchery && TEST_ptr(retrieved_path = OSSL_PROVIDER_get0_default_search_path(ctx)) 46*e7be843bSPierre Pronchery && TEST_str_eq(path, retrieved_path) 47*e7be843bSPierre Pronchery && TEST_str_ne(retrieved_path, retrieved_defctx_path); 48*e7be843bSPierre Pronchery 49*e7be843bSPierre Pronchery OSSL_LIB_CTX_free(ctx); 50*e7be843bSPierre Pronchery return ok; 51*e7be843bSPierre Pronchery } 52*e7be843bSPierre Pronchery setup_tests(void)53*e7be843bSPierre Proncheryint setup_tests(void) 54*e7be843bSPierre Pronchery { 55*e7be843bSPierre Pronchery ADD_TEST(test_default_libctx); 56*e7be843bSPierre Pronchery ADD_TEST(test_explicit_libctx); 57*e7be843bSPierre Pronchery return 1; 58*e7be843bSPierre Pronchery } 59*e7be843bSPierre Pronchery 60