You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rspamd.robot 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. *** Settings ***
  2. Library Collections
  3. Library OperatingSystem
  4. Library Process
  5. *** Keywords ***
  6. Check Controller Errors
  7. @{result} = HTTP GET ${LOCAL_ADDR} ${PORT_CONTROLLER} /errors
  8. Should Be Equal As Integers ${result}[0] 200
  9. Log ${result}[1]
  10. Check Pidfile
  11. [Arguments] ${pidfile} ${timeout}=1 min
  12. Wait Until Created ${pidfile} timeout=${timeout}
  13. ${size} = Get File Size ${pidfile}
  14. Should Not Be Equal As Integers ${size} 0
  15. Check Rspamc
  16. [Arguments] ${result} @{args} &{kwargs}
  17. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  18. ${has_rc} = Evaluate 'rc' in $kwargs
  19. ${inverse} = Evaluate 'inverse' in $kwargs
  20. ${re} = Evaluate 're' in $kwargs
  21. ${rc} = Set Variable If ${has_rc} == True ${kwargs}[rc] 0
  22. FOR ${i} IN @{args}
  23. Run Keyword If ${re} == True Check Rspamc Match Regexp ${result.stdout} ${i} ${inverse}
  24. ... ELSE Check Rspamc Match String ${result.stdout} ${i} ${inverse}
  25. END
  26. Run Keyword If @{args} == @{EMPTY} Check Rspamc Match Default ${result.stdout} ${inverse}
  27. Should Be Equal As Integers ${result.rc} ${rc}
  28. Check Rspamc Match Default
  29. [Arguments] ${subject} ${inverse}
  30. Run Keyword If ${inverse} == False Should Contain ${subject} success = true
  31. ... ELSE Should Not Contain ${subject} success = true
  32. Check Rspamc Match Regexp
  33. [Arguments] ${subject} ${re} ${inverse}
  34. Run Keyword If ${inverse} == False Should Match Regexp ${subject} ${re}
  35. ... ELSE Should Not Match Regexp ${subject} ${re}
  36. Check Rspamc Match String
  37. [Arguments] ${subject} ${str} ${inverse}
  38. Run Keyword If ${inverse} == False Should Contain ${subject} ${str}
  39. ... ELSE Should Not Contain ${subject} ${str}
  40. Generic Setup
  41. [Arguments] @{vargs} &{kwargs}
  42. &{d} = Run Rspamd @{vargs} &{kwargs}
  43. ${keys} = Get Dictionary Keys ${d}
  44. FOR ${i} IN @{keys}
  45. Run Keyword If '${RSPAMD_SCOPE}' == 'Suite' Set Suite Variable ${${i}} ${d}[${i}]
  46. ... ELSE IF '${RSPAMD_SCOPE}' == 'Test' Set Test Variable ${${i}} ${d}[${i}]
  47. ... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
  48. END
  49. Generic Teardown
  50. Run Keyword If '${CONTROLLER_ERRORS}' == 'True' Check Controller Errors
  51. Shutdown Process With Children ${RSPAMD_PID}
  52. Log does not contain segfault record
  53. Save Run Results ${TMPDIR} rspamd.log redis.log rspamd.conf clickhouse-config.xml
  54. Collect Lua Coverage
  55. Cleanup Temporary Directory ${TMPDIR}
  56. Log does not contain segfault record
  57. ${log} = Get File ${TMPDIR}/rspamd.log encoding_errors=ignore
  58. Should not contain ${log} Segmentation fault: msg=Segmentation fault detected
  59. Normal Teardown
  60. Generic Teardown
  61. Redis HSET
  62. [Arguments] ${hash} ${key} ${value}
  63. ${result} = Run Process redis-cli -h ${REDIS_ADDR} -p ${REDIS_PORT}
  64. ... HSET ${hash} ${key} ${value}
  65. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  66. Log ${result.stdout}
  67. Should Be Equal As Integers ${result.rc} 0
  68. Redis SET
  69. [Arguments] ${key} ${value}
  70. ${result} = Run Process redis-cli -h ${REDIS_ADDR} -p ${REDIS_PORT}
  71. ... SET ${key} ${value}
  72. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  73. Log ${result.stdout}
  74. Should Be Equal As Integers ${result.rc} 0
  75. Run Redis
  76. ${template} = Get File ${TESTDIR}/configs/redis-server.conf
  77. ${config} = Replace Variables ${template}
  78. Create File ${TMPDIR}/redis-server.conf ${config}
  79. Log ${config}
  80. ${result} = Run Process redis-server ${TMPDIR}/redis-server.conf
  81. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  82. Should Be Equal As Integers ${result.rc} 0
  83. Wait Until Keyword Succeeds 5x 1 sec Check Pidfile ${TMPDIR}/redis.pid timeout=0.5s
  84. Wait Until Keyword Succeeds 5x 1 sec Redis Check ${REDIS_ADDR} ${REDIS_PORT}
  85. ${REDIS_PID} = Get File ${TMPDIR}/redis.pid
  86. Run Keyword If '${REDIS_SCOPE}' == 'Test' Set Test Variable ${REDIS_PID}
  87. ... ELSE IF '${REDIS_SCOPE}' == 'Suite' Set Suite Variable ${REDIS_PID}
  88. ${redis_log} = Get File ${TMPDIR}/redis.log
  89. Log ${redis_log}
  90. Run Nginx
  91. ${template} = Get File ${TESTDIR}/configs/nginx.conf
  92. ${config} = Replace Variables ${template}
  93. Create File ${TMPDIR}/nginx.conf ${config}
  94. Log ${config}
  95. ${result} = Run Process nginx -c ${TMPDIR}/nginx.conf
  96. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  97. Should Be Equal As Integers ${result.rc} 0
  98. Wait Until Keyword Succeeds 10x 1 sec Check Pidfile ${TMPDIR}/nginx.pid timeout=0.5s
  99. Wait Until Keyword Succeeds 5x 1 sec TCP Connect ${NGINX_ADDR} ${NGINX_PORT}
  100. ${NGINX_PID} = Get File ${TMPDIR}/nginx.pid
  101. Run Keyword If '${NGINX_SCOPE}' == 'Test' Set Test Variable ${NGINX_PID}
  102. ... ELSE IF '${NGINX_SCOPE}' == 'Suite' Set Suite Variable ${NGINX_PID}
  103. ${nginx_log} = Get File ${TMPDIR}/nginx.log
  104. Log ${nginx_log}
  105. Run Rspamc
  106. [Arguments] @{args}
  107. ${result} = Run Process ${RSPAMC} -t 60 --header Queue-ID\=${TEST NAME}
  108. ... @{args} env:LD_LIBRARY_PATH=${TESTDIR}/../../contrib/aho-corasick
  109. Log ${result.stdout}
  110. [Return] ${result}
  111. Run Rspamd
  112. [Arguments] @{vargs} &{kwargs}
  113. ${has_CONFIG} = Evaluate 'CONFIG' in $kwargs
  114. ${has_TMPDIR} = Evaluate 'TMPDIR' in $kwargs
  115. ${CONFIG} = Set Variable If '${has_CONFIG}' == 'True' ${kwargs}[CONFIG] ${CONFIG}
  116. &{d} = Create Dictionary
  117. ${tmpdir} = Run Keyword If '${has_TMPDIR}' == 'True' Set Variable ${kwargs}[TMPDIR]
  118. ... ELSE Make Temporary Directory
  119. Set Directory Ownership ${tmpdir} ${RSPAMD_USER} ${RSPAMD_GROUP}
  120. ${template} = Get File ${CONFIG}
  121. FOR ${i} IN @{vargs}
  122. ${newvalue} = Replace Variables ${${i}}
  123. Set To Dictionary ${d} ${i}=${newvalue}
  124. END
  125. ${config} = Replace Variables ${template}
  126. ${config} = Replace Variables ${config}
  127. Log ${config}
  128. Create File ${tmpdir}/rspamd.conf ${config}
  129. ${result} = Run Process ${RSPAMD} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP}
  130. ... -c ${tmpdir}/rspamd.conf env:TMPDIR=${tmpdir} env:DBDIR=${tmpdir} env:LD_LIBRARY_PATH=${TESTDIR}/../../contrib/aho-corasick
  131. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  132. Should Be Equal As Integers ${result.rc} 0
  133. Wait Until Keyword Succeeds 10x 1 sec Check Pidfile ${tmpdir}/rspamd.pid timeout=0.5s
  134. Wait Until Keyword Succeeds 5x 1 sec Ping Rspamd ${LOCAL_ADDR} ${PORT_NORMAL}
  135. ${rspamd_pid} = Get File ${tmpdir}/rspamd.pid
  136. Set To Dictionary ${d} RSPAMD_PID=${rspamd_pid} TMPDIR=${tmpdir}
  137. [Return] &{d}
  138. Simple Teardown
  139. Generic Teardown
  140. Scan Message With Rspamc
  141. [Arguments] ${msg_file} @{vargs}
  142. ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} @{vargs} ${msg_file}
  143. [Return] ${result}
  144. Sync Fuzzy Storage
  145. [Arguments] @{vargs}
  146. ${len} = Get Length ${vargs}
  147. ${result} = Run Keyword If $len == 0 Run Process ${RSPAMADM} control -s
  148. ... ${TMPDIR}/rspamd.sock fuzzy_sync
  149. ... ELSE Run Process ${RSPAMADM} control -s ${vargs}[0]/rspamd.sock
  150. ... fuzzy_sync
  151. Log ${result.stdout}
  152. Sleep 0.1s Try give fuzzy storage time to sync