detect-distance: Convert unittests to new FAIL/PASS API

Ticket : #4020
pull/8118/head
Haleema Khan 3 years ago committed by Victor Julien
parent a654ef50de
commit f25d4cc546

@ -160,55 +160,34 @@ static int DetectDistanceSetup (DetectEngineCtx *de_ctx, Signature *s,
static int DetectDistanceTest01(void) static int DetectDistanceTest01(void)
{ {
int result = 0;
DetectEngineCtx *de_ctx = DetectEngineCtxInit(); DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
printf("no de_ctx: "); FAIL_IF_NULL(de_ctx);
goto end;
}
de_ctx->flags |= DE_QUIET; de_ctx->flags |= DE_QUIET;
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (content:\"|AA BB|\"; content:\"|CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE|\"; distance: 4; within: 19; sid:1; rev:1;)"); Signature *s = DetectEngineAppendSig(de_ctx,
if (de_ctx->sig_list == NULL) { "alert tcp any any -> any any (content:\"|AA BB|\"; content:\"|CC DD EE FF 00 11 22 33 "
printf("sig parse failed: "); "44 55 66 77 88 99 AA BB CC DD EE|\"; distance: 4; within: 19; sid:1; rev:1;)");
goto end; FAIL_IF_NULL(s);
}
SigMatch *sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_PMATCH]; SigMatch *sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_PMATCH];
if (sm == NULL) { FAIL_IF_NULL(sm);
printf("sm NULL: ");
goto end;
}
sm = sm->next; sm = sm->next;
if (sm == NULL) { FAIL_IF_NULL(sm);
printf("sm2 NULL: ");
goto end;
}
DetectContentData *co = (DetectContentData *)sm->ctx; DetectContentData *co = (DetectContentData *)sm->ctx;
if (co == NULL) { FAIL_IF_NULL(co);
printf("co == NULL: ");
goto end;
}
if (co->distance != 4) { FAIL_IF_NOT(co->distance = 4);
printf("distance %"PRIi32", expected 4: ", co->distance);
goto end;
}
/* within needs to be 23: distance + content_len as Snort auto fixes this */ /* within needs to be 23: distance + content_len as Snort auto fixes this */
if (co->within != 19) { FAIL_IF_NOT(co->within = 19);
printf("within %"PRIi32", expected 23: ", co->within);
goto end;
}
result = 1;
end:
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
return result;
PASS;
} }
/** /**
@ -218,25 +197,21 @@ end:
*/ */
static int DetectDistanceTestPacket01 (void) static int DetectDistanceTestPacket01 (void)
{ {
int result = 0;
uint8_t buf[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t buf[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint16_t buflen = sizeof(buf); uint16_t buflen = sizeof(buf);
Packet *p; Packet *p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
if (p == NULL)
goto end;
FAIL_IF_NULL(p);
char sig[] = "alert tcp any any -> any any (msg:\"suricata test\"; " char sig[] = "alert tcp any any -> any any (msg:\"suricata test\"; "
"byte_jump:1,2; content:\"|00|\"; " "byte_jump:1,2; content:\"|00|\"; "
"within:1; distance:2; sid:98711212; rev:1;)"; "within:1; distance:2; sid:98711212; rev:1;)";
p->flowflags = FLOW_PKT_ESTABLISHED | FLOW_PKT_TOCLIENT; p->flowflags = FLOW_PKT_ESTABLISHED | FLOW_PKT_TOCLIENT;
result = UTHPacketMatchSig(p, sig); FAIL_IF_NOT(UTHPacketMatchSig(p, sig));
UTHFreePacket(p); UTHFreePacket(p);
end:
return result; PASS;
} }
static void DetectDistanceRegisterTests(void) static void DetectDistanceRegisterTests(void)

Loading…
Cancel
Save