ossl_store_test.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright 2020 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/store.h>
  10. #include <openssl/ui.h>
  11. #include "testutil.h"
  12. typedef enum OPTION_choice {
  13. OPT_ERR = -1,
  14. OPT_EOF = 0,
  15. OPT_INFILE,
  16. OPT_TEST_ENUM
  17. } OPTION_CHOICE;
  18. static const char *infile = NULL;
  19. static int test_store_open(void)
  20. {
  21. int ret = 0;
  22. OSSL_STORE_CTX *sctx = NULL;
  23. OSSL_STORE_SEARCH *search = NULL;
  24. UI_METHOD *ui_method = NULL;
  25. ret = TEST_ptr(search = OSSL_STORE_SEARCH_by_alias("nothing"))
  26. && TEST_ptr(ui_method= UI_create_method("DummyUI"))
  27. && TEST_ptr(sctx = OSSL_STORE_open_ex(infile, NULL, NULL, ui_method,
  28. NULL, NULL, NULL))
  29. && TEST_false(OSSL_STORE_find(sctx, NULL))
  30. && TEST_true(OSSL_STORE_find(sctx, search));
  31. UI_destroy_method(ui_method);
  32. OSSL_STORE_SEARCH_free(search);
  33. OSSL_STORE_close(sctx);
  34. return ret;
  35. }
  36. static int test_store_search_by_key_fingerprint_fail(void)
  37. {
  38. int ret;
  39. OSSL_STORE_SEARCH *search = NULL;
  40. ret = TEST_ptr_null(search = OSSL_STORE_SEARCH_by_key_fingerprint(
  41. EVP_sha256(), NULL, 0));
  42. OSSL_STORE_SEARCH_free(search);
  43. return ret;
  44. }
  45. const OPTIONS *test_get_options(void)
  46. {
  47. static const OPTIONS test_options[] = {
  48. OPT_TEST_OPTIONS_DEFAULT_USAGE,
  49. { "in", OPT_INFILE, '<', },
  50. { NULL }
  51. };
  52. return test_options;
  53. }
  54. int setup_tests(void)
  55. {
  56. OPTION_CHOICE o;
  57. while ((o = opt_next()) != OPT_EOF) {
  58. switch (o) {
  59. case OPT_INFILE:
  60. infile = opt_arg();
  61. break;
  62. case OPT_TEST_CASES:
  63. break;
  64. default:
  65. case OPT_ERR:
  66. return 0;
  67. }
  68. }
  69. ADD_TEST(test_store_open);
  70. ADD_TEST(test_store_search_by_key_fingerprint_fail);
  71. return 1;
  72. }