]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
tests/lua: update lua tests for suricata.log lib 2531/head 2533/head
authorJason Ish <jason.ish@oisf.net>
Fri, 30 May 2025 16:28:40 +0000 (10:28 -0600)
committerJason Ish <jason.ish@oisf.net>
Fri, 30 May 2025 17:04:45 +0000 (11:04 -0600)
Ticket: #7727

25 files changed:
tests/datasets/datasets-lua-01/dataset.lua
tests/datasets/datasets-lua-02/dataset-dns.lua
tests/lua-flowfunctions/lua-flowfunctions.lua
tests/lua-flowstats/lua-scflowstats.lua
tests/lua-flowtuple/scflowtuple.lua
tests/lua-output-dns/test.lua
tests/lua-output-http-02/http.lua
tests/lua-output-http-03/http.lua
tests/lua-output-http/http.lua
tests/lua-output-smtp/smtp.lua
tests/lua-output-streaming/streaming-http.lua
tests/lua-scfileinfo/scfileinfo.lua
tests/lua-scpackettuple/scpackettuple.lua
tests/lua-scrule-ids/lua-scrule-ids.lua
tests/lua/lua-base64/output.lua
tests/lua/lua-hashlib-output/test.lua
tests/lua/lua-hashlib/test-hashing.lua
tests/lua/lua-packetlib-01/packet.lua
tests/lua/lua-packetlib-02-restricted-funcs-allowed/packet.lua
tests/lua/lua-packetlib-03/packet.lua
tests/lua/lua-packetlib-04-icmp-spdp/packet.lua
tests/lua/lua-packetlib-05-default-enabled/packet.lua
tests/lua/lua-tlslib-01/lua-tlsfunctions.lua
tests/lua/lua-transform-08/transform-dataset.lua
tests/ssh-lua-output/output.lua

index 1ad3960b8365ba5baf8f9af00b82d03e1318df8f..ad512a8bcf44ca4de2d6558d5b5c2894cc50c5b1 100644 (file)
@@ -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
index f68d91ea82bfa263f5615eba2244c6393cd38ad1..75d6262794e565826c805c747ce9460cabfe9260 100644 (file)
@@ -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
index e82010be9c066d2dd0a3d85a623cb96b655243a3..acffbb6c0cdca1cdc6365ca17ddd79e6f2954cf0 100644 (file)
@@ -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
index b195840ab3141402ec3ca9768181f7a4877dfdbe..0d3484423932652e14604534e65460901134e56f 100644 (file)
@@ -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)
index e2288a7f02ba4c69b1e090e61c5543bf672dda32..3eb15afe81aee6915344c9e37fd8b1c86c73f819 100644 (file)
@@ -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)
index db06e79ce7f4958c0e238dfce37e3969ea45e1a0..0dbb6eb3c4b6a2e8e123f439f66a1af93370996b 100644 (file)
@@ -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
 
index 38deddf6af0ca9a06e96bb1d224e646fb8de94f6..e5ccb624d40b8bb7fa15c2890bc1a5f306a7e7a9 100644 (file)
@@ -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
index 69e61917abbde3cf678b44532674b90d89d96b16..2a3551ee1d2a6bd2e55b48fab2c867a0b5eb65aa 100644 (file)
@@ -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
index 1979598df3bba8fa5dbca8bf4fbc00c276ab590f..6d4892634e8601a3025023efb93cf2db859eed60 100644 (file)
@@ -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
index 6f12108aadcf1206dc51c9e12a37ed23e1e9e7d2..a9caac207eecedc9681e639b4a1809a9c9b59bc0 100644 (file)
@@ -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
index 2b9fba8074345596cc674bd2ab457c29e3937f13..c83b036faad198bcb498154ad6cc3062ea759ba5 100644 (file)
@@ -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"
index f143e5a91d8f419cb184e6236d0f566e890891e4..d5bd220e8220348a06e70767c4d5356f2dd58889 100644 (file)
@@ -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
index 4a869a90f852bc3df913bba12e7fd5fdcd51b2cb..5799062b17505b66f408fb052dc6e9f87fc347b7 100644 (file)
@@ -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
index 9558ec3325bc788cd9ff27bd13cc2757bd77c054..95a9d702f3cc48d60e87776c37c8a07ed8f4cbdc 100644 (file)
@@ -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)
index 1ac52028ed9461420786b917da7211e9122301d8..4bf8c1ba11b407d855f81fc0a10c53da77621092 100644 (file)
@@ -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
 
index 524892842e0946a7941a0d8e859dcef47bcfebcc..d071b8227d689cf1fad0bb54324004696738ac82 100644 (file)
@@ -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
 
index 4d90b11be0f0ec810cc4ea47005aaccce9c3e1ff..cc74b0ef4ab34f0a1fbfb3adeb766d6a07d95243 100644 (file)
@@ -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
 
index 5ec6c2864e326707bcbed98d649436670fbf47b2..1c33223030740c4d29a6c4092fc61199f0ae0663 100644 (file)
@@ -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
index 5ec6c2864e326707bcbed98d649436670fbf47b2..3d79dd2386a60ba07b51588e865047b37fca1c53 100644 (file)
@@ -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
index ebf18c2035cd75f41da92c351d22d8e194e61b54..ba88c8272daf2e06ea5abdde5e3a5488eb586a51 100644 (file)
@@ -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
 
index 7e6a062b552262d07fa12879c9e367e952db5b8e..e7cc1a3a793f92db349a2504ba79856449a67cfa 100644 (file)
@@ -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
 
index 5ec6c2864e326707bcbed98d649436670fbf47b2..3d79dd2386a60ba07b51588e865047b37fca1c53 100644 (file)
@@ -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
index 32436f0c594de06ab3d2834f475d5f3521fb9771..cec0862c20bcb9c78c4cbd345bb33f39b0b5a849 100644 (file)
@@ -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
 
index 9bace9a65a2f84a5594f75686e8854fc3188d479..29745d8e3a4e11fe83a255a76639b22137c78a53 100644 (file)
@@ -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
index d4f70ec285b531237fe4628cdadd427244c17843..704e25046938db00cfc27ed43c9e608d495171f9 100644 (file)
@@ -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