Просмотр исходного кода

Merge pull request #4886 from fatalbanana/rspamd-3.8-tests

rspamd-3.8: fix tests
rspamd-3.8
Vsevolod Stakhov 2 месяцев назад
Родитель
Сommit
451e516a08
Аккаунт пользователя с таким Email не найден

+ 9
- 2
lualib/lua_maps.lua Просмотреть файл

@@ -294,6 +294,11 @@ local function rspamd_map_add_from_ucl(opt, mtype, description, callback)
end

if opt[1] then
local function check_plain_map(line)
return lua_util.str_startswith(line, 'http')
or lua_util.str_startswith(line, 'file:')
or lua_util.str_startswith(line, '/')
end
-- Adjust each element if needed
local adjusted
for i, source in ipairs(opt) do
@@ -311,6 +316,7 @@ local function rspamd_map_add_from_ucl(opt, mtype, description, callback)
if mtype == 'radix' then

if string.find(opt[1], '^%d') then
-- List of numeric stuff (hope it's ipnets definitions)
local map = rspamd_config:radix_from_ucl(opt)

if map then
@@ -338,7 +344,7 @@ local function rspamd_map_add_from_ucl(opt, mtype, description, callback)
end
end
elseif mtype == 'regexp' or mtype == 'glob' then
if string.find(opt[1], '^/%a') or string.find(opt[1], '^http') then
if check_plain_map(opt[1]) then
-- Plain table
local map = rspamd_config:add_map {
type = mtype,
@@ -372,7 +378,8 @@ local function rspamd_map_add_from_ucl(opt, mtype, description, callback)
end
end
else
if string.find(opt[1], '^/%a') or string.find(opt[1], '^http') then
-- Not regexp/glob
if check_plain_map(opt[1]) then
-- Plain table
local map = rspamd_config:add_map {
type = mtype,

+ 1
- 1
src/libmime/lang_detection.c Просмотреть файл

@@ -898,7 +898,7 @@ rspamd_language_detector_init(struct rspamd_config *cfg)
rspamd_language_detector_process_chain(cfg, chain);
});

if (!rspamd_multipattern_compile(ret->stop_words[i].mp, &err)) {
if (!rspamd_multipattern_compile(ret->stop_words[i].mp, 0, &err)) {
msg_err_config("cannot compile stop words for %z language group: %e",
i, err);
g_error_free(err);

+ 1
- 1
src/libmime/message.c Просмотреть файл

@@ -674,7 +674,7 @@ rspamd_check_gtube(struct rspamd_task *task, struct rspamd_mime_text_part *part)
RSPAMD_MULTIPATTERN_DEFAULT);

GError *err = NULL;
rspamd_multipattern_compile(gtube_matcher, &err);
rspamd_multipattern_compile(gtube_matcher, RSPAMD_MULTIPATTERN_COMPILE_NO_FS, &err);

if (err != NULL) {
/* It will be expensive, but I don't care, still better than to abort */

+ 4
- 4
src/libmime/mime_parser.c Просмотреть файл

@@ -1,11 +1,11 @@
/*-
* Copyright 2016 Vsevolod Stakhov
/*
* Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -169,7 +169,7 @@ rspamd_mime_parser_init_lib(void)
rspamd_multipattern_add_pattern(lib_ctx->mp_boundary, "\n--", 0);

GError *err = NULL;
if (!rspamd_multipattern_compile(lib_ctx->mp_boundary, &err)) {
if (!rspamd_multipattern_compile(lib_ctx->mp_boundary, RSPAMD_MULTIPATTERN_COMPILE_NO_FS, &err)) {
msg_err("fatal error: cannot compile multipattern for mime parser boundaries: %e", err);
g_error_free(err);
g_abort();

+ 5
- 3
src/libserver/url.c Просмотреть файл

@@ -1,5 +1,5 @@
/*
* Copyright 2023 Vsevolod Stakhov
* Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -539,6 +539,7 @@ void rspamd_url_init(const gchar *tld_file)
{
GError *err = NULL;
gboolean ret = TRUE;
int mp_compile_flags = 0;

if (url_scanner != NULL) {
rspamd_url_deinit();
@@ -564,6 +565,7 @@ void rspamd_url_init(const gchar *tld_file)
url_scanner->matchers_full = NULL;
url_scanner->search_trie_full = NULL;
url_scanner->has_tld_file = false;
mp_compile_flags |= RSPAMD_MULTIPATTERN_COMPILE_NO_FS;
}

rspamd_url_add_static_matchers(url_scanner);
@@ -577,13 +579,13 @@ void rspamd_url_init(const gchar *tld_file)
url_scanner->matchers_full->len);
}

if (!rspamd_multipattern_compile(url_scanner->search_trie_strict, &err)) {
if (!rspamd_multipattern_compile(url_scanner->search_trie_strict, mp_compile_flags, &err)) {
msg_err("cannot compile url matcher static patterns, fatal error: %e", err);
abort();
}

if (url_scanner->search_trie_full) {
if (!rspamd_multipattern_compile(url_scanner->search_trie_full, &err)) {
if (!rspamd_multipattern_compile(url_scanner->search_trie_full, mp_compile_flags, &err)) {
msg_err("cannot compile tld patterns, url matching will be "
"incomplete: %e",
err);

+ 18
- 13
src/libutil/multipattern.c Просмотреть файл

@@ -1,11 +1,11 @@
/*-
* Copyright 2016 Vsevolod Stakhov
/*
* Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -466,7 +466,7 @@ rspamd_multipattern_try_save_hs(struct rspamd_multipattern *mp,
#endif

gboolean
rspamd_multipattern_compile(struct rspamd_multipattern *mp, GError **err)
rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError **err)
{
g_assert(mp != NULL);
g_assert(!mp->compiled);
@@ -483,7 +483,7 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, GError **err)
rspamd_cryptobox_hash_update(&mp->hash_state, (void *) &plt, sizeof(plt));
rspamd_cryptobox_hash_final(&mp->hash_state, hash);

if (!rspamd_multipattern_try_load_hs(mp, hash)) {
if ((flags & RSPAMD_MULTIPATTERN_COMPILE_NO_FS) || !rspamd_multipattern_try_load_hs(mp, hash)) {
hs_database_t *db = NULL;

if (hs_compile_multi((const char *const *) mp->hs_pats->data,
@@ -504,18 +504,23 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, GError **err)
return FALSE;
}

if (hs_cache_dir != NULL) {
char fpath[PATH_MAX];
rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmp", hs_cache_dir,
(gint) rspamd_cryptobox_HASHBYTES / 2, hash);
mp->hs_db = rspamd_hyperscan_from_raw_db(db, fpath);
if (!(flags & RSPAMD_MULTIPATTERN_COMPILE_NO_FS)) {
if (hs_cache_dir != NULL) {
char fpath[PATH_MAX];
rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmp", hs_cache_dir,
(gint) rspamd_cryptobox_HASHBYTES / 2, hash);
mp->hs_db = rspamd_hyperscan_from_raw_db(db, fpath);
}
else {
/* Should not happen in the real life */
mp->hs_db = rspamd_hyperscan_from_raw_db(db, NULL);
}

rspamd_multipattern_try_save_hs(mp, hash);
}
else {
/* Should not happen in the real life */
mp->hs_db = rspamd_hyperscan_from_raw_db(db, NULL);
}

rspamd_multipattern_try_save_hs(mp, hash);
}

for (i = 0; i < MAX_SCRATCH; i++) {

+ 6
- 3
src/libutil/multipattern.h Просмотреть файл

@@ -1,11 +1,11 @@
/*-
* Copyright 2016 Vsevolod Stakhov
/*
* Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -117,12 +117,15 @@ void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp,
void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp,
const gchar *pattern, gsize patlen, gint flags);


#define RSPAMD_MULTIPATTERN_COMPILE_NO_FS (0x1u << 0u)
/**
* Compiles multipattern structure
* @param mp
* @return
*/
gboolean rspamd_multipattern_compile(struct rspamd_multipattern *mp,
int flags,
GError **err);

/**

+ 4
- 4
src/lua/lua_trie.c Просмотреть файл

@@ -1,11 +1,11 @@
/*-
* Copyright 2016 Vsevolod Stakhov
/*
* Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -142,7 +142,7 @@ lua_trie_create(lua_State *L)

lua_pop(L, 1); /* table */

if (!rspamd_multipattern_compile(trie, &err)) {
if (!rspamd_multipattern_compile(trie, 0, &err)) {
msg_err("cannot compile multipattern: %e", err);
g_error_free(err);
rspamd_multipattern_destroy(trie);

+ 24
- 38
test/functional/cases/001_merged/160_antivirus.robot Просмотреть файл

@@ -1,5 +1,4 @@
*** Settings ***
Suite Teardown Antivirus Teardown
Library Process
Library ${RSPAMD_TESTDIR}/lib/rspamd.py
Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot
@@ -14,19 +13,19 @@ ${SETTINGS_FPROT} {symbols_enabled = [FPROT_VIRUS, FPROT2_VIRUS_DUPLICATE_DEFA

*** Test Cases ***
CLAMAV MISS
Run Dummy Clam ${RSPAMD_PORT_CLAM}
${process} = Run Dummy Clam ${RSPAMD_PORT_CLAM}
Scan File ${MESSAGE}
... Settings=${SETTINGS_CLAM}
Do Not Expect Symbol CLAM_VIRUS
Shutdown clamav
[Teardown] Terminate Process ${process}

CLAMAV HIT
Run Dummy Clam ${RSPAMD_PORT_CLAM} 1
${process} = Run Dummy Clam ${RSPAMD_PORT_CLAM} 1
Scan File ${MESSAGE2}
... Settings=${SETTINGS_CLAM}
Expect Symbol CLAM_VIRUS
Do Not Expect Symbol CLAMAV_VIRUS_FAIL
Shutdown clamav
[Teardown] Terminate Process ${process}

CLAMAV CACHE HIT
Scan File ${MESSAGE2}
@@ -41,16 +40,16 @@ CLAMAV CACHE MISS
Do Not Expect Symbol CLAMAV_VIRUS_FAIL

FPROT MISS
Run Dummy Fprot ${RSPAMD_PORT_FPROT}
${process} = Run Dummy Fprot ${RSPAMD_PORT_FPROT}
Scan File ${MESSAGE2}
... Settings=${SETTINGS_FPROT}
Do Not Expect Symbol FPROT_VIRUS
Do Not Expect Symbol FPROT_EICAR
Shutdown fport
[Teardown] Terminate Process ${process}

FPROT HIT - PATTERN
Run Dummy Fprot ${RSPAMD_PORT_FPROT} 1
Run Dummy Fprot ${RSPAMD_PORT_FPROT2_DUPLICATE} 1 /tmp/dummy_fprot_dupe.pid
${process1} = Run Dummy Fprot ${RSPAMD_PORT_FPROT} 1
${process2} = Run Dummy Fprot ${RSPAMD_PORT_FPROT2_DUPLICATE} 1 /tmp/dummy_fprot_dupe.pid
Scan File ${MESSAGE}
... Settings=${SETTINGS_FPROT}
Expect Symbol FPROT_EICAR
@@ -58,8 +57,7 @@ FPROT HIT - PATTERN
Expect Symbol FPROT2_VIRUS_DUPLICATE_PATTERN
Do Not Expect Symbol FPROT2_VIRUS_DUPLICATE_DEFAULT
Do Not Expect Symbol FPROT2_VIRUS_DUPLICATE_NOPE
Shutdown fport
Shutdown fport duplicate
[Teardown] Double FProt Teardown ${process1} ${process2}

FPROT CACHE HIT
Scan File ${MESSAGE}
@@ -76,19 +74,19 @@ FPROT CACHE MISS
Do Not Expect Symbol FPROT_VIRUS

AVAST MISS
Run Dummy Avast ${RSPAMD_PORT_AVAST}
${process} = Run Dummy Avast ${RSPAMD_PORT_AVAST}
Scan File ${MESSAGE}
... Settings=${SETTINGS_AVAST}
Do Not Expect Symbol AVAST_VIRUS
Shutdown avast
[Teardown] Terminate Process ${process}

AVAST HIT
Run Dummy Avast ${RSPAMD_PORT_AVAST} 1
${process} = Run Dummy Avast ${RSPAMD_PORT_AVAST} 1
Scan File ${MESSAGE2}
... Settings=${SETTINGS_AVAST}
Expect Symbol AVAST_VIRUS
Do Not Expect Symbol AVAST_VIRUS_FAIL
Shutdown avast
[Teardown] Terminate Process ${process}

AVAST CACHE HIT
Scan File ${MESSAGE2}
@@ -103,26 +101,10 @@ AVAST CACHE MISS
Do Not Expect Symbol AVAST_VIRUS_FAIL

*** Keywords ***
Antivirus Teardown
Shutdown clamav
Shutdown fport
Shutdown avast

Shutdown clamav
${clamav_pid} = Get File if exists /tmp/dummy_clamav.pid
Run Keyword if ${clamav_pid} Shutdown Process With Children ${clamav_pid}

Shutdown fport
${fport_pid} = Get File if exists /tmp/dummy_fprot.pid
Run Keyword if ${fport_pid} Shutdown Process With Children ${fport_pid}

Shutdown fport duplicate
${fport_pid} = Get File if exists /tmp/dummy_fprot_dupe.pid
Run Keyword if ${fport_pid} Shutdown Process With Children ${fport_pid}

Shutdown avast
${avast_pid} = Get File if exists /tmp/dummy_avast.pid
Run Keyword if ${avast_pid} Shutdown Process With Children ${avast_pid}
Double FProt Teardown
[Arguments] ${process1} ${process2}
Terminate Process ${process1}
Terminate Process ${process2}

Run Dummy
[Arguments] @{varargs}
@@ -137,15 +119,19 @@ Run Dummy
Log To Console ${res.stdout}
Log To Console ${res.stderr}
Fail Dummy server failed to start
[Return] ${process}

Run Dummy Clam
[Arguments] ${port} ${found}= ${pid}=/tmp/dummy_clamav.pid
Run Dummy ${RSPAMD_TESTDIR}/util/dummy_clam.py ${port} ${found} ${pid}
${process} = Run Dummy ${RSPAMD_TESTDIR}/util/dummy_clam.py ${port} ${found} ${pid}
[Return] ${process}

Run Dummy Fprot
[Arguments] ${port} ${found}= ${pid}=/tmp/dummy_fprot.pid
Run Dummy ${RSPAMD_TESTDIR}/util/dummy_fprot.py ${port} ${found} ${pid}
${process} = Run Dummy ${RSPAMD_TESTDIR}/util/dummy_fprot.py ${port} ${found} ${pid}
[Return] ${process}

Run Dummy Avast
[Arguments] ${port} ${found}= ${pid}=/tmp/dummy_avast.pid
Run Dummy ${RSPAMD_TESTDIR}/util/dummy_avast.py ${port} ${found} ${pid}
${process} = Run Dummy ${RSPAMD_TESTDIR}/util/dummy_avast.py ${port} ${found} ${pid}
[Return] ${process}

+ 5
- 4
test/functional/cases/001_merged/310_udp.robot Просмотреть файл

@@ -1,6 +1,6 @@
*** Settings ***
Test Setup UDP Setup
Test Teardown UDP Teardown
Suite Setup UDP Setup
Suite Teardown UDP Teardown
Library Process
Library ${RSPAMD_TESTDIR}/lib/rspamd.py
Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot
@@ -31,10 +31,11 @@ UDP Setup
Run Dummy UDP

UDP Teardown
${udp_pid} = Get File /tmp/dummy_udp.pid
Shutdown Process With Children ${udp_pid}
Terminate Process ${DUMMY_UDP_PROC}
Wait For Process ${DUMMY_UDP_PROC}

Run Dummy UDP
[Arguments]
${result} = Start Process ${RSPAMD_TESTDIR}/util/dummy_udp.py 5005
Wait Until Created /tmp/dummy_udp.pid
Set Suite Variable ${DUMMY_UDP_PROC} ${result}

+ 3
- 2
test/functional/cases/001_merged/__init__.robot Просмотреть файл

@@ -1,6 +1,6 @@
*** Settings ***
Suite Setup Multi Setup
Suite Teardown Rspamd Redis Teardown
Suite Teardown Multi Teardown
Library ${RSPAMD_TESTDIR}/lib/rspamd.py
Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot
Variables ${RSPAMD_TESTDIR}/lib/vars.py
@@ -25,4 +25,5 @@ Multi Teardown
Rspamd Teardown
Dummy Http Teardown
Dummy Https Teardown
Redis Teardown
Redis Teardown
Try Reap Zombies

+ 5
- 5
test/functional/cases/140_proxy.robot Просмотреть файл

@@ -30,21 +30,21 @@ Proxy Setup
# Run slave & copy variables
Set Suite Variable ${CONFIG} ${RSPAMD_TESTDIR}/configs/lua_test.conf
Rspamd Setup
Set Suite Variable ${SLAVE_PID} ${RSPAMD_PID}
Set Suite Variable ${SLAVE_PROCESS} ${RSPAMD_PROCESS}
Set Suite Variable ${SLAVE_TMPDIR} ${RSPAMD_TMPDIR}

# Run proxy & copy variables
Set Suite Variable ${CONFIG} ${RSPAMD_TESTDIR}/configs/proxy.conf
Rspamd Setup
Set Suite Variable ${PROXY_PID} ${RSPAMD_PID}
Rspamd Setup check_port=${RSPAMD_PORT_PROXY}
Set Suite Variable ${PROXY_PROCESS} ${RSPAMD_PROCESS}
Set Suite Variable ${PROXY_TMPDIR} ${RSPAMD_TMPDIR}

Proxy Teardown
# Restore variables & run normal teardown
Set Suite Variable ${RSPAMD_PID} ${PROXY_PID}
Set Suite Variable ${RSPAMD_PROCESS} ${PROXY_PROCESS}
Set Suite Variable ${RSPAMD_TMPDIR} ${PROXY_TMPDIR}
Rspamd Teardown
# Do it again for slave
Set Suite Variable ${RSPAMD_PID} ${SLAVE_PID}
Set Suite Variable ${RSPAMD_PROCESS} ${SLAVE_PROCESS}
Set Suite Variable ${RSPAMD_TMPDIR} ${SLAVE_TMPDIR}
Rspamd Teardown

+ 11
- 8
test/functional/cases/150_rspamadm.robot Просмотреть файл

@@ -1,18 +1,18 @@
*** Settings ***
Library Process
Library ../lib/rspamd.py
Suite Teardown Terminate All Processes kill=True
Suite Setup Rspamadm Setup
Suite Teardown Rspamadm Teardown
Library ${RSPAMD_TESTDIR}/lib/rspamd.py
Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot

*** Test Cases ***
Config Test
${result} = Run Process ${RSPAMADM} configtest
${result} = Rspamadm configtest
Should Match Regexp ${result.stderr} ^$
Should Match Regexp ${result.stdout} ^syntax OK$
Should Be Equal As Integers ${result.rc} 0

Config Help
${result} = Run Process ${RSPAMADM} confighelp
${result} = Rspamadm confighelp
Should Match Regexp ${result.stderr} ^$
Should Be Equal As Integers ${result.rc} 0

@@ -20,26 +20,29 @@ Simple interpreter
${handle} = Start Process ${RSPAMADM} lua stdin=PIPE
${result} = Write to stdin ${handle} 1+1
Should Be Equal As Strings ${result} 2\n
Wait For Process ${handle}

Simple interpreter, two results
${handle} = Start Process ${RSPAMADM} lua stdin=PIPE
${result} = Write to stdin ${handle} 1+1, 2 * 5
Should Be Equal ${result} 2\n10\n
Wait For Process ${handle}

Process message callback
${handle} = Start Process ${RSPAMADM} lua stdin=PIPE
${result} = Write to stdin ${handle} .load ${RSPAMD_TESTDIR}/lua/rspamadm/test_message_callback.lua\n.message message_callback ${RSPAMD_TESTDIR}/messages/empty_part.eml
Should Contain ${result} n parts = 2
Should Contain ${result} 1\n2\n4\n6
Wait For Process ${handle}

Lua batch mode
${result} = Run Process ${RSPAMADM} lua -b ${RSPAMD_TESTDIR}/lua/rspamadm/test_batch.lua
${result} = Rspamadm lua -b ${RSPAMD_TESTDIR}/lua/rspamadm/test_batch.lua
Should Be Equal ${result.stderr} hello world
Should Match Regexp ${result.stdout} ^$
Should Be Equal As Integers ${result.rc} 0

Verbose mode
${result} = Run Process ${RSPAMADM} -v lua ${RSPAMD_TESTDIR}/lua/rspamadm/test_verbose.lua
${result} = Rspamadm -v lua ${RSPAMD_TESTDIR}/lua/rspamadm/test_verbose.lua
Should Match Regexp ${result.stderr} ^$
Should Match Regexp ${result.stdout} hello world\n
Should Be Equal As Integers ${result.rc} 0

+ 2
- 0
test/functional/cases/151_rspamadm_async.robot Просмотреть файл

@@ -9,6 +9,8 @@ Variables ${RSPAMD_TESTDIR}/lib/vars.py
*** Variables ***
${CONFIG} ${RSPAMD_TESTDIR}/configs/plugins.conf
${REDIS_SCOPE} Test
# For dummy http
${RSPAMD_SCOPE} Test
${RSPAMD_URL_TLD} ${RSPAMD_TESTDIR}/../lua/unit/test_tld.dat

*** Test Cases ***

+ 1
- 0
test/functional/configs/composites.conf Просмотреть файл

@@ -1,5 +1,6 @@
options = {
pidfile = "{= env.TMPDIR =}/rspamd.pid"
url_tld = "{= env.TESTDIR =}/../lua/unit/test_tld.dat"
}
logging = {
type = "file",

+ 1
- 1
test/functional/configs/redis-server.conf Просмотреть файл

@@ -1,5 +1,5 @@
bind ${RSPAMD_REDIS_ADDR}
daemonize yes
daemonize no
loglevel debug
logfile ${RSPAMD_TMPDIR}/redis.log
pidfile ${RSPAMD_TMPDIR}/redis.pid

+ 12
- 5
test/functional/lib/rspamd.py Просмотреть файл

@@ -41,11 +41,11 @@ import tempfile

from robot.api import logger
from robot.libraries.BuiltIn import BuiltIn
import demjson
import json


def Check_JSON(j):
d = demjson.decode(j, strict=True)
d = json.JSONDecoder(strict=True).decode(j.decode('utf-8'))
logger.debug('got json %s' % d)
assert len(d) > 0
assert 'error' not in d
@@ -54,9 +54,9 @@ def Check_JSON(j):

def check_json_log(fn):
line_count = 0
f = open(fn, 'r')
f = open(fn, 'r', encoding="utf-8")
for l in f.readlines():
d = demjson.decode(l, strict=True)
d = json.JSONDecoder(strict=True).decode(l)
assert len(d) > 0
line_count = line_count + 1
assert line_count > 0
@@ -201,7 +201,7 @@ def Scan_File(filename, **headers):
c.request("POST", "/checkv2", open(filename, "rb"), headers)
r = c.getresponse()
assert r.status == 200
d = demjson.decode(r.read())
d = json.JSONDecoder(strict=True).decode(r.read().decode('utf-8'))
c.close()
BuiltIn().set_test_variable("${SCAN_RESULT}", d)
return
@@ -244,6 +244,13 @@ def TCP_Connect(addr, port):
s.close()


def try_reap_zombies():
try:
os.waitpid(-1, os.WNOHANG)
except ChildProcessError:
pass


def ping_rspamd(addr, port):
return str(urlopen("http://%s:%s/ping" % (addr, port)).read())


+ 33
- 39
test/functional/lib/rspamd.robot Просмотреть файл

@@ -204,11 +204,12 @@ Redis SET
Should Be Equal As Integers ${result.rc} 0

Redis Teardown
${redis_pid} = Get Variable Value ${REDIS_PID}
Shutdown Process With Children ${redis_pid}
Terminate Process ${REDIS_PROCESS}
Wait For Process ${REDIS_PROCESS}
Cleanup Temporary Directory ${REDIS_TMPDIR}

Rspamd Setup
[Arguments] ${check_port}=${RSPAMD_PORT_NORMAL}
# Create and chown temporary directory
${RSPAMD_TMPDIR} = Make Temporary Directory
Set Directory Ownership ${RSPAMD_TMPDIR} ${RSPAMD_USER} ${RSPAMD_GROUP}
@@ -216,7 +217,7 @@ Rspamd Setup
# Export ${RSPAMD_TMPDIR} to appropriate scope according to ${RSPAMD_SCOPE}
Export Scoped Variables ${RSPAMD_SCOPE} RSPAMD_TMPDIR=${RSPAMD_TMPDIR}

Run Rspamd
Run Rspamd check_port=${check_port}

Rspamd Redis Setup
Run Redis
@@ -226,7 +227,8 @@ Rspamd Teardown
IF '${CONTROLLER_ERRORS}' == 'True'
Run Keyword And Warn On Failure Check Controller Errors
END
Shutdown Process With Children ${RSPAMD_PID}
Terminate Process ${RSPAMD_PROCESS}
Wait For Process ${RSPAMD_PROCESS}
Save Run Results ${RSPAMD_TMPDIR} configdump.stdout configdump.stderr rspamd.stderr rspamd.stdout rspamd.conf rspamd.log redis.log clickhouse-config.xml
Log does not contain segfault record
Collect Lua Coverage
@@ -242,20 +244,17 @@ Run Redis
${config} = Replace Variables ${template}
Create File ${RSPAMD_TMPDIR}/redis-server.conf ${config}
Log ${config}
${result} = Run Process redis-server ${RSPAMD_TMPDIR}/redis-server.conf
IF ${result.rc} != 0
Log ${result.stderr}
END
Should Be Equal As Integers ${result.rc} 0
${result} = Start Process redis-server ${RSPAMD_TMPDIR}/redis-server.conf
Wait Until Keyword Succeeds 5x 1 sec Check Pidfile ${RSPAMD_TMPDIR}/redis.pid timeout=0.5s
Wait Until Keyword Succeeds 5x 1 sec Redis Check ${RSPAMD_REDIS_ADDR} ${RSPAMD_REDIS_PORT}
${REDIS_PID} = Get File ${RSPAMD_TMPDIR}/redis.pid
${REDIS_PID} = Convert To Number ${REDIS_PID}
Export Scoped Variables ${REDIS_SCOPE} REDIS_PID=${REDIS_PID} REDIS_TMPDIR=${RSPAMD_TMPDIR}
Export Scoped Variables ${REDIS_SCOPE} REDIS_PID=${REDIS_PID} REDIS_PROCESS=${result} REDIS_TMPDIR=${RSPAMD_TMPDIR}
${redis_log} = Get File ${RSPAMD_TMPDIR}/redis.log
Log ${redis_log}

Run Rspamd
[Arguments] ${check_port}=${RSPAMD_PORT_NORMAL}
Export Rspamd Variables To Environment

# Dump templated config or errors to log
@@ -284,12 +283,13 @@ Run Rspamd
Set Directory Ownership ${RSPAMD_TMPDIR} ${RSPAMD_USER} ${RSPAMD_GROUP}

# Run Rspamd
${result} = Run Process ${RSPAMD} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP}
${result} = Start Process ${RSPAMD} -f -u ${RSPAMD_USER} -g ${RSPAMD_GROUP}
... -c ${CONFIG}
... --var\=TMPDIR\=${RSPAMD_TMPDIR}
... --var\=DBDIR\=${RSPAMD_TMPDIR}
... --var\=LOCAL_CONFDIR\=/non-existent
... --var\=CONFDIR\=${RSPAMD_TESTDIR}/../../conf/
... --insecure
... env:RSPAMD_LOCAL_CONFDIR=/non-existent
... env:RSPAMD_TMPDIR=${RSPAMD_TMPDIR}
... env:RSPAMD_CONFDIR=${RSPAMD_TESTDIR}/../../conf/
@@ -298,24 +298,26 @@ Run Rspamd
... env:ASAN_OPTIONS=quarantine_size_mb=2048:malloc_context_size=20:fast_unwind_on_malloc=0:log_path=${RSPAMD_TMPDIR}/rspamd-asan
... stdout=${RSPAMD_TMPDIR}/rspamd.stdout stderr=${RSPAMD_TMPDIR}/rspamd.stderr

# Log stdout/stderr
${rspamd_stdout} = Get File ${RSPAMD_TMPDIR}/rspamd.stdout encoding_errors=ignore
${rspamd_stderror} = Get File ${RSPAMD_TMPDIR}/rspamd.stderr encoding_errors=ignore
Log ${rspamd_stdout}
Log ${rspamd_stderror}
Export Scoped Variables ${RSPAMD_SCOPE} RSPAMD_PROCESS=${result}

# Abort if it failed
Should Be Equal As Integers ${result.rc} 0
# Confirm worker is reachable
Wait Until Keyword Succeeds 15x 1 sec Ping Rspamd ${RSPAMD_LOCAL_ADDR} ${check_port}

# Wait for pid file to be written
Wait Until Keyword Succeeds 10x 1 sec Check Pidfile ${RSPAMD_TMPDIR}/rspamd.pid timeout=0.5s
Rspamadm Setup
${RSPAMADM_TMPDIR} = Make Temporary Directory
Set Suite Variable ${RSPAMADM_TMPDIR}

# Confirm worker is reachable
Wait Until Keyword Succeeds 5x 1 sec Ping Rspamd ${RSPAMD_LOCAL_ADDR} ${RSPAMD_PORT_NORMAL}
Rspamadm Teardown
Cleanup Temporary Directory ${RSPAMADM_TMPDIR}

# Read PID from PIDfile and export it to appropriate scope as ${RSPAMD_PID}
${RSPAMD_PID} = Get File ${RSPAMD_TMPDIR}/rspamd.pid
Export Scoped Variables ${RSPAMD_SCOPE} RSPAMD_PID=${RSPAMD_PID}
Rspamadm
[Arguments] @{args}
${result} = Run Process ${RSPAMADM}
... --var\=TMPDIR\=${RSPAMADM_TMPDIR}
... --var\=DBDIR\=${RSPAMADM_TMPDIR}
... --var\=LOCAL_CONFDIR\=/nonexistent
... @{args}
[Return] ${result}

Run Nginx
${template} = Get File ${RSPAMD_TESTDIR}/configs/nginx.conf
@@ -370,29 +372,21 @@ Sync Fuzzy Storage
Sleep 0.1s Try give fuzzy storage time to sync

Run Dummy Http
${fileExists} = File Exists /tmp/dummy_http.pid
IF ${fileExists} is True
${http_pid} = Get File /tmp/dummy_http.pid
Shutdown Process With Children ${http_pid}
END
${result} = Start Process ${RSPAMD_TESTDIR}/util/dummy_http.py -pf /tmp/dummy_http.pid
Wait Until Created /tmp/dummy_http.pid timeout=2 second
Export Scoped Variables ${RSPAMD_SCOPE} DUMMY_HTTP_PROC=${result}

Run Dummy Https
${fileExists} = File Exists /tmp/dummy_https.pid
IF ${fileExists} is True
${http_pid} = Get File /tmp/dummy_https.pid
Shutdown Process With Children ${http_pid}
END
${result} = Start Process ${RSPAMD_TESTDIR}/util/dummy_http.py
... -c ${RSPAMD_TESTDIR}/util/server.pem -k ${RSPAMD_TESTDIR}/util/server.pem
... -pf /tmp/dummy_https.pid -p 18081
Wait Until Created /tmp/dummy_https.pid timeout=2 second
Export Scoped Variables ${RSPAMD_SCOPE} DUMMY_HTTPS_PROC=${result}

Dummy Http Teardown
${http_pid} = Get File /tmp/dummy_http.pid
Shutdown Process With Children ${http_pid}
Terminate Process ${DUMMY_HTTP_PROC}
Wait For Process ${DUMMY_HTTP_PROC}

Dummy Https Teardown
${https_pid} = Get File /tmp/dummy_https.pid
Shutdown Process With Children ${https_pid}
Terminate Process ${DUMMY_HTTPS_PROC}
Wait For Process ${DUMMY_HTTPS_PROC}

+ 1
- 48
test/functional/lib/vars.py Просмотреть файл

@@ -11,54 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import shutil
import socket

Загрузка…
Отмена
Сохранить