diff options
author | Richard Levitte <levitte@openssl.org> | 2019-02-20 22:55:43 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-03-11 20:40:13 +0100 |
commit | 021a65527735af2ddc063d9300138660e3782a15 (patch) | |
tree | e231a2cd57d82e92d78370b89d788282a0be1b07 /test/provider_internal_test.c | |
parent | 16c2f1bdb5f051ee2c0ac96182a0fb5bad7daa68 (diff) | |
download | openssl-new-021a65527735af2ddc063d9300138660e3782a15.tar.gz |
Add provider tests
Two tests are added, one that tests the internal API, the other tests
the public API. Those two tests both test the same provider, which
acts both as a built-in provider and as a loadable provider module.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8287)
Diffstat (limited to 'test/provider_internal_test.c')
-rw-r--r-- | test/provider_internal_test.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/provider_internal_test.c b/test/provider_internal_test.c new file mode 100644 index 0000000000..c423808f3e --- /dev/null +++ b/test/provider_internal_test.c @@ -0,0 +1,79 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <stddef.h> +#include "internal/provider.h" +#include "testutil.h" + +extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME; + +static char buf[256]; +static size_t buf_l = 0; +static OSSL_PARAM greeting_request[] = { + { "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf), &buf_l }, + { NULL, 0, NULL, 0, NULL } +}; + +static int test_provider(OSSL_PROVIDER *prov) +{ + const char *name = NULL; + const char *greeting = NULL; + char expected_greeting[256]; + int ret = 0; + + if (!TEST_ptr(name = ossl_provider_name(prov))) + return 0; + + snprintf(expected_greeting, sizeof(expected_greeting), + "Hello OpenSSL %.20s, greetings from %s!", + OPENSSL_VERSION_STR, name); + + ret = + TEST_true(ossl_provider_activate(prov)) + && TEST_true(ossl_provider_get_params(prov, greeting_request)) + && TEST_ptr(greeting = greeting_request[0].buffer) + && TEST_size_t_gt(greeting_request[0].buffer_size, 0) + && TEST_str_eq(greeting, expected_greeting); + + ossl_provider_free(prov); + return ret; +} + +static int test_builtin_provider(void) +{ + const char *name = "p_test_builtin"; + OSSL_PROVIDER *prov = NULL; + + return + TEST_ptr(prov = + ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME)) + && test_provider(prov); +} + +#ifndef OPENSSL_NO_SHARED +static int test_loaded_provider(void) +{ + const char *name = "p_test"; + OSSL_PROVIDER *prov = NULL; + + return + TEST_ptr(prov = ossl_provider_new(NULL, name, NULL)) + && test_provider(prov); +} +#endif + +int setup_tests(void) +{ + ADD_TEST(test_builtin_provider); +#ifndef OPENSSL_NO_SHARED + ADD_TEST(test_loaded_provider); +#endif + return 1; +} + |