diff --git a/unit_tests/6.eml b/unit_tests/6.eml new file mode 100644 index 00000000..3ef1187f --- /dev/null +++ b/unit_tests/6.eml @@ -0,0 +1,17 @@ +Return-Path: +X-Original-To: sj@acts.hu +X-Envelope-To: sj@acts.hu +Received: from mcqw.com (unknown [111.177.117.51]) + by lithium.acts.hu (Postfix) with ESMTP id 12AC620EBC9 + for ; Sun, 1 Nov 2015 15:34:10 +0100 (CET) +Received: from cloudvm-1e7a8fc ([127.0.0.1]) by localhost via TCP with ESMTPA; Sun, 01 Nov 2015 22:26:34 +0800 +MIME-Version: 1.0 +From: "JML lighting" +Sender: "JML lighting" +To: sj@acts.hu +Reply-To: "JML lighting" +Date: 1 Nov 2015 22:26:34 +0800 +Subject: =?utf-8?B?TmV3IGRlc2lnbiB1bHRyYSBzbGltIGxlZCAgcGFuZWwgbGlnaHQ=?= +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: base64 +Message-Id: <20151101142653.111156815AF6D@acts.hu> diff --git a/unit_tests/7.eml b/unit_tests/7.eml new file mode 100644 index 00000000..36b6a8d0 --- /dev/null +++ b/unit_tests/7.eml @@ -0,0 +1,18 @@ +Return-Path: +X-Original-To: sj@acts.hu +X-Envelope-To: sj@acts.hu +Received: from mcqw.com (unknown [111.177.117.51]) + by lithium.acts.hu (Postfix) with ESMTP id 12AC620EBC9 + for ; Sun, 1 Nov 2015 15:34:10 +0100 (CET) +Received: from cloudvm-1e7a8fc ([127.0.0.1]) by localhost via TCP with ESMTPA; Sun, 01 Nov 2015 22:26:34 +0800 +MIME-Version: 1.0 +From: "JML lighting" +Sender: "JML lighting" +To: sj@acts.hu +Reply-To: "JML lighting" +Date: 1 Nov 2015 22:26:34 +0800 +Subject: =?utf-8?B?TmV3IGRlc2lnbiB1bHRyYSBzbGltIGxlZCAgcGFuZWwgbGlnaHQ=?= +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: base64 +Message-Id: <20151101142653.111156815AF6D@acts.hu> + diff --git a/unit_tests/8.eml b/unit_tests/8.eml new file mode 100644 index 00000000..672c1cdd --- /dev/null +++ b/unit_tests/8.eml @@ -0,0 +1,19 @@ +Return-Path: +X-Original-To: sj@acts.hu +X-Envelope-To: sj@acts.hu +Received: from mcqw.com (unknown [111.177.117.51]) + by lithium.acts.hu (Postfix) with ESMTP id 12AC620EBC9 + for ; Sun, 1 Nov 2015 15:34:10 +0100 (CET) +Received: from cloudvm-1e7a8fc ([127.0.0.1]) by localhost via TCP with ESMTPA; Sun, 01 Nov 2015 22:26:34 +0800 +MIME-Version: 1.0 +From: "JML lighting" +Sender: "JML lighting" +To: sj@acts.hu +Reply-To: "JML lighting" +Date: 1 Nov 2015 22:26:34 +0800 +Subject: =?utf-8?B?TmV3IGRlc2lnbiB1bHRyYSBzbGltIGxlZCAgcGFuZWwgbGlnaHQ=?= +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: base64 +Message-Id: <20151101142653.111156815AF6D@acts.hu> + + diff --git a/unit_tests/Makefile.in b/unit_tests/Makefile.in index f3837276..5273735b 100644 --- a/unit_tests/Makefile.in +++ b/unit_tests/Makefile.in @@ -24,7 +24,7 @@ RUNNING_GROUP = `@id_bin@ -gn $(RUNNING_USER)` INSTALL = @INSTALL@ -all: check_parser_utils check_rules smtp +all: check_parser_utils check_rules check_digest smtp check_parser_utils: check_parser_utils.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) @@ -32,6 +32,9 @@ check_parser_utils: check_parser_utils.c ../src/libpiler.a check_rules: check_rules.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) +check_digest: check_digest.c ../src/libpiler.a + $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) + smtp: smtp.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) @@ -39,7 +42,7 @@ install: @echo clean: - rm -f check_parser_utils check_rules smtp + rm -f check_parser_utils check_rules check_digest smtp distclean: clean rm -f Makefile diff --git a/unit_tests/check_digest.c b/unit_tests/check_digest.c new file mode 100644 index 00000000..d2b88a87 --- /dev/null +++ b/unit_tests/check_digest.c @@ -0,0 +1,138 @@ +/* + * check_rules.c, SJ + */ + +#include +#include +#include +#include +#include +#include +#include "../src/piler.h" + + +struct digest_test { + char s[SMALLBUFSIZE]; + char *digest1; + char *digest2; +}; + + +struct digest_test tests[] = { + {"1.eml", "63e4649b52c0fb45571b32aecc502234e6414abb36317eea25a1bd2f4e3cbe9e", "93e71b5f72d195f51333e261d57bffc9b27c95ef44bf6478090db3067571e242"}, + {"2.eml", "668cb3b91b944af786667323442576b9813d65f3cd3bc33e9d5da303c79de038", "de90475409dd6ab24e80c1b7a987715c40fe8d28d91337b7f063b477159c7b3c"}, + {"3.eml", "0d546d4cb4a8ce74ea5fd4cc51dbb4ebeaa7542f1c691817579da7eeab8d4771", "f585d011340d292ee52ddedb07cda662a8f1e46329d14a2ce92dca0604387bab"}, + {"4.eml", "6008daed3613af4af71aa1f82550fd592d19c14c1aa7d8d5db2be1552174c518", "5f0744384bc3f96167380442c108c04a762313c79778c928ee5274981632ff45"}, + {"5.eml", "63e4649b52c0fb45571b32aecc502234e6414abb36317eea25a1bd2f4e3cbe9e", "04d6ae67d34b2d5c41cf96357b8eb3954ebd570943cd83cfb1db028801806efd"}, + {"6.eml", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "a01d130e2b5761bf28cddd116c00fe9b3982bfbeb4c629c569ccfea6ba965ce4"}, + {"7.eml", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "ca1597c1309b5b8418ccd5981a4b7672a0f3b0989720891eb3ba2a47069206b4"}, + {"8.eml", "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b", "e3496806ff20e5075baf8b2ede02d1613acfeb261f0b3108eeeba92347d93e72"} +}; + + +void static test_digest_string(){ + int i; + char digest[2*DIGEST_LENGTH+1]; + struct digest_test tests[] = { + {"Piler archives every email it receives.", "68bcdb6f15eeabdcedce3e4fc8faf7eb620272ebd55f365d08aca40adf18fe83", ""}, + {"It has a built-in access control to prevent a user to access other's messages.", "3acc35b154420e8749e7ebd9adc3a397d3ecfd86c891ecb87b7718e146d314d5", ""}, + {"Auditors can see every archived email.", "619e008882474f26a0fee3699d4694f256db116204ebd5d436052052beed60c3", ""}, + {"Piler parses the header and extracts the From:, To: and Cc: addresses (in case of From: it only stores the first email address, since some spammers include tons of addresses in the From: field), and when a user searches for his emails then piler tries to match his email addresses against the email addresses in the messages.", "ab1cc87020ffe78d310481381a42064601337b388b8804309b8f4a52cfd55e0f", ""}, + {"To sum it up, a regular user can see only the emails he sent or received.", "987282a0c946db345afc63d15e74b0ec53ac776b3ec638540befa9b9b64f8b02", ""} + }; + + for(i=0; i body digest: %s, digest: %s\n", tests[i].s, sdata.bodydigest, sdata.digest); + + for(j=1; j<=state.n_attachments; j++){ + unlink(state.attachments[j].internalname); + } + + unlink(sdata.tmpframe); + + assert(strcmp(sdata.bodydigest, tests[i].digest1) == 0 && "test_make_digests()"); + assert(strcmp(sdata.digest, tests[i].digest2) == 0 && "test_make_digests()"); + + } + + close_database(&sdata); + + printf("test_make_digests() OK\n"); +} + + +int main(){ + struct __config cfg; + + (void) openlog("digest_test", LOG_PID, LOG_MAIL); + + cfg = read_config("test.conf"); + + setlocale(LC_MESSAGES, cfg.locale); + setlocale(LC_CTYPE, cfg.locale); + + + test_digest_string(); + test_digest_file(); + + test_make_digests(&cfg); + + return 0; +} +