2020-05-13 18:24:08 +00:00
|
|
|
/*-
|
|
|
|
* SSLsplit - transparent SSL/TLS interception
|
|
|
|
* https://www.roe.ch/SSLsplit
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017-2020, Soner Tari <sonertari@gmail.com>.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "protohttp.h"
|
|
|
|
#include "protopop3.h"
|
|
|
|
#include "protosmtp.h"
|
|
|
|
|
|
|
|
#include <check.h>
|
|
|
|
|
2020-05-14 09:07:14 +00:00
|
|
|
static void
|
|
|
|
proto_free(pxy_conn_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
global_t *global = ctx->global;
|
|
|
|
pxy_thrmgr_ctx_t *thrmgr = ctx->thrmgr;
|
|
|
|
proxyspec_t *spec = ctx->spec;
|
|
|
|
|
|
|
|
pxy_conn_ctx_free(ctx, 1);
|
|
|
|
proxyspec_free(spec);
|
|
|
|
pxy_thrmgr_free(thrmgr);
|
|
|
|
global_free(global);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to initialize further than just calling the *_new() functions,
|
|
|
|
* because the *_free() functions called in proto_free() depend on those extra
|
|
|
|
* initialization.
|
|
|
|
*/
|
2020-05-13 18:24:08 +00:00
|
|
|
static pxy_conn_ctx_t *
|
2020-05-14 09:07:14 +00:00
|
|
|
proto_init(protocol_t proto)
|
2020-05-13 18:24:08 +00:00
|
|
|
{
|
|
|
|
global_t *global = global_new();
|
2020-05-14 09:07:14 +00:00
|
|
|
|
2020-05-13 18:24:08 +00:00
|
|
|
pxy_thrmgr_ctx_t *thrmgr = pxy_thrmgr_new(global);
|
2020-05-14 09:07:14 +00:00
|
|
|
thrmgr->num_thr = 1;
|
|
|
|
thrmgr->thr = malloc(thrmgr->num_thr * sizeof(pxy_thr_ctx_t*));
|
|
|
|
memset(thrmgr->thr, 0, thrmgr->num_thr * sizeof(pxy_thr_ctx_t*));
|
|
|
|
thrmgr->thr[0] = malloc(sizeof(pxy_thr_ctx_t));
|
|
|
|
memset(thrmgr->thr[0], 0, sizeof(pxy_thr_ctx_t));
|
|
|
|
|
2020-05-15 16:13:47 +00:00
|
|
|
proxyspec_t *spec = proxyspec_new(global, "sslproxy", NULL);
|
2020-05-14 09:07:14 +00:00
|
|
|
if (proto == PROTO_HTTP) {
|
|
|
|
spec->http = 1;
|
|
|
|
} else if (proto == PROTO_POP3) {
|
|
|
|
spec->pop3 = 1;
|
|
|
|
} else if (proto == PROTO_SMTP) {
|
|
|
|
spec->smtp = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pxy_conn_ctx_t *ctx = proxy_conn_ctx_new(0, thrmgr, spec, global, 0);
|
|
|
|
pxy_thrmgr_assign_thr(ctx);
|
|
|
|
pxy_thr_attach(ctx);
|
|
|
|
|
|
|
|
return ctx;
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_01)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
http_ctx->seen_keyword_count = 1;
|
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_02)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
http_ctx->seen_keyword_count = 1;
|
2020-05-14 09:07:14 +00:00
|
|
|
http_ctx->http_method = strdup("GET");
|
2020-05-13 18:24:08 +00:00
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_03)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
2020-05-14 09:07:14 +00:00
|
|
|
http_ctx->http_method = strdup("GET");
|
2020-05-13 18:24:08 +00:00
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 0, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_04)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
2020-05-14 09:07:14 +00:00
|
|
|
http_ctx->http_method = strdup("GET1");
|
2020-05-13 18:24:08 +00:00
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 0, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_05)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
http_ctx->seen_keyword_count = 1;
|
2020-05-14 09:07:14 +00:00
|
|
|
http_ctx->http_method = strdup("GET1");
|
2020-05-13 18:24:08 +00:00
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
|
|
|
|
|
|
|
rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
|
|
|
|
2020-05-14 09:07:14 +00:00
|
|
|
free(http_ctx->http_method);
|
|
|
|
http_ctx->http_method = strdup("GET");
|
2020-05-13 18:24:08 +00:00
|
|
|
rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_06)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
http_ctx->seen_keyword_count = 1;
|
2020-05-14 09:07:14 +00:00
|
|
|
http_ctx->http_method = strdup("GET");
|
2020-05-13 18:24:08 +00:00
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
|
|
|
|
|
|
|
rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
|
|
|
|
|
|
|
// Normally we don't call protohttp_validate() if ctx->protoctx->is_valid is set,
|
|
|
|
// So both not_valid and is_valid are set.
|
|
|
|
// This is for testing purposes only.
|
2020-05-14 09:07:14 +00:00
|
|
|
free(http_ctx->http_method);
|
|
|
|
http_ctx->http_method = strdup("GET1");
|
2020-05-13 18:24:08 +00:00
|
|
|
rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 0, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_07)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
http_ctx->seen_bytes = 8193;
|
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 0, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 8193, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_08)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
http_ctx->seen_bytes = 8193;
|
|
|
|
http_ctx->seen_keyword_count = 1;
|
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 8193, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_09)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
http_ctx->seen_bytes = 8193;
|
2020-05-14 09:07:14 +00:00
|
|
|
http_ctx->http_method = strdup("GET");
|
2020-05-13 18:24:08 +00:00
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 0, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 8193, "wrong seen_bytes");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protohttp_validate_10)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_HTTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protohttp_ctx_t *http_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
http_ctx->seen_bytes = 8193;
|
|
|
|
http_ctx->seen_keyword_count = 1;
|
2020-05-14 09:07:14 +00:00
|
|
|
http_ctx->http_method = strdup("GET");
|
2020-05-13 18:24:08 +00:00
|
|
|
int rv = protohttp_validate(ctx);
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(http_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(http_ctx->seen_keyword_count == 1, "wrong seen_keyword_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
fail_unless(http_ctx->seen_bytes == 8193, "wrong seen_bytes");
|
|
|
|
|
2020-05-14 09:07:14 +00:00
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
2020-05-14 09:07:14 +00:00
|
|
|
END_TEST
|
2020-05-13 18:24:08 +00:00
|
|
|
|
|
|
|
START_TEST(protopop3_validate_01)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_POP3);
|
2020-05-13 18:24:08 +00:00
|
|
|
protopop3_ctx_t *pop3_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'C', 'A', 'P', 'A'};
|
|
|
|
int rv = protopop3_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array02[] = {'U', 'S', 'E', 'R', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protopop3_validate(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 2, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array03[] = {'P', 'A', 'S', 'S', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protopop3_validate(ctx, array03, sizeof(array03));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 3, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
|
|
|
|
// Normally we don't call protopop3_validate() if ctx->protoctx->is_valid is set,
|
|
|
|
// so pop3_ctx->seen_command_count never goes above 3.
|
|
|
|
// This is for testing purposes only.
|
|
|
|
char array04[] = {'Q', 'U', 'I', 'T'};
|
|
|
|
rv = protopop3_validate(ctx, array04, sizeof(array04));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 4, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protopop3_validate_02)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_POP3);
|
2020-05-13 18:24:08 +00:00
|
|
|
protopop3_ctx_t *pop3_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'C', 'A', 'P'};
|
|
|
|
int rv = protopop3_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protopop3_validate_03)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_POP3);
|
2020-05-13 18:24:08 +00:00
|
|
|
protopop3_ctx_t *pop3_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'C', 'A', 'P', 'A'};
|
|
|
|
int rv = protopop3_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array02[] = {'U', 'S', 'E', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protopop3_validate(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protopop3_validate_04)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_POP3);
|
2020-05-13 18:24:08 +00:00
|
|
|
protopop3_ctx_t *pop3_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'C', 'A', 'P', 'A'};
|
|
|
|
int rv = protopop3_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array02[] = {'U', 'S', 'E', 'R', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protopop3_validate(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 2, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array03[] = {'P', 'A', 'S', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protopop3_validate(ctx, array03, sizeof(array03));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 2, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protopop3_validate_05)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_POP3);
|
2020-05-13 18:24:08 +00:00
|
|
|
protopop3_ctx_t *pop3_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'C', 'A', 'P', 'A'};
|
|
|
|
int rv = protopop3_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array02[] = {'U', 'S', 'E', 'R', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protopop3_validate(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 2, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array03[] = {'P', 'A', 'S', 'S', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protopop3_validate(ctx, array03, sizeof(array03));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 3, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
|
|
|
|
// Normally we don't call protopop3_validate() if ctx->protoctx->is_valid is set,
|
|
|
|
// So both not_valid and is_valid are set.
|
|
|
|
// This is for testing purposes only.
|
|
|
|
char array04[] = {'Q', 'U', 'I'};
|
|
|
|
rv = protopop3_validate(ctx, array04, sizeof(array04));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 3, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
|
|
|
|
// Again, this is for testing purposes only.
|
|
|
|
rv = protopop3_validate(ctx, array04, sizeof(array04));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 3, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protopop3_validate_06)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_POP3);
|
2020-05-13 18:24:08 +00:00
|
|
|
protopop3_ctx_t *pop3_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'C', 'A', 'P'};
|
|
|
|
int rv = protopop3_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
rv = protopop3_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(pop3_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(pop3_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
2020-05-14 09:07:14 +00:00
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
2020-05-14 09:07:14 +00:00
|
|
|
END_TEST
|
2020-05-13 18:24:08 +00:00
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_01)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'E', 'H', 'L', 'O'};
|
|
|
|
int rv = protosmtp_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array02[] = {'A', 'U', 'T', 'H', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protosmtp_validate(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 2, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array03[] = {'M', 'A', 'I', 'L', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protosmtp_validate(ctx, array03, sizeof(array03));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 3, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
|
|
|
|
// Normally we don't call protosmtp_validate() if ctx->protoctx->is_valid is set,
|
|
|
|
// so smtp_ctx->seen_command_count never goes above 3.
|
|
|
|
// This is for testing purposes only.
|
|
|
|
char array04[] = {'Q', 'U', 'I', 'T'};
|
|
|
|
rv = protosmtp_validate(ctx, array04, sizeof(array04));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 4, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_02)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'E', 'H', 'L'};
|
|
|
|
int rv = protosmtp_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_03)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'E', 'H', 'L', 'O'};
|
|
|
|
int rv = protosmtp_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array02[] = {'A', 'U', 'T', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protosmtp_validate(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_04)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'E', 'H', 'L', 'O'};
|
|
|
|
int rv = protosmtp_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array02[] = {'A', 'U', 'T', 'H', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protosmtp_validate(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 2, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array03[] = {'M', 'A', 'I', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protosmtp_validate(ctx, array03, sizeof(array03));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 2, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_05)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'E', 'H', 'L', 'O'};
|
|
|
|
int rv = protosmtp_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 1, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array02[] = {'A', 'U', 'T', 'H', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protosmtp_validate(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 2, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
char array03[] = {'M', 'A', 'I', 'L', ' ', 's', 'o', 'n', 'e', 'r'};
|
|
|
|
rv = protosmtp_validate(ctx, array03, sizeof(array03));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 3, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
|
|
|
|
// Normally we don't call protosmtp_validate() if ctx->protoctx->is_valid is set,
|
|
|
|
// So both not_valid and is_valid are set.
|
|
|
|
// This is for testing purposes only.
|
|
|
|
char array04[] = {'Q', 'U', 'I'};
|
|
|
|
rv = protosmtp_validate(ctx, array04, sizeof(array04));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 3, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
|
|
|
|
|
|
|
// Again, this is for testing purposes only.
|
|
|
|
rv = protosmtp_validate(ctx, array04, sizeof(array04));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 3, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 1, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_06)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'E', 'H', 'L'};
|
|
|
|
int rv = protosmtp_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
rv = protosmtp_validate(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_response_01)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'2', '2', '0', ' ', 's', 'm', 't', 'p'};
|
|
|
|
int rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_response_02)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'1', '9', '9', ' ', 's', 'm', 't', 'p'};
|
|
|
|
int rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_response_03)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'6', '0', '0', ' ', 's', 'm', 't', 'p'};
|
|
|
|
int rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_response_04)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'2', '2', '0', ' ', 's', 'm', 't', 'p'};
|
|
|
|
int rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
// Normally we don't call protosmtp_validate_response() more than once.
|
|
|
|
// This is for testing purposes only.
|
|
|
|
fail_unless(rv == 0, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 0, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
// Normally we don't call protosmtp_validate_response() more than once,
|
|
|
|
// but smtp_ctx->not_valid should be set to 1.
|
|
|
|
// This is for testing purposes only.
|
|
|
|
char array02[] = {'1', '9', '9', ' ', 's', 'm', 't', 'p'};
|
|
|
|
rv = protosmtp_validate_response(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_response_05)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'1', '9', '9', ' ', 's', 'm', 't', 'p'};
|
|
|
|
int rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
// Normally we don't call protosmtp_validate_response() more than once.
|
|
|
|
// This is for testing purposes only.
|
|
|
|
rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
|
|
|
|
|
|
|
// Normally we don't call protosmtp_validate_response() more than once,
|
|
|
|
// but smtp_ctx->not_valid should remain 1.
|
|
|
|
// This is for testing purposes only.
|
|
|
|
char array02[] = {'2', '2', '0', ' ', 's', 'm', 't', 'p'};
|
|
|
|
rv = protosmtp_validate_response(ctx, array02, sizeof(array02));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_response_06)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'2', '2', '0', '0', ' ', 's', 'm', 't', 'p'};
|
|
|
|
int rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_response_07)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
|
|
|
char array01[] = {'1', '9', '9', '9', ' ', 's', 'm', 't', 'p'};
|
|
|
|
int rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(protosmtp_validate_response_08)
|
|
|
|
{
|
2020-05-14 09:07:14 +00:00
|
|
|
pxy_conn_ctx_t *ctx = proto_init(PROTO_SMTP);
|
2020-05-13 18:24:08 +00:00
|
|
|
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
|
|
|
|
|
2020-05-15 16:13:47 +00:00
|
|
|
char array01[] = {'6', '0', '0', '0', ' ', 's', 'm', 't', 'p'};
|
2020-05-13 18:24:08 +00:00
|
|
|
int rv = protosmtp_validate_response(ctx, array01, sizeof(array01));
|
|
|
|
|
|
|
|
fail_unless(rv == -1, "wrong return value");
|
|
|
|
fail_unless(smtp_ctx->not_valid == 1, "wrong not_valid");
|
|
|
|
fail_unless(smtp_ctx->seen_command_count == 0, "wrong seen_command_count");
|
|
|
|
fail_unless(ctx->protoctx->is_valid == 0, "wrong is_valid");
|
2020-05-14 09:07:14 +00:00
|
|
|
|
|
|
|
proto_free(ctx);
|
2020-05-13 18:24:08 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
Suite *
|
|
|
|
proto_suite(void)
|
|
|
|
{
|
|
|
|
Suite *s;
|
|
|
|
TCase *tc;
|
|
|
|
|
|
|
|
s = suite_create("proto");
|
|
|
|
|
|
|
|
tc = tcase_create("protohttp_validate");
|
|
|
|
tcase_add_test(tc, protohttp_validate_01);
|
|
|
|
tcase_add_test(tc, protohttp_validate_02);
|
|
|
|
tcase_add_test(tc, protohttp_validate_03);
|
|
|
|
tcase_add_test(tc, protohttp_validate_04);
|
|
|
|
tcase_add_test(tc, protohttp_validate_05);
|
|
|
|
tcase_add_test(tc, protohttp_validate_06);
|
|
|
|
tcase_add_test(tc, protohttp_validate_07);
|
|
|
|
tcase_add_test(tc, protohttp_validate_08);
|
|
|
|
tcase_add_test(tc, protohttp_validate_09);
|
|
|
|
tcase_add_test(tc, protohttp_validate_10);
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
tc = tcase_create("protopop3_validate");
|
|
|
|
tcase_add_test(tc, protopop3_validate_01);
|
|
|
|
tcase_add_test(tc, protopop3_validate_02);
|
|
|
|
tcase_add_test(tc, protopop3_validate_03);
|
|
|
|
tcase_add_test(tc, protopop3_validate_04);
|
|
|
|
tcase_add_test(tc, protopop3_validate_05);
|
|
|
|
tcase_add_test(tc, protopop3_validate_06);
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
tc = tcase_create("protosmtp_validate");
|
|
|
|
tcase_add_test(tc, protosmtp_validate_01);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_02);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_03);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_04);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_05);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_06);
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
tc = tcase_create("protosmtp_validate_response");
|
|
|
|
tcase_add_test(tc, protosmtp_validate_response_01);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_response_02);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_response_03);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_response_04);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_response_05);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_response_06);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_response_07);
|
|
|
|
tcase_add_test(tc, protosmtp_validate_response_08);
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set noet ft=c: */
|