meson.build 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. # Copy test files to the build directory
  70. configure_file(input: 'ca-bundle.crt', output: 'ca-bundle.crt', copy: true)
  71. configure_file(input: 'image.jpg', output: 'image.jpg', copy: true)
  72. subdir(join_paths('www', 'dir'))
  73. subdir(join_paths('www2', 'dir'))
  74. subdir(join_paths('www3', 'dir'))
  75. test(
  76. 'main',
  77. executable(
  78. 'main',
  79. 'test.cc',
  80. dependencies: [
  81. cpp_httplib_dep,
  82. gtest_dep
  83. ]
  84. ),
  85. depends: [
  86. key_pem,
  87. cert_pem,
  88. cert2_pem,
  89. rootca_key_pem,
  90. rootca_cert_pem,
  91. client_key_pem,
  92. client_cert_pem
  93. ],
  94. workdir: meson.current_build_dir(),
  95. timeout: 300
  96. )