From 8f93cd5f989508cfc4aed590b9998b8878065999 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Wed, 22 Jan 2025 16:30:28 -0600 Subject: [PATCH] test: test lua require with builtin lib for output scripts --- tests/lua/lua-hashlib-output/README.md | 3 ++ tests/lua/lua-hashlib-output/suricata.yaml | 13 +++++++ tests/lua/lua-hashlib-output/test.lua | 43 +++++++++++++++++++++ tests/lua/lua-hashlib-output/test.pcap | Bin 0 -> 131 bytes tests/lua/lua-hashlib-output/test.yaml | 10 +++++ 5 files changed, 69 insertions(+) create mode 100644 tests/lua/lua-hashlib-output/README.md create mode 100644 tests/lua/lua-hashlib-output/suricata.yaml create mode 100644 tests/lua/lua-hashlib-output/test.lua create mode 100644 tests/lua/lua-hashlib-output/test.pcap create mode 100644 tests/lua/lua-hashlib-output/test.yaml diff --git a/tests/lua/lua-hashlib-output/README.md b/tests/lua/lua-hashlib-output/README.md new file mode 100644 index 000000000..101025fca --- /dev/null +++ b/tests/lua/lua-hashlib-output/README.md @@ -0,0 +1,3 @@ +A rather simple test to make sure that out built-in libraries can be +loaded by a Lua output script. + diff --git a/tests/lua/lua-hashlib-output/suricata.yaml b/tests/lua/lua-hashlib-output/suricata.yaml new file mode 100644 index 000000000..c7319fcca --- /dev/null +++ b/tests/lua/lua-hashlib-output/suricata.yaml @@ -0,0 +1,13 @@ +%YAML 1.1 +--- + +include: ../../../etc/suricata-3.1.2.yaml + +rule-files: + +outputs: + - lua: + enabled: yes + scripts-dir: . + scripts: + - test.lua diff --git a/tests/lua/lua-hashlib-output/test.lua b/tests/lua/lua-hashlib-output/test.lua new file mode 100644 index 000000000..d356f1cc1 --- /dev/null +++ b/tests/lua/lua-hashlib-output/test.lua @@ -0,0 +1,43 @@ +local hashlib = require("suricata.hashlib") + +-- We don't actually use, but the script will fail to run if it fails +-- to "require". +local dataset = require("suricata.dataset") + +-- www.suricata-ids.org +local expected_md5 = "27170ec0609347c6a158bb5b694822a5" + +filename = "results.log" + +function init (args) + local needs = {} + needs["protocol"] = "dns" + return needs +end + +function setup (args) + SCLogNotice("lua: setup()") + file = assert(io.open(SCLogPath() .. "/" .. filename, "w")) +end + +function log(args) + queries = DnsGetQueries() + if queries ~= nil then + for n, t in pairs(queries) do + if hashlib.md5_hexdigest(t["rrname"]) == expected_md5 then + msg = "OK" + else + msg = "FAIL" + end + 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/lua-hashlib-output/test.pcap b/tests/lua/lua-hashlib-output/test.pcap new file mode 100644 index 0000000000000000000000000000000000000000..d3065bd4074208b05070f91d186ac123233c355f GIT binary patch literal 131 zc-p&ic+)~A1{MYcU}0bcl6D=St_%#m%7P3G z4uXy;Tmp>TK+L$