From: Jason Ish Date: Fri, 30 May 2025 16:28:40 +0000 (-0600) Subject: tests/lua: update lua tests for suricata.log lib X-Git-Tag: suricata-7.0.11~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F2533%2Fhead;p=thirdparty%2Fsuricata-verify.git tests/lua: update lua tests for suricata.log lib Ticket: #7727 --- diff --git a/tests/datasets/datasets-lua-01/dataset.lua b/tests/datasets/datasets-lua-01/dataset.lua index 1ad3960b8..ad512a8bc 100644 --- a/tests/datasets/datasets-lua-01/dataset.lua +++ b/tests/datasets/datasets-lua-01/dataset.lua @@ -1,5 +1,6 @@ local dataset = require "suricata.dataset" local flow = require("suricata.flow") +local logger = require("suricata.log") function init (args) local needs = {} @@ -11,7 +12,7 @@ function thread_init (args) conn_new, err = dataset.new() ret, err = conn_new:get("conn-seen") if err ~= nil then - SCLogWarning("dataset warning: " .. err) + logger.warning("dataset warning: " .. err) return 0 end end @@ -23,7 +24,7 @@ function match (args) ret, err = conn_new:add(str, #str); if ret == 1 then - SCLogInfo(str .. " => " .. ret) + logger.info(str .. " => " .. ret) end return ret end diff --git a/tests/datasets/datasets-lua-02/dataset-dns.lua b/tests/datasets/datasets-lua-02/dataset-dns.lua index f68d91ea8..75d626279 100644 --- a/tests/datasets/datasets-lua-02/dataset-dns.lua +++ b/tests/datasets/datasets-lua-02/dataset-dns.lua @@ -1,6 +1,7 @@ local flow = require("suricata.flow") local dataset = require("suricata.dataset") local dns = require("suricata.dns") +local logger = require("suricata.log") function init (args) local needs = {} @@ -11,7 +12,7 @@ function thread_init (args) dns_new = dataset.new() ret, err = dns_new:get("dns-seen") if err ~= nil then - SCLogWarning("dataset warning: " .. err) + logger.warning("dataset warning: " .. err) return 0 end end @@ -28,11 +29,11 @@ function match (args) ret, err = dns_new:add(str, #str); if err ~= nil then - SCLogWarning("lua warning " .. err) + logger.warning("lua warning " .. err) return 0 end if ret == 1 then - SCLogNotice(str .. " => " .. ret) + logger.notice(str .. " => " .. ret) end return ret end diff --git a/tests/lua-flowfunctions/lua-flowfunctions.lua b/tests/lua-flowfunctions/lua-flowfunctions.lua index e82010be9..acffbb6c0 100644 --- a/tests/lua-flowfunctions/lua-flowfunctions.lua +++ b/tests/lua-flowfunctions/lua-flowfunctions.lua @@ -2,6 +2,7 @@ name = "flow_http_lua.log" local flow = require("suricata.flow") +local logger = require("suricata.log") function init (args) local needs = {} @@ -13,7 +14,7 @@ end function setup (args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogInfo("Log Filename " .. filename) + logger.info("Log Filename " .. filename) http = 0 end @@ -34,6 +35,6 @@ function log(args) end function deinit (args) - SCLogInfo ("HTTP logged: " .. http); + logger.info ("HTTP logged: " .. http); file:close(file) end diff --git a/tests/lua-flowstats/lua-scflowstats.lua b/tests/lua-flowstats/lua-scflowstats.lua index b195840ab..0d3484423 100644 --- a/tests/lua-flowstats/lua-scflowstats.lua +++ b/tests/lua-flowstats/lua-scflowstats.lua @@ -2,6 +2,7 @@ name = "lua-scflowstats.log" local flow = require("suricata.flow") +local logger = require("suricata.log") function init(args) local needs = {} @@ -12,7 +13,7 @@ end function setup(args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogInfo("lua SCFlowStats Log Filename " .. filename) + logger.info("lua SCFlowStats Log Filename " .. filename) end function log(args) diff --git a/tests/lua-flowtuple/scflowtuple.lua b/tests/lua-flowtuple/scflowtuple.lua index e2288a7f0..3eb15afe8 100644 --- a/tests/lua-flowtuple/scflowtuple.lua +++ b/tests/lua-flowtuple/scflowtuple.lua @@ -1,5 +1,6 @@ -- simple SCFlowTuple log test local flow = require("suricata.flow") +local logger = require("suricata.log") name = "scflow-tuple.log" @@ -13,7 +14,7 @@ end function setup(args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogNotice("lua SCFlowTuple Log Filename " .. filename) + logger.notice("lua SCFlowTuple Log Filename " .. filename) end function log(args) diff --git a/tests/lua-output-dns/test.lua b/tests/lua-output-dns/test.lua index db06e79ce..0dbb6eb3c 100644 --- a/tests/lua-output-dns/test.lua +++ b/tests/lua-output-dns/test.lua @@ -1,6 +1,7 @@ local flow = require("suricata.flow") -local packet = require "suricata.packet" -local dns = require "suricata.dns" +local packet = require("suricata.packet") +local dns = require("suricata.dns") +local logger = require("suricata.log") filename = "lua-dns.log" @@ -11,7 +12,7 @@ function init (args) end function setup (args) - SCLogNotice("lua: setup()") + logger.notice("lua: setup()") file = assert(io.open(SCLogPath() .. "/" .. filename, "w")) end diff --git a/tests/lua-output-http-02/http.lua b/tests/lua-output-http-02/http.lua index 38deddf6a..e5ccb624d 100644 --- a/tests/lua-output-http-02/http.lua +++ b/tests/lua-output-http-02/http.lua @@ -2,6 +2,7 @@ local flow = require("suricata.flow") local packet = require "suricata.packet" local http = require("suricata.http") +local logger = require("suricata.log") name = "http_lua.log" @@ -14,7 +15,7 @@ end function setup (args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogInfo("HTTP Log Filename " .. filename) + logger.info("HTTP Log Filename " .. filename) http_tx = 0 end @@ -52,6 +53,6 @@ function log(args) end function deinit (args) - SCLogInfo ("HTTP transactions logged: " .. http_tx); + logger.info ("HTTP transactions logged: " .. http_tx); file:close(file) end diff --git a/tests/lua-output-http-03/http.lua b/tests/lua-output-http-03/http.lua index 69e61917a..2a3551ee1 100644 --- a/tests/lua-output-http-03/http.lua +++ b/tests/lua-output-http-03/http.lua @@ -2,6 +2,7 @@ local flow = require("suricata.flow") local packet = require "suricata.packet" local http = require("suricata.http") +local logger = require("suricata.log") name = "http_lua.log" @@ -14,7 +15,7 @@ end function setup (args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogInfo("HTTP Log Filename " .. filename) + logger.info("HTTP Log Filename " .. filename) http_tx = 0 end @@ -48,6 +49,6 @@ function log(args) end function deinit (args) - SCLogInfo ("HTTP transactions logged: " .. http_tx); + logger.info ("HTTP transactions logged: " .. http_tx); file:close(file) end diff --git a/tests/lua-output-http/http.lua b/tests/lua-output-http/http.lua index 1979598df..6d4892634 100644 --- a/tests/lua-output-http/http.lua +++ b/tests/lua-output-http/http.lua @@ -2,6 +2,7 @@ local packet = require "suricata.packet" local flow = require("suricata.flow") local http = require("suricata.http") +local logger = require("suricata.log") name = "http_lua.log" @@ -51,6 +52,6 @@ function log(args) end function deinit (args) - SCLogInfo ("HTTP transactions logged: " .. http_tx); + logger.info ("HTTP transactions logged: " .. http_tx); file:close(file) end diff --git a/tests/lua-output-smtp/smtp.lua b/tests/lua-output-smtp/smtp.lua index 6f12108aa..a9caac207 100644 --- a/tests/lua-output-smtp/smtp.lua +++ b/tests/lua-output-smtp/smtp.lua @@ -1,6 +1,7 @@ -- simple fast-log to file lua module local packet = require "suricata.packet" local smtp = require "suricata.smtp" +local logger = require("suricata.log") name = "smtp_lua.log" @@ -13,7 +14,7 @@ end function setup (args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogInfo("Log Filename " .. filename) + logger.info("Log Filename " .. filename) count = 0 end @@ -34,6 +35,6 @@ function log(args) end function deinit (args) - SCLogInfo ("transactions logged: " .. count); + logger.info ("transactions logged: " .. count); file:close(file) end diff --git a/tests/lua-output-streaming/streaming-http.lua b/tests/lua-output-streaming/streaming-http.lua index 2b9fba807..c83b036fa 100644 --- a/tests/lua-output-streaming/streaming-http.lua +++ b/tests/lua-output-streaming/streaming-http.lua @@ -1,4 +1,5 @@ local flow = require "suricata.flow" +local logger = require("suricata.log") function init (args) local needs = {} @@ -16,7 +17,7 @@ function log(args) ts = f:timestring_legacy() ipver, srcip, dstip, proto, sp, dp = f:tuple() data, data_open, data_close = SCStreamingBuffer() - SCLogNotice("called with data_open " .. tostring(data_open) .. " data_close " .. tostring(data_close)); + logger.notice("called with data_open " .. tostring(data_open) .. " data_close " .. tostring(data_close)); filename = filepath .. "/http-" .. proto .. "-" .. srcip .. "-" .. dstip .. "-" .. sp .. "-" .. dp file_mode = "a" diff --git a/tests/lua-scfileinfo/scfileinfo.lua b/tests/lua-scfileinfo/scfileinfo.lua index f143e5a91..d5bd220e8 100644 --- a/tests/lua-scfileinfo/scfileinfo.lua +++ b/tests/lua-scfileinfo/scfileinfo.lua @@ -1,4 +1,5 @@ local filelib = require("suricata.file") +local logger = require("suricata.log") -- Output test for SCFileInfo file_name = "scfileinfo.log" @@ -10,7 +11,7 @@ end function setup(args) filename = SCLogPath() .. "/" .. file_name output = assert(io.open(filename, "w")) - SCLogInfo("lua SCFileInfo Log Filename " .. filename) + logger.info("lua SCFileInfo Log Filename " .. filename) end function log(args) @@ -35,6 +36,6 @@ function log(args) end function deinit(args) - SCLogInfo ("SCFileInfo logging finished"); + logger.info ("SCFileInfo logging finished"); output:close() end diff --git a/tests/lua-scpackettuple/scpackettuple.lua b/tests/lua-scpackettuple/scpackettuple.lua index 4a869a90f..5799062b1 100644 --- a/tests/lua-scpackettuple/scpackettuple.lua +++ b/tests/lua-scpackettuple/scpackettuple.lua @@ -1,4 +1,5 @@ local packet = require "suricata.packet" +local logger = require("suricata.log") -- simple SCPacketTuple log test name = "scpacket-tuple.log" @@ -12,7 +13,7 @@ end function setup(args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogInfo("Lua SCPacketTuple Log Filename " .. filename) + logger.info("Lua SCPacketTuple Log Filename " .. filename) packets = 0 end @@ -28,6 +29,6 @@ function log(args) end function deinit(args) - SCLogInfo ("Packets logged: " .. packets); + logger.info ("Packets logged: " .. packets); file:close(file) end diff --git a/tests/lua-scrule-ids/lua-scrule-ids.lua b/tests/lua-scrule-ids/lua-scrule-ids.lua index 9558ec332..95a9d702f 100644 --- a/tests/lua-scrule-ids/lua-scrule-ids.lua +++ b/tests/lua-scrule-ids/lua-scrule-ids.lua @@ -1,6 +1,7 @@ -- lua_pushinteger output test for SCRuleIds and ... local packet = require "suricata.packet" local rule = require "suricata.rule" +local logger = require "suricata.log" name = "lua-scrule-ids.log" @@ -14,7 +15,7 @@ end function setup(args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogInfo("lua SCRuleIds Log Filename " .. filename) + logger.info("lua SCRuleIds Log Filename " .. filename) end function log(args) diff --git a/tests/lua/lua-base64/output.lua b/tests/lua/lua-base64/output.lua index 1ac52028e..4bf8c1ba1 100644 --- a/tests/lua/lua-base64/output.lua +++ b/tests/lua/lua-base64/output.lua @@ -3,6 +3,7 @@ local base64 = require("suricata.base64") local dns = require("suricata.dns") +local logger = require("suricata.log") local expected_base64 = "d3d3LnN1cmljYXRhLWlkcy5vcmc=" @@ -15,7 +16,7 @@ function init (args) end function setup (args) - SCLogNotice("lua: setup()") + logger.notice("lua: setup()") file = assert(io.open(SCLogPath() .. "/" .. filename, "w")) end diff --git a/tests/lua/lua-hashlib-output/test.lua b/tests/lua/lua-hashlib-output/test.lua index 524892842..d071b8227 100644 --- a/tests/lua/lua-hashlib-output/test.lua +++ b/tests/lua/lua-hashlib-output/test.lua @@ -1,5 +1,6 @@ local hashlib = require("suricata.hashlib") local dns = require("suricata.dns") +local logger = require("suricata.log") -- We don't actually use, but the script will fail to run if it fails -- to "require". @@ -17,7 +18,7 @@ function init (args) end function setup (args) - SCLogNotice("lua: setup()") + logger.notice("lua: setup()") file = assert(io.open(SCLogPath() .. "/" .. filename, "w")) end diff --git a/tests/lua/lua-hashlib/test-hashing.lua b/tests/lua/lua-hashlib/test-hashing.lua index 4d90b11be..cc74b0ef4 100644 --- a/tests/lua/lua-hashlib/test-hashing.lua +++ b/tests/lua/lua-hashlib/test-hashing.lua @@ -1,5 +1,6 @@ local hashlib = require("suricata.hashlib") local dns = require("suricata.dns") +local logger = require("suricata.log") local expected_sha256 = "080bdfdfcd8c2c7fce747f9be4603ced6253caac70894ad89d605309588c60f6" local expected_sha1 = "00f495ffd50c8b5ef3645f61486dae496db0fe2e" @@ -131,17 +132,17 @@ function match(args) local rrname = tx:rrname() if not test_sha256(rrname) then - SCLogError("test_sha256 failed") + logger.error("test_sha256 failed") return 0 end if not test_sha1(rrname) then - SCLogError("test_sha1 failed") + logger.error("test_sha1 failed") return 0 end if not test_md5(rrname) then - SCLogError("test_md5 failed") + logger.error("test_md5 failed") return 0 end diff --git a/tests/lua/lua-packetlib-01/packet.lua b/tests/lua/lua-packetlib-01/packet.lua index 5ec6c2864..1c3322303 100644 --- a/tests/lua/lua-packetlib-01/packet.lua +++ b/tests/lua/lua-packetlib-01/packet.lua @@ -1,4 +1,5 @@ local packet = require "suricata.packet" +local logger = require "suricata.log" function init (args) local needs = {} @@ -13,7 +14,7 @@ function match (args) for line in payload:gmatch("([^\r\n]*)[\r\n]+") do if line == "GET /index.html HTTP/1.0" then ipver, srcip, dstip, proto, sp, dp = p:tuple() - SCLogNotice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line)); + logger.notice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line)); return 1 end end diff --git a/tests/lua/lua-packetlib-02-restricted-funcs-allowed/packet.lua b/tests/lua/lua-packetlib-02-restricted-funcs-allowed/packet.lua index 5ec6c2864..3d79dd238 100644 --- a/tests/lua/lua-packetlib-02-restricted-funcs-allowed/packet.lua +++ b/tests/lua/lua-packetlib-02-restricted-funcs-allowed/packet.lua @@ -1,4 +1,5 @@ local packet = require "suricata.packet" +local logger = require("suricata.log") function init (args) local needs = {} @@ -13,7 +14,7 @@ function match (args) for line in payload:gmatch("([^\r\n]*)[\r\n]+") do if line == "GET /index.html HTTP/1.0" then ipver, srcip, dstip, proto, sp, dp = p:tuple() - SCLogNotice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line)); + logger.notice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line)); return 1 end end diff --git a/tests/lua/lua-packetlib-03/packet.lua b/tests/lua/lua-packetlib-03/packet.lua index ebf18c203..ba88c8272 100644 --- a/tests/lua/lua-packetlib-03/packet.lua +++ b/tests/lua/lua-packetlib-03/packet.lua @@ -1,4 +1,5 @@ local packet = require "suricata.packet" +local logger = require("suricata.log") function init (args) local needs = {} @@ -10,7 +11,7 @@ function match (args) if p:sp() == 6666 and p:dp() == 63 then ts = p:timestring_iso8601() - SCLogNotice(string.format("%s %d->%d (pcap_cnt:%d) match!", ts, p:sp(), p:dp(), p:pcap_cnt())); + logger.notice(string.format("%s %d->%d (pcap_cnt:%d) match!", ts, p:sp(), p:dp(), p:pcap_cnt())); return 1 end diff --git a/tests/lua/lua-packetlib-04-icmp-spdp/packet.lua b/tests/lua/lua-packetlib-04-icmp-spdp/packet.lua index 7e6a062b5..e7cc1a3a7 100644 --- a/tests/lua/lua-packetlib-04-icmp-spdp/packet.lua +++ b/tests/lua/lua-packetlib-04-icmp-spdp/packet.lua @@ -1,4 +1,5 @@ local packet = require "suricata.packet" +local logger = require("suricata.log") function init (args) local needs = {} @@ -10,12 +11,12 @@ function match (args) sp, err = p:sp() if err == nil then - SCLogError("sp() should have failed for icmp") + logger.error("sp() should have failed for icmp") return 0 end if err ~= "sp only available for tcp, udp and sctp" then - SCLogError("sp() error message mismatch") + logger.error("sp() error message mismatch") return 0 end diff --git a/tests/lua/lua-packetlib-05-default-enabled/packet.lua b/tests/lua/lua-packetlib-05-default-enabled/packet.lua index 5ec6c2864..3d79dd238 100644 --- a/tests/lua/lua-packetlib-05-default-enabled/packet.lua +++ b/tests/lua/lua-packetlib-05-default-enabled/packet.lua @@ -1,4 +1,5 @@ local packet = require "suricata.packet" +local logger = require("suricata.log") function init (args) local needs = {} @@ -13,7 +14,7 @@ function match (args) for line in payload:gmatch("([^\r\n]*)[\r\n]+") do if line == "GET /index.html HTTP/1.0" then ipver, srcip, dstip, proto, sp, dp = p:tuple() - SCLogNotice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line)); + logger.notice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line)); return 1 end end diff --git a/tests/lua/lua-tlslib-01/lua-tlsfunctions.lua b/tests/lua/lua-tlslib-01/lua-tlsfunctions.lua index 32436f0c5..cec0862c2 100644 --- a/tests/lua/lua-tlslib-01/lua-tlsfunctions.lua +++ b/tests/lua/lua-tlslib-01/lua-tlsfunctions.lua @@ -2,6 +2,7 @@ name = "tlslib_lua.log" local tls = require("suricata.tls") +local logger = require("suricata.log") function init (args) local needs = {} @@ -12,7 +13,7 @@ end function setup (args) filename = SCLogPath() .. "/" .. name file = assert(io.open(filename, "a")) - SCLogInfo("Log Filename " .. filename) + logger.info("Log Filename " .. filename) http = 0 end diff --git a/tests/lua/lua-transform-08/transform-dataset.lua b/tests/lua/lua-transform-08/transform-dataset.lua index 9bace9a65..29745d8e3 100644 --- a/tests/lua/lua-transform-08/transform-dataset.lua +++ b/tests/lua/lua-transform-08/transform-dataset.lua @@ -1,14 +1,15 @@ local dataset = require("suricata.dataset") +local logger = require("suricata.log") function thread_init(args) dataset_new, err = dataset.new() if err ~= nil then - SCLogWarning("dataset warning: " .. err) + logger.warning("dataset warning: " .. err) return 0 end ret, err = dataset_new:get("versions-seen") if err ~= nil then - SCLogWarning("dataset warning: " .. err) + logger.warning("dataset warning: " .. err) return 0 end end @@ -16,11 +17,11 @@ end function transform(input, args) ret, err = dataset_new:add(input, #input) if err ~= nil then - SCLogWarning("lua warning: " .. err) + logger.warning("lua warning: " .. err) return 0 end if ret == 1 then - SCLogNotice(input .. " => " .. ret) + logger.notice(input .. " => " .. ret) end return ret end diff --git a/tests/ssh-lua-output/output.lua b/tests/ssh-lua-output/output.lua index d4f70ec28..704e25046 100644 --- a/tests/ssh-lua-output/output.lua +++ b/tests/ssh-lua-output/output.lua @@ -1,4 +1,5 @@ local ssh = require("suricata.ssh") +local logger = require("suricata.log") filename = "results.log" @@ -9,7 +10,7 @@ function init (args) end function setup (args) - SCLogNotice("lua: setup()") + logger.notice("lua: setup()") file = assert(io.open(SCLogPath() .. "/" .. filename, "w")) end