0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00
openvpn3/test/unittests
David Sommerseth ae6bf893bb
mbedtls: Add unit tests for x509_get_subject() and x509_get_common_name()
These functions are found in openvpn/mbedtls/pki/x509certinfo.hpp.

This change also adds support to build coreUnitTests against mbed TLS
instead of OpenSSL (default) by providing -DUSE_MBEDTLS=true to cmake.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-08 10:00:44 +01:00
..
comp-testdata Move compression unit test from common to core repository 2019-04-15 17:05:09 +02:00
CMakeLists.txt mbedtls: Add unit tests for x509_get_subject() and x509_get_common_name() 2019-11-08 10:00:44 +01:00
core_tests.cpp Add OPENVPN_LOG implementation that can collect logs in a variable 2019-11-07 09:58:54 +01:00
README-comp.txt Convert unit test to Googletest 2019-04-15 17:23:37 +02:00
README.md Document unit tests 2019-11-07 09:58:54 +01:00
test_b64.cpp Fix base64 unit test with mbedtls and windows 2019-04-18 14:47:16 +02:00
test_common.h Add OPENVPN_LOG implementation that can collect logs in a variable 2019-11-07 09:58:54 +01:00
test_comp.cpp Convert unit test to Googletest 2019-04-15 17:23:37 +02:00
test_cpu_time.cpp Add macOS implementation in cpu time helper and adjust unit test 2019-11-07 09:58:55 +01:00
test_helper.hpp Replace OPENVPN_INSECURE_RANDOM with FakeRandom class 2019-11-07 09:58:54 +01:00
test_log.cpp Only initialise static member in OpenSSLContext once 2019-08-29 16:21:57 +02:00
test_mbedtls_x509certinfo.cpp mbedtls: Add unit tests for x509_get_subject() and x509_get_common_name() 2019-11-08 10:00:44 +01:00
test_openssl_x509certinfo.cpp openssl: Add unit tests for OpenSSLPKI::x509_get_*() functions 2019-11-08 10:00:41 +01:00
test_route_emulation.cpp Add unit tests for route emulation and establish common test suite 2019-03-12 11:36:29 +01:00
test_sitnl.cpp test_sitnl.cpp: account for old iptools output 2019-05-14 16:32:03 +03:00
test_verify_x509_name.cpp verify-x509-name: Implement base class for processing this option 2019-11-08 10:00:34 +01:00
unittests.vcxproj win: add OpenSSL as solution configuration 2019-06-05 13:54:13 +03:00
unittests.vcxproj.filters Integrate Google Test framework 2017-09-27 16:16:18 +08:00

Unit test framework for OpenVPN3

The unit test framework is written in the Google Test framework.

Building/running the unit tests

Before building the unit tests themselves, you should build the dependencies as described in the README.rst.

The unit test cmake files assume here that the deps directory is on the same level as the openvpn3 directory unless overridden by the DEP_DIR variable.

Building unit tests (assuming you are in the openvpn3 directory):

➜ mkdir ../unittests
➜ cd ../unittests
➜ cmake ../openvpn3
➜ cmake --build . --target coreUnitTests

Note: On Linux and Mac OS you can use make coreUnitTests instead of cmake --build

Run the unit tests:

➜  ./test/unittests/coreUnitTests --gtest_shuffle

On a Mac with OpenSSL from homebrew:

➜ cmake ../openvpn3 -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1

Using mbed TLS instead of OpenSSL

➜ cmake ../openvpn3 -DUSE_MBEDTLS

A full list of build options can shown with

➜ cmake -LAH .

Example for building and running on Windows:

➜ cmake -DDEP_DIR=C:\o3\deps -DUSE_MBEDTLS=true -DCMAKE_GENERATOR_PLATFORM=x64 C:\o3\openvpn3
➜ cmake --build . --target coreUnitTests
➜ test\unittests\Debug\coreUnitTests.exe --gtest_output="xml:test_core.xml" --gtest_shuffle

Writing unit tetss

Each new test suite should be a new a file called test_suitename.cpp and added to the CMAKELists.txt file. Eah test includes an #include test_common.h at the top to setup common openvpn3 library parameter and to set the OPENVPN_EXTERN define to extern. This is done so header files that define globals can be included multiple times. The only file that includes headers without the OPENVPN_EXTERN being set is the core_tests.cpp file. All global includes should be done in this file.

Currently all tests can fit in the same compilation unit coreUnitTests. If a unit test requires special compile/includes or other options that are not compatible with the rest of the unit tests, another compilation unit should be added to the CMAKELists.txt

The test_helper.cc file adds helper functions that can be used for unit tests. See the file for more information.