Debian Codegraph @

test/functional/cases/120_fuzzy/lib.robot

raw
1 *** Settings ***
2 Library OperatingSystem
3 Library ${RSPAMD_TESTDIR}/lib/rspamd.py
4 Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot
5 Variables ${RSPAMD_TESTDIR}/lib/vars.py
6
7 *** Variables ***
8 ${CONFIG} ${RSPAMD_TESTDIR}/configs/fuzzy.conf
9 ${FLAG1_SYMBOL} R_TEST_FUZZY_DENIED
10 ${FLAG2_SYMBOL} R_TEST_FUZZY_WHITE
11 ${REDIS_SCOPE} Suite
12 ${RSPAMD_FLAG1_NUMBER} 50
13 ${RSPAMD_FLAG2_NUMBER} 51
14 ${RSPAMD_FUZZY_BACKEND} redis
15 ${RSPAMD_FUZZY_ENCRYPTED_ONLY} false
16 ${RSPAMD_FUZZY_ENCRYPTION_KEY} null
17 ${RSPAMD_FUZZY_INCLUDE} ${RSPAMD_TESTDIR}/configs/empty.conf
18 ${RSPAMD_FUZZY_KEY} null
19 ${RSPAMD_FUZZY_SERVER_MODE} servers
20 ${RSPAMD_FUZZY_SHINGLES_KEY} null
21 ${RSPAMD_SCOPE} Suite
22 ${RSPAMD_SETTINGS_FUZZY_CHECK} ${EMPTY}
23 ${RSPAMD_SETTINGS_FUZZY_WORKER} ${EMPTY}
24 @{MESSAGES_SKIP} ${RSPAMD_TESTDIR}/messages/priority.eml
25 @{MESSAGES} ${RSPAMD_TESTDIR}/messages/spam_message.eml ${RSPAMD_TESTDIR}/messages/zip.eml
26 @{RANDOM_MESSAGES} ${RSPAMD_TESTDIR}/messages/bad_message.eml ${RSPAMD_TESTDIR}/messages/zip-doublebad.eml
27
28 *** Keywords ***
29 Fuzzy Skip Add Test Base
30 [Arguments] ${message}
31 Set Suite Variable ${RSPAMD_FUZZY_ADD_${message}} 0
32 ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -w 10 -f
33 ... ${RSPAMD_FLAG1_NUMBER} fuzzy_add ${message}
34 Check Rspamc ${result}
35 Sync Fuzzy Storage
36 Scan File ${message}
37 Expect Symbol R_TEST_FUZZY_DENIED
38 Create File ${RSPAMD_TMPDIR}/skip_hash.map.tmp 2d875d4737c59c4822fd01dadeba52a329de3933f766c6f167904c6a426bbfa7ea63a66bf807b25c5ee853baee58bfb18d3b423fcd13cfa7c3d77a840039a1ea
39 Move File ${RSPAMD_TMPDIR}/skip_hash.map.tmp ${RSPAMD_TMPDIR}/skip_hash.map
40 Sleep 1s Wait for reload
41 Scan File ${message}
42 Do Not Expect Symbol R_TEST_FUZZY_DENIED
43
44 Fuzzy Add Test
45 [Arguments] ${message}
46 Set Suite Variable ${RSPAMD_FUZZY_ADD_${message}} 0
47 ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -w 10 -f
48 ... ${RSPAMD_FLAG1_NUMBER} fuzzy_add ${message}
49 Check Rspamc ${result}
50 Sync Fuzzy Storage
51 Scan File ${message}
52 Expect Symbol ${FLAG1_SYMBOL}
53 Set Suite Variable ${RSPAMD_FUZZY_ADD_${message}} 1
54
55 Fuzzy Add Test Write Only
56 [Arguments] ${message}
57 Set Suite Variable ${RSPAMD_FUZZY_ADD_${message}} 0
58 ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -w 10 -f
59 ... ${RSPAMD_FLAG1_NUMBER} fuzzy_add ${message}
60 Check Rspamc ${result}
61 Sync Fuzzy Storage
62 # Do not scan - in write-only mode CHECK is not performed
63 Set Suite Variable ${RSPAMD_FUZZY_ADD_${message}} 1
64
65 Fuzzy Delete Test
66 [Arguments] ${message}
67 IF ${RSPAMD_FUZZY_ADD_${message}} == 0
68 Fail "Fuzzy Add was not run"
69 END
70 ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -f ${RSPAMD_FLAG1_NUMBER} fuzzy_del
71 ... ${message}
72 Check Rspamc ${result}
73 Sync Fuzzy Storage
74 Scan File ${message}
75 Do Not Expect Symbol ${FLAG1_SYMBOL}
76
77 Fuzzy Fuzzy Test
78 [Arguments] ${message}
79 IF ${RSPAMD_FUZZY_ADD_${message}} != 1
80 Fail "Fuzzy Add was not run"
81 END
82 @{path_info} = Path Splitter ${message}
83 @{fuzzy_files} = List Files In Directory ${pathinfo}[0] pattern=${pathinfo}[1].fuzzy* absolute=1
84 FOR ${i} IN @{fuzzy_files}
85 Scan File ${i}
86 Expect Symbol ${FLAG1_SYMBOL}
87 END
88
89 Fuzzy Encrypted Test
90 [Arguments] ${message}
91 @{path_info} = Path Splitter ${message}
92 @{fuzzy_files} = List Files In Directory ${pathinfo}[0] pattern=${pathinfo}[1].fuzzy* absolute=1
93 FOR ${i} IN @{fuzzy_files}
94 ${result} = Run Rspamc -p -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_NORMAL} --key ${RSPAMD_FUZZY_ENCRYPTION_KEY} ${i}
95 Check Rspamc ${result} ${FLAG1_SYMBOL}
96 END
97
98 Fuzzy Miss Test
99 [Arguments] ${message}
100 Scan File ${message}
101 Do Not Expect Symbol ${FLAG1_SYMBOL}
102
103 Fuzzy Write Only No Check Test
104 [Arguments] ${message}
105 IF ${RSPAMD_FUZZY_ADD_${message}} != 1
106 Fail "Fuzzy Add was not run"
107 END
108 # In write-only mode, CHECK is not sent, so symbol should not appear
109 Scan File ${message}
110 Do Not Expect Symbol ${FLAG1_SYMBOL}
111
112 Fuzzy Multi Flag Test
113 [Arguments] ${message}
114 ${flag_numbers} = Create List ${RSPAMD_FLAG1_NUMBER} ${RSPAMD_FLAG2_NUMBER}
115 FOR ${i} IN @{flag_numbers}
116 ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -w 10
117 ... -f ${i} fuzzy_add ${message}
118 Check Rspamc ${result}
119 END
120 Sync Fuzzy Storage
121 Scan File ${message}
122 Expect Symbol ${FLAG1_SYMBOL}
123 Expect Symbol ${FLAG2_SYMBOL}
124
125 Fuzzy Multi Flag Delete Test
126 [Arguments] ${message}
127 ${flag_numbers} = Create List ${RSPAMD_FLAG1_NUMBER} ${RSPAMD_FLAG2_NUMBER}
128 FOR ${i} IN @{flag_numbers}
129 ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -w 10
130 ... -f ${i} fuzzy_add ${message}
131 Check Rspamc ${result}
132 END
133 Sync Fuzzy Storage
134 Scan File ${message}
135 Expect Symbol ${FLAG1_SYMBOL}
136 Expect Symbol ${FLAG2_SYMBOL}
137 ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -f ${RSPAMD_FLAG1_NUMBER} fuzzy_del
138 ... ${message}
139 Check Rspamc ${result}
140 Sync Fuzzy Storage
141 Scan File ${message}
142 Do Not Expect Symbol ${FLAG1_SYMBOL}
143 Do Not Expect Symbol ${FLAG2_SYMBOL}
144
145 Fuzzy Multimessage Multi Flag Delete Test
146 FOR ${i} IN @{MESSAGES}
147 Fuzzy Multi Flag Delete Test ${i}
148 END
149
150 Fuzzy Setup Encrypted
151 [Arguments] ${algorithm}
152 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
153 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTED_ONLY} true
154 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB1}
155 Set Suite Variable ${RSPAMD_FUZZY_CLIENT_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB1}
156 Set Suite Variable ${RSPAMD_FUZZY_INCLUDE} ${RSPAMD_TESTDIR}/configs/fuzzy-encryption-key.conf
157 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} servers
158 Rspamd Redis Setup
159
160 Fuzzy Setup Encrypted Dyn1
161 [Arguments] ${algorithm}
162 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
163 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTED_ONLY} true
164 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB1}
165 Set Suite Variable ${RSPAMD_FUZZY_CLIENT_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB2}
166 Set Suite Variable ${RSPAMD_FUZZY_INCLUDE} ${RSPAMD_TESTDIR}/configs/fuzzy-encryption-key.conf
167 Rspamd Redis Setup
168
169 Fuzzy Setup Encrypted Dyn2
170 [Arguments] ${algorithm}
171 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
172 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTED_ONLY} true
173 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB1}
174 Set Suite Variable ${RSPAMD_FUZZY_CLIENT_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB3}
175 Set Suite Variable ${RSPAMD_FUZZY_INCLUDE} ${RSPAMD_TESTDIR}/configs/fuzzy-encryption-key.conf
176 Rspamd Redis Setup
177
178 Fuzzy Setup Encrypted Keyed
179 [Arguments] ${algorithm}
180 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
181 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTED_ONLY} true
182 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB1}
183 Set Suite Variable ${RSPAMD_FUZZY_CLIENT_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB1}
184 Set Suite Variable ${RSPAMD_FUZZY_KEY} mYN888sydwLTfE32g2hN
185 Set Suite Variable ${RSPAMD_FUZZY_SHINGLES_KEY} hXUCgul9yYY3Zlk1QIT2
186 Rspamd Redis Setup
187
188 Fuzzy Setup Plain
189 [Arguments] ${algorithm}
190 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
191 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} servers
192 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_CHECK} servers = "${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_FUZZY}";
193 Rspamd Redis Setup
194
195 Fuzzy Setup Keyed
196 [Arguments] ${algorithm}
197 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
198 Set Suite Variable ${RSPAMD_FUZZY_KEY} mYN888sydwLTfE32g2hN
199 Set Suite Variable ${RSPAMD_FUZZY_SHINGLES_KEY} hXUCgul9yYY3Zlk1QIT2
200 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} servers
201 Rspamd Redis Setup
202
203 Fuzzy Setup Plain Fasthash
204 Fuzzy Setup Plain fasthash
205
206 Fuzzy Setup Plain Mumhash
207 Fuzzy Setup Plain mumhash
208
209 Fuzzy Setup Plain Siphash
210 Fuzzy Setup Plain siphash
211
212 Fuzzy Setup Plain Xxhash
213 Fuzzy Setup Plain xxhash
214
215 Fuzzy Setup Keyed Fasthash
216 Fuzzy Setup Keyed fasthash
217
218 Fuzzy Setup Keyed Mumhash
219 Fuzzy Setup Keyed mumhash
220
221 Fuzzy Setup Keyed Siphash
222 Fuzzy Setup Keyed siphash
223
224 Fuzzy Setup Keyed Xxhash
225 Fuzzy Setup Keyed xxhash
226
227 Fuzzy Setup Encrypted Siphash
228 Fuzzy Setup Encrypted siphash
229
230 Fuzzy Setup Encrypted Dyn1 Siphash
231 Fuzzy Setup Encrypted Dyn1 siphash
232
233 Fuzzy Setup Encrypted Dyn2 Siphash
234 Fuzzy Setup Encrypted Dyn2 siphash
235
236 Fuzzy Skip Hash Test Message
237 FOR ${i} IN @{MESSAGES_SKIP}
238 Fuzzy Skip Add Test Base ${i}
239 END
240
241 Fuzzy Multimessage Add Test
242 FOR ${i} IN @{MESSAGES}
243 Fuzzy Add Test ${i}
244 END
245
246 Fuzzy Multimessage Add Test Write Only
247 FOR ${i} IN @{MESSAGES}
248 Fuzzy Add Test Write Only ${i}
249 END
250
251 Fuzzy Multimessage Fuzzy Test
252 FOR ${i} IN @{MESSAGES}
253 Fuzzy Fuzzy Test ${i}
254 END
255
256 Fuzzy Multimessage Fuzzy Encrypted Test
257 FOR ${i} IN @{MESSAGES}
258 Fuzzy Encrypted Test ${i}
259 END
260
261 Fuzzy Multimessage Miss Test
262 FOR ${i} IN @{RANDOM_MESSAGES}
263 Fuzzy Miss Test ${i}
264 END
265
266 Fuzzy Multimessage Delete Test
267 FOR ${i} IN @{MESSAGES}
268 Fuzzy Delete Test ${i}
269 END
270
271 Fuzzy Multimessage Multi Flag Test
272 FOR ${i} IN @{MESSAGES}
273 Fuzzy Multi Flag Test ${i}
274 END
275
276 Fuzzy Multimessage Write Only No Check Test
277 FOR ${i} IN @{MESSAGES}
278 Fuzzy Write Only No Check Test ${i}
279 END
280
281 Fuzzy Setup Split Servers
282 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} siphash
283 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} split
284 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_CHECK} read_servers = "${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_FUZZY}"; write_servers = "${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_FUZZY}";
285 Rspamd Redis Setup
286
287 Fuzzy Setup Read Only
288 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} siphash
289 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} read_only
290 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_CHECK} read_only = true;
291 Rspamd Redis Setup
292
293 Fuzzy Setup Write Only
294 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} siphash
295 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} write_only
296 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_CHECK} mode = "write_only";
297 Rspamd Redis Setup
298
299 Fuzzy Setup TCP
300 [Arguments] ${algorithm}
301 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
302 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} servers
303 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_CHECK} tcp = "auto"; tcp_threshold = 5;
304 Rspamd Redis Setup
305
306 Fuzzy Setup TCP Siphash
307 Fuzzy Setup TCP siphash
308
309 Fuzzy Setup TCP Encrypted
310 [Arguments] ${algorithm}
311 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
312 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTED_ONLY} true
313 Set Suite Variable ${RSPAMD_FUZZY_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB1}
314 Set Suite Variable ${RSPAMD_FUZZY_CLIENT_ENCRYPTION_KEY} ${RSPAMD_KEY_PUB1}
315 Set Suite Variable ${RSPAMD_FUZZY_INCLUDE} ${RSPAMD_TESTDIR}/configs/fuzzy-encryption-key.conf
316 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} servers
317 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_WORKER} tcp = true;
318 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_CHECK} tcp = "auto"; tcp_threshold = 5;
319 Rspamd Redis Setup
320
321 Fuzzy Setup TCP Encrypted Siphash
322 Fuzzy Setup TCP Encrypted siphash
323
324 Fuzzy Setup TCP Explicit
325 [Arguments] ${algorithm}
326 Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} ${algorithm}
327 Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} servers
328 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_WORKER} tcp = true;
329 Set Suite Variable ${RSPAMD_SETTINGS_FUZZY_CHECK} tcp = "yes";
330 Rspamd Redis Setup
331
332 Fuzzy Setup TCP Explicit Siphash
333 Fuzzy Setup TCP Explicit siphash
334
335 Fuzzy TCP High Rate Test
336 # Send multiple messages to exceed rate threshold and trigger TCP
337 FOR ${i} IN RANGE 10
338 FOR ${message} IN @{MESSAGES}
339 ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -w 10 -f
340 ... ${RSPAMD_FLAG1_NUMBER} fuzzy_add ${message}
341 Check Rspamc ${result}
342 END
343 END
344 Sync Fuzzy Storage
345 # Verify that fuzzy check still works
346 FOR ${message} IN @{MESSAGES}
347 Scan File ${message}
348 Expect Symbol ${FLAG1_SYMBOL}
349 END