0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 04:02:15 +02:00

Add proto test to unittests w/2nd executable

The new test file, test_proto.cpp, is moved from test/ssl/proto.cpp
and only minimally changed.  The 2nd executable is based upon
core_tests.cpp, same as the 1st executable.  But note that the CMake
file has differences between the executables.

Signed-off-by: Mark Deric <jmark@openvpn.net>
This commit is contained in:
Mark Deric 2023-06-06 09:31:22 -07:00
parent 5f1f207bfd
commit f9be22ba53
2 changed files with 39 additions and 26 deletions

View File

@ -60,6 +60,12 @@ add_executable(coreUnitTests
test_buffer.cpp
)
add_executable(protoUnitTests
core_tests.cpp
test_proto.cpp
)
if (${USE_MBEDTLS})
target_sources(coreUnitTests PRIVATE
test_mbedtls_x509certinfo.cpp
@ -100,6 +106,7 @@ endif ()
add_core_dependencies(coreUnitTests)
add_json_library(coreUnitTests)
add_core_dependencies(protoUnitTests)
# xxHash
target_compile_definitions(coreUnitTests PRIVATE -DHAVE_XXHASH)
@ -116,14 +123,20 @@ find_package(LZO)
if (LZO_FOUND)
target_compile_definitions(coreUnitTests PRIVATE -DHAVE_LZO)
target_link_libraries(coreUnitTests lzo::lzo)
target_compile_definitions(protoUnitTests PRIVATE -DHAVE_LZO)
target_link_libraries(protoUnitTests lzo::lzo)
message("lzo found, running lzo compression tests")
else ()
message("lzo not found, skipping lzo compression tests")
endif ()
target_link_libraries(coreUnitTests ${GTEST_LIB} ${EXTRA_LIBS})
target_link_libraries(protoUnitTests ${GTEST_LIB} ${EXTRA_LIBS})
target_compile_definitions(coreUnitTests PRIVATE ${CORE_TEST_DEFINES})
target_compile_definitions(protoUnitTests PRIVATE ${CORE_TEST_DEFINES})
target_include_directories(coreUnitTests PRIVATE ${EXTRA_INCLUDES})
target_include_directories(protoUnitTests PRIVATE ${EXTRA_INCLUDES})
add_test(NAME CoreTests COMMAND coreUnitTests)
add_test(NAME ProtoTests COMMAND protoUnitTests)

View File

@ -4,7 +4,7 @@
// packet encryption, packet authentication, and
// packet compression.
//
// Copyright (C) 2012-2022 OpenVPN Inc.
// Copyright (C) 2012-2023 OpenVPN Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License Version 3
@ -21,6 +21,8 @@
// Unit test for OpenVPN Protocol implementation (class ProtoContext)
#include "test_common.h"
#include <iostream>
#include <string>
#include <sstream>
@ -30,6 +32,8 @@
#include <limits>
#include <thread>
#define OPENVPN_DEBUG_COMPRESS 0 // debug level for compression objects (0)
#include <openvpn/common/platform.hpp>
#ifdef OPENVPN_PLATFORM_WIN
@ -48,8 +52,6 @@
#define USE_TLS_CRYPT_V2
#endif
#define OPENVPN_INSTRUMENTATION
// Data limits for Blowfish and other 64-bit block-size ciphers
#ifndef BF
#define BF 0
@ -133,6 +135,9 @@
#define N_RETRIES 5
#endif
// potentially, the above manifest constants can be converted to variables and modified
// within the different TEST() functions that replace main() in the original file
// abort if we reach this limit
// #define DROUGHT_LIMIT 100000
@ -177,8 +182,6 @@
#define COMP_METH CompressContext::LZO_STUB
#endif
#include <openvpn/log/logsimple.hpp>
#include <openvpn/common/exception.hpp>
#include <openvpn/common/file.hpp>
#include <openvpn/common/count.hpp>
@ -591,7 +594,9 @@ class TestProto : public ProtoContext
size_t n_control_send_ = 0;
size_t n_control_recv_ = 0;
BufferPtr templ;
#if !FEEDBACK
size_t iteration = 0;
#endif
char progress_[11];
bool disable_xmit_ = false;
};
@ -657,7 +662,9 @@ class NoisyWire
const unsigned int drop_prob_arg,
const unsigned int corrupt_prob_arg)
: title(title_arg),
#ifdef VERBOSE
now(now_arg),
#endif
random(rand_arg),
reorder_prob(reorder_prob_arg),
drop_prob(drop_prob_arg),
@ -819,7 +826,9 @@ class NoisyWire
}
std::string title;
#ifdef VERBOSE
TimePtr now;
#endif
RandomAPI &random;
unsigned int reorder_prob;
unsigned int drop_prob;
@ -885,15 +894,15 @@ int test(const int thread_num)
const Time::Duration time_step = Time::Duration::binary_ms(100);
// client config files
const std::string ca_crt = read_text("ca.crt");
const std::string client_crt = read_text("client.crt");
const std::string client_key = read_text("client.key");
const std::string server_crt = read_text("server.crt");
const std::string server_key = read_text("server.key");
const std::string dh_pem = read_text("dh.pem");
const std::string tls_auth_key = read_text("tls-auth.key");
const std::string tls_crypt_v2_server_key = read_text("tls-crypt-v2-server.key");
const std::string tls_crypt_v2_client_key = read_text("tls-crypt-v2-client.key");
const std::string ca_crt = read_text(UNITTEST_SOURCE_DIR "../ssl/ca.crt");
const std::string client_crt = read_text(UNITTEST_SOURCE_DIR "../ssl/client.crt");
const std::string client_key = read_text(UNITTEST_SOURCE_DIR "../ssl/client.key");
const std::string server_crt = read_text(UNITTEST_SOURCE_DIR "../ssl/server.crt");
const std::string server_key = read_text(UNITTEST_SOURCE_DIR "../ssl/server.key");
const std::string dh_pem = read_text(UNITTEST_SOURCE_DIR "../ssl/dh.pem");
const std::string tls_auth_key = read_text(UNITTEST_SOURCE_DIR "../ssl/tls-auth.key");
const std::string tls_crypt_v2_server_key = read_text(UNITTEST_SOURCE_DIR "../ssl/tls-crypt-v2-server.key");
const std::string tls_crypt_v2_client_key = read_text(UNITTEST_SOURCE_DIR "../ssl/tls-crypt-v2-client.key");
// client config
ClientSSLAPI::Config::Ptr cc(new ClientSSLAPI::Config());
@ -1182,25 +1191,17 @@ int test_retry(const int thread_num)
return ret;
}
int main(int argc, char *argv[])
TEST(proto, base_1_thread)
{
int ret = 0;
// process-wide initialization
InitProcess::Init init;
// set global MbedTLS debug level
#if defined(USE_MBEDTLS)
mbedtls_debug_set_threshold(1);
#endif
if (argc >= 2 && !strcmp(argv[1], "test"))
{
const std::string out = SelfTest::crypto_self_test();
OPENVPN_LOG(out);
goto out;
}
#if N_THREADS >= 2
// probably ought to set ret in this compile path too
std::thread *threads[N_THREADS];
int i;
for (i = 0; i < N_THREADS; ++i)
@ -1217,6 +1218,5 @@ int main(int argc, char *argv[])
ret = test_retry(1);
#endif
out:
return ret;
EXPECT_EQ(ret, 0);
}