| 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..10\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
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use lib qw(blib/arch blib/lib ../ ../blib/lib ../blib/arch); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use LaBrea::Tarpit::DShield qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | move2_Q | ||||||||||||||||||||||||||||
| 14 | deliver2_DShield | ||||||||||||||||||||||||||||
| 15 | 1 | ); | |||||||||||||||||||||||||||
| 16 | 1 | $loaded = 1; | |||||||||||||||||||||||||||
| 17 | 1 | print "ok 1\n"; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | $test = 2; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | sub ok { | ||||||||||||||||||||||||||
|
Subroutine
ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 9 | print "ok $test\n"; | |||||||||||||||||||||||||||
| 23 | 9 | ++$test; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub next_sec { | ||||||||||||||||||||||||||
|
Subroutine
next_sec: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | 1 | my ($then) = @_; | |||||||||||||||||||||||||||
| 28 | 1 | my $now; | |||||||||||||||||||||||||||
| 29 | # wait for epoch | ||||||||||||||||||||||||||||
| 30 | 1 | ▶ | do { select(undef,undef,undef,0.1); $now = time } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | while ( $then >= $now ); | ||||||||||||||||||||||||||||
| 32 | 1 | $now; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | local $SIG{ALRM} = sub { die "test timeout"; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | umask 027; | |||||||||||||||||||||||||||
| 38 | 1 | ▶ | if (-d 'tmp') { # clean up previous test runs | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | opendir(T,'tmp'); | |||||||||||||||||||||||||||
| 40 | 0 | @_ = grep(!/^\./, readdir(T)); | |||||||||||||||||||||||||||
| 41 | 0 | closedir T; | |||||||||||||||||||||||||||
| 42 | 0 | foreach(@_) { | |||||||||||||||||||||||||||
| 43 | 0 | unlink "tmp/$_"; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||
| 46 | 1 | ▶ | mkdir 'tmp', 0750 unless (-e 'tmp' && -d 'tmp'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e "tmp" and -d "tmp"
MC/DC0%0/2
-e "tmp" and -d "tmp"
-e "tmp"
-d "tmp"
Truth table33%1/3
A and B
A= -e "tmp"B= -d "tmp"
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | my $smtp_response = 'dshield.smtp.response'; | |||||||||||||||||||||||||||
| 50 | 1 | my $sendmail_response = 'dshield.sendmail.response'; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | ▶ | sub compare_files { | ||||||||||||||||||||||||||
|
Subroutine
compare_files: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 53 | 2 | my ($cf,$q) = @_; # comparison file, q file | |||||||||||||||||||||||||||
| 54 | 2 | local(*F); | |||||||||||||||||||||||||||
| 55 | 2 | open (F,$cf); | |||||||||||||||||||||||||||
| 56 | 2 | $cf = ''; | |||||||||||||||||||||||||||
| 57 | 2 | ▶ | while (<F>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 24 | $cf .= $_; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 2 | tweak_version_string(\$cf); | |||||||||||||||||||||||||||
| 61 | 2 | close F; | |||||||||||||||||||||||||||
| 62 | 2 | open (F,$q); | |||||||||||||||||||||||||||
| 63 | 2 | $q = ''; | |||||||||||||||||||||||||||
| 64 | 2 | ▶ | while (<F>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 24 | $q .= $_; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 2 | tweak_version_string(\$q); | |||||||||||||||||||||||||||
| 68 | 2 | ▶ | return ($q eq $cf) ? '' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | : "queue file:\n$q\nne expected:\n$cf\nnot "; | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 4 | ▶ | sub tweak_version_string { | ||||||||||||||||||||||||||
|
Subroutine
tweak_version_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | 4 | my ($tp) = @_; | |||||||||||||||||||||||||||
| 74 | 4 | $$tp =~ s/VERSION/$LaBrea::Tarpit::DShield::VERSION/; | |||||||||||||||||||||||||||
| 75 | 4 | $$tp =~ s/LaBrea_Tarpit_DShield\s+[\S]+/LaBrea_Tarpit_DShield current:version:string/; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 1 | ▶ | sub create_cache { | ||||||||||||||||||||||||||
|
Subroutine
create_cache: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 78 | 1 | my ($in,$out) = @_; | |||||||||||||||||||||||||||
| 79 | 1 | local (*IN,*OUT); | |||||||||||||||||||||||||||
| 80 | 1 | open (IN,$in); | |||||||||||||||||||||||||||
| 81 | 1 | select IN; | |||||||||||||||||||||||||||
| 82 | 1 | $| = 1; | |||||||||||||||||||||||||||
| 83 | 1 | open (OUT,'>'.$out); | |||||||||||||||||||||||||||
| 84 | 1 | select OUT; | |||||||||||||||||||||||||||
| 85 | 1 | $| = 1; | |||||||||||||||||||||||||||
| 86 | 1 | select STDOUT; | |||||||||||||||||||||||||||
| 87 | 1 | ▶ | while (<IN>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 4 | print OUT $_; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 1 | close IN; | |||||||||||||||||||||||||||
| 91 | 1 | close OUT; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | my $config = { | |||||||||||||||||||||||||||
| 95 | 'DShield' => 'tmp/DShield.cache', # path/to/file | ||||||||||||||||||||||||||||
| 96 | 'UserID' => '12321', # DShield UserID | ||||||||||||||||||||||||||||
| 97 | 'To' => 'test@dshield.org', # or report@dshield.org | ||||||||||||||||||||||||||||
| 98 | 'From' => 'john.doe@foo.com', | ||||||||||||||||||||||||||||
| 99 | 'Reply-To' => 'mary.doe@foo.com', # optional | ||||||||||||||||||||||||||||
| 100 | # optional | ||||||||||||||||||||||||||||
| 101 | 'Obfuscate' => 'complete or partial', | ||||||||||||||||||||||||||||
| 102 | # either one or more working SMTP server's | ||||||||||||||||||||||||||||
| 103 | 'smtp' => 'iceman.dshield.org,mail.euclidian.com', | ||||||||||||||||||||||||||||
| 104 | # or a sendmail compatible mail transport command | ||||||||||||||||||||||||||||
| 105 | 'sendmail' => '/usr/lib/sendmail -t -oi', | ||||||||||||||||||||||||||||
| 106 | }; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | my $ds = $config->{DShield}; | |||||||||||||||||||||||||||
| 110 | 1 | my $in = './dshield.cache'; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | &create_cache($in,$ds); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 1 | $ds =~ m|(.*/)|; | |||||||||||||||||||||||||||
| 115 | 1 | my $dir = $1; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | ## 2 trap chk_config errors | ||||||||||||||||||||||||||||
| 118 | 1 | delete $config->{sendmail}; | |||||||||||||||||||||||||||
| 119 | 1 | ▶ | print "did not trap chk_config errors\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | unless deliver2_DShield($config) =~ /unknown/; | ||||||||||||||||||||||||||||
| 121 | 1 | &ok; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 1 | delete $config->{Obfuscate}; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | ## 3 should fall through to end, no queue files | ||||||||||||||||||||||||||||
| 126 | 1 | $_ = deliver2_DShield($config); | |||||||||||||||||||||||||||
| 127 | 1 | ▶ | print "unknown error $_" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | if $_; | ||||||||||||||||||||||||||||
| 129 | 1 | &ok; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | ## 4 create qf1 | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 1 | my $now = &next_sec(time); | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 1 | my $dbfsmtp = $dir . 'dF' . $now .'.'. $$ .'.'. 0 . '.smtp'; | |||||||||||||||||||||||||||
| 136 | 1 | my $dbfsendmail = $dir . 'dF' . $now .'.'. $$ .'.'. 0 . '.sendmail'; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 1 | $_ = move2_Q($config,1); | |||||||||||||||||||||||||||
| 139 | 1 | ▶ | print "failed: $_\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | if $_; | ||||||||||||||||||||||||||||
| 141 | 1 | &ok; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | ## 5 create smtp response | ||||||||||||||||||||||||||||
| 144 | 1 | $_ = deliver2_DShield($config,2); | |||||||||||||||||||||||||||
| 145 | 1 | ▶ | print "$_\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | if $_; | ||||||||||||||||||||||||||||
| 147 | 1 | &ok; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | ## 6 check smtp data | ||||||||||||||||||||||||||||
| 150 | 1 | print compare_files($smtp_response,$dbfsmtp); | |||||||||||||||||||||||||||
| 151 | 1 | &ok; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 1 | delete $config->{smtp}; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # set the cache file to executable for dummy sendmail | ||||||||||||||||||||||||||||
| 156 | 1 | chmod 0755, $ds; | |||||||||||||||||||||||||||
| 157 | 1 | $config->{sendmail} = $ds; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | ## 7 create the sendmail response | ||||||||||||||||||||||||||||
| 161 | 1 | $_ = deliver2_DShield($config,2); | |||||||||||||||||||||||||||
| 162 | 1 | ▶ | print "$_\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | if $_; | ||||||||||||||||||||||||||||
| 164 | 1 | &ok; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | ## 8 check smtp data | ||||||||||||||||||||||||||||
| 167 | 1 | print compare_files($sendmail_response,$dbfsendmail); | |||||||||||||||||||||||||||
| 168 | 1 | &ok; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | ## 9 this should unlink all qFiles | ||||||||||||||||||||||||||||
| 171 | 1 | $_ = deliver2_DShield($config,1); | |||||||||||||||||||||||||||
| 172 | 1 | ▶ | print "$_\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | if $_; | ||||||||||||||||||||||||||||
| 174 | 1 | &ok; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | ## 10 verify that they are gone | ||||||||||||||||||||||||||||
| 177 | 1 | local *D; | |||||||||||||||||||||||||||
| 178 | 1 | opendir(D, $dir); | |||||||||||||||||||||||||||
| 179 | 1 | @_ = grep(/qF/, readdir(D)); | |||||||||||||||||||||||||||
| 180 | 1 | closedir D; | |||||||||||||||||||||||||||
| 181 | 1 | ▶ | print "failed to delete sent files in queue\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | if @_; | ||||||||||||||||||||||||||||
| 183 | 1 | &ok; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||