~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to contrib/phishing/test/pdomain.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
Import upstream version 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Phishing module test.
 
3
 *
 
4
 *  Copyright (C) 2006 T�r�k Edvin <edwintorok@gmail.com>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
19
 *  MA 02110-1301, USA.
 
20
 *
 
21
 *  $Log $
 
22
 */
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <check.h>
 
26
#include <test-config.h>
 
27
#include <clamav.h>
 
28
#include <clamav-config.h>
 
29
#include "pdomain.h"
 
30
#include <phish_domaincheck_db.h>
 
31
#define FULLFLAG 0xFFFF
 
32
static struct regex_list_test {
 
33
        const char* inputReal;
 
34
        const char* inputDisp;
 
35
        int output;
 
36
        unsigned short flags;
 
37
} regex_list_tests[] = {
 
38
        {"www.google.com","www.google.com",0,FULLFLAG},
 
39
        {"http://abcdef","jj",0,FULLFLAG},
 
40
        {"http://abcdefj","jj",1,FULLFLAG},
 
41
        {"http://ab.f.com","jj",0,FULLFLAG},
 
42
        {"http://a.f.com","jj",1,FULLFLAG},
 
43
        {"http://b.f.com","jj",1,FULLFLAG},
 
44
        {"http://c.f.com","jj",1,FULLFLAG},
 
45
        {"http://d.f.com","jj",1,FULLFLAG},
 
46
        {"http://f.f.com","jj",0,FULLFLAG},
 
47
        {"http://e.f.com","jj",1,FULLFLAG},
 
48
        {"http://ae.f.net","jj",1,FULLFLAG},
 
49
        {"http://cb.f.com","jj",0,FULLFLAG},
 
50
        {"http://abcf","jj",0,FULLFLAG},
 
51
        {"virus.zip","viiirii.zip",0,FULLFLAG},
 
52
        {"http://zztest.com","jj",1,0xFEF7}
 
53
};
 
54
/*static int regex_list_tests_cnt = sizeof(regex_list_tests)/sizeof(regex_list_tests[0]);*/
 
55
static int regex_list_tests_i=-1;
 
56
static struct cl_engine* engine;
 
57
 
 
58
static void regex_list_tests_setup(void)
 
59
{
 
60
        int rc;
 
61
        unsigned int signo;
 
62
        engine=NULL;
 
63
        rc = cl_loaddb(REGEXTEST_FILE,&engine,&signo);
 
64
        fail_unless(rc==0,cl_strerror(rc));
 
65
        fail_unless(is_domainlist_ok(engine));
 
66
        regex_list_tests_i=0;
 
67
}
 
68
 
 
69
static void regex_list_tests_teardown(void)
 
70
{
 
71
        cl_free(engine);
 
72
        engine=NULL;
 
73
}
 
74
 
 
75
 
 
76
static int regex_list_test_function(const char* input1,const char* input2,const unsigned short flag_expected)
 
77
{
 
78
        unsigned short flags=FULLFLAG;
 
79
        int rc;
 
80
        fail_unless(is_domainlist_ok(engine));
 
81
        rc = domainlist_match(engine,input1,input2,0,&flags);
 
82
        fail_unless(flags == flag_expected);
 
83
        return rc;
 
84
}
 
85
 
 
86
START_TEST(regex_list_test_create)
 
87
{
 
88
        fail_unless( regex_list_test_function("","",FULLFLAG)!=-1,
 
89
                        "Initialization failed");
 
90
}
 
91
END_TEST
 
92
/* standard cruft */
 
93
#define REGEX_LIST_TEST(x) \
 
94
START_TEST(regex_list_test_##x)\
 
95
{\
 
96
        const int regex_list_test_nr = (x);\
 
97
        struct regex_list_test test = regex_list_tests[regex_list_test_nr];\
 
98
        const int output = regex_list_test_function(test.inputReal,test.inputDisp,test.flags);\
 
99
        const int expectedoutput = test.output;\
 
100
        char failed_msg[512];\
 
101
        snprintf(failed_msg,sizeof(failed_msg),"Failed at test:%d (input: %s %s;expected:%d, got:%d)",\
 
102
                        regex_list_test_nr,test.inputReal,test.inputDisp,expectedoutput,output);\
 
103
        fail_unless(output==expectedoutput,failed_msg);\
 
104
}\
 
105
END_TEST
 
106
 
 
107
 
 
108
REGEX_LIST_TEST(0)
 
109
REGEX_LIST_TEST(1)
 
110
REGEX_LIST_TEST(2)
 
111
REGEX_LIST_TEST(3)
 
112
REGEX_LIST_TEST(4)
 
113
REGEX_LIST_TEST(5)
 
114
REGEX_LIST_TEST(6)
 
115
REGEX_LIST_TEST(7)
 
116
REGEX_LIST_TEST(8)
 
117
REGEX_LIST_TEST(9)
 
118
REGEX_LIST_TEST(10)
 
119
REGEX_LIST_TEST(11)
 
120
REGEX_LIST_TEST(12)
 
121
REGEX_LIST_TEST(13)
 
122
REGEX_LIST_TEST(14)
 
123
#define ADD_REGEX_LIST_TEST(x)  tcase_add_test(tc_core, regex_list_test_##x)
 
124
 
 
125
 
 
126
TCase* create_pdomain_testcase(void)
 
127
{
 
128
        TCase* tc_core = tcase_create("Regex List");
 
129
        tcase_add_test(tc_core, regex_list_test_create);
 
130
        ADD_REGEX_LIST_TEST(0);
 
131
        ADD_REGEX_LIST_TEST(1);
 
132
        ADD_REGEX_LIST_TEST(2);
 
133
        ADD_REGEX_LIST_TEST(3);
 
134
        ADD_REGEX_LIST_TEST(4);
 
135
        ADD_REGEX_LIST_TEST(5);
 
136
        ADD_REGEX_LIST_TEST(6);
 
137
        ADD_REGEX_LIST_TEST(7);
 
138
        ADD_REGEX_LIST_TEST(8);
 
139
        ADD_REGEX_LIST_TEST(9);
 
140
        ADD_REGEX_LIST_TEST(10);
 
141
        ADD_REGEX_LIST_TEST(11);
 
142
        ADD_REGEX_LIST_TEST(12);
 
143
        ADD_REGEX_LIST_TEST(13);
 
144
        ADD_REGEX_LIST_TEST(14);
 
145
        tcase_add_checked_fixture(tc_core, regex_list_tests_setup, regex_list_tests_teardown);
 
146
        return tc_core;
 
147
}
 
148
 
 
149
 
 
150
 
 
151
 
 
152