Skip to content

Commit

Permalink
updating unittests in src/app-layer-htp.c to new FAIL/PASS API
Browse files Browse the repository at this point in the history
Ticket: OISF#6935
  • Loading branch information
Nancyenos committed Oct 8, 2024
1 parent 501f79c commit fd7b1e9
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions src/app-layer-htp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3070,8 +3070,7 @@ static int HTPParserTest01a(void)
memset(&ssn, 0, sizeof(ssn));

f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
if (f == NULL)
goto end;
FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP1;
Expand All @@ -3090,39 +3089,25 @@ static int HTPParserTest01a(void)
flags = STREAM_TOSERVER;

r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, flags, &httpbuf1[u], 1);
if (r != 0) {
printf("toserver chunk %" PRIu32 " returned %" PRId32 ", expected"
" 0: ", u, r);
goto end;
}
FAIL_IF(r != 0);
}

htp_state = f->alstate;
if (htp_state == NULL) {
printf("no http state: ");
goto end;
}
FAIL_IF_NULL(htp_state);

htp_tx_t *tx = HTPStateGetTx(htp_state, 0);

htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
if (strcmp(bstr_util_strdup_to_c(h->value), "Victor/1.0")
|| tx->request_method_number != HTP_M_POST ||
tx->request_protocol_number != HTP_PROTOCOL_1_0)
{
printf("expected header value: Victor/1.0 and got %s: and expected"
" method: POST and got %s, expected protocol number HTTP/1.0"
" and got: %s \n", bstr_util_strdup_to_c(h->value),
bstr_util_strdup_to_c(tx->request_method),
bstr_util_strdup_to_c(tx->request_protocol));
goto end;
}
result = 1;
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
FAIL_IF_NULL(h);

FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value), "Victor/1.0"));
FAIL_IF(tx->request_method_number != HTP_M_POST);
FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);

AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(true);
UTHFreeFlow(f);
return result;
PASS;
}

/** \test See how it deals with an incomplete request. */
Expand All @@ -3140,8 +3125,7 @@ static int HTPParserTest02(void)

f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
if (f == NULL)
goto end;
f->protoctx = &ssn;
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP1;

Expand Down

0 comments on commit fd7b1e9

Please sign in to comment.