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