1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# Copyright (c) 2018-2020 Ribose Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
if (BUILD_TESTING_GENERATORS)
add_subdirectory(data/test_key_validity)
endif()
# fixture to copy the test data directory
add_test(
NAME setupTestData
COMMAND "${CMAKE_COMMAND}" -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/data" "${CMAKE_CURRENT_BINARY_DIR}/data"
)
set_tests_properties(setupTestData PROPERTIES FIXTURES_SETUP testdata)
# rnp_tests
include(GoogleTest)
if (GTEST_SOURCES)
# use Googletest sources if specified
add_subdirectory(${GTEST_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
set(GTestMain gtest_main)
elseif (NOT DOWNLOAD_GTEST)
# use preinstalled googletest
find_package(GTest REQUIRED)
set(GTestMain GTest::Main)
else()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL "4.8.5")
set(GTEST_GIT_TAG "c43f710")
else()
set(GTEST_GIT_TAG "HEAD")
endif()
# download and build googletest
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "${GTEST_GIT_TAG}"
)
# maintain compiler/linker settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# explicitly disable unneeded gmock build
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
set(GTestMain gtest_main)
endif()
find_package(JSON-C 0.11 REQUIRED)
if (CRYPTO_BACKEND_LOWERCASE STREQUAL "botan")
find_package(Botan2 2.14.0 REQUIRED)
endif()
if (CRYPTO_BACKEND_LOWERCASE STREQUAL "openssl")
find_package(OpenSSL 1.1.1 REQUIRED)
endif()
add_executable(rnp_tests
../rnp/rnpcfg.cpp
../rnp/fficli.cpp
../rnp/rnp.cpp
../rnpkeys/rnpkeys.cpp
../rnpkeys/main.cpp
../rnpkeys/tui.cpp
../fuzzing/keyring.c
../fuzzing/keyring_g10.cpp
../fuzzing/keyring_kbx.c
../fuzzing/keyimport.c
../fuzzing/sigimport.c
../fuzzing/dump.c
../fuzzing/verify_detached.c
../fuzzing/verify.c
cipher.cpp
cipher_cxx.cpp
cli.cpp
exportkey.cpp
ffi.cpp
ffi-enc.cpp
ffi-uid.cpp
ffi-key-sig.cpp
ffi-key-prop.cpp
ffi-key.cpp
file-utils.cpp
generatekey.cpp
kbx-nsigs-test.cpp
key-add-userid.cpp
key-grip.cpp
key-prefs.cpp
key-protect.cpp
key-store-search.cpp
key-unlock.cpp
key-validate.cpp
large-packet.cpp
large-mpi.cpp
load-g10.cpp
load-g23.cpp
load-pgp.cpp
log-switch.cpp
partial-length.cpp
pipe.cpp
rnp_tests.cpp
rng-randomness.cpp
s2k-iterations.cpp
streams.cpp
support.cpp
user-prefs.cpp
utils-hex2bin.cpp
utils-rnpcfg.cpp
issues/1030.cpp
issues/1115.cpp
issues/1171.cpp
issues/oss-fuzz-25489.cpp
fuzz_keyring.cpp
fuzz_keyring_g10.cpp
fuzz_keyring_kbx.cpp
fuzz_keyimport.cpp
fuzz_sigimport.cpp
fuzz_dump.cpp
fuzz_verify_detached.cpp
fuzz_verify.cpp
)
if(MSVC)
find_package(WindowsSDK)
GetUMWindowsSDKLibraryDir(WIN_LIBRARY_DIR)
message (STATUS "WIN_LIBRARY_DIR: ${WIN_LIBRARY_DIR}")
find_library(SHLWAPI_LIBRARY
PATHS
${WIN_LIBRARY_DIR}
NAMES shlwapi)
find_path(GETOPT_INCLUDE_DIR
NAMES getopt.h
)
find_library(GETOPT_LIBRARY
NAMES getopt
)
find_path(DIRENT_INCLUDE_DIR
NAMES dirent.h
)
target_include_directories(rnp_tests
PRIVATE
"${GETOPT_INCLUDE_DIR}"
"${DIRENT_INCLUDE_DIR}"
)
target_link_libraries(rnp_tests
PRIVATE
"${SHLWAPI_LIBRARY}"
"${GETOPT_LIBRARY}"
)
endif()
target_include_directories(rnp_tests
PRIVATE
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/src/lib"
"${BOTAN2_INCLUDE_DIRS}"
)
target_link_libraries(rnp_tests
PRIVATE
librnp-static
JSON-C::JSON-C
sexp
${GTestMain}
)
if (CRYPTO_BACKEND_LOWERCASE STREQUAL "openssl")
target_link_libraries(rnp_tests PRIVATE OpenSSL::Crypto)
endif()
target_compile_definitions(rnp_tests
PRIVATE
RNP_RUN_TESTS
RNP_STATIC
)
# Centos 7 with CLang 7.0.1 reports strange memory leak in GoogleTest, maybe there is a better solution
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0.1)
set_target_properties(rnp_tests PROPERTIES CXX_VISIBILITY_PRESET hidden)
endif()
gtest_discover_tests(rnp_tests
PROPERTIES
FIXTURES_REQUIRED testdata
TIMEOUT 3000
ENVIRONMENT "RNP_TEST_DATA=${CMAKE_CURRENT_SOURCE_DIR}/data"
)
# cli_tests
# Note that we do this call early because Google Test will also do
# this but with less strict version requirements, which will cause
# problems for us.
find_package(Python3 COMPONENTS Interpreter)
find_package(GnuPG 2.2 COMPONENTS gpg gpgconf)
function(add_cli_test suite)
set(_test_name cli_tests-${suite})
add_test(
NAME ${_test_name}
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/cli_tests.py" -v -d "${suite}"
)
set(_env)
list(APPEND _env
"RNP_TESTS_RNP_PATH=$<TARGET_FILE:rnp>"
"RNP_TESTS_RNPKEYS_PATH=$<TARGET_FILE:rnpkeys>"
"RNP_TESTS_GPG_PATH=${GPG_EXECUTABLE}"
"RNP_TESTS_GPGCONF_PATH=${GPGCONF_EXECUTABLE}"
)
set_tests_properties(${_test_name} PROPERTIES
TIMEOUT 3000
FIXTURES_REQUIRED testdata
ENVIRONMENT "${_env}"
)
endfunction()
# get a list of test suites
execute_process(
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/cli_tests.py" -ls
RESULT_VARIABLE _ec
OUTPUT_VARIABLE suitelist
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT _ec EQUAL 0)
message(FATAL_ERROR "Failed to retrieve test suite list for cli_tests")
endif()
# convert to a CMake list
string(REGEX REPLACE ";" "\\\\;" suitelist "${suitelist}")
string(REGEX REPLACE "\n" ";" suitelist "${suitelist}")
# create a CTest test for each suite
foreach(suite IN LISTS suitelist)
add_cli_test("${suite}")
endforeach()
|