0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 04:02:15 +02:00
openvpn3/test/unittests
Arne Schwabe 8833600936 Allow outputting certificates in PEM encoding during handshake
This allow debugging the certificates the server sends. It did this as hack
two times before. I think it is now time to get this officially in.

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-05-29 19:32:19 +00:00
..
comp-testdata Move compression unit test from common to core repository 2019-04-15 17:05:09 +02:00
input Improve psid cookie unit tests [OVPN3-1069] 2023-10-25 09:10:40 -07:00
output test_path: add missing output file for windows build 2022-07-06 11:17:18 +02:00
pki [test/misc] Convert OpenSSL PKI test to unittest 2022-07-01 15:57:30 +02:00
userpass UserPass: Add unittest 2023-11-08 21:05:01 +01:00
.gitignore unitests: added test_time to .gitignore 2023-11-24 21:06:16 +01:00
CMakeLists.txt UT: Allow to run unittests with as root via ctest 2024-05-22 16:19:11 +00:00
core_tests.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
gen_ip_shifts.py Add unit test for shifts of IPv6 addresses 2023-02-01 16:43:53 +01:00
README-comp.txt Fix some typos in unittest README files 2021-02-11 02:14:19 +01:00
README-proto-tests.rst unittest: Add proto test cmake parameters w/README 2023-06-16 18:37:02 +02:00
README.md Remove OPENVPN_EXTERN 2023-04-27 23:35:41 +02:00
test_acc_certcheck.cpp Implement certcheck used by the appcontrol feature 2024-05-17 09:18:18 +00:00
test_acc.cpp Add missing length check in parsing ACC messages, add more related tests 2024-01-04 17:51:23 +01:00
test_b64.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_buffer_ip.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_buffer.cpp unittests: Fix -Wsigned-compare errors 2023-02-28 12:30:30 +01:00
test_capture.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_clamp_typerange.cpp test_clamp_typerange: avoid -Wconversion warning 2023-10-11 12:28:55 +02:00
test_cleanup.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_cliopt.cpp OpenVPN 3 Core library version 3.8.5 2024-05-03 14:50:21 +02:00
test_common.h Remove OPENVPN_EXTERN 2023-04-27 23:35:41 +02:00
test_comp.cpp Switched C casts to static_cast 2023-08-23 18:44:16 +02:00
test_continuation.cpp Addressed 2nd set of -Wconversion warnings 2023-08-21 13:51:50 +00:00
test_cpu_time.cpp Switched C casts to static_cast 2023-08-23 18:44:16 +02:00
test_crypto_hashstr.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_crypto.cpp Addressed 2nd set of -Wconversion warnings 2023-08-21 13:51:50 +00:00
test_csum.cpp Addressed 2nd set of -Wconversion warnings 2023-08-21 13:51:50 +00:00
test_dns.cpp apply --dns options the new way 2024-05-13 14:07:53 +02:00
test_format.cpp Fix misc wrong types 2023-09-28 11:33:44 +02:00
test_header_deps.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_headredact.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_helper.hpp Add various moves as suggested by Coverity 2024-01-31 17:02:45 +01:00
test_hostport.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_http_proxy.cpp unittests: Fix -Wsigned-compare errors 2023-02-28 12:30:30 +01:00
test_ip.cpp OpenVPN 3 Core library version 3.8.5 2024-05-03 14:50:21 +02:00
test_iphelper.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_log.cpp Fix various "auto causes copy" Coverity warnings 2024-01-31 17:02:28 +01:00
test_mbedtls_authcert.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_mbedtls_x509certinfo.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_misc_unix.cpp Eliminate some conversion warnings 2023-03-08 15:21:50 +00:00
test_numeric_cast.cpp Add numeric limiting headers and tests 2023-02-23 23:06:45 +01:00
test_openssl_authcert.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_openssl_misc.cpp Fix accessing a null pointer when PKCS7 is invalid 2024-01-25 12:02:12 +01:00
test_openssl_x509certinfo.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_opensslpki.cpp Allow outputting certificates in PEM encoding during handshake 2024-05-29 19:32:19 +00:00
test_optfilt.cpp unittests: Fix -Wsigned-compare errors 2023-02-28 12:30:30 +01:00
test_ostream_containers.cpp Improve C2os unit tests with better templates 2024-03-28 11:27:23 +00:00
test_parseargv.cpp unittests: Fix -Wsigned-compare errors 2023-02-28 12:30:30 +01:00
test_path.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_peer_fingerprint.cpp Addressed 2nd set of -Wconversion warnings 2023-08-21 13:51:50 +00:00
test_pipe.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_pktid.cpp Switched C casts to static_cast 2023-08-23 18:44:16 +02:00
test_pktstream.cpp PacketStream: templatize stream segment length word 2023-09-17 10:08:36 -06:00
test_prefixlen.cpp unittests: Fix -Wsigned-compare errors 2023-02-28 12:30:30 +01:00
test_proto.cpp Spell none cipher with lowercase 2024-05-08 16:39:25 +00:00
test_psid_cookie.cpp remove 'prng' argument from SSLLib::RandomAPI ctor 2023-11-22 04:49:31 +01:00
test_randapi.cpp introduce base types for strong and weak RNGs 2023-11-22 04:49:31 +01:00
test_rc.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_relack.cpp Do not use id_t unqualified in unit tests 2023-06-22 19:07:21 +02:00
test_reliable.cpp Do not use id_t unqualified in unit tests 2023-06-22 19:07:21 +02:00
test_remotelist.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_route_emulation.cpp unittests: Fix -Wsigned-compare errors 2023-02-28 12:30:30 +01:00
test_route.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_safestr.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_session_id.cpp remove 'prng' argument from SSLLib::RandomAPI ctor 2023-11-22 04:49:31 +01:00
test_sitnl.cpp Change some arguments to const refs 2024-01-31 17:02:47 +01:00
test_splitlines.cpp SplitLines/UserPass: Review fixes 2023-11-08 21:05:06 +01:00
test_ssl.cpp introduce base types for strong and weak RNGs 2023-11-22 04:49:31 +01:00
test_sslctx.cpp Implement certcheck used by the appcontrol feature 2024-05-17 09:18:18 +00:00
test_statickey.cpp remove 'prng' argument from SSLLib::RandomAPI ctor 2023-11-22 04:49:31 +01:00
test_streq.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_time.cpp Switched C casts to static_cast 2023-08-23 18:44:16 +02:00
test_tun_builder.cpp Fix RouteBase string formatting bug 2024-03-29 03:13:00 +00:00
test_typeindex.cpp unittests: Fix -Wsigned-compare errors 2023-02-28 12:30:30 +01:00
test_userpass.cpp test_splitlines: New UT for SplitLines 2023-11-08 21:05:05 +01:00
test_validatecreds.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_verify_x509_name.cpp Reformatting source code to new coding style 2023-01-18 19:24:15 +01:00
test_weak.cpp unittests: Fix -Wsigned-compare errors 2023-02-28 12:30:30 +01:00
test_wstring.cpp wstring: fix UTF-8 and MULTI_SZ conv functions 2024-05-13 14:07:53 +02: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.

The directory for cmake to build a project can be everywhere, but it is recommended to keep it outside of the source tree.

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

➜ mkdir ../unit_test_build
➜ cd ../unit_test_build
➜ 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 together with short descriptions can be shown with

➜ cmake -LH .

Examplary commands 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

Frequently used command line options

Show the help for gtest command line options:

➜ ./test/unittests/coreUnitTests --help

Run only tests starting with Base64 or a sepcific Base64 test:

➜ ./test/unittests/coreUnitTests --gtest_filter='Base64.*'
➜ ./test/unittests/coreUnitTests --gtest_filter=Base64.tooshortdest

Run all test but the Base64 tests

➜ ./test/unittests/coreUnitTests --gtest_filter='-Base64.*'

Multiple pattern can be specified with a list separated by :

➜ ./test/unittests/coreUnitTests --gtest_filter='OpenSSL_X509_get_serial.*:Base64.*'

Shuffle order the order in which the tests are run:

➜ ./test/unittests/coreUnitTests --gtest_shuffle

If a certain order yields failures, repeat that order:

➜ ./test/unittests/coreUnitTests --gtest_shuffle --gtest_random_seed=23

Run also the tests that are normally disabled

➜ ./test/unittests/coreUnitTests --gtest_also_run_disabled_tests

Writing unit tests

Each new test suite should be a new a file called test_suitename.cpp and added to the CMakeLists.txt file. Each test includes an #include test_common.h at the top to setup common openvpn3 library parameters.

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.