--- /dev/null
+To test that SCFlowvarGet (lua) doesn't always return nil.
+
+The original issue emerged due to a lua detection script that used a single rule to set up
+a flow variable and match on it.
+
+The problem is that during detection, the steps happen in this order:
+- pattern matching
+- lua script execution
+- setting flow variables as part of post match
+
+So, a workaround is to have 2 rules:
+- one that does the pattern matching and setting the flow var
+- another second one that does the Lua script
+
+This test works based on that.
+
+Pcap provided by Chris Knott at https://redmine.openinfosecfoundation.org/issues/2094
--- /dev/null
+function init (args)
+ local needs = {}
+ needs["http.request_headers"] = tostring(true)
+ needs["flowvar"] = {"TestVar"}
+ return needs
+end
+
+function match(args)
+ print "Before loading Variable"
+ testVar = ScFlowvarGet(0);
+ if testVar then
+ print "testVar is set"
+ else
+ print "testVar is not set"
+ return 0
+ end
+ return 1
+end
--- /dev/null
+alert http any any -> any any (msg: "Test"; http.request_line; pcre: "^/GET (.*)$/G, flow:TestVar"; flowbits: set, flowtestvar; noalert; sid:6677000; rev:1;)
+alert http any any -> any any (msg: "Test2"; flow: to_server; lua:test.lua; flowbits: isset, flowtestvar; sid:6677001; rev:1;)