aheinecke@405: # Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@405: # Software engineering by Intevation GmbH aheinecke@405: # aheinecke@405: # This file is Free Software under the GNU GPL (v>=2) aheinecke@405: # and comes with ABSOLUTELY NO WARRANTY! aheinecke@405: # See LICENSE.txt for details. aheinecke@405: aheinecke@7: set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) aheinecke@7: andre@304: include_directories(${CMAKE_CURRENT_BINARY_DIR} andre@304: ${CMAKE_SOURCE_DIR}/ui andre@304: ${CMAKE_SOURCE_DIR}/common andre@304: ${CMAKE_SOURCE_DIR}/cinst) aheinecke@7: aheinecke@7: find_package(Qt5Test) rrenkert@140: include_directories(${Qt5Test_INCLUDE_DIRS}) aheinecke@43: find_program(HIAWATHA_EXECUTABLE hiawatha) andre@773: find_program(OPENSSL_EXECUTABLE openssl) aheinecke@43: aheinecke@43: if (NOT HIAWATHA_EXECUTABLE) andre@636: message (STATUS "WARNING: hiawatha webserver not found. Downloader will not be run.") aheinecke@43: else() aheinecke@43: add_definitions(-DHIAWATHA_EXECUTABLE="${HIAWATHA_EXECUTABLE}") aheinecke@43: endif() aheinecke@7: andre@773: if (UNIX AND NOT OPENSSL_EXECUTABLE) andre@773: message (STATUS "WARNING: openssl (the tool) not found. Binary verification tests will not be run.") andre@773: endif() andre@773: aheinecke@409: macro(add_custom_test _source _additional_sources) aheinecke@7: set(_test ${_source}) aheinecke@7: get_filename_component(_name ${_source} NAME_WE) aheinecke@326: set(_test_sources_with_resources ${_test} aheinecke@326: "${_additional_sources};${CMAKE_CURRENT_SOURCE_DIR}/common.cpp") andre@220: qt5_add_resources(_test_sources_with_resources andre@220: ${CMAKE_CURRENT_SOURCE_DIR}/data/testdata.qrc) andre@220: add_executable(${_name} ${_test_sources_with_resources}) aheinecke@409: add_test(tb-${_name} ${_name}) aheinecke@496: target_link_libraries(${_name} aheinecke@560: tbadminlib aheinecke@560: tblib aheinecke@496: ui_common aheinecke@496: Qt5::Test Qt5::Widgets aheinecke@408: trustbridge_common andre@908: ${CURL_LIBRARIES} aheinecke@68: ${POLARSSL_LIBRARIES} aheinecke@68: ${EXTRA_STATIC_LIBS}) aheinecke@7: endmacro() aheinecke@7: aheinecke@7: # Add the current source dir to the definition aheinecke@7: # so that it can be used in file names in the tests. aheinecke@7: add_definitions(-DSOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") aheinecke@560: add_custom_test(certlistparsertest.cpp "") aheinecke@48: aheinecke@48: # Downloader rrenkert@139: if (HIAWATHA_EXECUTABLE) aheinecke@407: qt5_add_resources(DOWNLOADER_SOURCES_WITH_RESOURCES ${TRUSTBRIDGE_RESOURCES}) aheinecke@409: add_custom_test(downloadertest.cpp "${DOWNLOADER_SOURCES_WITH_RESOURCES}") rrenkert@139: endif() aheinecke@48: aheinecke@100: # Cinstprocess aheinecke@496: add_custom_test(cinstprocesstest.cpp "") aheinecke@293: add_dependencies(cinstprocesstest cinst) aheinecke@409: add_custom_test(commontest.cpp "") aheinecke@100: aheinecke@560: add_custom_test(createcertlisttest.cpp "") andre@1014: andre@1014: # Disabled for now at it executes too much and brings up the mainwindow andre@1014: # add_custom_test(mainwindowtest.cpp "") aheinecke@468: aheinecke@563: # Using fakeinstaller here would cause windows UAC heuristics to trigger aheinecke@563: add_executable(fakeinst fakeinstaller.c) aheinecke@563: andre@220: if (WIN32) aheinecke@496: add_custom_test(windowsstoretest.cpp "${CMAKE_SOURCE_DIR}/cinst/windowsstore.c") andre@636: andre@1025: if (NOT CMAKE_STRIP) andre@967: message(STATUS "WARNING CMAKE_STRIP not set. Please set this in your toolchain file. Falling back to: i686-w64-mingw32-strip") andre@967: set (CMAKE_STRIP "i686-w64-mingw32-strip") andre@967: endif() andre@967: andre@636: if (OSSLSIGNCODE_EXECUTABLE) andre@636: add_custom_test (binverifytest.cpp "") andre@636: add_custom_command( andre@636: TARGET binverifytest andre@636: POST_BUILD andre@636: COMMAND ${OSSLSIGNCODE_EXECUTABLE} sign -certs ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.pem andre@636: -key ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.key andre@636: -h sha256 -in ${CMAKE_CURRENT_BINARY_DIR}/fakeinst.exe andre@636: -out ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-signed.exe andre@636: ) andre@637: add_custom_command( andre@637: TARGET binverifytest andre@637: POST_BUILD andre@637: COMMAND ${OSSLSIGNCODE_EXECUTABLE} sign -certs ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.pem andre@637: -key ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning-other.key andre@637: -h sha256 -in ${CMAKE_CURRENT_BINARY_DIR}/fakeinst.exe andre@637: -out ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-other-key.exe andre@637: ) andre@637: add_custom_command( andre@637: TARGET binverifytest andre@637: POST_BUILD andre@637: COMMAND ${OSSLSIGNCODE_EXECUTABLE} sign -certs ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning-other.pem andre@637: -key ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning-other.key andre@637: -h sha256 -in ${CMAKE_CURRENT_BINARY_DIR}/fakeinst.exe andre@637: -out ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-other-cert.exe andre@637: ) andre@637: add_custom_command( andre@637: TARGET binverifytest andre@637: POST_BUILD andre@637: COMMAND ${OSSLSIGNCODE_EXECUTABLE} sign -certs ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.pem andre@637: -key ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.key andre@637: -h sha256 -in ${CMAKE_CURRENT_BINARY_DIR}/fakeinst.exe andre@637: -out ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-invalid.exe && andre@637: ${CMAKE_STRIP} ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-invalid.exe andre@637: ) andre@636: endif() andre@636: else () andre@773: if (OPENSSL_EXECUTABLE) andre@773: add_custom_test (binverifytest.cpp "") andre@773: add_custom_command( andre@773: TARGET binverifytest andre@773: POST_BUILD andre@773: COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/append-sig.sh ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.key andre@773: ${CMAKE_CURRENT_BINARY_DIR}/fakeinst ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-signed andre@773: ) andre@774: add_custom_command( andre@774: TARGET binverifytest andre@774: POST_BUILD andre@774: COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/append-sig.sh ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning-other.key andre@774: ${CMAKE_CURRENT_BINARY_DIR}/fakeinst ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-other-key andre@774: ) andre@774: add_custom_command( andre@774: TARGET binverifytest andre@774: POST_BUILD andre@774: COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/append-sig.sh ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.key andre@774: ${CMAKE_CURRENT_BINARY_DIR}/fakeinst ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-invalid && andre@774: sed -i s/Fakeinstaller/Bakeinstaller/g ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-invalid andre@774: ) andre@773: endif() andre@636: endif () andre@220: andre@834: if (WIN32 OR NSS_FOUND) aheinecke@326: include_directories(${NSS_INCLUDE_DIRS}) aheinecke@331: set(NSSTEST_SOURCES aheinecke@331: ${CMAKE_SOURCE_DIR}/cinst/nssstore_linux.c aheinecke@331: ${CMAKE_SOURCE_DIR}/cinst/nssstore_win.c) aheinecke@409: add_custom_test(nsstest.cpp "${NSSTEST_SOURCES}") aheinecke@326: target_link_libraries(nsstest ${NSS_LIBRARIES}) aheinecke@326: if (WIN32) aheinecke@326: target_link_libraries(nsstest -luserenv) aheinecke@326: endif() aheinecke@326: aheinecke@326: add_dependencies(nsstest mozilla) aheinecke@556: aheinecke@556: # NSS code searches the mozilla process in the same path as the caller aheinecke@556: if (WIN32) aheinecke@556: file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/mozilla.exe" link) aheinecke@556: file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/../../cinst/mozilla.exe" target) aheinecke@556: else() aheinecke@556: file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/mozilla" link) aheinecke@556: file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/../../cinst/mozilla" target) aheinecke@556: endif() aheinecke@556: aheinecke@556: if (NOT EXISTS ${link}) aheinecke@556: if (CMAKE_HOST_UNIX) aheinecke@556: set(command ln -s ${target} ${link}) aheinecke@556: else() aheinecke@556: set(command cmd.exe /c mklink ${link} ${target}) aheinecke@556: endif() aheinecke@556: execute_process(COMMAND ${command} aheinecke@556: RESULT_VARIABLE result aheinecke@556: ERROR_VARIABLE output) aheinecke@556: if (NOT ${result} EQUAL 0) aheinecke@580: message(STATUS "Could not create symbolic link for: ${target} --> ${output}. NSS Test might fail.") aheinecke@556: endif() aheinecke@556: endif() andre@307: endif() andre@304: aheinecke@409: #add_custom_test(${CMAKE_SOURCE_DIR}/ui/main.cpp "${TRUSTBRIDGE_SOURCES}") aheinecke@7: