detect/base64_data: Convert unittests to FAIL/PASS API

Ticket: #6320
pull/14233/head
Jhonny Sousa 9 months ago committed by Victor Julien
parent 1efe70a234
commit 051bc324d6

@ -67,47 +67,22 @@ static int g_file_data_buffer_id = 0;
static int DetectBase64DataSetupTest01(void)
{
DetectEngineCtx *de_ctx = NULL;
SigMatch *sm;
int retval = 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 smtp any any -> any any (msg:\"DetectBase64DataSetupTest\"; "
"base64_decode; base64_data; content:\"content\"; sid:1; rev:1;)");
if (de_ctx->sig_list == NULL) {
printf("SigInit failed: ");
goto end;
}
sm = de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH];
if (sm == NULL) {
printf("DETECT_SM_LIST_PMATCH should not be NULL: ");
goto end;
}
if (sm->type != DETECT_BASE64_DECODE) {
printf("sm->type should be DETECT_BASE64_DECODE: ");
goto end;
}
if (de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_BASE64_DATA] == NULL) {
printf("DETECT_SM_LIST_BASE64_DATA should not be NULL: ");
goto end;
}
retval = 1;
end:
if (de_ctx != NULL) {
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
}
return retval;
Signature *s = DetectEngineAppendSig(de_ctx,
"alert smtp any any -> any any (msg:\"DetectBase64DataSetupTest\"; "
"base64_decode; base64_data; content:\"content\"; sid:1; rev:1;)");
FAIL_IF_NULL(s);
SigMatch *sm = s->init_data->smlists[DETECT_SM_LIST_PMATCH];
FAIL_IF_NULL(sm);
FAIL_IF_NOT(sm->type == DETECT_BASE64_DECODE);
FAIL_IF_NULL(s->init_data->smlists[DETECT_SM_LIST_BASE64_DATA]);
DetectEngineCtxFree(de_ctx);
PASS;
}
/**
@ -116,30 +91,18 @@ end:
*/
static int DetectBase64DataSetupTest04(void)
{
DetectEngineCtx *de_ctx = NULL;
int retval = 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:\"some b64thing\"; flow:established,from_server; file_data; content:\"sometext\"; fast_pattern; base64_decode:relative; base64_data; content:\"foobar\"; nocase; tag:session,120,seconds; sid:1111111; rev:1;)");
if (de_ctx->sig_list == NULL) {
printf("SigInit failed: ");
goto end;
}
retval = 1;
end:
if (de_ctx != NULL) {
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
}
return retval;
Signature *s = DetectEngineAppendSig(de_ctx,
"alert tcp any any -> any any (msg:\"some b64thing\"; flow:established,from_server; "
"file_data; content:\"sometext\"; fast_pattern; base64_decode:relative; base64_data; "
"content:\"foobar\"; nocase; tag:session,120,seconds; sid:1111111; rev:1;)");
FAIL_IF_NULL(s);
DetectEngineCtxFree(de_ctx);
PASS;
}
static void DetectBase64DataRegisterTests(void)
@ -149,4 +112,4 @@ static void DetectBase64DataRegisterTests(void)
UtRegisterTest("DetectBase64DataSetupTest01", DetectBase64DataSetupTest01);
UtRegisterTest("DetectBase64DataSetupTest04", DetectBase64DataSetupTest04);
}
#endif /* UNITTESTS */
#endif /* UNITTESTS */
Loading…
Cancel
Save