added a few unit tests

This commit is contained in:
SJ 2015-11-27 12:17:19 +01:00
parent 045068fe3c
commit b0c97aa129
8 changed files with 378 additions and 18 deletions

6
configure vendored
View File

@ -3490,7 +3490,7 @@ fi
echo "\"Configure command: ./configure $PARAMS\"" >> $CONFIGURE_PARAMS_FILE echo "\"Configure command: ./configure $PARAMS\"" >> $CONFIGURE_PARAMS_FILE
SUBDIRS="src etc util init.d test" SUBDIRS="src etc util init.d unit_tests"
@ -4891,7 +4891,7 @@ CFLAGS="$static -O2 -Wall -g"
LIBS="$antispam_libs $sunos_libs " LIBS="$antispam_libs $sunos_libs "
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o $objs" OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o $objs"
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile" ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile unit_tests/Makefile contrib/imap/Makefile"
cat >confcache <<\_ACEOF cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure # This file is a shell script that caches the results of configure
@ -5589,7 +5589,7 @@ do
"etc/Makefile") CONFIG_FILES="$CONFIG_FILES etc/Makefile" ;; "etc/Makefile") CONFIG_FILES="$CONFIG_FILES etc/Makefile" ;;
"util/Makefile") CONFIG_FILES="$CONFIG_FILES util/Makefile" ;; "util/Makefile") CONFIG_FILES="$CONFIG_FILES util/Makefile" ;;
"init.d/Makefile") CONFIG_FILES="$CONFIG_FILES init.d/Makefile" ;; "init.d/Makefile") CONFIG_FILES="$CONFIG_FILES init.d/Makefile" ;;
"test/Makefile") CONFIG_FILES="$CONFIG_FILES test/Makefile" ;; "unit_tests/Makefile") CONFIG_FILES="$CONFIG_FILES unit_tests/Makefile" ;;
"contrib/imap/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/imap/Makefile" ;; "contrib/imap/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/imap/Makefile" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;

View File

@ -86,7 +86,7 @@ fi
echo "\"Configure command: ./configure $PARAMS\"" >> $CONFIGURE_PARAMS_FILE echo "\"Configure command: ./configure $PARAMS\"" >> $CONFIGURE_PARAMS_FILE
SUBDIRS="src etc util init.d test" SUBDIRS="src etc util init.d unit_tests"
dnl static build dnl static build
@ -558,7 +558,7 @@ CFLAGS="$static -O2 -Wall -g"
LIBS="$antispam_libs $sunos_libs " LIBS="$antispam_libs $sunos_libs "
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o $objs" OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o $objs"
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile]) AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile unit_tests/Makefile contrib/imap/Makefile])
AC_OUTPUT AC_OUTPUT

View File

@ -679,7 +679,7 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
strncat(puf, " ", sizeof(puf)-1); strncat(puf, " ", sizeof(puf)-1);
if(strncasecmp(puf, "http://", 7) == 0 || strncasecmp(puf, "https://", 8) == 0) fixURL(puf); if(strncasecmp(puf, "http://", 7) == 0 || strncasecmp(puf, "https://", 8) == 0) fixURL(puf, sizeof(puf)-1);
if(state->is_header == 0 && strncmp(puf, "__URL__", 7) && (puf[0] == ' ' || (strlen(puf) > MAX_WORD_LEN && cfg->enable_cjk == 0) || isHexNumber(puf)) ) continue; if(state->is_header == 0 && strncmp(puf, "__URL__", 7) && (puf[0] == ' ' || (strlen(puf) > MAX_WORD_LEN && cfg->enable_cjk == 0) || isHexNumber(puf)) ) continue;

View File

@ -28,8 +28,8 @@ void split_email_address(char *s);
int does_it_seem_like_an_email_address(char *email); int does_it_seem_like_an_email_address(char *email);
void reassembleToken(char *p); void reassembleToken(char *p);
void degenerateToken(unsigned char *p); void degenerateToken(unsigned char *p);
void fixURL(char *url); void fixURL(char *buf, int buflen);
int extractNameFromHeaderLine(char *s, char *name, char *resultbuf); void extractNameFromHeaderLine(char *s, char *name, char *resultbuf);
char *determine_attachment_type(char *filename, char *type); char *determine_attachment_type(char *filename, char *type);
char *get_attachment_extractor_by_filename(char *filename); char *get_attachment_extractor_by_filename(char *filename);
void parse_reference(struct parser_state *state, char *s); void parse_reference(struct parser_state *state, char *s);

View File

@ -723,18 +723,18 @@ void degenerateToken(unsigned char *p){
} }
void fixURL(char *url){ void fixURL(char *buf, int buflen){
int len=0; int len=0;
char *p, *q, fixed_url[SMALLBUFSIZE]; char *p, *q, fixed_url[SMALLBUFSIZE];
if(strlen(url) < 3) return; if(strlen(buf) < 3) return;
memset(fixed_url, 0, sizeof(fixed_url)); memset(fixed_url, 0, sizeof(fixed_url));
p = url; p = buf;
if(strncasecmp(url, "http://", 7) == 0) p += 7; if(strncasecmp(buf, "http://", 7) == 0) p += 7;
if(strncasecmp(url, "https://", 8) == 0) p += 8; if(strncasecmp(buf, "https://", 8) == 0) p += 8;
q = strchr(p, '/'); q = strchr(p, '/');
if(q) *q = '\0'; if(q) *q = '\0';
@ -748,12 +748,12 @@ void fixURL(char *url){
fixed_url[len-1] = '\0'; fixed_url[len-1] = '\0';
} }
strcpy(url, fixed_url); snprintf(buf, buflen, "%s", fixed_url);
} }
int extractNameFromHeaderLine(char *s, char *name, char *resultbuf){ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf){
int rc=0, extended=0; int extended=0;
char buf[SMALLBUFSIZE], puf[SMALLBUFSIZE], *p, *q, *encoding; char buf[SMALLBUFSIZE], puf[SMALLBUFSIZE], *p, *q, *encoding;
snprintf(buf, sizeof(buf)-1, "%s", s); snprintf(buf, sizeof(buf)-1, "%s", s);
@ -826,11 +826,9 @@ int extractNameFromHeaderLine(char *s, char *name, char *resultbuf){
snprintf(resultbuf, TINYBUFSIZE-1, "%s", puf); snprintf(resultbuf, TINYBUFSIZE-1, "%s", puf);
} }
rc = 1;
} }
} }
return rc;
} }

36
unit_tests/Makefile.in Normal file
View File

@ -0,0 +1,36 @@
SHELL = @SHELL@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
includedir = @includedir@
libdir = @libdir@
libexecdir = @libexecdir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
mandir = @mandir@
datarootdir = @datarootdir@
localstatedir = @localstatedir@
CC = @CC@
CFLAGS = @CFLAGS@ @CPPFLAGS@
DEFS = @defs@
INCDIR = -I. -I.. -I../.. -I../../src -I../src @INCDIR@ @sql_includes@
LIBDIR = -L. @LIBDIR@ @LDFLAGS@ -L../src
LIBS = @LIBS@ @sql_libs@
RUNNING_USER = @RUNNING_USER@
RUNNING_GROUP = `@id_bin@ -gn $(RUNNING_USER)`
INSTALL = @INSTALL@
all: check_parser_utils
check_parser_utils: check_parser_utils.c ../src/libpiler.a
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR)
clean:
rm -f check_parser_utils
distclean: clean
rm -f Makefile

View File

@ -0,0 +1,285 @@
/*
* check_parser_utils.c, SJ
*/
#include <stdio.h>
#include <locale.h>
#include <stdbool.h>
#include <assert.h>
#include "../src/piler.h"
struct date_test {
char date_str[SMALLBUFSIZE];
time_t timestamp;
};
struct name_from_header_test {
char line[SMALLBUFSIZE];
char *token;
char *expected_result;
};
struct str_pair {
char line[SMALLBUFSIZE];
char *expected_result;
};
static void test_parse_date_header(){
int i;
struct __config cfg;
struct date_test date_test[] = {
{"Date: Mon, 02 Nov 2015 09:39:31 -0000", 1446457171},
{"Date: Mon, 2 Nov 2015 10:39:45 +0100", 1446457185},
{"Date: Sun, 1 Nov 2015 17:23:07 +0100 (CET)", 1446394987},
{"Date: 3 Nov 2015 15:19:30 +0100", 1446560370},
{"Date: Mon, 3 Feb 2014 13:21:07 +0100", 1391430067},
{"Date: Sat, 4 Aug 2007 13:36:52 GMT-0700", 1186256212},
{"Date: Sat, 4 Aug 07 13:36:52 GMT-0700", 1186256212},
{"Date: 16 Dec 07 20:45:52", 1197837952},
{"Date: 03 Jun 06 05:59:00 +0100", 1149307140},
{"Date: 30.06.2005 17:47:42", 1120150062},
{"Date: 03-Feb-2014 08:09:10", 1391414950},
{"Date: 13 Mar 2013 14:56:02 UTC", 1363186562}
};
cfg = read_config("test.conf");
setlocale(LC_MESSAGES, cfg.locale);
setlocale(LC_CTYPE, cfg.locale);
for(i=0; i<sizeof(date_test)/sizeof(struct date_test); i++){
assert(parse_date_header(date_test[i].date_str, &cfg) == date_test[i].timestamp && "test_parse_date_header()");
}
printf("test_parse_date_header() OK\n");
}
static void test_extractNameFromHeaderLine(){
int i;
char resultbuf[SMALLBUFSIZE];
struct name_from_header_test name_from_header_test[] = {
{"Content-Type: text/plain; charset=UTF-8", "charset", "UTF-8"},
{"Content-Type: text/plain; charset=\"utf-8\"", "charset", "utf-8"},
{"Content-Type: text/plain; charset=us-ascii", "charset", "us-ascii"},
{"Content-Type: text/plain; charset=\"iso-8859-2\"", "charset", "iso-8859-2"},
{"Content-Type: text/calendar; method=REQUEST; charset=\"utf-8\"", "charset", "utf-8"},
{"Content-Type: text/plain; charset=\"utf-8\"; format=flowed", "charset", "utf-8"},
{"Content-Type: text/calendar; charset=\"utf-8\"; method=CANCEL", "charset", "utf-8"},
{"Content-Type: text/plain; format=flowed; charset=\"US-ASCII\"", "charset", "US-ASCII"},
{"Content-Type: text/plain; charset=\"UTF-8\"; format=flowed", "charset", "UTF-8"},
{"Content-Type: multipart/alternative; charset=\"UTF-8\"; boundary=\"b1_8c387891290303ff3c6ca75c8e238b54\"", "charset", "UTF-8"},
{"Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII", "charset", "US-ASCII"},
{"Content-Type: message/delivery-status; name=\"Delivery report\"", "name", "Delivery report"},
{"Content-Disposition: attachment; filename=\"Delivery report\"; size=1193;", "name", "Delivery report"},
{"Content-Disposition: attachment; filename=\"AAAAA_ABC_150924.xls\"", "name", "AAAAA_ABC_150924.xls"},
{"Content-Type: image/jpeg; name=\"image001.jpg\"", "name", "image001.jpg"},
{"Content-Disposition: inline; filename=\"image001.jpg\"; size=5403;", "name", "image001.jpg"},
{"Content-Type: application/octet-stream; name=xxxxxDrRestoreGUI.log", "name", "xxxxxDrRestoreGUI.log"},
{"Content-Disposition: inline; filename=\"Legjobb_Munkahely_Felmeres_2012.jpg\"", "name", "Legjobb_Munkahely_Felmeres_2012.jpg"},
{"Content-Type: image/png; name=\"=?iso-8859-2?Q?N=E9vtelen.png?=\"", "name", "Névtelen.png"},
{"Content-Type: application/msword; name=", "name", ""},
{"Content-Disposition: attachment; filename=", "name", ""},
{"Content-Disposition: attachment; filename=\"NDA - Suto - 20151109.pdf\";", "name", "NDA - Suto - 20151109.pdf"},
{"Content-Type: image/png; name=\"Screenshot from 2015-11-10 10:07:13.png\"", "name", "Screenshot from 2015-11-10 10:07:13.png"},
{"Content-Disposition: attachment; filename=\"zzzzz Email Examples.zip\";", "name", "zzzzz Email Examples.zip"},
{"foo: bar; title=Economy", "title", "Economy"},
{"foo: bar; title=\"US-$ rates\"", "title", "US-$ rates"},
{"foo: bar; title*=iso-8859-1'en'%A3%20rates", "title", "£ rates"},
{"foo: bar; title*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates", "title", "£ and € rates"}
};
for(i=0; i<sizeof(name_from_header_test)/sizeof(struct name_from_header_test); i++){
extractNameFromHeaderLine(name_from_header_test[i].line, name_from_header_test[i].token, resultbuf);
assert(strcmp(resultbuf, name_from_header_test[i].expected_result) == 0 && "test_extractNameFromHeaderLine");
}
printf("test_extractNameFromHeaderLine() OK\n");
}
static void test_fixupEncodedHeaderLine(){
int i;
char buf[SMALLBUFSIZE];
struct str_pair pair[] = {
{"=?utf-8?Q?Tanjoubi,_azaz_sz=C3=BClet=C3=A9snap!_10_=C3=A9ves_az_I_Love_Su?= =?utf-8?Q?shi!?=", "Tanjoubi, azaz születésnap! 10 éves az I Love Su shi!"},
{"=?UTF-8?Q?IAM:_N2YPF_-_#1_Request_new_privilege?=", "IAM: N2YPF - #1 Request new privilege"},
{"=?UTF-8?B?SG9neWFuIMOtcmp1bmsgcGFuYXN6bGV2ZWxldD8=?=", "Hogyan írjunk panaszlevelet?"},
{"Re: [Bitbucket] Issue #627: ldap user can't login (jsuto/piler)", "Re: [Bitbucket] Issue #627: ldap user can't login (jsuto/piler)"},
{"=?iso-8859-2?Q?RE:_test.aaa.fu_z=F3na?=", "RE: test.aaa.fu zóna"},
{"=?iso-8859-2?Q?V=E1ltoz=E1s_az_IT_szervezetben_/_Personal_changes_in_the_?=", "Változás az IT szervezetben / Personal changes in the "},
{"Re: AAAmil /29 UZ736363", "Re: AAAmil /29 UZ736363"},
{"=?UTF-8?Q?[JIRA]_Created:_(HUDSS-196)_T=C5=B1zfal_?=", "[JIRA] Created: (HUDSS-196) Tűzfal "},
{"=?iso-8859-2?Q?RE:_Baptista_Szeretetszolg=E1lat?=", "RE: Baptista Szeretetszolgálat"},
{"=?iso-8859-2?B?SXR0IGF6IE1OQiBuYWd5IGRvYuFzYTogaXNt6XQgYmVsZW55+mxuYWsgYSBoaXRlbGV66XNiZSAoMjAxNS4xMS4wMy4gLSBzakBhY3RzLmh1KQ==?=", "Itt az MNB nagy dobása: ismét belenyúlnak a hitelezésbe (2015.11.03. - sj@acts.hu)"},
{"=?UTF-8?B?TGludXggQURNSU4gaG96esOhZsOpcsOpc2Vr?=", "Linux ADMIN hozzáférések"},
{"Burn 14 Calories a Minute with This Workout!", "Burn 14 Calories a Minute with This Workout!"},
{"=?utf-8?Q?Help=20Net=20Security=20Newsletter=20=2D=20=20November=203rd=202015?=", "Help Net Security Newsletter - November 3rd 2015"},
{"=?ISO-8859-2?Q?Re=3A_kimen=F5_levelez=E9si_probl=E9ma_-_cscs=40aaaaa=2Efu?=", "Re: kimenő levelezési probléma - cscs@aaaaa.fu"},
{"Re: cccc@aaa.fu - e-mail =?UTF-8?B?a8OpcmTDqXM=?=", "Re: cccc@aaa.fu - e-mail kérdés"},
{"=?WINDOWS-1250?Q?<AZ-17226/1-2015>=20www.xxxxx.com=20new=20virtual=20?=", "<AZ-17226/1-2015> www.xxxxx.com new virtual "},
{"Re: FW: =?ISO-8859-2?Q?Sopron-Gy=F5r_optikai_sz=E1l_probl=E9?=", "Re: FW: Sopron-Győr optikai szál problé"},
{"=?UTF-8?Q?Megh=C3=ADv=C3=B3=20a=20Pulzus=20felm=C3=A9r=C3=A9sre=20/=20Inv?= =?UTF-8?Q?itation=20to=20the=20Pulse=20Survey?=", "Meghívó a Pulzus felmérésre / Inv itation to the Pulse Survey"},
{"=?iso-8859-2?Q?vhost_l=E9trehoz=E1sa?=", "vhost létrehozása"},
{"Re: MAIL =?UTF-8?B?U1pPTEfDgUxUQVTDgVMgSElCQSAgIEdUUzogOTE1NDUyMQ==?=", "Re: MAIL SZOLGÁLTATÁS HIBA GTS: 9154521"},
{"[spam???] Better Sex. Better Body. Better Life.", "[spam???] Better Sex. Better Body. Better Life."},
{"1gy2tt. V3l4d. M5sk6nt", "1gy2tt. V3l4d. M5sk6nt"},
{"=?iso-8859-2?B?03Jp4XNpIG1lZ2xlcGV06XMsIG5pbmNzIHT2YmIgbWVudHPpZyBBbWVyaWthIHN64W3hcmEgKDIwMTUuMTEuMDYuIC0gc2pAYWN0cy5odSk=?=", "Óriási meglepetés, nincs több mentség Amerika számára (2015.11.06. - sj@acts.hu)"},
{"=?utf-8?B?Rlc6IEVtYWlsIGZvZ2Fkw6FzaSBoaWJh?=", "FW: Email fogadási hiba"},
{"=?ISO-8859-15?Q?RE=3A_FW=3A_K=E9rd=E9s?=", "RE: FW: Kérdés"},
{"=?iso-8859-2?Q?RE:_spam_tilt=E1s?=", "RE: spam tiltás"},
{"Subject: Administrator has responded to your request for 'Cloud Operations", "Subject: Administrator has responded to your request for 'Cloud Operations"},
{"Subject: =?GB2312?B?VFYgYmFjayBLSVQgc3RyaXAgcmYgcmVtb3RlIENvbnRyb2wgIFVTRDUuNS9TRVQ=?=", "Subject: TV back KIT strip rf remote Control USD5.5/SET"},
{"Subject: =?UTF-8?Q?Ha_rossz_a_k=C3=B6z=C3=A9rzete?=", "Subject: Ha rossz a közérzete"},
{"Subject: =?UTF-8?B?SsOhdHNzeiBhIHZpbMOhZyBsZWdixZFrZXrFsWJiIGxvdHTDs2rDoW4gSU5HWUVO?=", "Subject: Játssz a világ legbőkezűbb lottóján INGYEN"},
{"Subject: =?UTF-8?B?w5Zua29ybcOhbnl6YXRpIGFkYXRiw6F6aXMgMiwzIEZ0IC8gZGIgw6Fyb24=?=", "Subject: Önkormányzati adatbázis 2,3 Ft / db áron"},
{"Subject: =?UTF-8?Q?Experience=20a=20Crazy=20Reward=20Delivered=20to=20you?=", "Subject: Experience a Crazy Reward Delivered to you"},
{"Subject: =?windows-1251?B?ze7i7uPu5O3o5SDv7uTg8OroIOTr/yDC4Pjo?=", "Subject: Новогодние подарки для Ваши"},
{"Subject: =?utf-8?Q?Divatos,_=C3=BCde_sz=C3=ADneinek_k=C3=B6sz=C3=B6nhet=C5=91en_el?=", "Subject: Divatos, üde színeinek köszönhetően el"},
};
for(i=0; i<sizeof(pair)/sizeof(struct str_pair); i++){
snprintf(buf, sizeof(buf)-1, "%s", pair[i].line);
fixupEncodedHeaderLine(buf, sizeof(buf)-1);
assert(strcmp(buf, pair[i].expected_result) == 0 && "test_fixupEncodedHeaderLine");
//printf(" {\"%s\", \"%s\"},\n", pair[i].line, buf);
}
printf("test_fixupEncodedHeaderLine() OK\n");
}
static void test_translateLine(){
int i;
char buf[SMALLBUFSIZE];
struct parser_state state;
struct str_pair pair[] = {
{"From: \"'user@domain'\"", "From user@domain "},
{"From: \"''user@domain'\"", "From 'user@domain "},
{"From: \"''user'@domain'\"", "From 'user'@domain "},
{"From: \"'user'@domain'\"", "From user'@domain "},
{"From: Mike D'Amaaaaa <mike@aaa.fu>", "From Mike D'Amaaaaa mike@aaa.fu "},
{"From: VMware Technical Support <webform@vmware.com>", "From VMware Technical Support webform@vmware.com "}
/*
* TODO: we need many more tests here
*/
};
for(i=0; i<sizeof(pair)/sizeof(struct str_pair); i++){
init_state(&state);
state.message_state = MSG_FROM;
state.is_header = 1;
snprintf(buf, sizeof(buf)-1, "%s", pair[i].line);
translateLine((unsigned char*)buf, &state);
//printf(" {\"%s\", \"%s\"},\n", pair[i].line, buf);
assert(strcmp(buf, pair[i].expected_result) == 0 && "test_translateLine");
}
printf("test_translateLine() OK\n");
}
static void test_fixURL(){
int i;
char buf[SMALLBUFSIZE];
struct str_pair pair[] = {
{"http://www.aaa.fu", "__URL__wwwXaaaXfu "},
{"http://www.aaa.fu/", "__URL__wwwXaaaXfu "},
{"http://www.aaa.fu/ahaha", "__URL__wwwXaaaXfu "},
{"http://www.aaa.fu/bbb/ccc", "__URL__wwwXaaaXfu "},
{"http://www.aaa.fu/ahahah/aiaiai?url=http://iii.oo/", "__URL__wwwXaaaXfu "},
{"https://www.aaa.fu/", "__URL__wwwXaaaXfu "}
};
for(i=0; i<sizeof(pair)/sizeof(struct str_pair); i++){
snprintf(buf, sizeof(buf)-1, "%s", pair[i].line);
fixURL(buf, sizeof(buf)-1);
//printf(" {\"%s\", \"%s\"},\n", pair[i].line, buf);
assert(strcmp(buf, pair[i].expected_result) == 0 && "test_fixURL");
}
printf("test_fixURL() OK\n");
}
static void test_degenerateToken(){
int i;
char buf[SMALLBUFSIZE];
struct str_pair pair[] = {
{"Hello", "Hello"},
{"Hello!", "Hello"},
{"Hello!!", "Hello"},
{"Hello!!!", "Hello"},
{"Hello?", "Hello"},
{"Hello??", "Hello"},
{"Hello???", "Hello"},
{"Hello.", "Hello"},
{"Hello..", "Hello"},
{"Hello...", "Hello"}
};
for(i=0; i<sizeof(pair)/sizeof(struct str_pair); i++){
snprintf(buf, sizeof(buf)-1, "%s", pair[i].line);
degenerateToken((unsigned char*)buf);
//printf(" {\"%s\", \"%s\"},\n", pair[i].line, buf);
assert(strcmp(buf, pair[i].expected_result) == 0 && "test_degenerateToken");
}
printf("test_degenerateToken() OK\n");
}
/*
other functions to test in the future:
- int extract_boundary(char *p, struct parser_state *state)
- void fix_email_address_for_sphinx(char *s)
- void reassembleToken(char *p)
*/
int main(){
test_parse_date_header();
test_extractNameFromHeaderLine();
test_fixupEncodedHeaderLine();
test_translateLine();
test_fixURL();
test_degenerateToken();
return 0;
}

41
unit_tests/test.conf Normal file
View File

@ -0,0 +1,41 @@
archive_emails_not_having_message_id=0
archive_only_mydomains=0
backlog=20
cipher_list=ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
clamd_socket=/tmp/clamd
default_retention_days=2557
enable_cjk=0
enable_folders=0
encrypt_messages=1
extra_to_field=X-Envelope-To:
extract_attachments=1
helper_timeout=20
hostid=piler.yourdomain.com
iv=
listen_addr=0.0.0.0
listen_port=25
max_requests_per_child=1000
memcached_servers=127.0.0.1
memcached_to_db_interval=900
memcached_ttl=86400
min_word_len=1
mmap_dedup_test=0
mysql_connect_timeout=2
mysqldb=piler
mysqlpwd=verystrongpassword
mysqlsocket=/var/run/mysqld/mysqld.sock
mysqluser=piler
number_of_worker_processes=10
pemfile=/usr/local/etc/piler.pem
pidfile=/var/run/piler/piler.pid
piler_header_field=X-piler-id:
process_rcpt_to_addresses=0
server_id=0
spam_header_line=
syslog_recipients=0
tls_enable=0
tweak_sent_time_offset=0
update_counters_to_memcached=0
username=piler
verbosity=1
workdir=.