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