| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  Unit tests for regular expression processing. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Copyright (C) 2008 Sourcefire, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Authors: Török Edvin | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  *  it under the terms of the GNU General Public License version 2 as | 
					
						
							|  |  |  |  *  published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  *  GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  *  along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 
					
						
							|  |  |  |  *  MA 02110-1301, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #if HAVE_CONFIG_H
 | 
					
						
							|  |  |  | #include "clamav-config.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <limits.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <check.h>
 | 
					
						
							|  |  |  | #include "../libclamav/clamav.h"
 | 
					
						
							|  |  |  | #include "../libclamav/others.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | #include "../libclamav/mbox.h"
 | 
					
						
							|  |  |  | #include "../libclamav/message.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | #include "../libclamav/htmlnorm.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | #include "../libclamav/phishcheck.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | #include "../libclamav/regex_suffix.h"
 | 
					
						
							|  |  |  | #include "../libclamav/regex_list.h"
 | 
					
						
							|  |  |  | #include "../libclamav/phish_domaincheck_db.h"
 | 
					
						
							|  |  |  | #include "../libclamav/phish_whitelist.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | #include "checks.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | static size_t cb_called = 0; | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | static int cb_fail(void *cbdata, const char *suffix, size_t len, const struct regex_list *regex) | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	fail("this pattern is not supposed to have a suffix"); | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | static int cb_expect_single(void *cbdata, const char *suffix, size_t len, const struct regex_list *regex) | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	const char *expected = cbdata; | 
					
						
							|  |  |  | 	cb_called++; | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 	fail_unless_fmt(suffix && strcmp(suffix, expected) == 0, | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 			"suffix mismatch, was: %s, expected: %s\n", suffix, expected); | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct regex_list regex; | 
					
						
							|  |  |  | START_TEST (empty) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char pattern[] = ""; | 
					
						
							|  |  |  | 	int rc; | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	regex_t *preg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	errmsg_expected(); | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	preg = malloc(sizeof(*regex.preg)); | 
					
						
							|  |  |  | 	fail_unless(!!preg, "malloc"); | 
					
						
							|  |  |  | 	rc = cli_regex2suffix(pattern, preg, cb_fail, NULL); | 
					
						
							|  |  |  | 	free(preg); | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	fail_unless(rc == REG_EMPTY, "empty pattern"); | 
					
						
							|  |  |  | 	fail_unless(cb_called == 0, "callback shouldn't be called"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | END_TEST | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | START_TEST (one) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	char pattern[] = "a"; | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	int rc; | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	regex_t *preg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	preg = malloc(sizeof(*regex.preg)); | 
					
						
							|  |  |  | 	fail_unless(!!preg, "malloc"); | 
					
						
							|  |  |  | 	rc = cli_regex2suffix(pattern, preg, cb_expect_single, pattern); | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	fail_unless(rc == 0, "single character pattern"); | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	cli_regfree(preg); | 
					
						
							|  |  |  | 	free(preg); | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	fail_unless(cb_called == 1, "callback should be called once"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | END_TEST | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | static const char *ex1[] = | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  |  {"com|de","moc","ed",NULL}; | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | static const char *ex2[] = | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  |  {"xd|(a|e)bc","dx","cba","cbe",NULL}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const char **tests[] = { | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	ex1, | 
					
						
							|  |  |  | 	ex2 | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | static int cb_expect_multi(void *cbdata, const char *suffix, size_t len, const struct regex_list *r) | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	const char **exp = cbdata; | 
					
						
							|  |  |  | 	fail_unless(!!exp, "expected data"); | 
					
						
							|  |  |  | 	exp++; | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 	fail_unless_fmt(!!*exp, "expected no suffix, got: %s\n",suffix); | 
					
						
							|  |  |  | 	fail_unless_fmt(!!exp[cb_called], "expected less suffixes, but already got: %d\n", cb_called); | 
					
						
							|  |  |  | 	fail_unless_fmt(strcmp(exp[cb_called], suffix) == 0, | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 			"suffix mismatch, was: %s, expected: %s\n",suffix, exp[cb_called]); | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 	fail_unless_fmt(strlen(suffix) == len, "incorrect suffix len, expected: %d, got: %d\n", strlen(suffix), len); | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	cb_called++; | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | START_TEST (test_suffix) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int rc; | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	regex_t *preg; | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	const char *pattern = tests[_i][0]; | 
					
						
							|  |  |  | 	size_t n=0; | 
					
						
							|  |  |  | 	const char **p=tests[_i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fail_unless(!!pattern, "test pattern"); | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	preg = malloc(sizeof(*regex.preg)); | 
					
						
							|  |  |  | 	fail_unless(!!preg, "malloc"); | 
					
						
							|  |  |  | 	rc = cli_regex2suffix(pattern, preg, cb_expect_multi, tests[_i]); | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	fail_unless(rc == 0, "single character pattern"); | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	cli_regfree(preg); | 
					
						
							|  |  |  | 	free(preg); | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	p++; | 
					
						
							|  |  |  | 	while(*p++) n++; | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 	fail_unless_fmt(cb_called == n, | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 			"suffix number mismatch, expected: %d, was: %d\n", n, cb_called); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | END_TEST | 
					
						
							| 
									
										
										
										
											2008-08-20 12:55:42 +00:00
										 |  |  | #endif /* CHECK_HAVE_LOOPS */
 | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void setup(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	cb_called = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void teardown(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | static struct regex_matcher matcher; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void rsetup(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-03 19:26:57 +00:00
										 |  |  | 	int rc; | 
					
						
							| 
									
										
										
										
											2008-11-04 10:40:24 +00:00
										 |  |  | #ifdef USE_MPOOL
 | 
					
						
							| 
									
										
										
										
											2009-01-26 19:47:02 +00:00
										 |  |  | 	matcher.mempool = mpool_create(); | 
					
						
							| 
									
										
										
										
											2008-11-03 19:26:57 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-02-15 15:01:37 +02:00
										 |  |  | 	rc = init_regex_list(&matcher, 1); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	fail_unless(rc == 0, "init_regex_list"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void rteardown(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	regex_list_done(&matcher); | 
					
						
							| 
									
										
										
										
											2008-11-04 10:40:24 +00:00
										 |  |  | #ifdef USE_MPOOL
 | 
					
						
							| 
									
										
										
										
											2009-01-26 19:47:02 +00:00
										 |  |  | 	mpool_destroy(matcher.mempool); | 
					
						
							| 
									
										
										
										
											2008-11-03 19:26:57 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct rtest { | 
					
						
							|  |  |  | 	const char *pattern;/* NULL if not meant for whitelist testing */ | 
					
						
							|  |  |  | 	const char *realurl; | 
					
						
							|  |  |  | 	const char *displayurl; | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	int result;/* 0 - phish, 1 - whitelisted, 2 - clean, 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 12:44:16 +00:00
										 |  |  | 		      3 - blacklisted if 2nd db is loaded, | 
					
						
							|  |  |  | 		      4 - invalid regex*/ | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | } rtests[] = { | 
					
						
							| 
									
										
										
										
											2010-07-26 13:16:51 +03:00
										 |  |  |         {NULL,"http://fake.example.com", "http://foo@key.com/", 0}, | 
					
						
							|  |  |  | 	{NULL,"http://fake.example.com", "foo.example.com@key.com", 0}, | 
					
						
							|  |  |  | 	{NULL,"http://fake.example.com", "foo@key.com", 2}, | 
					
						
							| 
									
										
										
										
											2008-08-04 12:44:16 +00:00
										 |  |  | 	{NULL,"http://fake.example.com","=====key.com",0}, | 
					
						
							|  |  |  | 	{NULL,"http://key.com","=====key.com",2}, | 
					
						
							| 
									
										
										
										
											2008-10-01 09:56:54 +00:00
										 |  |  | 	{NULL," http://key.com","=====key.com",2}, | 
					
						
							| 
									
										
										
										
											2008-08-04 12:44:16 +00:00
										 |  |  | 	{NULL,"http://key.com@fake.example.com","key.com",0}, | 
					
						
							| 
									
										
										
										
											2008-10-01 09:56:54 +00:00
										 |  |  | 	{NULL," http://key.com@fake.example.com","key.com",0}, | 
					
						
							|  |  |  | 	{NULL," http://key.com@fake.example.com ","key.com",0}, | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	/* entry taken from .wdb with a / appended */ | 
					
						
							|  |  |  | 	{".+\\.ebayrtm\\.com([/?].*)?:.+\\.ebay\\.(de|com|co\\.uk)([/?].*)?/", | 
					
						
							|  |  |  | 		"http://srx.main.ebayrtm.com", | 
					
						
							|  |  |  | 		"pages.ebay.de", | 
					
						
							| 
									
										
										
										
											2008-07-29 10:36:26 +00:00
										 |  |  | 		1 /* should be whitelisted */}, | 
					
						
							|  |  |  | 	{".+\\.ebayrtm\\.com([/?].*)?:.+\\.ebay\\.(de|com|co\\.uk)([/?].*)?/", | 
					
						
							|  |  |  | 		"http://srx.main.ebayrtm.com.evil.example.com", | 
					
						
							|  |  |  | 		"pages.ebay.de", | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 		0}, | 
					
						
							|  |  |  | 	{".+\\.ebayrtm\\.com([/?].*)?:.+\\.ebay\\.(de|com|co\\.uk)([/?].*)?/", | 
					
						
							|  |  |  | 		"www.www.ebayrtm.com?somecgi", | 
					
						
							|  |  |  | 		"www.ebay.com/something",1}, | 
					
						
							|  |  |  | 	{NULL, | 
					
						
							|  |  |  | 		"http://key.com","go to key.com",2 | 
					
						
							| 
									
										
										
										
											2008-07-29 16:45:21 +00:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2009-02-23 12:35:45 +00:00
										 |  |  | 	{":.+\\.paypal\\.(com|de|fr|it)([/?].*)?:.+\\.ebay\\.(at|be|ca|ch|co\\.uk|de|es|fr|ie|in|it|nl|ph|pl|com(\\.(au|cn|hk|my|sg))?)([/?].*)?/", | 
					
						
							|  |  |  | 	    "http://www.paypal.com", "pics.ebay.com", 1}, | 
					
						
							| 
									
										
										
										
											2008-07-29 16:45:21 +00:00
										 |  |  | 	{NULL, "http://somefakeurl.example.com","someotherdomain-key.com",2}, | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	{NULL, "http://somefakeurl.example.com","someotherdomain.key.com",0}, | 
					
						
							|  |  |  | 	{NULL, "http://1.test.example.com/something","test",3}, | 
					
						
							|  |  |  | 	{NULL, "http://1.test.example.com/2","test",3}, | 
					
						
							|  |  |  | 	{NULL, "http://user@1.test.example.com/2","test",3}, | 
					
						
							| 
									
										
										
										
											2008-08-04 12:44:16 +00:00
										 |  |  | 	{NULL, "http://user@1.test.example.com/2/test","test",3}, | 
					
						
							|  |  |  | 	{NULL, "http://user@1.test.example.com/","test",3}, | 
					
						
							|  |  |  | 	{NULL, "http://x.exe","http:///x.exe",2}, | 
					
						
							|  |  |  | 	{".+\\.ebayrtm\\.com([/?].*)?:[^.]+\\.ebay\\.(de|com|co\\.uk)/", | 
					
						
							|  |  |  | 		"http://srx.main.ebayrtm.com", | 
					
						
							|  |  |  | 		"pages.ebay.de", | 
					
						
							|  |  |  | 		1 /* should be whitelisted */}, | 
					
						
							|  |  |  | 	{".+\\.ebayrtm\\.com([/?].*)?:.+[r-t]\\.ebay\\.(de|com|co\\.uk)/", | 
					
						
							|  |  |  | 		"http://srx.main.ebayrtm.com", | 
					
						
							|  |  |  | 		"pages.ebay.de", | 
					
						
							|  |  |  | 		1 /* should be whitelisted */}, | 
					
						
							|  |  |  | 	{".+\\.ebayrtm\\.com([/?].*)?:.+[r-t]\\.ebay\\.(de|com|co\\.uk)/", | 
					
						
							|  |  |  | 		"http://srx.main.ebayrtm.com", | 
					
						
							|  |  |  | 		"pages.ebay.de", | 
					
						
							|  |  |  | 		1 /* should be whitelisted */}, | 
					
						
							|  |  |  | 	{"[t-","","",4}, | 
					
						
							|  |  |  | 	{NULL,"http://co.uk","http:// co.uk",2}, | 
					
						
							|  |  |  | 	{NULL,"http://co.uk","     ",2}, | 
					
						
							|  |  |  | 	{NULL,"127.0.0.1","pages.ebay.de",2}, | 
					
						
							|  |  |  | 	{".+\\.ebayrtm\\.com([/?].*)?:.+\\.ebay\\.(de|com|co\\.uk)([/?].*)?/", | 
					
						
							|  |  |  | 		"http://pages.ebay.de@fake.example.com","pages.ebay.de",0}, | 
					
						
							|  |  |  | 	{NULL,"http://key.com","https://key.com",0}, | 
					
						
							|  |  |  | 	{NULL,"http://key.com%00fake.example.com","https://key.com",0}, | 
					
						
							| 
									
										
										
										
											2009-02-19 08:50:04 +00:00
										 |  |  | 	{NULL,"http://key.com.example.com","key.com.invalid",0} | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | START_TEST (regex_list_match_test) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *info; | 
					
						
							|  |  |  | 	const struct rtest *rtest = &rtests[_i]; | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	char *pattern, *realurl; | 
					
						
							|  |  |  | 	int rc; | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(!rtest->pattern) { | 
					
						
							|  |  |  | 		fail_unless(rtest->result != 1, | 
					
						
							|  |  |  | 				"whitelist test must have pattern set"); | 
					
						
							|  |  |  | 		/* this test entry is not meant for whitelist testing */ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 12:44:16 +00:00
										 |  |  | 	fail_unless(rtest->result == 0 || rtest->result == 1 || rtest->result==4, | 
					
						
							|  |  |  | 			"whitelist test result must be either 0 or 1 or 4"); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	pattern = cli_strdup(rtest->pattern); | 
					
						
							|  |  |  | 	fail_unless(!!pattern, "cli_strdup"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	rc = regex_list_add_pattern(&matcher, pattern); | 
					
						
							| 
									
										
										
										
											2008-08-04 12:44:16 +00:00
										 |  |  | 	if(rtest->result == 4) { | 
					
						
							|  |  |  | 		fail_unless(rc, "regex_list_add_pattern should return error"); | 
					
						
							|  |  |  | 		free(pattern); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		fail_unless(rc == 0,"regex_list_add_pattern"); | 
					
						
							| 
									
										
										
										
											2008-07-25 20:01:40 +00:00
										 |  |  | 	free(pattern); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	matcher.list_loaded = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rc = cli_build_regex_list(&matcher); | 
					
						
							|  |  |  | 	fail_unless(rc == 0,"cli_build_regex_list"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fail_unless(is_regex_ok(&matcher),"is_regex_ok"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	realurl = cli_strdup(rtest->realurl); | 
					
						
							|  |  |  | 	rc = regex_list_match(&matcher, realurl, rtest->displayurl, NULL, 1, &info, 1); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	fail_unless(rc == rtest->result,"regex_list_match"); | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	/* regex_list_match is not supposed to modify realurl in this case */ | 
					
						
							|  |  |  | 	fail_unless(!strcmp(realurl, rtest->realurl), "realurl altered"); | 
					
						
							|  |  |  | 	free(realurl); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | END_TEST | 
					
						
							| 
									
										
										
										
											2008-08-20 12:55:42 +00:00
										 |  |  | #endif /* CHECK_HAVE_LOOPS */
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct cl_engine *engine; | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | static int loaded_2 = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void psetup_impl(int load2) | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	FILE *f; | 
					
						
							|  |  |  | 	int rc; | 
					
						
							| 
									
										
										
										
											2009-03-06 09:09:06 +00:00
										 |  |  | 	unsigned signo=0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-13 15:55:35 +00:00
										 |  |  | 	engine = cl_engine_new(); | 
					
						
							| 
									
										
										
										
											2008-11-12 18:02:33 +00:00
										 |  |  | 	fail_unless(!!engine , "cl_engine_new"); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-12 18:02:33 +00:00
										 |  |  | 	phishing_init(engine); | 
					
						
							|  |  |  | 	fail_unless(!!engine->phishcheck, "phishing_init"); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	rc = init_domainlist(engine); | 
					
						
							|  |  |  | 	fail_unless(rc == 0,"init_domainlist"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	f = fdopen(open_testfile("input/daily.pdb"),"r"); | 
					
						
							|  |  |  | 	fail_unless(!!f, "fopen daily.pdb"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 15:01:37 +02:00
										 |  |  | 	rc = load_regex_matcher(engine->domainlist_matcher,  f, &signo, 0, 0, NULL, 1); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	fail_unless(rc == 0, "load_regex_matcher"); | 
					
						
							|  |  |  | 	fclose(f); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-06 09:09:06 +00:00
										 |  |  | 	fail_unless_fmt(signo == 201, "Incorrect number of signatures: %u, expected %u", signo, 201); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	if(load2) { | 
					
						
							| 
									
										
										
										
											2009-03-09 11:23:12 +00:00
										 |  |  | 		f = fdopen(open_testfile("input/daily.gdb"),"r"); | 
					
						
							|  |  |  | 		fail_unless(!!f, "fopen daily.gdb"); | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-06 09:09:06 +00:00
										 |  |  | 		signo = 0; | 
					
						
							| 
									
										
										
										
											2010-02-15 15:01:37 +02:00
										 |  |  | 		rc = load_regex_matcher(engine->domainlist_matcher,  f, &signo, 0, 0, NULL, 1); | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 		fail_unless(rc == 0, "load_regex_matcher"); | 
					
						
							|  |  |  | 		fclose(f); | 
					
						
							| 
									
										
										
										
											2009-03-06 09:09:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-11 20:06:35 +00:00
										 |  |  | 		fail_unless_fmt(signo == 4, "Incorrect number of signatures: %u, expected %u", signo, 4); | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	loaded_2 = load2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	rc = init_whitelist(engine); | 
					
						
							|  |  |  | 	fail_unless(rc == 0,"init_whitelist"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	f = fdopen(open_testfile("input/daily.wdb"),"r"); | 
					
						
							| 
									
										
										
										
											2009-03-06 09:09:06 +00:00
										 |  |  | 	signo = 0; | 
					
						
							| 
									
										
										
										
											2010-02-15 15:01:37 +02:00
										 |  |  | 	rc = load_regex_matcher(engine->whitelist_matcher, f, &signo, 0, 1, NULL, 1); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	fail_unless(rc == 0,"load_regex_matcher"); | 
					
						
							|  |  |  | 	fclose(f); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-06 09:09:06 +00:00
										 |  |  | 	fail_unless_fmt(signo == 31, "Incorrect number of signatures: %u, expected %u", signo, 31); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	rc = cli_build_regex_list(engine->whitelist_matcher); | 
					
						
							|  |  |  | 	fail_unless(rc == 0,"cli_build_regex_list"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rc = cli_build_regex_list(engine->domainlist_matcher); | 
					
						
							|  |  |  | 	fail_unless(rc == 0,"cli_build_regex_list"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fail_unless(is_regex_ok(engine->whitelist_matcher),"is_regex_ok"); | 
					
						
							|  |  |  | 	fail_unless(is_regex_ok(engine->domainlist_matcher),"is_regex_ok"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | static void psetup(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	psetup_impl(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void psetup2(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	psetup_impl(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | static void pteardown(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	if(engine) { | 
					
						
							| 
									
										
										
										
											2008-11-12 18:02:33 +00:00
										 |  |  | 		cl_engine_free(engine); | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	engine = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void do_phishing_test(const struct rtest *rtest) | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *realurl; | 
					
						
							|  |  |  | 	cli_ctx ctx; | 
					
						
							|  |  |  | 	const char *virname; | 
					
						
							|  |  |  | 	tag_arguments_t hrefs; | 
					
						
							|  |  |  | 	int rc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(&ctx, 0, sizeof(ctx)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	realurl = cli_strdup(rtest->realurl); | 
					
						
							|  |  |  | 	fail_unless(!!realurl, "cli_strdup"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hrefs.count = 1; | 
					
						
							|  |  |  | 	hrefs.value = cli_malloc(sizeof(*hrefs.value)); | 
					
						
							|  |  |  | 	fail_unless(!!hrefs.value, "cli_malloc"); | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	hrefs.value[0] = (unsigned char*)realurl; | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	hrefs.contents = cli_malloc(sizeof(*hrefs.contents)); | 
					
						
							|  |  |  | 	fail_unless(!!hrefs.contents, "cli_malloc"); | 
					
						
							|  |  |  | 	hrefs.tag = cli_malloc(sizeof(*hrefs.tag)); | 
					
						
							|  |  |  | 	fail_unless(!!hrefs.tag, "cli_malloc"); | 
					
						
							| 
									
										
										
										
											2008-07-29 10:59:21 +00:00
										 |  |  | 	hrefs.tag[0] = (unsigned char*)cli_strdup("href"); | 
					
						
							| 
									
										
										
										
											2010-04-13 16:19:47 +03:00
										 |  |  | 	hrefs.contents[0] = (unsigned char*)cli_strdup(rtest->displayurl); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ctx.engine = engine; | 
					
						
							|  |  |  | 	ctx.virname = &virname; | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-07 18:49:47 +00:00
										 |  |  | 	rc = phishingScan(&ctx, &hrefs); | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 20:01:40 +00:00
										 |  |  | 	html_tag_arg_free(&hrefs); | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 	fail_unless(rc == CL_CLEAN,"phishingScan"); | 
					
						
							|  |  |  | 	switch(rtest->result) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 			fail_unless_fmt(ctx.found_possibly_unwanted, | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 					"this should be phishing, realURL: %s, displayURL: %s", | 
					
						
							|  |  |  | 					rtest->realurl, rtest->displayurl); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 			fail_unless_fmt(!ctx.found_possibly_unwanted, | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 					"this should be whitelisted, realURL: %s, displayURL: %s", | 
					
						
							|  |  |  | 					rtest->realurl, rtest->displayurl); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 			fail_unless_fmt(!ctx.found_possibly_unwanted, | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 					"this should be clean, realURL: %s, displayURL: %s", | 
					
						
							|  |  |  | 					rtest->realurl, rtest->displayurl); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 		case 3: | 
					
						
							|  |  |  | 			if(!loaded_2) | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 				fail_unless_fmt(!ctx.found_possibly_unwanted, | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 					"this should be clean, realURL: %s, displayURL: %s", | 
					
						
							|  |  |  | 					rtest->realurl, rtest->displayurl); | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 				fail_unless_fmt(ctx.found_possibly_unwanted, | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 					"this should be blacklisted, realURL: %s, displayURL: %s", | 
					
						
							|  |  |  | 					rtest->realurl, rtest->displayurl); | 
					
						
							| 
									
										
										
										
											2008-10-22 17:27:44 +00:00
										 |  |  | 				fail_unless_fmt(!strstr((const char*)ctx.virname,"Blacklisted"), | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 						"should be blacklisted, but is: %s\n", ctx.virname); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | START_TEST (phishingScan_test) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	do_phishing_test(&rtests[_i]); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | END_TEST | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-10 18:53:38 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2009-02-18 14:54:16 +00:00
										 |  |  | static struct uc { | 
					
						
							|  |  |  |     const char *in; | 
					
						
							|  |  |  |     const char *host; | 
					
						
							|  |  |  |     const char *path; | 
					
						
							|  |  |  | } uc[] = { | 
					
						
							|  |  |  |     {":example/%25%32%35", "example/", "%25"}, | 
					
						
							|  |  |  |     {":example/%25%32%35%25%32%35", "example/", "%25%25"}, | 
					
						
							|  |  |  |     {":example/abc%25%32%35asd", "example/", "abc%25asd"}, | 
					
						
							|  |  |  |     {":www.example.com/","www.example.com/",""}, | 
					
						
							|  |  |  |     {":%31%32%37%2e%30%2e%30%2e%31/%2E%73%65%63%75%72%65/%77%77%77%2e%65%78%61%6d%70%6c%65%2e%63%6f%6d/",  | 
					
						
							|  |  |  | 	"127.0.0.1/",".secure/www.example.com/"}, | 
					
						
							|  |  |  |     {":127.0.0.1/uploads/%20%20%20%20/.verify/.blah=abcd-ef=gh/", | 
					
						
							|  |  |  | 	"127.0.0.1/","uploads/%20%20%20%20/.verify/.blah=abcd-ef=gh/"}, | 
					
						
							|  |  |  |     {"http://example%23.com/%61%40%62%252B", | 
					
						
							|  |  |  | 	"example%23.com/", "a@b+"}, | 
					
						
							|  |  |  |     {"http://example.com/blah/..","example.com/",""}, | 
					
						
							|  |  |  |     {"http://example.com/blah/../x","example.com/","x"}, | 
					
						
							|  |  |  |     {"http://example.com/./a","example.com/","a"} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | START_TEST (test_url_canon) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     char urlbuff[1024+3]; | 
					
						
							| 
									
										
										
										
											2009-02-19 08:50:04 +00:00
										 |  |  |     char *host = NULL; | 
					
						
							|  |  |  |     const char *path = NULL; | 
					
						
							| 
									
										
										
										
											2009-02-18 14:54:16 +00:00
										 |  |  |     size_t host_len, path_len; | 
					
						
							|  |  |  |     struct uc *u = &uc[_i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cli_url_canon(u->in, strlen(u->in), urlbuff, sizeof(urlbuff), &host, &host_len, &path, &path_len); | 
					
						
							|  |  |  |     fail_unless(!!host && !!path, "null results\n"); | 
					
						
							|  |  |  |     fail_unless_fmt(!strcmp(u->host, host), "host incorrect: %s\n", host); | 
					
						
							|  |  |  |     fail_unless_fmt(!strcmp(u->path, path), "path incorrect: %s\n", path); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | END_TEST | 
					
						
							| 
									
										
										
										
											2009-05-15 11:53:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct regex_test { | 
					
						
							|  |  |  |     const char *regex; | 
					
						
							|  |  |  |     const char *text; | 
					
						
							|  |  |  |     int match; | 
					
						
							|  |  |  | } rg[] = { | 
					
						
							|  |  |  |     {"\\.exe$", "test.exe", 1}, | 
					
						
							|  |  |  |     {"\\.exe$", "test.eXe", 0}, | 
					
						
							|  |  |  |     {"(?i)\\.exe$", "test.exe", 1}, | 
					
						
							|  |  |  |     {"(?i)\\.exe$", "test.eXe", 1} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | START_TEST (test_regexes) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     regex_t reg; | 
					
						
							|  |  |  |     struct regex_test *tst = &rg[_i]; | 
					
						
							|  |  |  |     int match; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fail_unless(cli_regcomp(®, tst->regex, REG_EXTENDED | REG_NOSUB) == 0, "cli_regcomp"); | 
					
						
							|  |  |  |     match = (cli_regexec(®, tst->text, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1; | 
					
						
							|  |  |  |     fail_unless_fmt(match == tst->match, "cli_regexec failed for %s and %s\n", tst->regex, tst->text); | 
					
						
							|  |  |  |     cli_regfree(®); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | END_TEST | 
					
						
							| 
									
										
										
										
											2009-03-10 18:53:38 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-02-18 14:54:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | START_TEST(phishing_fake_test) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buf[4096]; | 
					
						
							|  |  |  | 	FILE *f = fdopen(open_testfile("input/daily.pdb"),"r"); | 
					
						
							|  |  |  | 	fail_unless(!!f,"fopen daily.pdb"); | 
					
						
							|  |  |  | 	while(fgets(buf, sizeof(buf), f)) { | 
					
						
							|  |  |  | 		struct rtest rtest; | 
					
						
							|  |  |  | 		const char *pdb = strchr(buf,':'); | 
					
						
							|  |  |  | 		fail_unless(!!pdb, "missing : in pdb"); | 
					
						
							|  |  |  | 		rtest.realurl = pdb; | 
					
						
							|  |  |  | 		rtest.displayurl = pdb; | 
					
						
							|  |  |  | 		rtest.result = 2; | 
					
						
							|  |  |  | 		do_phishing_test(&rtest); | 
					
						
							|  |  |  | 		rtest.realurl = "http://fake.example.com"; | 
					
						
							|  |  |  | 		rtest.result = 0; | 
					
						
							|  |  |  | 		do_phishing_test(&rtest); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fclose(f); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | END_TEST | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | Suite *test_regex_suite(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Suite *s = suite_create("regex"); | 
					
						
							| 
									
										
										
										
											2009-05-15 11:53:22 +00:00
										 |  |  | 	TCase *tc_api, *tc_matching, *tc_phish, *tc_phish2, *tc_regex; | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	tc_api = tcase_create("cli_regex2suffix"); | 
					
						
							|  |  |  | 	suite_add_tcase(s, tc_api); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	tcase_add_checked_fixture (tc_api, setup, teardown); | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	tcase_add_test(tc_api, empty); | 
					
						
							|  |  |  | 	tcase_add_test(tc_api, one); | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	tcase_add_loop_test(tc_api, test_suffix, 0, sizeof(tests)/sizeof(tests[0])); | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	tc_matching = tcase_create("regex_list"); | 
					
						
							|  |  |  | 	suite_add_tcase(s, tc_matching); | 
					
						
							|  |  |  | 	tcase_add_checked_fixture (tc_matching, rsetup, rteardown); | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	tcase_add_loop_test(tc_matching, regex_list_match_test, 0, sizeof(rtests)/sizeof(rtests[0])); | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	tc_phish = tcase_create("phishingScan"); | 
					
						
							|  |  |  | 	suite_add_tcase(s, tc_phish); | 
					
						
							| 
									
										
										
										
											2008-09-16 10:32:20 +00:00
										 |  |  | 	tcase_add_unchecked_fixture(tc_phish, psetup, pteardown); | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 	tcase_add_loop_test(tc_phish, phishingScan_test, 0, sizeof(rtests)/sizeof(rtests[0])); | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-07-29 15:37:23 +00:00
										 |  |  | 	tcase_add_test(tc_phish, phishing_fake_test); | 
					
						
							| 
									
										
										
										
											2008-07-25 16:03:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	tc_phish2 = tcase_create("phishingScan with 2 dbs"); | 
					
						
							|  |  |  | 	suite_add_tcase(s, tc_phish2); | 
					
						
							| 
									
										
										
										
											2008-09-16 10:32:20 +00:00
										 |  |  | 	tcase_add_unchecked_fixture(tc_phish2, psetup2, pteardown); | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	tcase_add_loop_test(tc_phish2, phishingScan_test, 0, sizeof(rtests)/sizeof(rtests[0])); | 
					
						
							| 
									
										
										
										
											2008-08-10 16:19:01 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 	tcase_add_test(tc_phish2, phishing_fake_test); | 
					
						
							| 
									
										
										
										
											2009-03-10 18:53:38 +00:00
										 |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							| 
									
										
										
										
											2009-02-18 14:54:16 +00:00
										 |  |  | 	tcase_add_loop_test(tc_phish, test_url_canon, 0, sizeof(uc)/sizeof(uc[0])); | 
					
						
							| 
									
										
										
										
											2009-03-10 18:53:38 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-08-01 14:50:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-15 11:53:22 +00:00
										 |  |  | 	tc_regex = tcase_create("cli_regcomp/execute"); | 
					
						
							|  |  |  | 	suite_add_tcase(s, tc_regex); | 
					
						
							|  |  |  | #ifdef CHECK_HAVE_LOOPS
 | 
					
						
							|  |  |  | 	tcase_add_loop_test(tc_regex, test_regexes, 0, sizeof(rg)/sizeof(rg[0])); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-07-25 07:25:36 +00:00
										 |  |  | 	return s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |