]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: add unittest for byte_extract/isdataat
authorVictor Julien <victor@inliniac.net>
Sat, 21 Oct 2017 08:01:20 +0000 (10:01 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 24 Oct 2017 11:47:02 +0000 (13:47 +0200)
src/tests/detect-engine-content-inspection.c

index a855a21ea3b7d9d8c379cee132e9d73d65f1feb3..7b27ff874516a93fa8096b921baca08743fb8a57 100644 (file)
@@ -209,6 +209,19 @@ static int DetectEngineContentInspectionTest09(void) {
     TEST_FOOTER;
 }
 
+/** \test mix in byte_extract */
+static int DetectEngineContentInspectionTest10(void) {
+    TEST_HEADER;
+    /* extract first byte as lenght field and check with isdataat */
+    TEST_RUN("9abcdefghi", 10, "byte_extract:1,0,data_size,string; isdataat:data_size;", true, 2);
+    TEST_RUN("9abcdefgh", 9, "byte_extract:1,0,data_size,string; isdataat:!data_size;", true, 2);
+    /* anchor len field to pattern 'x' to test recursion */
+    TEST_RUN("x9x9abcdefghi", 13, "content:\"x\"; byte_extract:1,0,data_size,string,relative; isdataat:data_size,relative;", true, 3);
+    TEST_RUN("x9x9abcdefgh", 12, "content:\"x\"; byte_extract:1,0,data_size,string,relative; isdataat:!data_size,relative;", true, 5);
+    TEST_RUN("x9x9abcdefgh", 12, "content:\"x\"; depth:1; byte_extract:1,0,data_size,string,relative; isdataat:!data_size,relative;", false, 3);
+    TEST_FOOTER;
+}
+
 void DetectEngineContentInspectionRegisterTests(void)
 {
     UtRegisterTest("DetectEngineContentInspectionTest01",
@@ -229,6 +242,8 @@ void DetectEngineContentInspectionRegisterTests(void)
                    DetectEngineContentInspectionTest08);
     UtRegisterTest("DetectEngineContentInspectionTest09",
                    DetectEngineContentInspectionTest09);
+    UtRegisterTest("DetectEngineContentInspectionTest10",
+                   DetectEngineContentInspectionTest10);
 }
 
 #undef TEST_HEADER