*/
static int DetectHttpClientBodyTest01(void)
{
- DetectEngineCtx *de_ctx = NULL;
- int result = 0;
- SigMatch *sm = NULL;
-
- de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL)
- goto end;
-
+ DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
- "(msg:\"Testing http_client_body\"; "
- "content:\"one\"; http_client_body; sid:1;)");
- if (de_ctx->sig_list != NULL) {
- result = 1;
- } else {
- goto end;
- }
- sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_MATCH];
- if (sm != NULL) {
- result &= (sm->type == DETECT_CONTENT);
- result &= (sm->next == NULL);
- }
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
+ "(msg:\"Testing http_client_body\"; "
+ "content:\"one\"; http_client_body; sid:1;)");
+ FAIL_IF_NULL(s);
- end:
- DetectEngineCtxFree(de_ctx);
+ SigMatch *sm = de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_MATCH];
+ FAIL_IF_NOT_NULL(sm);
- return result;
+ DetectEngineCtxFree(de_ctx);
+ PASS;
}
/**
* \test Test that a signature containing an valid http_client_body entry is
* parsed.
+ * \todo error in sig 'http_client_body:;'
*/
static int DetectHttpClientBodyTest02(void)
{
- DetectEngineCtx *de_ctx = NULL;
- int result = 0;
-
- de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL)
- goto end;
-
+ DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
- "(msg:\"Testing http_client_body\"; "
- "content:\"one\"; http_client_body:; sid:1;)");
- if (de_ctx->sig_list != NULL)
- result = 1;
- end:
- DetectEngineCtxFree(de_ctx);
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
+ "(msg:\"Testing http_client_body\"; "
+ "content:\"one\"; http_client_body:; sid:1;)");
+ FAIL_IF_NULL(s);
- return result;
+ DetectEngineCtxFree(de_ctx);
+ PASS;
}
/**
- * \test Test that an invalid signature containing no content but a http_client_body
- * is invalidated.
+ * \test Test invalid signatures
*/
static int DetectHttpClientBodyTest03(void)
{
- DetectEngineCtx *de_ctx = NULL;
- int result = 0;
-
- de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL)
- goto end;
-
+ DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
- "(msg:\"Testing http_client_body\"; "
- "http_client_body; sid:1;)");
- if (de_ctx->sig_list == NULL)
- result = 1;
-
- end:
- DetectEngineCtxFree(de_ctx);
-
- return result;
-}
-/**
- * \test Test that an invalid signature containing a rawbytes along with a
- * http_client_body is invalidated.
- */
-static int DetectHttpClientBodyTest04(void)
-{
- DetectEngineCtx *de_ctx = NULL;
- int result = 0;
-
- de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL)
- goto end;
-
- de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
- "(msg:\"Testing http_client_body\"; "
- "content:\"one\"; rawbytes; http_client_body; sid:1;)");
- if (de_ctx->sig_list == NULL)
- result = 1;
+ const char *sigs[] = {
+ "alert tcp any any -> any any (http_client_body; sid:1;)",
+ "alert tcp any any -> any any "
+ "(msg:\"Testing http_client_body\"; "
+ "content:\"one\"; rawbytes; http_client_body; sid:2;)",
+ NULL,
+ };
- end:
+ for (uint32_t i = 0; sigs[i] != NULL; i++) {
+ Signature *s = DetectEngineAppendSig(de_ctx, sigs[i]);
+ FAIL_IF_NOT_NULL(s);
+ }
DetectEngineCtxFree(de_ctx);
-
- return result;
+ PASS;
}
/**
*/
static int DetectHttpClientBodyTest05(void)
{
- DetectEngineCtx *de_ctx = NULL;
- int result = 0;
-
- de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL)
- goto end;
-
+ DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
- "(msg:\"Testing http_client_body\"; "
- "content:\"one\"; http_client_body; nocase; sid:1;)");
- if (de_ctx->sig_list != NULL)
- result = 1;
- end:
- DetectEngineCtxFree(de_ctx);
+ const char *sigs[] = {
+ "alert tcp any any -> any any (content:\"one\"; http_client_body; nocase; sid:1;)",
+ NULL,
+ };
- return result;
+ for (uint32_t i = 0; sigs[i] != NULL; i++) {
+ Signature *s = DetectEngineAppendSig(de_ctx, sigs[i]);
+ FAIL_IF_NULL(s);
+ }
+ DetectEngineCtxFree(de_ctx);
+ PASS;
}
/**
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
- "(msg:\"http client body test\"; "
- "content:\"message\"; http_client_body; "
- "sid:1;)");
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
+ "(msg:\"http client body test\"; "
+ "content:\"message\"; http_client_body; "
+ "sid:1;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
- "(msg:\"http client body test\"; "
- "content:\"message\"; http_client_body; "
- "sid:1;)");
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
+ "(msg:\"http client body test\"; "
+ "content:\"message\"; http_client_body; "
+ "sid:1;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
- "(msg:\"http client body test\"; "
- "content:\"message\"; http_client_body; "
- "sid:1;)");
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
+ "(msg:\"http client body test\"; "
+ "content:\"message\"; http_client_body; "
+ "sid:1;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
- "(msg:\"http client body test\"; "
- "content:\"body1This\"; http_client_body; "
- "sid:1;)");
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
+ "(msg:\"http client body test\"; "
+ "content:\"body1This\"; http_client_body; "
+ "sid:1;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
- "(msg:\"http client body test\"; "
- "content:\"body1This\"; http_client_body; nocase;"
- "sid:1;)");
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
+ "(msg:\"http client body test\"; "
+ "content:\"body1This\"; http_client_body; nocase;"
+ "sid:1;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
- "(msg:\"http client body test\"; "
- "content:!\"message1\"; http_client_body; "
- "sid:1;)");
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
+ "(msg:\"http client body test\"; "
+ "content:!\"message1\"; http_client_body; "
+ "sid:1;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
- "(msg:\"http client body test\"; "
- "content:!\"message\"; http_client_body; "
- "sid:1;)");
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
+ "(msg:\"http client body test\"; "
+ "content:!\"message\"; http_client_body; "
+ "sid:1;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
- "(msg:\"http client body test\"; "
- "content:\"abcdefghijklmnopqrstuvwxyz0123456789\"; http_client_body; "
- "sid:1;)");
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx,
+ "alert http any any -> any any "
+ "(msg:\"http client body test\"; "
+ "content:\"abcdefghijklmnopqrstuvwxyz0123456789\"; http_client_body; "
+ "sid:1;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
goto end;
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert icmp any any -> any any "
- "(content:\"one\"; offset:10; http_client_body; pcre:/two/; "
- "content:\"three\"; distance:10; http_client_body; within:10; "
- "content:\"four\"; distance:10; sid:1;)");
- if (de_ctx->sig_list == NULL) {
- printf("de_ctx->sig_list == NULL\n");
- goto end;
- }
+ Signature *s = DetectEngineAppendSig(de_ctx,
+ "alert icmp any any -> any any "
+ "(content:\"one\"; offset:10; http_client_body; pcre:/two/; "
+ "content:\"three\"; distance:10; http_client_body; within:10; "
+ "content:\"four\"; distance:10; sid:1;)");
+ FAIL_IF_NULL(s);
result = 1;
goto end;
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert icmp any any -> any any "
- "(content:\"one\"; within:5; http_client_body; sid:1;)");
- if (de_ctx->sig_list == NULL) {
- printf("de_ctx->sig_list == NULL\n");
- goto end;
- }
+ Signature *s =
+ DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
+ "(content:\"one\"; within:5; http_client_body; sid:1;)");
+ FAIL_IF_NULL(s);
result = 1;
goto end;
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert icmp any any -> any any "
- "(content:\"one\"; http_client_body; within:5; sid:1;)");
- if (de_ctx->sig_list == NULL) {
- printf("de_ctx->sig_list != NULL\n");
- goto end;
- }
+ Signature *s =
+ DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
+ "(content:\"one\"; http_client_body; within:5; sid:1;)");
+ FAIL_IF_NULL(s);
result = 1;
goto end;
de_ctx->flags |= DE_QUIET;
- de_ctx->sig_list = SigInit(de_ctx, "alert icmp any any -> any any "
- "(content:\"one\"; within:5; sid:1;)");
- if (de_ctx->sig_list == NULL) {
- printf("de_ctx->sig_list == NULL\n");
- goto end;
- }
+ Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
+ "(content:\"one\"; within:5; sid:1;)");
+ FAIL_IF_NULL(s);
result = 1;
UtRegisterTest("DetectHttpClientBodyTest01", DetectHttpClientBodyTest01);
UtRegisterTest("DetectHttpClientBodyTest02", DetectHttpClientBodyTest02);
UtRegisterTest("DetectHttpClientBodyTest03", DetectHttpClientBodyTest03);
- UtRegisterTest("DetectHttpClientBodyTest04", DetectHttpClientBodyTest04);
UtRegisterTest("DetectHttpClientBodyTest05", DetectHttpClientBodyTest05);
UtRegisterTest("DetectHttpClientBodyTest06", DetectHttpClientBodyTest06);
UtRegisterTest("DetectHttpClientBodyTest07", DetectHttpClientBodyTest07);