From: Vsevolod Stakhov Date: Wed, 19 Nov 2025 14:03:15 +0000 (+0000) Subject: [Fix] Fix test files to handle missing map env vars X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5715ac6fc4b23f259974f081a8a7b563d43631ba;p=thirdparty%2Frspamd.git [Fix] Fix test files to handle missing map env vars - Add defensive checks in maps_kv.lua to skip map creation if env vars not set - Ensure test config file is always saved to robot-save directory Fixes issue where external_relay test would crash because maps_kv.lua tried to create maps with nil URLs when RADIX_MAP/MAP_MAP/REGEXP_MAP env vars were not defined. --- diff --git a/test/functional/lua/maps_kv.lua b/test/functional/lua/maps_kv.lua index b90f44d0ca..8bf1117f1d 100644 --- a/test/functional/lua/maps_kv.lua +++ b/test/functional/lua/maps_kv.lua @@ -2,25 +2,35 @@ local rspamd_ip = require 'rspamd_ip' local rspamd_logger = require 'rspamd_logger' local lua_maps = require "lua_maps" -local radix_map = rspamd_config:add_map ({ - url = rspamd_env.RADIX_MAP, - type = 'radix', -}) +-- Only load maps if environment variables are set +local radix_map, map_map, regexp_map -local map_map = rspamd_config:add_map ({ - url = rspamd_env.MAP_MAP, - type = 'map', -}) +if rspamd_env.RADIX_MAP then + radix_map = rspamd_config:add_map ({ + url = rspamd_env.RADIX_MAP, + type = 'radix', + }) +end -local regexp_map = rspamd_config:add_map ({ - url = rspamd_env.REGEXP_MAP, - type = 'regexp', -}) +if rspamd_env.MAP_MAP then + map_map = rspamd_config:add_map ({ + url = rspamd_env.MAP_MAP, + type = 'map', + }) +end + +if rspamd_env.REGEXP_MAP then + regexp_map = rspamd_config:add_map ({ + url = rspamd_env.REGEXP_MAP, + type = 'regexp', + }) +end rspamd_config:register_symbol({ name = 'RADIX_KV', score = 1.0, callback = function() + if not radix_map then return true, 'map not loaded' end local sip = {'8.8.8.8', '::1', '192.168.1.1', '10.0.1.1'} local expected = {'test one', 'another', '1', false} for i = 1, #sip do @@ -42,6 +52,7 @@ rspamd_config:register_symbol({ name = 'MAP_KV', score = 1.0, callback = function() + if not map_map then return true, 'map not loaded' end local str = {'foo', 'asdf.example.com', 'asdf', 'barf'} local expected = {'bar', 'value', '', false} for i = 1, #str do @@ -58,6 +69,7 @@ rspamd_config:register_symbol({ name = 'REGEXP_KV', score = 1.0, callback = function() + if not regexp_map then return true, 'map not loaded' end local str = {'foo', 'asdf.example.com', 'asdf', 'barf'} local expected = {'bar', 'value', '1', false} for i = 1, #str do