DShield/t/chk_config.t

filter: Statementstmt 100% 86 / 86 Branchbran 50.0% 24 / 48 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 82.7% 115 / 139 CC 2 SCAR 3.2
CC
2
Cov
82%
END
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Util/t/labrea_whoami.t ↑ Summary blib/lib/LaBrea/Tarpit/Util.pm »
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as erl test.pl'
3  
4 ######################### We start with some black magic to print on failure.
5  
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
8  
9 1 ▶BEGIN { $| = 1; print "1..24\n"; }
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶END {print "not ok 1\n" unless $loaded;}
Subroutine END: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $loaded 0 1 1
11 1 ▶use LaBrea::Tarpit::DShield qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 chk_config
13 move2_Q
14 1 );
15 1 $loaded = 1;
16 1 print "ok 1\n";
17  
18 1 $test = 2;
19  
20 23 ▶sub ok {
Subroutine ok: called CC=1 SCAR=0.0
21 23 print "ok $test\n";
22 23 ++$test;
23 }
24  
25 =pod
26  
27 Need to test this:
28  
29 my $config = {
30 'DShield' => 'tmp/DShield.cache', # path/to/file
31 'UserID' => '0', # DShield UserID
32 'To' => 'test@dshield.org', # or report@dshield.org
33 'From' => 'john.doe@foo.com',
34 'Reply-To' => 'john.doe@foo.com', # optional
35 # optional
36 'Obfuscate' => 'complete or partial',
37 # either one or more working SMTP server's
38 'smtp' => 'iceman.dshield.org,mail.euclidian.com',
39 # or a sendmail compatible mail transport command
40 'sendmail' => '/usr/lib/sendmail -t -oi',
41 };
42  
43 order is:
44  
45 UserID
46 DShield
47 To
48 From
49 Reply-To
50 smtp
51 sendmail
52 Obfuscate
53  
54 =cut
55  
56 1 my $config = {};
57  
58 ### NOTE ###
59 # Test for UserID moved to 'move2_Q', tests 2,3,4,5,6
60 ###
61  
62 ## check various UserID combinations
63 ## 2 absent
64 1 ▶print "missing UserID not found\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ = move2_Q($config)) eq "missing DShield UserID" 0 1 1
65 unless ($_ = move2_Q($config)) eq 'missing DShield UserID';
66 1 &ok;
67  
68 ## 3 undefined
69 1 $config->{UserID} = undef;
70 1 ▶print "undef UserID not found\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ = move2_Q($config)) eq "missing DShield UserID" 0 1 1
71 unless ($_ = move2_Q($config)) eq 'missing DShield UserID';
72 1 &ok;
73  
74 ## 4 non-numeric
75 1 $config->{UserID} = 'crap';
76 1 ▶print "non-numeric UserID not found\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ = move2_Q($config)) eq "missing DShield UserID" 0 1 1
77 unless ($_ = move2_Q($config)) eq 'missing DShield UserID';
78 1 &ok;
79  
80 ## 5 -- 0 OK
81 1 $config->{UserID} = 0;
82 1 ▶print "zero UserID not accepted\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless move2_Q($config) eq "missing DShield queue directory" 0 1 1
83 unless move2_Q($config) eq 'missing DShield queue directory';
84 1 &ok;
85  
86 ## 6 other mumeric
87 1 $config->{UserID} = '12345';
88 1 ▶print "zero UserID not accepted\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless move2_Q($config) eq "missing DShield queue directory" 0 1 1
89 unless move2_Q($config) eq 'missing DShield queue directory';
90 1 &ok;
91  
92 # missing DShield file checked above, twice... but....
93  
94 ## 7 should not insert leading './'
95 1 $config->{DShield} = 'tmp/crap';
96 1 chk_config($config);
97 print "inserted extra './' in DShield filename\nnot "
98 1 ▶ unless $config->{DShield} eq 'tmp/crap';
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"DShield"} eq "tmp/crap" 0 1 1
99 1 &ok;
100  
101 ## 8 insert './' where needed
102 1 $config->{DShield} = 'tmp';
103 1 chk_config($config);
104 print "failed to insert './' in DShield filename\nnot "
105 1 ▶ unless $config->{DShield} eq './tmp';
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"DShield"} eq "./tmp" 0 1 1
106 1 &ok;
107  
108 ## 9 check one insertion of './' only
109 1 $_ = chk_config($config);
110 print "inserted extra './' in DShield filename\nnot "
111 1 ▶ unless $config->{DShield} eq './tmp';
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"DShield"} eq "./tmp" 0 1 1
112 1 &ok;
113  
114 ## 10 response above should find missing To:
115 1 ▶print "failed to detect missing To:\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ /missing or invalid To:/ 0 1 1
116 unless $_ =~ /missing or invalid To:/;
117 1 &ok;
118  
119 ## 11 corrupt mail format
120 1 $config->{To} = 'a@b';
121 1 ▶print "failed to detect corrupt To:\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless chk_config($config) =~ /missing or invalid To:/ 0 1 1
122 unless chk_config($config) =~ /missing or invalid To:/;
123 1 &ok;
124  
125 ## 12 To is OK
126 1 $config->{To} = 'a@b.c';
127 1 ▶print "refused good To:\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ = chk_config($config)) =~ /missing or invalid From:/ 0 1 1
128 unless ($_ = chk_config($config)) =~ /missing or invalid From:/;
129 1 &ok;
130  
131 ## 13 corrupt mail format
132 1 $config->{From} = 'a@b';
133 1 ▶print "failed to detect corrupt From:\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless chk_config($config) =~ /missing or invalid From:/ 0 1 1
134 unless chk_config($config) =~ /missing or invalid From:/;
135 1 &ok;
136  
137 ## 14 From is OK
138 1 $config->{From} = 'a@b.f';
139 1 ▶print "refused good From:\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ = chk_config($config)) =~ /missing mail agent/ 0 1 1
140 unless ($_ = chk_config($config)) =~ /missing mail agent/;
141 1 &ok;
142  
143 ## 15 Reply-To should eq From
144 print "did not preset absent Reply-To\nnot "
145 1 ▶ unless $config->{'Reply-To'} eq 'a@b.f';
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"Reply-To"} eq "a\@b.f" 0 1 1
146 1 &ok;
147  
148 ## 16 missing Reply-To
149 1 $config->{'Reply-To'} = undef;
150 1 ▶print "accepted undefined Reply-To\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless chk_config($config) =~ /invalid Reply-To/ 0 1 1
151 unless chk_config($config) =~ /invalid Reply-To/;
152 1 &ok;
153  
154 ## 17 corrupt mail format
155 1 $config->{'Reply-To'} = 'a@b';
156 1 ▶print "failed to detect corrupt Reply-To:\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless chk_config($config) =~ /invalid Reply-To/ 0 1 1
157 unless chk_config($config) =~ /invalid Reply-To/;
158 1 &ok;
159  
160 ## 18 From is OK
161 1 $config->{'Reply-To'} = 'a@b.r';
162 1 ▶print "refused good Reply-To:\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ = chk_config($config)) =~ /missing mail agent/ 0 1 1
163 unless ($_ = chk_config($config)) =~ /missing mail agent/;
164 1 &ok;
165  
166 ## 19 mail agents found
167 1 $config->{smtp} = '_SomeRandomString_123453211_';
168 1 ▶print "failed to recognize SMTP mail agent\nnot "
Branch: 1 branch
BranchTrueFalseTotal
if chk_config($config) 0 1 1
169 if chk_config($config);
170 1 &ok;
171  
172 1 delete $config->{smtp};
173 ## 20
174 1 $config->{sendmail} = '_SomeRandomString_123453211_';
175 1 ▶print "accepted bogus sendmail agent\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless chk_config($config) =~ /sendmail agent missing/ 0 1 1
176 unless chk_config($config) =~ /sendmail agent missing/;
177 1 &ok;
178  
179 1 $config->{smtp} = '_SomeRandomString_123453211_';
180 1 delete $config->{sendmail};
181  
182 ## 21 obfuscate
183 1 $config->{Obfuscate} = '0'; # false
184 1 ▶print "failed Obfuscate false test\nnot "
Branch: 1 branch
BranchTrueFalseTotal
if chk_config($config) 0 1 1
185 if chk_config($config);
186 1 &ok;
187  
188 ## 22 obfuscate, invalid keyword
189 1 $config->{Obfuscate} = 'crap';
190 1 ▶print "accepted bad Obfuscate keyword\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless chk_config($config) =~ /unknown/ 0 1 1
191 unless chk_config($config) =~ /unknown/;
192 1 &ok;
193  
194 ## 23
195 1 $config->{Obfuscate} = 'PaRtIaL';
196 1 ▶print "failed to accept 'partial' keyword\nnot "
Branch: 1 branch
BranchTrueFalseTotal
if $_ = chk_config($config) 0 1 1
197 if ($_ = chk_config($config));
198 1 &ok;
199  
200 ## 24
201 1 $config->{Obfuscate} = 'cOmPlEtE';
202 1 ▶print "failed to accept 'complete' keyword\nnot "
Branch: 1 branch
BranchTrueFalseTotal
if $_ = chk_config($config) 0 1 1
203 if ($_ = chk_config($config));
204 1 &ok;
« Util/t/labrea_whoami.t ↑ Summary blib/lib/LaBrea/Tarpit/Util.pm »