#ifdef UNITTESTS
static int HTPFileParserTest01(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
HtpState *http_state = NULL;
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 <<<<\n");
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, http_state, 0);
- if (tx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(tx);
+ FAIL_IF_NULL(tx->request_method);
- if (tx->request_method == NULL || memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0)
- {
- printf("expected method POST, got %s \n", bstr_util_strdup_to_c(tx->request_method));
- goto end;
- }
+ FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
static int HTPFileParserTest02(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 <<<<\n");
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf3, httplen3);
- if (r != 0) {
- printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
- if (r != 0) {
- printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, http_state, 0);
- if (tx == NULL) {
- goto end;
- }
-
- if (tx->request_method == NULL || memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0)
- {
- printf("expected method POST, got %s \n", bstr_util_strdup_to_c(tx->request_method));
- goto end;
- }
-
- if (http_state->files_ts == NULL || http_state->files_ts->tail == NULL ||
- http_state->files_ts->tail->state != FILE_STATE_CLOSED) {
- goto end;
- }
-
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ FAIL_IF_NULL(tx);
+ FAIL_IF_NULL(tx->request_method);
+ FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0);
+ FAIL_IF_NULL(http_state->files_ts);
+ FAIL_IF_NULL(http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->tail->state != FILE_STATE_CLOSED);
+
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
static int HTPFileParserTest03(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 <<<<\n");
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf3, httplen3);
- if (r != 0) {
- printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
- if (r != 0) {
- printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf5, httplen5);
- if (r != 0) {
- printf("toserver chunk 5 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf6, httplen6);
- if (r != 0) {
- printf("toserver chunk 6 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, http_state, 0);
- if (tx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(tx);
+ FAIL_IF_NULL(tx->request_method);
- if (tx->request_method == NULL || memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0)
- {
- printf("expected method POST, got %s \n", bstr_util_strdup_to_c(tx->request_method));
- goto end;
- }
+ FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0);
- if (http_state->files_ts == NULL || http_state->files_ts->tail == NULL ||
- http_state->files_ts->tail->state != FILE_STATE_CLOSED) {
- goto end;
- }
-
- if (http_state->files_ts->head == NULL ||
- FileDataSize(http_state->files_ts->head) != 11)
- {
- if (http_state->files_ts->head != NULL)
- printf("filedata len not 11 but %"PRIu64": ",
- FileDataSize(http_state->files_ts->head));
- goto end;
- }
+ FAIL_IF_NULL(http_state->files_ts);
+ FAIL_IF_NULL(http_state->files_ts->head);
+ FAIL_IF_NULL(http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->tail->state != FILE_STATE_CLOSED);
+ FAIL_IF(FileDataSize(http_state->files_ts->head) != 11);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
static int HTPFileParserTest04(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 <<<<\n");
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf3, httplen3);
- if (r != 0) {
- printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
- if (r != 0) {
- printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf5, httplen5);
- if (r != 0) {
- printf("toserver chunk 5 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf6, httplen6);
- if (r != 0) {
- printf("toserver chunk 6 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, http_state, 0);
- if (tx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(tx);
+ FAIL_IF_NULL(tx->request_method);
- if (tx->request_method == NULL || memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0)
- {
- printf("expected method POST, got %s: ", bstr_util_strdup_to_c(tx->request_method));
- goto end;
- }
+ FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0);
- if (http_state->files_ts == NULL || http_state->files_ts->tail == NULL ||
- http_state->files_ts->tail->state != FILE_STATE_CLOSED) {
- goto end;
- }
+ FAIL_IF_NULL(http_state->files_ts);
+ FAIL_IF_NULL(http_state->files_ts->head);
+ FAIL_IF_NULL(http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->tail->state != FILE_STATE_CLOSED);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
static int HTPFileParserTest05(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, http_state, 0);
- if (tx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(tx);
+ FAIL_IF_NULL(tx->request_method);
- if (tx->request_method == NULL || memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0)
- {
- printf("expected method POST, got %s \n", bstr_util_strdup_to_c(tx->request_method));
- goto end;
- }
+ FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0);
- if (http_state->files_ts == NULL || http_state->files_ts->tail == NULL ||
- http_state->files_ts->tail->state != FILE_STATE_CLOSED) {
- goto end;
- }
-
- if (http_state->files_ts->head == http_state->files_ts->tail)
- goto end;
+ FAIL_IF_NULL(http_state->files_ts);
+ FAIL_IF_NULL(http_state->files_ts->head);
+ FAIL_IF_NULL(http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->tail->state != FILE_STATE_CLOSED);
- if (http_state->files_ts->head->next != http_state->files_ts->tail)
- goto end;
-
- if (StreamingBufferCompareRawData(http_state->files_ts->head->sb,
- (uint8_t *)"filecontent", 11) != 1)
- {
- goto end;
- }
+ FAIL_IF(http_state->files_ts->head == http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->head->next != http_state->files_ts->tail);
- if (StreamingBufferCompareRawData(http_state->files_ts->tail->sb,
- (uint8_t *)"FILECONTENT", 11) != 1)
- {
- goto end;
- }
+ FAIL_IF(StreamingBufferCompareRawData(http_state->files_ts->head->sb,
+ (uint8_t *)"filecontent", 11) != 1);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ FAIL_IF(StreamingBufferCompareRawData(http_state->files_ts->tail->sb,
+ (uint8_t *)"FILECONTENT", 11) != 1);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
/** \test first multipart part contains file but doesn't end in first chunk */
static int HTPFileParserTest06(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, http_state, 0);
- if (tx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(tx);
+ FAIL_IF_NULL(tx->request_method);
- if (tx->request_method == NULL || memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0)
- {
- printf("expected method POST, got %s \n", bstr_util_strdup_to_c(tx->request_method));
- goto end;
- }
+ FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0);
- if (http_state->files_ts == NULL || http_state->files_ts->tail == NULL ||
- http_state->files_ts->tail->state != FILE_STATE_CLOSED) {
- goto end;
- }
+ FAIL_IF_NULL(http_state->files_ts);
+ FAIL_IF_NULL(http_state->files_ts->head);
+ FAIL_IF_NULL(http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->tail->state != FILE_STATE_CLOSED);
- if (http_state->files_ts->head == http_state->files_ts->tail)
- goto end;
+ FAIL_IF(http_state->files_ts->head == http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->head->next != http_state->files_ts->tail);
- if (http_state->files_ts->head->next != http_state->files_ts->tail)
- goto end;
+ FAIL_IF(StreamingBufferCompareRawData(http_state->files_ts->head->sb,
+ (uint8_t *)"filecontent", 11) != 1);
- if (StreamingBufferCompareRawData(http_state->files_ts->head->sb,
- (uint8_t *)"filecontent", 11) != 1)
- {
- goto end;
- }
-
- if (StreamingBufferCompareRawData(http_state->files_ts->tail->sb,
- (uint8_t *)"FILECONTENT", 11) != 1)
- {
- goto end;
- }
+ FAIL_IF(StreamingBufferCompareRawData(http_state->files_ts->tail->sb,
+ (uint8_t *)"FILECONTENT", 11) != 1);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
/** \test POST, but not multipart */
static int HTPFileParserTest07(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /filename HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Length: 11\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, http_state, 0);
- if (tx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(tx);
+ FAIL_IF_NULL(tx->request_method);
+ FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0);
- if (tx->request_method == NULL || memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0)
- {
- printf("expected method POST, got %s \n", bstr_util_strdup_to_c(tx->request_method));
- goto end;
- }
+ FAIL_IF_NULL(http_state->files_ts);
+ FAIL_IF_NULL(http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->tail->state != FILE_STATE_CLOSED);
- if (http_state->files_ts == NULL || http_state->files_ts->tail == NULL ||
- http_state->files_ts->tail->state != FILE_STATE_CLOSED) {
- printf("state != FILE_STATE_CLOSED");
- goto end;
- }
+ FAIL_IF(StreamingBufferCompareRawData(http_state->files_ts->tail->sb,
+ (uint8_t *)"FILECONTENT", 11) != 1);
- if (StreamingBufferCompareRawData(http_state->files_ts->tail->sb,
- (uint8_t *)"FILECONTENT", 11) != 1)
- {
- goto end;
- }
-
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
static int HTPFileParserTest08(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
HtpState *http_state = NULL;
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 <<<<\n");
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
- FLOWLOCK_WRLOCK(f);
void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP,f->alstate, 0);
+ FAIL_IF_NULL(tx);
+
AppLayerDecoderEvents *decoder_events = AppLayerParserGetEventsByTx(IPPROTO_TCP, ALPROTO_HTTP, tx);
- if (decoder_events == NULL) {
- printf("no app events: ");
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NULL(decoder_events);
- if (decoder_events->cnt != 2) {
- printf("expected 2 events: ");
- goto end;
- }
+ FAIL_IF(decoder_events->cnt != 2);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
/** \test invalid header: Somereallylongheaderstr: has no value */
static int HTPFileParserTest09(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 <<<<\n");
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf3, httplen3);
- if (r != 0) {
- printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
- if (r != 0) {
- printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
- FLOWLOCK_WRLOCK(f);
void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP,f->alstate, 0);
+ FAIL_IF_NULL(tx);
+
AppLayerDecoderEvents *decoder_events = AppLayerParserGetEventsByTx(IPPROTO_TCP, ALPROTO_HTTP, tx);
- if (decoder_events == NULL) {
- printf("no app events: ");
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NULL(decoder_events);
- if (decoder_events->cnt != 1) {
- printf("expected 1 event: ");
- goto end;
- }
+ FAIL_IF(decoder_events->cnt != 1);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
/** \test empty entries */
static int HTPFileParserTest10(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 <<<<\n");
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf3, httplen3);
- if (r != 0) {
- printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
- if (r != 0) {
- printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
- result = 0;
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- result = 0;
- goto end;
- }
+ FAIL_IF_NULL(http_state);
- FLOWLOCK_WRLOCK(f);
void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP,f->alstate, 0);
+ FAIL_IF_NULL(tx);
AppLayerDecoderEvents *decoder_events = AppLayerParserGetEventsByTx(IPPROTO_TCP, ALPROTO_HTTP, tx);
- if (decoder_events != NULL) {
- printf("app events: ");
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT_NULL(decoder_events);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
/** \test filedata cut in two pieces */
static int HTPFileParserTest11(void)
{
- int result = 0;
- Flow *f = NULL;
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
"Host: www.server.lan\r\n"
"Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
memset(&ssn, 0, sizeof(ssn));
- f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
- if (f == NULL)
- goto end;
+ Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
+ FAIL_IF_NULL(f);
f->protoctx = &ssn;
f->proto = IPPROTO_TCP;
f->alproto = ALPROTO_HTTP;
StreamTcpInitConfig(TRUE);
SCLogDebug("\n>>>> processing chunk 1 <<<<\n");
- FLOWLOCK_WRLOCK(f);
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_START, httpbuf1,
httplen1);
- if (r != 0) {
- printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP, STREAM_TOSERVER,
httpbuf2, httplen2);
- if (r != 0) {
- printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP, STREAM_TOSERVER,
httpbuf3, httplen3);
- if (r != 0) {
- printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
SCLogDebug("\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
- FLOWLOCK_WRLOCK(f);
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP,
STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
- if (r != 0) {
- printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT(r == 0);
http_state = f->alstate;
- if (http_state == NULL) {
- printf("no http state: ");
- goto end;
- }
+ FAIL_IF_NULL(http_state);
- FLOWLOCK_WRLOCK(f);
void *txtmp = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP,f->alstate, 0);
+ FAIL_IF_NULL(txtmp);
+
AppLayerDecoderEvents *decoder_events = AppLayerParserGetEventsByTx(IPPROTO_TCP, ALPROTO_HTTP, txtmp);
- if (decoder_events != NULL) {
- printf("app events: ");
- FLOWLOCK_UNLOCK(f);
- goto end;
- }
- FLOWLOCK_UNLOCK(f);
+ FAIL_IF_NOT_NULL(decoder_events);
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, http_state, 0);
- if (tx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(tx);
+ FAIL_IF_NULL(tx->request_method);
- if (tx->request_method == NULL || memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0)
- {
- printf("expected method POST, got %s \n", bstr_util_strdup_to_c(tx->request_method));
- goto end;
- }
+ FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method), "POST", 4) != 0);
- if (http_state->files_ts == NULL || http_state->files_ts->tail == NULL ||
- http_state->files_ts->tail->state != FILE_STATE_CLOSED) {
- printf("state != FILE_STATE_CLOSED: ");
- goto end;
- }
+ FAIL_IF_NULL(http_state->files_ts);
+ FAIL_IF_NULL(http_state->files_ts->tail);
+ FAIL_IF(http_state->files_ts->tail->state != FILE_STATE_CLOSED);
- if (StreamingBufferCompareRawData(http_state->files_ts->head->sb,
- (uint8_t *)"FILECONTENT", 11) != 1)
- {
- goto end;
- }
+ FAIL_IF(StreamingBufferCompareRawData(http_state->files_ts->tail->sb,
+ (uint8_t *)"FILECONTENT", 11) != 1);
- result = 1;
-end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
StreamTcpFreeConfig(TRUE);
UTHFreeFlow(f);
- return result;
+ PASS;
}
void AppLayerHtpFileRegisterTests (void);