Skip to content

Commit

Permalink
test: test lua require with builtin lib for output scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonish committed Jan 22, 2025
1 parent 06c213c commit 8ea5d63
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/lua/lua-hashlib-output/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A rather simple test to make sure that out built-in libraries can be
loaded by a Lua output script.

13 changes: 13 additions & 0 deletions tests/lua/lua-hashlib-output/suricata.yaml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions tests/lua/lua-hashlib-output/test.lua
Original file line number Diff line number Diff line change
@@ -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
Binary file added tests/lua/lua-hashlib-output/test.pcap
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/lua/lua-hashlib-output/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
requires:
min-version: 8

pcap: ../../cond-log-dns-dig/input.pcap

checks:
- shell:
args: grep "OK" results.log | wc -l
expect: 2

0 comments on commit 8ea5d63

Please sign in to comment.