Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 4053, convert unit tests to FAIL/PASS API #5495

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 14 additions & 37 deletions src/detect-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,89 +125,66 @@ static int DetectMsgSetup (DetectEngineCtx *de_ctx, Signature *s, const char *ms
#ifdef UNITTESTS
static int DetectMsgParseTest01(void)
{
int result = 0;
Signature *sig = NULL;
const char *teststringparsed = "flow stateless to_server";
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
FAIL_IF_NULL(de_ctx);

FILE *fd = SCClassConfGenerateValidDummyClassConfigFD01();
SCClassConfLoadClassficationConfigFile(de_ctx, fd);

sig = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"flow stateless to_server\"; flow:stateless,to_server; content:\"flowstatelesscheck\"; classtype:bad-unknown; sid: 40000002; rev: 1;)");
if(sig == NULL)
goto end;
FAIL_IF_NULL(sig);

if (strcmp(sig->msg, teststringparsed) != 0) {
printf("got \"%s\", expected: \"%s\": ", sig->msg, teststringparsed);
goto end;
}
FAIL_IF(strcmp(sig->msg, teststringparsed) != 0);

result = 1;
end:
if (sig != NULL)
SigFree(de_ctx, sig);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
return result;

PASS;
}

static int DetectMsgParseTest02(void)
{
int result = 0;
Signature *sig = NULL;
const char *teststringparsed = "msg escape tests wxy'\"\\;:";
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
FAIL_IF_NULL(de_ctx);

sig = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"msg escape tests \\w\\x\\y\\'\\\"\\\\;\\:\"; flow:to_server,established; content:\"blah\"; uricontent:\"/blah/\"; sid: 100;)");
if(sig == NULL)
goto end;
FAIL_IF_NULL(sig);

if (strcmp(sig->msg, teststringparsed) != 0) {
printf("got \"%s\", expected: \"%s\": ",sig->msg, teststringparsed);
goto end;
}
FAIL_IF(strcmp(sig->msg, teststringparsed) != 0);

result = 1;
end:
if (sig != NULL)
SigFree(de_ctx, sig);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
return result;
PASS;
}

static int DetectMsgParseTest03(void)
{
int result = 0;
Signature *sig = NULL;
const char *teststringparsed = "flow stateless to_server";
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;

FAIL_IF_NULL(de_ctx);

FILE *fd = SCClassConfGenerateValidDummyClassConfigFD01();
SCClassConfLoadClassficationConfigFile(de_ctx, fd);

sig = SigInit(de_ctx, "alert tcp any any -> any any (msg: \"flow stateless to_server\"; flow:stateless,to_server; content:\"flowstatelesscheck\"; classtype:bad-unknown; sid: 40000002; rev: 1;)");
if(sig == NULL)
goto end;
FAIL_IF_NULL(sig);

if (strcmp(sig->msg, teststringparsed) != 0) {
printf("got \"%s\", expected: \"%s\": ", sig->msg, teststringparsed);
goto end;
}
FAIL_IF(strcmp(sig->msg, teststringparsed) != 0);

result = 1;
end:
if (sig != NULL)
SigFree(de_ctx, sig);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
return result;
PASS;
}

/**
Expand Down