meson.build 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # SPDX-FileCopyrightText: 2021 Andrea Pappacoda
  2. #
  3. # SPDX-License-Identifier: MIT
  4. gtest_dep = dependency('gtest', main: true)
  5. libcurl_dep = dependency('libcurl')
  6. openssl = find_program('openssl')
  7. test_conf = files('test.conf')
  8. key_pem = custom_target(
  9. 'key_pem',
  10. output: 'key.pem',
  11. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  12. )
  13. temp_req = custom_target(
  14. 'temp_req',
  15. input: key_pem,
  16. output: 'temp_req',
  17. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@']
  18. )
  19. cert_pem = custom_target(
  20. 'cert_pem',
  21. input: [temp_req, key_pem],
  22. output: 'cert.pem',
  23. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '3650', '-req', '-signkey', '@INPUT1@', '-out', '@OUTPUT@']
  24. )
  25. cert2_pem = custom_target(
  26. 'cert2_pem',
  27. input: key_pem,
  28. output: 'cert2.pem',
  29. command: [openssl, 'req', '-x509', '-config', test_conf, '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-out', '@OUTPUT@', '-extensions', 'SAN']
  30. )
  31. key_encrypted_pem = custom_target(
  32. 'key_encrypted_pem',
  33. output: 'key_encrypted.pem',
  34. command: [openssl, 'genrsa', '-passout', 'pass:test123!', '-out', '@OUTPUT@', '2048']
  35. )
  36. cert_encrypted_pem = custom_target(
  37. 'cert_encrypted_pem',
  38. input: key_encrypted_pem,
  39. output: 'cert_encrypted.pem',
  40. command: [openssl, 'req', '-x509', '-config', test_conf, '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-out', '@OUTPUT@', '-extensions', 'SAN']
  41. )
  42. rootca_key_pem = custom_target(
  43. 'rootca_key_pem',
  44. output: 'rootCA.key.pem',
  45. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  46. )
  47. rootca_cert_pem = custom_target(
  48. 'rootca_cert_pem',
  49. input: rootca_key_pem,
  50. output: 'rootCA.cert.pem',
  51. command: [openssl, 'req', '-x509', '-new', '-batch', '-config', files('test.rootCA.conf'), '-key', '@INPUT@', '-days', '1024', '-out', '@OUTPUT@']
  52. )
  53. client_key_pem = custom_target(
  54. 'client_key_pem',
  55. output: 'client.key.pem',
  56. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  57. )
  58. client_temp_req = custom_target(
  59. 'client_temp_req',
  60. input: client_key_pem,
  61. output: 'client_temp_req',
  62. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@']
  63. )
  64. client_cert_pem = custom_target(
  65. 'client_cert_pem',
  66. input: [client_temp_req, rootca_cert_pem, rootca_key_pem],
  67. output: 'client.cert.pem',
  68. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '370', '-req', '-CA', '@INPUT1@', '-CAkey', '@INPUT2@', '-CAcreateserial', '-out', '@OUTPUT@']
  69. )
  70. client_encrypted_key_pem = custom_target(
  71. 'client_encrypted_key_pem',
  72. output: 'client_encrypted.key.pem',
  73. command: [openssl, 'genrsa', '-aes256', '-passout', 'pass:test012!', '-out', '@OUTPUT@', '2048']
  74. )
  75. client_encrypted_temp_req = custom_target(
  76. 'client_encrypted_temp_req',
  77. input: client_encrypted_key_pem,
  78. output: 'client_encrypted_temp_req',
  79. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-passin', 'pass:test012!', '-out', '@OUTPUT@']
  80. )
  81. client_encrypted_cert_pem = custom_target(
  82. 'client_encrypted_cert_pem',
  83. input: [client_encrypted_temp_req, rootca_cert_pem, rootca_key_pem],
  84. output: 'client_encrypted.cert.pem',
  85. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '370', '-req', '-CA', '@INPUT1@', '-CAkey', '@INPUT2@', '-CAcreateserial', '-out', '@OUTPUT@']
  86. )
  87. # Copy test files to the build directory
  88. configure_file(input: 'ca-bundle.crt', output: 'ca-bundle.crt', copy: true)
  89. configure_file(input: 'image.jpg', output: 'image.jpg', copy: true)
  90. subdir(join_paths('www', 'dir'))
  91. subdir(join_paths('www2', 'dir'))
  92. subdir(join_paths('www3', 'dir'))
  93. # GoogleTest 1.13.0 requires C++14
  94. test_options = []
  95. if gtest_dep.version().version_compare('>=1.13.0')
  96. test_options += 'cpp_std=c++14'
  97. endif
  98. test(
  99. 'main',
  100. executable(
  101. 'main',
  102. 'test.cc',
  103. dependencies: [
  104. cpp_httplib_dep,
  105. gtest_dep,
  106. libcurl_dep
  107. ],
  108. override_options: test_options
  109. ),
  110. depends: [
  111. key_pem,
  112. cert_pem,
  113. cert2_pem,
  114. key_encrypted_pem,
  115. cert_encrypted_pem,
  116. rootca_key_pem,
  117. rootca_cert_pem,
  118. client_key_pem,
  119. client_cert_pem,
  120. client_encrypted_key_pem,
  121. client_encrypted_cert_pem
  122. ],
  123. workdir: meson.current_build_dir(),
  124. timeout: 300
  125. )