meson.build 4.2 KB

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