]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
tests/lua: update for suricata.config lua lib
authorJason Ish <jason.ish@oisf.net>
Fri, 30 May 2025 22:22:34 +0000 (16:22 -0600)
committerJason Ish <jason.ish@oisf.net>
Sat, 31 May 2025 22:00:13 +0000 (16:00 -0600)
25 files changed:
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-stats-pre8/README.md [new file with mode: 0644]
tests/lua-output-stats-pre8/suricata.yaml [new file with mode: 0644]
tests/lua-output-stats-pre8/test.lua [new file with mode: 0644]
tests/lua-output-stats-pre8/test.pcap [new file with mode: 0644]
tests/lua-output-stats-pre8/test.yaml [new file with mode: 0644]
tests/lua-output-stats/test.lua
tests/lua-output-stats/test.yaml
tests/lua-output-streaming/streaming-http.lua
tests/lua-output-streaming/streaming-tcp.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-fastlog/fast.lua
tests/lua/lua-hashlib-output/test.lua
tests/lua/lua-tlslib-01/lua-tlsfunctions.lua
tests/ssh-lua-output/output.lua

index acffbb6c0cdca1cdc6365ca17ddd79e6f2954cf0..b527c442ff3d23b45b990aa9efb3b2e689e90b8a 100644 (file)
@@ -3,6 +3,7 @@ name = "flow_http_lua.log"
 
 local flow = require("suricata.flow")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 function init (args)
     local needs = {}
@@ -12,7 +13,7 @@ function init (args)
 end
 
 function setup (args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.info("Log Filename " .. filename)
     http = 0
index 0d3484423932652e14604534e65460901134e56f..77cf804554ab762ecfaba7c6e3ff6c348ea0fbc9 100644 (file)
@@ -3,6 +3,7 @@ name = "lua-scflowstats.log"
 
 local flow = require("suricata.flow")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 function init(args)
     local needs = {}
@@ -11,7 +12,7 @@ function init(args)
 end
 
 function setup(args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.info("lua SCFlowStats Log Filename " .. filename)
 end
index 3eb15afe81aee6915344c9e37fd8b1c86c73f819..6046090566fcf4e9a801c2ffb983c4830b773580 100644 (file)
@@ -1,6 +1,7 @@
 -- simple SCFlowTuple log test
 local flow = require("suricata.flow")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 name = "scflow-tuple.log"
 
@@ -12,7 +13,7 @@ end
 
 
 function setup(args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.notice("lua SCFlowTuple Log Filename " .. filename)
 end
index 0dbb6eb3c4b6a2e8e123f439f66a1af93370996b..e5e26aafde7eeca9a200ade9decffefbfd842f0d 100644 (file)
@@ -2,6 +2,7 @@ local flow = require("suricata.flow")
 local packet = require("suricata.packet")
 local dns = require("suricata.dns")
 local logger = require("suricata.log")
+local config = require "suricata.config"
 
 filename = "lua-dns.log"
 
@@ -13,7 +14,7 @@ end
 
 function setup (args)
    logger.notice("lua: setup()")
-   file = assert(io.open(SCLogPath() .. "/" .. filename, "w"))
+   file = assert(io.open(config.log_path() .. "/" .. filename, "w"))
 end
 
 function log(args)
index e5ccb624d40b8bb7fa15c2890bc1a5f306a7e7a9..d12da9dd908942e508414c73978aa4e9cc3ca0e1 100644 (file)
@@ -3,6 +3,7 @@ local flow = require("suricata.flow")
 local packet = require "suricata.packet"
 local http = require("suricata.http")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 name = "http_lua.log"
 
@@ -13,7 +14,7 @@ function init (args)
 end
 
 function setup (args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.info("HTTP Log Filename " .. filename)
     http_tx = 0
index 2a3551ee1d2a6bd2e55b48fab2c867a0b5eb65aa..c5d4b8f959c64c60ffde400e03e865fc21ea9588 100644 (file)
@@ -3,6 +3,7 @@ local flow = require("suricata.flow")
 local packet = require "suricata.packet"
 local http = require("suricata.http")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 name = "http_lua.log"
 
@@ -13,7 +14,7 @@ function init (args)
 end
 
 function setup (args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.info("HTTP Log Filename " .. filename)
     http_tx = 0
index 6d4892634e8601a3025023efb93cf2db859eed60..2ae540480dc13fee9ead88827afe6d1536bfbab0 100644 (file)
@@ -3,6 +3,7 @@ local packet = require "suricata.packet"
 local flow = require("suricata.flow")
 local http = require("suricata.http")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 name = "http_lua.log"
 
@@ -13,7 +14,7 @@ function init (args)
 end
 
 function setup (args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     http_tx = 0
 end
index a9caac207eecedc9681e639b4a1809a9c9b59bc0..93fd88132b427bf4ca9c9e595508fa45b7b761d5 100644 (file)
@@ -2,6 +2,7 @@
 local packet = require "suricata.packet"
 local smtp = require "suricata.smtp"
 local logger = require("suricata.log")
+local config = require "suricata.config"
 
 name = "smtp_lua.log"
 
@@ -12,7 +13,7 @@ function init (args)
 end
 
 function setup (args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.info("Log Filename " .. filename)
     count = 0
diff --git a/tests/lua-output-stats-pre8/README.md b/tests/lua-output-stats-pre8/README.md
new file mode 100644 (file)
index 0000000..bdafb8c
--- /dev/null
@@ -0,0 +1,3 @@
+Tests the output of stats being logged by Lua.
+
+PCAPs created by Jason Ish.
diff --git a/tests/lua-output-stats-pre8/suricata.yaml b/tests/lua-output-stats-pre8/suricata.yaml
new file mode 100644 (file)
index 0000000..5cd3ea7
--- /dev/null
@@ -0,0 +1,9 @@
+%YAML 1.1
+---
+
+outputs:
+  - lua:
+      enabled: yes
+      scripts-dir: .
+      scripts:
+        - test.lua
diff --git a/tests/lua-output-stats-pre8/test.lua b/tests/lua-output-stats-pre8/test.lua
new file mode 100644 (file)
index 0000000..d3c0f6d
--- /dev/null
@@ -0,0 +1,29 @@
+filename = "lua-stats.log"
+
+function init (args)
+    local needs = {}
+    needs["type"] = "stats"
+    return needs
+end
+
+function setup (args)
+   file = assert(io.open(SCLogPath() .. "/" .. filename, "w"))
+end
+
+function log(args)
+    for n, v in ipairs(args) do
+        --print(n .. " - " .. v["name"] .. " == " .. v["value"]);
+        if (v["name"] == "decoder.pkts") then
+            msg = string.format("packets %u", v["value"]);
+            write(msg)
+        end
+    end
+end
+
+function deinit(args)
+   file:close(file)
+end
+
+function write(msg)
+   file:write(msg .. "\n")
+end
diff --git a/tests/lua-output-stats-pre8/test.pcap b/tests/lua-output-stats-pre8/test.pcap
new file mode 100644 (file)
index 0000000..20db7a1
Binary files /dev/null and b/tests/lua-output-stats-pre8/test.pcap differ
diff --git a/tests/lua-output-stats-pre8/test.yaml b/tests/lua-output-stats-pre8/test.yaml
new file mode 100644 (file)
index 0000000..b259497
--- /dev/null
@@ -0,0 +1,9 @@
+requires:
+  lt-version: 8
+  features:
+    - HAVE_LUA
+
+checks:
+  - shell:
+      args: grep 'packets 10' lua-stats.log | wc -l
+      expect: 1
index d3c0f6dcdd124bfade9788202bb18d906f094a47..65c7c8a8014c8814c66836128b1a28bf6dc470d9 100644 (file)
@@ -1,3 +1,5 @@
+local config = require("suricata.config")
+
 filename = "lua-stats.log"
 
 function init (args)
@@ -7,7 +9,7 @@ function init (args)
 end
 
 function setup (args)
-   file = assert(io.open(SCLogPath() .. "/" .. filename, "w"))
+   file = assert(io.open(config.log_path() .. "/" .. filename, "w"))
 end
 
 function log(args)
index 0513752f76eed46517841523412f487a1ee119b7..253a0be0eac81e5eb92b4d8865d8bd037fad90ec 100644 (file)
@@ -1,6 +1,5 @@
 requires:
-  features:
-    - HAVE_LUA
+  min-version: 8
 
 checks:
   - shell:
index c83b036faad198bcb498154ad6cc3062ea759ba5..f105df39acdeb0e94815916588b376acb8e84e44 100644 (file)
@@ -1,5 +1,6 @@
 local flow = require "suricata.flow"
 local logger = require("suricata.log")
+local config = require "suricata.config"
 
 function init (args)
     local needs = {}
@@ -9,7 +10,7 @@ function init (args)
 end
 
 function setup (args)
-    filepath = SCLogPath()
+    filepath = config.log_path()
 end
 
 function log(args)
index f54c7e36874fc38a32efe003ab26c16389592cc2..3cae85a0fa40cc6a48b2ad39e077404083c8a702 100644 (file)
@@ -1,4 +1,5 @@
 local flow = require("suricata.flow")
+local config = require("suricata.config")
 
 function init (args)
     local needs = {}
@@ -8,7 +9,7 @@ function init (args)
 end
 
 function setup (args)
-    filepath = SCLogPath()
+    filepath = config.log_path()
     alerts = 0
 end
 
index d5bd220e8220348a06e70767c4d5356f2dd58889..a0d3bf601dc3378bad1937551178b34695e9ffc0 100644 (file)
@@ -1,5 +1,6 @@
 local filelib = require("suricata.file")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 -- Output test for SCFileInfo
 file_name = "scfileinfo.log"
@@ -9,7 +10,7 @@ function init (args)
 end
 
 function setup(args)
-    filename = SCLogPath() .. "/" .. file_name
+    filename = config.log_path() .. "/" .. file_name
     output = assert(io.open(filename, "w"))
     logger.info("lua SCFileInfo Log Filename " .. filename)
 end
index 5799062b17505b66f408fb052dc6e9f87fc347b7..d6507cddf0f1de0429da918eb1942624d7dc1ced 100644 (file)
@@ -1,5 +1,6 @@
 local packet = require "suricata.packet"
 local logger = require("suricata.log")
+local config = require "suricata.config"
 
 -- simple SCPacketTuple log test
 name = "scpacket-tuple.log"
@@ -11,7 +12,7 @@ function init(args)
 end
 
 function setup(args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.info("Lua SCPacketTuple Log Filename " .. filename)
     packets = 0
index 95a9d702f3cc48d60e87776c37c8a07ed8f4cbdc..6d97e38339f29bfdd3954e959034bc92f137fdcb 100644 (file)
@@ -2,6 +2,7 @@
 local packet = require "suricata.packet"
 local rule = require "suricata.rule"
 local logger = require "suricata.log"
+local config = require "suricata.config"
 
 name = "lua-scrule-ids.log"
 
@@ -13,7 +14,7 @@ function init(args)
 end
 
 function setup(args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.info("lua SCRuleIds Log Filename " .. filename)
 end
index 4bf8c1ba11b407d855f81fc0a10c53da77621092..4169543582eea537e53d8be92169f73df4417223 100644 (file)
@@ -4,6 +4,7 @@
 local base64 = require("suricata.base64")
 local dns = require("suricata.dns")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 local expected_base64 = "d3d3LnN1cmljYXRhLWlkcy5vcmc="
 
@@ -17,7 +18,7 @@ end
 
 function setup (args)
    logger.notice("lua: setup()")
-   file = assert(io.open(SCLogPath() .. "/" .. filename, "w"))
+   file = assert(io.open(config.log_path() .. "/" .. filename, "w"))
 end
 
 function log(args)
index f72283ef00c90694cfbd98b1b965951194e10bde..abeb9d055a79b2a88516163bc075f0aca3c43381 100644 (file)
@@ -18,6 +18,7 @@
 
 local packet = require("suricata.packet")
 local rule = require("suricata.rule")
+local config = require("suricata.config")
 
 function init()
     local needs     = {}
@@ -27,7 +28,7 @@ function init()
 end
 
 function setup()
-    filename = SCLogPath() .. "/fast.log"
+    filename = config.log_path() .. "/fast.log"
     file = assert(io.open(filename, "a"))
     alert_count = 0
 end
index d071b8227d689cf1fad0bb54324004696738ac82..c1ca1b616b909aa54fa6caa0cc7ee2bf27d39452 100644 (file)
@@ -1,6 +1,7 @@
 local hashlib = require("suricata.hashlib")
 local dns = require("suricata.dns")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 -- We don't actually use, but the script will fail to run if it fails
 -- to "require".
@@ -19,7 +20,7 @@ end
 
 function setup (args)
    logger.notice("lua: setup()")
-   file = assert(io.open(SCLogPath() .. "/" .. filename, "w"))
+   file = assert(io.open(config.log_path() .. "/" .. filename, "w"))
 end
 
 function log(args)
index cec0862c20bcb9c78c4cbd345bb33f39b0b5a849..d520bc3f043ad51c034e531ab2516fb383579707 100644 (file)
@@ -3,6 +3,7 @@ name = "tlslib_lua.log"
 
 local tls = require("suricata.tls")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 function init (args)
     local needs = {}
@@ -11,7 +12,7 @@ function init (args)
 end
 
 function setup (args)
-    filename = SCLogPath() .. "/" .. name
+    filename = config.log_path() .. "/" .. name
     file = assert(io.open(filename, "a"))
     logger.info("Log Filename " .. filename)
     http = 0
index 704e25046938db00cfc27ed43c9e608d495171f9..63ad208dab68e56103a709be1899e6c19e9cd87e 100644 (file)
@@ -1,5 +1,6 @@
 local ssh = require("suricata.ssh")
 local logger = require("suricata.log")
+local config = require("suricata.config")
 
 filename = "results.log"
 
@@ -11,7 +12,7 @@ end
 
 function setup (args)
     logger.notice("lua: setup()")
-    file = assert(io.open(SCLogPath() .. "/" .. filename, "w"))
+    file = assert(io.open(config.log_path() .. "/" .. filename, "w"))
 end
 
 function log(args)