provider_default_search_path_test.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  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
  8. */
  9. #include <stddef.h>
  10. #include <openssl/provider.h>
  11. #include "testutil.h"
  12. static int test_default_libctx(void)
  13. {
  14. OSSL_LIB_CTX *ctx = NULL;
  15. char *path = "./some/path";
  16. const char *retrieved_path = NULL;
  17. int ok;
  18. ok = TEST_true(OSSL_PROVIDER_set_default_search_path(ctx, path))
  19. && TEST_ptr(retrieved_path = OSSL_PROVIDER_get0_default_search_path(ctx))
  20. && TEST_str_eq(path, retrieved_path);
  21. return ok;
  22. }
  23. static int test_explicit_libctx(void)
  24. {
  25. OSSL_LIB_CTX *ctx = NULL;
  26. char *def_libctx_path = "./some/path";
  27. char *path = "./another/location";
  28. const char *retrieved_defctx_path = NULL;
  29. const char *retrieved_path = NULL;
  30. int ok;
  31. /* Set search path for default context, then create a new context and set
  32. another path for it. Finally, get both paths and make sure they are
  33. still what we set and are separate. */
  34. ok = TEST_true(OSSL_PROVIDER_set_default_search_path(NULL, def_libctx_path))
  35. && TEST_ptr(ctx = OSSL_LIB_CTX_new())
  36. && TEST_true(OSSL_PROVIDER_set_default_search_path(ctx, path))
  37. && TEST_ptr(retrieved_defctx_path = OSSL_PROVIDER_get0_default_search_path(NULL))
  38. && TEST_str_eq(def_libctx_path, retrieved_defctx_path)
  39. && TEST_ptr(retrieved_path = OSSL_PROVIDER_get0_default_search_path(ctx))
  40. && TEST_str_eq(path, retrieved_path)
  41. && TEST_str_ne(retrieved_path, retrieved_defctx_path);
  42. OSSL_LIB_CTX_free(ctx);
  43. return ok;
  44. }
  45. int setup_tests(void)
  46. {
  47. ADD_TEST(test_default_libctx);
  48. ADD_TEST(test_explicit_libctx);
  49. return 1;
  50. }