view ui/tests/CMakeLists.txt @ 831:747a48996c1f

(Issue13) Precompile uninstaller Create-dist-packge now creates a temporary installer that only writes the uninstaller. Then it excutes this installer (using wine) to create the uninstaller. That uninstaller is then packaged normaly and packaged instead of the written uninstaller.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 24 Jul 2014 15:59:00 +0200
parents 44fa5de02b52
children 8081ed84589d
line wrap: on
line source
# Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
# Software engineering by Intevation GmbH
#
# This file is Free Software under the GNU GPL (v>=2)
# and comes with ABSOLUTELY NO WARRANTY!
# See LICENSE.txt for details.

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})

include_directories(${CMAKE_CURRENT_BINARY_DIR}
   ${CMAKE_SOURCE_DIR}/ui
   ${CMAKE_SOURCE_DIR}/common
   ${CMAKE_SOURCE_DIR}/cinst)

find_package(Qt5Test)
include_directories(${Qt5Test_INCLUDE_DIRS})
find_program(HIAWATHA_EXECUTABLE hiawatha)
find_program(OSSLSIGNCODE_EXECUTABLE osslsigncode)
find_program(OPENSSL_EXECUTABLE openssl)

if (NOT HIAWATHA_EXECUTABLE)
   message (STATUS "WARNING: hiawatha webserver not found. Downloader will not be run.")
else()
  add_definitions(-DHIAWATHA_EXECUTABLE="${HIAWATHA_EXECUTABLE}")
endif()

if (WIN32 AND NOT OSSLSIGNCODE_EXECUTABLE)
   message (STATUS "WARNING: osslsigncode not found. Authenticode tests will not be run.")
endif()

if (UNIX AND NOT OPENSSL_EXECUTABLE)
   message (STATUS "WARNING: openssl (the tool) not found. Binary verification tests will not be run.")
endif()

macro(add_custom_test _source _additional_sources)
  set(_test ${_source})
  get_filename_component(_name ${_source} NAME_WE)
  set(_test_sources_with_resources ${_test}
     "${_additional_sources};${CMAKE_CURRENT_SOURCE_DIR}/common.cpp")
  qt5_add_resources(_test_sources_with_resources
     ${CMAKE_CURRENT_SOURCE_DIR}/data/testdata.qrc)
  add_executable(${_name} ${_test_sources_with_resources})
  add_test(tb-${_name} ${_name})
  target_link_libraries(${_name}
     tbadminlib
     tblib
     ui_common
     Qt5::Test Qt5::Widgets
     trustbridge_common
     ${POLARSSL_LIBRARIES}
     ${EXTRA_STATIC_LIBS})
endmacro()

# Add the current source dir to the definition
# so that it can be used in file names in the tests.
add_definitions(-DSOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_custom_test(certlistparsertest.cpp "")

# Downloader
if (HIAWATHA_EXECUTABLE)
  qt5_add_resources(DOWNLOADER_SOURCES_WITH_RESOURCES ${TRUSTBRIDGE_RESOURCES})
  add_custom_test(downloadertest.cpp "${DOWNLOADER_SOURCES_WITH_RESOURCES}")
endif()

# Cinstprocess
add_custom_test(cinstprocesstest.cpp "")
add_dependencies(cinstprocesstest cinst)
add_custom_test(commontest.cpp "")

add_custom_test(createcertlisttest.cpp "")
add_custom_test(mainwindowtest.cpp "")

# Using fakeinstaller here would cause windows UAC heuristics to trigger
add_executable(fakeinst fakeinstaller.c)

if (WIN32)
   add_custom_test(windowsstoretest.cpp "${CMAKE_SOURCE_DIR}/cinst/windowsstore.c")

   if (OSSLSIGNCODE_EXECUTABLE)
      add_custom_test (binverifytest.cpp "")
      add_custom_command(
         TARGET binverifytest
         POST_BUILD
         COMMAND ${OSSLSIGNCODE_EXECUTABLE} sign -certs ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.pem
         -key ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.key
         -h sha256 -in ${CMAKE_CURRENT_BINARY_DIR}/fakeinst.exe
         -out ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-signed.exe
         )
      add_custom_command(
         TARGET binverifytest
         POST_BUILD
         COMMAND ${OSSLSIGNCODE_EXECUTABLE} sign -certs ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.pem
         -key ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning-other.key
         -h sha256 -in ${CMAKE_CURRENT_BINARY_DIR}/fakeinst.exe
         -out ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-other-key.exe
         )
      add_custom_command(
         TARGET binverifytest
         POST_BUILD
         COMMAND ${OSSLSIGNCODE_EXECUTABLE} sign -certs ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning-other.pem
         -key ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning-other.key
         -h sha256 -in ${CMAKE_CURRENT_BINARY_DIR}/fakeinst.exe
         -out ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-other-cert.exe
         )
      add_custom_command(
         TARGET binverifytest
         POST_BUILD
         COMMAND ${OSSLSIGNCODE_EXECUTABLE} sign -certs ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.pem
         -key ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.key
         -h sha256 -in ${CMAKE_CURRENT_BINARY_DIR}/fakeinst.exe
         -out ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-invalid.exe &&
         ${CMAKE_STRIP} ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-invalid.exe
         )
    endif()
else ()
   if (OPENSSL_EXECUTABLE)
      add_custom_test (binverifytest.cpp "")
      add_custom_command(
         TARGET binverifytest
         POST_BUILD
         COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/append-sig.sh ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.key
                 ${CMAKE_CURRENT_BINARY_DIR}/fakeinst ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-signed
         )
      add_custom_command(
         TARGET binverifytest
         POST_BUILD
         COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/append-sig.sh ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning-other.key
                 ${CMAKE_CURRENT_BINARY_DIR}/fakeinst ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-other-key
         )
      add_custom_command(
         TARGET binverifytest
         POST_BUILD
         COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/append-sig.sh ${CMAKE_CURRENT_SOURCE_DIR}/data/codesign/codesigning.key
                 ${CMAKE_CURRENT_BINARY_DIR}/fakeinst ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-invalid &&
                 sed -i s/Fakeinstaller/Bakeinstaller/g ${CMAKE_CURRENT_BINARY_DIR}/fakeinst-invalid
         )
   endif()
endif ()

if (NSS_FOUND)
   include_directories(${NSS_INCLUDE_DIRS})
   set(NSSTEST_SOURCES
      ${CMAKE_SOURCE_DIR}/cinst/nssstore_linux.c
      ${CMAKE_SOURCE_DIR}/cinst/nssstore_win.c)
   add_custom_test(nsstest.cpp "${NSSTEST_SOURCES}")
   target_link_libraries(nsstest ${NSS_LIBRARIES})
   if (WIN32)
      target_link_libraries(nsstest -luserenv)
   endif()

   add_dependencies(nsstest mozilla)

   # NSS code searches the mozilla process in the same path as the caller
   if (WIN32)
      file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/mozilla.exe" link)
      file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/../../cinst/mozilla.exe" target)
   else()
      file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/mozilla" link)
      file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/../../cinst/mozilla" target)
   endif()

   if (NOT EXISTS ${link})
      if (CMAKE_HOST_UNIX)
         set(command ln -s ${target} ${link})
      else()
         set(command cmd.exe /c mklink ${link} ${target})
      endif()
      execute_process(COMMAND ${command}
         RESULT_VARIABLE result
         ERROR_VARIABLE output)
      if (NOT ${result} EQUAL 0)
         message(STATUS "Could not create symbolic link for: ${target} --> ${output}. NSS Test might fail.")
      endif()
   endif()
endif()

#add_custom_test(${CMAKE_SOURCE_DIR}/ui/main.cpp "${TRUSTBRIDGE_SOURCES}")

http://wald.intevation.org/projects/trustbridge/