add no engine tests
This commit is contained in:
Родитель
17afe685f0
Коммит
3f3112236f
|
@ -48,7 +48,8 @@ if(${run_unittests})
|
|||
|
||||
#normally, with proper include paths, the below tests can be run under windows too.
|
||||
if(${use_openssl})
|
||||
add_subdirectory(x509_openssl_ut)
|
||||
add_subdirectory(x509_openssl_ut/engine)
|
||||
add_subdirectory(x509_openssl_ut/no_engine)
|
||||
endif()
|
||||
|
||||
add_subdirectory(string_tokenizer_ut)
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
|
||||
set(theseTestsName x509_openssl_ut)
|
||||
set(theseTestsName x509_openssl_ut_engine)
|
||||
|
||||
set(${theseTestsName}_test_files
|
||||
${theseTestsName}.c
|
||||
../x509_openssl_ut.c
|
||||
)
|
||||
|
||||
if(LINUX)
|
||||
|
@ -19,7 +19,7 @@ if(LINUX)
|
|||
endif()
|
||||
|
||||
set(${theseTestsName}_c_files
|
||||
../../adapters/x509_openssl.c
|
||||
../../../adapters/x509_openssl.c
|
||||
)
|
||||
|
||||
set(${theseTestsName}_h_files
|
|
@ -0,0 +1,23 @@
|
|||
#Copyright (c) Microsoft. All rights reserved.
|
||||
#Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
|
||||
set(theseTestsName x509_openssl_ut_no_engine)
|
||||
|
||||
set(${theseTestsName}_test_files
|
||||
../x509_openssl_ut.c
|
||||
)
|
||||
|
||||
set(${theseTestsName}_c_files
|
||||
../../../adapters/x509_openssl.c
|
||||
)
|
||||
|
||||
set(${theseTestsName}_h_files
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENSSL_NO_ENGINE")
|
||||
|
||||
build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests")
|
||||
|
||||
compile_c_test_artifacts_as(${theseTestsName} C99)
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#include "testrunnerswitcher.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
size_t failedTestCount = 0;
|
||||
RUN_TEST_SUITE(x509_openssl_unittests, failedTestCount);
|
||||
return failedTestCount;
|
||||
}
|
|
@ -117,10 +117,12 @@ MOCKABLE_FUNCTION(, long, SSL_CTX_ctrl, SSL_CTX*, ctx, int, cmd, long, larg, voi
|
|||
MOCKABLE_FUNCTION(, unsigned long, ERR_peek_last_error);
|
||||
MOCKABLE_FUNCTION(, void, ERR_clear_error);
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
MOCKABLE_FUNCTION(, int, ENGINE_init, ENGINE*, e);
|
||||
MOCKABLE_FUNCTION(, int, ENGINE_set_default, ENGINE*, e, unsigned int, flags);
|
||||
MOCKABLE_FUNCTION(, EVP_PKEY*, ENGINE_load_private_key, ENGINE*, e, const char*, key_id, UI_METHOD*, ui_method, void*, callback_data);
|
||||
MOCKABLE_FUNCTION(, int, ENGINE_finish, ENGINE*, e);
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
MOCKABLE_FUNCTION(, int, EVP_PKEY_id, const EVP_PKEY*, pkey);
|
||||
|
@ -222,7 +224,9 @@ typedef struct replace_evp_pkey_st_tag
|
|||
#define TEST_X509_STORE (X509_STORE *)"le store"
|
||||
#define TEST_BIO_METHOD (BIO_METHOD*)"le method"
|
||||
#define TEST_BIO (BIO*)"le bio"
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#define TEST_ENGINE (ENGINE*)"the engine"
|
||||
#endif
|
||||
#define TEST_KEY_ID "the key id"
|
||||
|
||||
static const char* TEST_PUBLIC_CERTIFICATE = "PUBLIC CERTIFICATE";
|
||||
|
@ -285,10 +289,12 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
REGISTER_GLOBAL_MOCK_RETURNS(SSL_CTX_use_PrivateKey, 1, 0);
|
||||
REGISTER_GLOBAL_MOCK_HOOK(SSL_CTX_ctrl, my_SSL_CTX_ctrl);
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
REGISTER_GLOBAL_MOCK_RETURNS(ENGINE_init, 1, 0);
|
||||
REGISTER_GLOBAL_MOCK_RETURNS(ENGINE_set_default, 1, 0);
|
||||
REGISTER_GLOBAL_MOCK_RETURNS(ENGINE_load_private_key, g_evp_pkey, NULL);
|
||||
REGISTER_GLOBAL_MOCK_RETURNS(ENGINE_finish, 1, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_SUITE_CLEANUP(TestClassCleanup)
|
||||
|
@ -376,6 +382,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
setup_load_certificate_chain_mocks();
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
static void setup_add_credentials_engine()
|
||||
{
|
||||
// x509_openssl_add_pem_file_key
|
||||
|
@ -387,6 +394,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
STRICT_EXPECTED_CALL(ENGINE_finish(TEST_ENGINE));
|
||||
setup_load_certificate_chain_mocks();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*Tests_SRS_X509_OPENSSL_02_001: [ If any argument is NULL then x509_openssl_add_credentials shall fail and return a non-zero value. ]*/
|
||||
TEST_FUNCTION(x509_openssl_add_credentials_with_NULL_SSL_CTX_fails)
|
||||
|
@ -430,6 +438,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
//cleanup
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
TEST_FUNCTION(x509_openssl_engine_add_credentials_with_NULL_certificate_fails)
|
||||
{
|
||||
//arrange
|
||||
|
@ -442,7 +451,9 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
|
||||
//cleanup
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
TEST_FUNCTION(x509_openssl_engine_add_credentials_with_NULL_privatekey_fails)
|
||||
{
|
||||
//arrange
|
||||
|
@ -455,6 +466,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
|
||||
//cleanup
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_FUNCTION(x509_openssl_engine_add_credentials_with_NULL_engine_fails)
|
||||
{
|
||||
|
@ -504,6 +516,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
//cleanup
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
TEST_FUNCTION(x509_openssl_engine_add_credentials_happy_path)
|
||||
{
|
||||
setup_add_credentials_engine();
|
||||
|
@ -517,6 +530,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
|
||||
//cleanup
|
||||
}
|
||||
#endif
|
||||
|
||||
void x509_openssl_add_credentials_fails(bool is_rsa, bool use_engine)
|
||||
{
|
||||
|
@ -530,10 +544,12 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
{
|
||||
setup_add_credentials_pem_file(is_rsa);
|
||||
}
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
else
|
||||
{
|
||||
setup_add_credentials_engine();
|
||||
}
|
||||
#endif
|
||||
|
||||
umock_c_negative_tests_snapshot();
|
||||
|
||||
|
@ -566,11 +582,13 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
calls_cannot_fail = is_rsa ? calls_cannot_fail_rsa : calls_cannot_fail_ecc;
|
||||
calls_cannot_fail_size = is_rsa ? sizeof(calls_cannot_fail_rsa) / sizeof(calls_cannot_fail_rsa[0]) : sizeof(calls_cannot_fail_ecc) / sizeof(calls_cannot_fail_ecc[0]);
|
||||
}
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
else
|
||||
{
|
||||
calls_cannot_fail = calls_cannot_fail_engine;
|
||||
calls_cannot_fail_size = sizeof(calls_cannot_fail_engine) / sizeof(calls_cannot_fail_engine[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
//act
|
||||
int result;
|
||||
|
@ -594,10 +612,12 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
{
|
||||
result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_PRIVATE_CERTIFICATE, KEY_TYPE_DEFAULT, NULL);
|
||||
}
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
else
|
||||
{
|
||||
result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_KEY_ID, KEY_TYPE_ENGINE, TEST_ENGINE);
|
||||
}
|
||||
#endif
|
||||
|
||||
//assert
|
||||
ASSERT_ARE_NOT_EQUAL(int, 0, result, tmp_msg);
|
||||
|
@ -619,10 +639,12 @@ BEGIN_TEST_SUITE(x509_openssl_unittests)
|
|||
x509_openssl_add_credentials_fails(/* is_rsa: */ false, /* use_engine: */ false);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
TEST_FUNCTION(x509_openssl_add_engine_credentials_fails)
|
||||
{
|
||||
x509_openssl_add_credentials_fails(/* is_rsa: */ false, /* use_engine: */ true);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*Tests_SRS_X509_OPENSSL_02_010: [ If ssl_ctx is NULL then x509_openssl_add_certificates shall fail and return a non-zero value. ]*/
|
||||
TEST_FUNCTION(x509_openssl_add_certificates_with_NULL_ssl_ctx_fails)
|
||||
|
|
Загрузка…
Ссылка в новой задаче