2
0

prov_config_test.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2021 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 <openssl/evp.h>
  10. #include "testutil.h"
  11. static char *configfile = NULL;
  12. /*
  13. * Test to make sure there are no leaks or failures from loading the config
  14. * file twice.
  15. */
  16. static int test_double_config(void)
  17. {
  18. OSSL_LIB_CTX *ctx = OSSL_LIB_CTX_new();
  19. int testresult = 0;
  20. EVP_MD *sha256 = NULL;
  21. if (!TEST_ptr(configfile))
  22. return 0;
  23. if (!TEST_ptr(ctx))
  24. return 0;
  25. if (!TEST_true(OSSL_LIB_CTX_load_config(ctx, configfile)))
  26. return 0;
  27. if (!TEST_true(OSSL_LIB_CTX_load_config(ctx, configfile)))
  28. return 0;
  29. /* Check we can actually fetch something */
  30. sha256 = EVP_MD_fetch(ctx, "SHA2-256", NULL);
  31. if (!TEST_ptr(sha256))
  32. goto err;
  33. testresult = 1;
  34. err:
  35. EVP_MD_free(sha256);
  36. OSSL_LIB_CTX_free(ctx);
  37. return testresult;
  38. }
  39. OPT_TEST_DECLARE_USAGE("configfile\n")
  40. int setup_tests(void)
  41. {
  42. if (!test_skip_common_options()) {
  43. TEST_error("Error parsing test options\n");
  44. return 0;
  45. }
  46. if (!TEST_ptr(configfile = test_get_argument(0)))
  47. return 0;
  48. ADD_TEST(test_double_config);
  49. return 1;
  50. }