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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. Do Not Expect Symbol
  41. [Arguments] ${symbol}
  42. Dictionary Should Not Contain Key ${SCAN_RESULT}[symbols] ${symbol}
  43. ... msg=Symbol ${symbol} was not expected to be found in result
  44. Do Not Expect Symbols
  45. [Arguments] @{symbols}
  46. FOR ${symbol} IN @{symbols}
  47. Dictionary Should Not Contain Key ${SCAN_RESULT}[symbols] ${symbol}
  48. ... msg=Symbol ${symbol} was not expected to be found in result
  49. END
  50. Generic Setup
  51. [Arguments] @{vargs} &{kwargs}
  52. &{d} = Run Rspamd @{vargs} &{kwargs}
  53. ${keys} = Get Dictionary Keys ${d}
  54. FOR ${i} IN @{keys}
  55. Run Keyword If '${RSPAMD_SCOPE}' == 'Suite' Set Suite Variable ${${i}} ${d}[${i}]
  56. ... ELSE IF '${RSPAMD_SCOPE}' == 'Test' Set Test Variable ${${i}} ${d}[${i}]
  57. ... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
  58. END
  59. Expect Action
  60. [Arguments] ${action}
  61. Should Be Equal ${SCAN_RESULT}[action] ${action}
  62. Expect Email
  63. [Arguments] ${email}
  64. List Should Contain Value ${SCAN_RESULT}[emails] ${email}
  65. Expect Required Score
  66. [Arguments] ${required_score}
  67. Should Be Equal As Numbers ${SCAN_RESULT}[required_score] ${required_score}
  68. Expect Required Score To Be Null
  69. Should Be Equal ${SCAN_RESULT}[required_score] ${NONE}
  70. Expect Score
  71. [Arguments] ${score}
  72. Should Be Equal As Numbers ${SCAN_RESULT}[score] ${score}
  73. Expect Symbol
  74. [Arguments] ${symbol}
  75. Dictionary Should Contain Key ${SCAN_RESULT}[symbols] ${symbol}
  76. ... msg=Symbol ${symbol} wasn't found in result
  77. Expect URL
  78. [Arguments] ${url}
  79. List Should Contain Value ${SCAN_RESULT}[urls] ${url}
  80. Expect Extended URL
  81. [Arguments] ${url}
  82. ${found_url} = Set Variable ${FALSE}
  83. ${url_list} = Convert To List ${SCAN_RESULT}[urls]
  84. FOR ${item} IN @{url_list}
  85. ${d} = Convert To Dictionary ${item}
  86. ${found_url} = Evaluate "${d}[url]" == "${url}"
  87. Exit For Loop If ${found_url} == ${TRUE}
  88. END
  89. Should Be True ${found_url} msg="Expected URL was not found: ${url}"
  90. Expect Symbol With Exact Options
  91. [Arguments] ${symbol} @{options}
  92. Expect Symbol ${symbol}
  93. ${have_options} = Convert To List ${SCAN_RESULT}[symbols][${symbol}][options]
  94. Lists Should Be Equal ${have_options} ${options}
  95. ... msg="Symbol ${symbol} has options ${SCAN_RESULT}[symbols][${symbol}][options] but expected ${options}"
  96. Expect Symbol With Option
  97. [Arguments] ${symbol} ${option}
  98. Expect Symbol ${symbol}
  99. ${have_options} = Convert To List ${SCAN_RESULT}[symbols][${symbol}][options]
  100. Should Contain ${have_options} ${option}
  101. ... msg="Options for symbol ${symbol} ${SCAN_RESULT}[symbols][${symbol}][options] doesn't contain ${option}"
  102. Expect Symbol With Score
  103. [Arguments] ${symbol} ${score}
  104. Dictionary Should Contain Key ${SCAN_RESULT}[symbols] ${symbol}
  105. ... msg=Symbol ${symbol} wasn't found in result
  106. Should Be Equal As Numbers ${SCAN_RESULT}[symbols][${symbol}][score] ${score}
  107. ... msg="Symbol ${symbol} has score of ${SCAN_RESULT}[symbols][${symbol}][score] but expected ${score}"
  108. Expect Symbols With Scores
  109. [Arguments] &{symscores}
  110. FOR ${key} ${value} IN &{symscores}
  111. Dictionary Should Contain Key ${SCAN_RESULT}[symbols] ${key}
  112. ... msg=Symbol ${key} wasn't found in result
  113. Should Be Equal As Numbers ${SCAN_RESULT}[symbols][${key}][score] ${value}
  114. ... msg="Symbol ${key} has score of ${SCAN_RESULT}[symbols][${key}][score] but expected ${value}"
  115. END
  116. Expect Symbol With Score And Exact Options
  117. [Arguments] ${symbol} ${score} @{options}
  118. Expect Symbol With Exact Options ${symbol} @{options}
  119. Expect Symbol With Score ${symbol} ${score}
  120. Generic Teardown
  121. Run Keyword If '${CONTROLLER_ERRORS}' == 'True' Check Controller Errors
  122. Shutdown Process With Children ${RSPAMD_PID}
  123. Save Run Results ${TMPDIR} rspamd.conf rspamd.log redis.log clickhouse-config.xml
  124. Log does not contain segfault record
  125. Collect Lua Coverage
  126. Cleanup Temporary Directory ${TMPDIR}
  127. Log does not contain segfault record
  128. ${log} = Get File ${TMPDIR}/rspamd.log encoding_errors=ignore
  129. Should not contain ${log} Segmentation fault: msg=Segmentation fault detected
  130. Normal Teardown
  131. Generic Teardown
  132. Redis HSET
  133. [Arguments] ${hash} ${key} ${value}
  134. ${result} = Run Process redis-cli -h ${REDIS_ADDR} -p ${REDIS_PORT}
  135. ... HSET ${hash} ${key} ${value}
  136. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  137. Log ${result.stdout}
  138. Should Be Equal As Integers ${result.rc} 0
  139. Redis SET
  140. [Arguments] ${key} ${value}
  141. ${result} = Run Process redis-cli -h ${REDIS_ADDR} -p ${REDIS_PORT}
  142. ... SET ${key} ${value}
  143. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  144. Log ${result.stdout}
  145. Should Be Equal As Integers ${result.rc} 0
  146. Run Redis
  147. ${template} = Get File ${TESTDIR}/configs/redis-server.conf
  148. ${config} = Replace Variables ${template}
  149. Create File ${TMPDIR}/redis-server.conf ${config}
  150. Log ${config}
  151. ${result} = Run Process redis-server ${TMPDIR}/redis-server.conf
  152. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  153. Should Be Equal As Integers ${result.rc} 0
  154. Wait Until Keyword Succeeds 5x 1 sec Check Pidfile ${TMPDIR}/redis.pid timeout=0.5s
  155. Wait Until Keyword Succeeds 5x 1 sec Redis Check ${REDIS_ADDR} ${REDIS_PORT}
  156. ${REDIS_PID} = Get File ${TMPDIR}/redis.pid
  157. Run Keyword If '${REDIS_SCOPE}' == 'Test' Set Test Variable ${REDIS_PID}
  158. ... ELSE IF '${REDIS_SCOPE}' == 'Suite' Set Suite Variable ${REDIS_PID}
  159. ${redis_log} = Get File ${TMPDIR}/redis.log
  160. Log ${redis_log}
  161. Run Nginx
  162. ${template} = Get File ${TESTDIR}/configs/nginx.conf
  163. ${config} = Replace Variables ${template}
  164. Create File ${TMPDIR}/nginx.conf ${config}
  165. Log ${config}
  166. ${result} = Run Process nginx -c ${TMPDIR}/nginx.conf
  167. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  168. Should Be Equal As Integers ${result.rc} 0
  169. Wait Until Keyword Succeeds 10x 1 sec Check Pidfile ${TMPDIR}/nginx.pid timeout=0.5s
  170. Wait Until Keyword Succeeds 5x 1 sec TCP Connect ${NGINX_ADDR} ${NGINX_PORT}
  171. ${NGINX_PID} = Get File ${TMPDIR}/nginx.pid
  172. Run Keyword If '${NGINX_SCOPE}' == 'Test' Set Test Variable ${NGINX_PID}
  173. ... ELSE IF '${NGINX_SCOPE}' == 'Suite' Set Suite Variable ${NGINX_PID}
  174. ${nginx_log} = Get File ${TMPDIR}/nginx.log
  175. Log ${nginx_log}
  176. Run Rspamc
  177. [Arguments] @{args}
  178. ${result} = Run Process ${RSPAMC} -t 60 --header Queue-ID\=${TEST NAME}
  179. ... @{args} env:LD_LIBRARY_PATH=${TESTDIR}/../../contrib/aho-corasick
  180. Log ${result.stdout}
  181. [Return] ${result}
  182. Run Rspamd
  183. [Arguments] @{vargs} &{kwargs}
  184. ${has_CONFIG} = Evaluate 'CONFIG' in $kwargs
  185. ${has_TMPDIR} = Evaluate 'TMPDIR' in $kwargs
  186. ${CONFIG} = Set Variable If '${has_CONFIG}' == 'True' ${kwargs}[CONFIG] ${CONFIG}
  187. &{d} = Create Dictionary
  188. ${tmpdir} = Run Keyword If '${has_TMPDIR}' == 'True' Set Variable ${kwargs}[TMPDIR]
  189. ... ELSE Make Temporary Directory
  190. Set Directory Ownership ${tmpdir} ${RSPAMD_USER} ${RSPAMD_GROUP}
  191. ${template} = Get File ${CONFIG}
  192. # TODO: stop using this; we have Lupa now
  193. FOR ${i} IN @{vargs}
  194. ${newvalue} = Replace Variables ${${i}}
  195. Set To Dictionary ${d} ${i}=${newvalue}
  196. END
  197. ${config} = Replace Variables ${template}
  198. ${config} = Replace Variables ${config}
  199. Log ${config}
  200. Create File ${tmpdir}/rspamd.conf ${config}
  201. ${result} = Run Process ${RSPAMD} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP}
  202. ... -c ${tmpdir}/rspamd.conf env:TMPDIR=${tmpdir} env:DBDIR=${tmpdir} env:LD_LIBRARY_PATH=${TESTDIR}/../../contrib/aho-corasick
  203. ... env:RSPAMD_INSTALLROOT=${INSTALLROOT} stdout=DEVNULL stderr=DEVNULL
  204. Run Keyword If ${result.rc} != 0 Log ${result.stderr}
  205. Should Be Equal As Integers ${result.rc} 0
  206. Wait Until Keyword Succeeds 10x 1 sec Check Pidfile ${tmpdir}/rspamd.pid timeout=0.5s
  207. Wait Until Keyword Succeeds 5x 1 sec Ping Rspamd ${LOCAL_ADDR} ${PORT_NORMAL}
  208. ${rspamd_pid} = Get File ${tmpdir}/rspamd.pid
  209. Set To Dictionary ${d} RSPAMD_PID=${rspamd_pid} TMPDIR=${tmpdir}
  210. [Return] &{d}
  211. Simple Teardown
  212. Generic Teardown
  213. Scan File By Reference
  214. [Arguments] ${filename} &{headers}
  215. Set To Dictionary ${headers} File=${filename}
  216. ${result} = Scan File /dev/null &{headers}
  217. [Return] ${result}
  218. Scan Message With Rspamc
  219. [Arguments] ${msg_file} @{vargs}
  220. ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} @{vargs} ${msg_file}
  221. [Return] ${result}
  222. Sync Fuzzy Storage
  223. [Arguments] @{vargs}
  224. ${len} = Get Length ${vargs}
  225. ${result} = Run Keyword If $len == 0 Run Process ${RSPAMADM} control -s
  226. ... ${TMPDIR}/rspamd.sock fuzzy_sync
  227. ... ELSE Run Process ${RSPAMADM} control -s ${vargs}[0]/rspamd.sock
  228. ... fuzzy_sync
  229. Log ${result.stdout}
  230. Sleep 0.1s Try give fuzzy storage time to sync