meson.build 4.1 KB

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