tests: added unit test for attachment checking

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2018-02-04 10:58:35 +01:00
parent 3e22fbfd76
commit 644ff2b630
5 changed files with 108 additions and 5 deletions

View File

@ -3098,10 +3098,27 @@ tCKgKAYZGOMAqGJ1NjuiziYCE1UzaYxjfm52XZASf3ZNntqLqJw5BTfTMR2Tx/8/AGsLWCSb7+jo
AAAAAElFTkSuQmCC AAAAAElFTkSuQmCC
--b2_ajahhdddhjdhddh --b2_ajahhdddhjdhddh
Content-Type: image/jpeg; name="black.jpg" Content-Type: image/jpeg;
name="=?utf-8?B?4Lib4Lix4LiI4LiI4Lix4Lii4Liq4Liz4LiE4Lix4LiNIDUg4Lib4Lij4Liw?=
=?utf-8?B?4LiB4Liy4LijIOC4geC4seC4muC4geC4suC4o+C5gOC4hOC4peC4t+C5iA==?=
=?utf-8?B?4Lit4LiZ4LmE4Lir4Lin4LmD4LiZ4LiV4Lil4Liy4LiU4Lit4Lix4LiV4Lij?=
=?utf-8?B?4Liy4LmB4Lil4LiB4LmA4Lib4Lil4Li14LmI4Lii4LiZLuC5gOC4nuC4tA==?=
=?utf-8?B?4LmI4Lih4LmA4LiV4Li04LihLmRvY3g=?="
Content-Description: =?utf-8?B?4Lib4Lix4LiI4LiI4Lix4Lii4Liq4Liz4LiE4Lix4LiNIDUg4Lib4Lij4Liw?=
=?utf-8?B?4LiB4Liy4LijIOC4geC4seC4muC4geC4suC4o+C5gOC4hOC4peC4t+C5iA==?=
=?utf-8?B?4Lit4LiZ4LmE4Lir4Lin4LmD4LiZ4LiV4Lil4Liy4LiU4Lit4Lix4LiV4Lij?=
=?utf-8?B?4Liy4LmB4Lil4LiB4LmA4Lib4Lil4Li14LmI4Lii4LiZLuC5gOC4nuC4tA==?=
=?utf-8?B?4LmI4Lih4LmA4LiV4Li04LihLmRvY3g=?=
Content-Disposition: attachment;
filename="=?utf-8?B?4Lib4Lix4LiI4LiI4Lix4Lii4Liq4Liz4LiE4Lix4LiNIDUg4Lib4Lij4Liw?=
=?utf-8?B?4LiB4Liy4LijIOC4geC4seC4muC4geC4suC4o+C5gOC4hOC4peC4t+C5iA==?=
=?utf-8?B?4Lit4LiZ4LmE4Lir4Lin4LmD4LiZ4LiV4Lil4Liy4LiU4Lit4Lix4LiV4Lij?=
=?utf-8?B?4Liy4LmB4Lil4LiB4LmA4Lib4Lil4Li14LmI4Lii4LiZLuC5gOC4nuC4tA==?=
=?utf-8?B?4LmI4Lih4LmA4LiV4Li04LihLmRvY3g=?="; size=12345;
creation-date="Sun, 14 Jan 2018 06:24:32 GMT";
modification-date="Sun, 14 Jan 2018 06:24:32 GMT"
Content-Transfer-Encoding: base64 Content-Transfer-Encoding: base64
Content-ID: <c65e59aa31b90f70028fe927bc627ae1> Content-ID: <c65e59aa31b90f70028fe927bc627ae1>
Content-Disposition: inline; filename="black.jpg"
/9j/4SURRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA /9j/4SURRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA
agEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodpAAQAAAABAAAApAAAANAACvyA agEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodpAAQAAAABAAAApAAAANAACvyA

View File

@ -24,7 +24,7 @@ RUNNING_GROUP = `@id_bin@ -gn $(RUNNING_USER)`
INSTALL = @INSTALL@ INSTALL = @INSTALL@
all: check_parser_utils check_rules check_digest check_mydomains check_parser check_decoder check_hash check_misc smtp all: check_parser_utils check_rules check_digest check_mydomains check_parser check_decoder check_hash check_misc check_attachments smtp
check_parser_utils: check_parser_utils.c ../src/libpiler.a check_parser_utils: check_parser_utils.c ../src/libpiler.a
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR)
@ -50,6 +50,9 @@ check_hash: check_hash.c ../src/libpiler.a
check_misc: check_misc.c ../src/libpiler.a check_misc: check_misc.c ../src/libpiler.a
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR)
check_attachments: check_attachments.c ../src/libpiler.a
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR)
smtp: smtp.c ../src/libpiler.a smtp: smtp.c ../src/libpiler.a
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR)
@ -57,7 +60,7 @@ install:
@echo @echo
clean: clean:
rm -f check_parser_utils check_rules check_digest check_mydomains check_parser check_decoder check_hash check_misc smtp rm -f check_parser_utils check_rules check_digest check_mydomains check_parser check_decoder check_hash check_misc check_attachments smtp
distclean: clean distclean: clean
rm -f Makefile rm -f Makefile

View File

@ -0,0 +1,82 @@
/*
* check_attachments.c, SJ
*/
#include "test.h"
static void test_attachments(struct config *cfg){
unsigned int i;
int j;
char n_attachments[10];
struct stat st;
struct session_data sdata;
struct parser_state state;
struct data data;
struct attachments {
char s[SMALLBUFSIZE];
char *attachments[3];
int n_attachments;
};
struct attachments tests[] = {
{"1.eml", {"jatekbolt_logo.png", "ปัจจัยสำคัญ 5 ประการ กับการเคลื่อนไหวในตลาดอัตราแลกเปลี่ยน.เพิ่มเติม.docx", NULL}, 2},
{"30-subject.eml", {NULL, NULL, NULL}, 0},
};
TEST_HEADER();
snprintf(data.licence.hostname, TINYBUFSIZE-1, "yourdomain.com");
for(i=0; i<sizeof(tests)/sizeof(struct attachments); i++){
if(stat(tests[i].s, &st) != 0){
fprintf(stderr, "%s is not found, skipping\n", tests[i].s);
continue;
}
init_session_data(&sdata, cfg);
snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", tests[i].s);
snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", tests[i].s);
snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", tests[i].s);
state = parse_message(&sdata, 1, &data, cfg);
post_parse(&sdata, &state, cfg);
for(j=1; j<=state.n_attachments; j++){
unlink(state.attachments[j].internalname);
}
unlink(sdata.tmpframe);
snprintf(n_attachments, sizeof(n_attachments)-1, "%d", tests[i].n_attachments);
ASSERT(state.n_attachments == tests[i].n_attachments, n_attachments);
for(j=1; j<=state.n_attachments; j++){
ASSERT(!strcmp(tests[i].attachments[j-1], state.attachments[j].filename), tests[i].attachments[j-1]);
}
}
TEST_FOOTER();
}
int main(){
struct config cfg;
if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!");
cfg = read_config("test.conf");
setlocale(LC_MESSAGES, cfg.locale);
setlocale(LC_CTYPE, cfg.locale);
test_attachments(&cfg);
return 0;
}

View File

@ -20,7 +20,7 @@ struct digest_test {
struct digest_test tests[] = { struct digest_test tests[] = {
{"1.eml", "b675536ea7ba16adf9b19ccc2ef60351c2f82b1fa7b92fb18569bd3ba753cc60", "bcd87663be92f688d9cccb62e6e0504ee3f7cdec8e5b7679f8724bacc3b0c57f"}, {"1.eml", "7fa4f06f7085986007454b374f6685e4cf838d9e9f8878f3cba89cfe98e29f56", "bbbafb22e2d4c035584a5024e9d4feaf32172559b4d7cacc8b7af4bd548da53e"},
{"2.eml", "668cb3b91b944af786667323442576b9813d65f3cd3bc33e9d5da303c79de038", "de90475409dd6ab24e80c1b7a987715c40fe8d28d91337b7f063b477159c7b3c"}, {"2.eml", "668cb3b91b944af786667323442576b9813d65f3cd3bc33e9d5da303c79de038", "de90475409dd6ab24e80c1b7a987715c40fe8d28d91337b7f063b477159c7b3c"},
{"3.eml", "0d546d4cb4a8ce74ea5fd4cc51dbb4ebeaa7542f1c691817579da7eeab8d4771", "f585d011340d292ee52ddedb07cda662a8f1e46329d14a2ce92dca0604387bab"}, {"3.eml", "0d546d4cb4a8ce74ea5fd4cc51dbb4ebeaa7542f1c691817579da7eeab8d4771", "f585d011340d292ee52ddedb07cda662a8f1e46329d14a2ce92dca0604387bab"},
{"4.eml", "6008daed3613af4af71aa1f82550fd592d19c14c1aa7d8d5db2be1552174c518", "5f0744384bc3f96167380442c108c04a762313c79778c928ee5274981632ff45"}, {"4.eml", "6008daed3613af4af71aa1f82550fd592d19c14c1aa7d8d5db2be1552174c518", "5f0744384bc3f96167380442c108c04a762313c79778c928ee5274981632ff45"},

View File

@ -14,3 +14,4 @@ export LD_LIBRARY_PATH=../src
./check_misc ./check_misc
./check_hash ./check_hash
./check_decoder ./check_decoder
./check_attachments