asn1_stable_parse_test.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2023 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 *config_file = NULL;
  12. typedef enum OPTION_choice {
  13. OPT_ERR = -1,
  14. OPT_EOF = 0,
  15. OPT_CONFIG_FILE,
  16. OPT_TEST_ENUM
  17. } OPTION_CHOICE;
  18. const OPTIONS *test_get_options(void)
  19. {
  20. static const OPTIONS options[] = {
  21. OPT_TEST_OPTIONS_DEFAULT_USAGE,
  22. { "config", OPT_CONFIG_FILE, '<',
  23. "The configuration file to use for the libctx" },
  24. { NULL }
  25. };
  26. return options;
  27. }
  28. /*
  29. * Test that parsing a config file with incorrect stable settings aren't parsed
  30. * and appropriate errors are raised
  31. */
  32. static int test_asn1_stable_parse(void)
  33. {
  34. int testret = 0;
  35. unsigned long errcode;
  36. OSSL_LIB_CTX *newctx = OSSL_LIB_CTX_new();
  37. if (!TEST_ptr(newctx))
  38. goto out;
  39. if (!TEST_int_eq(OSSL_LIB_CTX_load_config(newctx, config_file), 0))
  40. goto err;
  41. errcode = ERR_peek_error();
  42. if (ERR_GET_LIB(errcode) != ERR_LIB_ASN1)
  43. goto err;
  44. if (ERR_GET_REASON(errcode) != ASN1_R_INVALID_STRING_TABLE_VALUE)
  45. goto err;
  46. ERR_clear_error();
  47. testret = 1;
  48. err:
  49. OSSL_LIB_CTX_free(newctx);
  50. out:
  51. return testret;
  52. }
  53. int setup_tests(void)
  54. {
  55. OPTION_CHOICE o;
  56. while ((o = opt_next()) != OPT_EOF) {
  57. switch (o) {
  58. case OPT_CONFIG_FILE:
  59. config_file = opt_arg();
  60. break;
  61. default:
  62. return 0;
  63. }
  64. }
  65. ADD_TEST(test_asn1_stable_parse);
  66. return 1;
  67. }