|
From: <jgr...@us...> - 2003-08-01 01:09:52
|
Update of /cvsroot/popfile/engine/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv29410/tests
Modified Files:
TestPOP3.tst
Log Message:
Added tests for TOP handling including toptoo and our caching mechanism. Of all the tests I've written so far these were the most interesting because they flushed out multiple bugs in our TOP handling/caching which are now fixed
Index: TestPOP3.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestPOP3.tst,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** TestPOP3.tst 31 Jul 2003 23:36:07 -0000 1.8
--- TestPOP3.tst 1 Aug 2003 01:09:50 -0000 1.9
***************
*** 308,311 ****
--- 308,330 ----
my $port = 9000 + int(rand(1000));
+
+ # This pipe is used to send signals to the child running
+ # the proxy to change its state, the following commands can
+ # be sent
+ #
+ # __QUIT Causes the child to terminate proxy service and
+ # exit
+ #
+ # __TOPTOO Causes the child to enable the toptoo option in
+ # the proxy
+ #
+ # __SECUREBAD Causes the child to define an incorrect secure
+ # server
+ #
+ # __SECUREOK Causes the child to define the correct secure
+ # server
+
+ pipe my $dreader, my $dwriter;
+ pipe my $ureader, my $uwriter;
my $pid2 = fork();
***************
*** 314,317 ****
--- 333,341 ----
# CHILD THAT WILL RUN THE POP3 PROXY
+ close $dwriter;
+ close $ureader;
+
+ $uwriter->autoflush(1);
+
my $p = new Proxy::POP3;
***************
*** 330,338 ****
$p->start();
! my $now = time;
! while ( $p->service() && ( ( $now + 15 ) > time ) ) {
}
my @kids = keys %{$p->{children__}};
while ( $#kids >= 0 ) {
--- 354,381 ----
$p->start();
! while ( 1 ) {
! last if !$p->service();
! if ( pipeready( $dreader ) ) {
! my $command = <$dreader>;
!
! print "[$command]\n";
!
! if ( $command =~ /__QUIT/ ) {
! print $uwriter "OK\n";
! last;
! }
!
! if ( $command =~ /__TOPTOO/ ) {
! $p->config_( 'toptoo', 1 );
! print $uwriter "OK\n";
! next;
! }
! }
}
+ close $dreader;
+ close $uwriter;
+
my @kids = keys %{$p->{children__}};
while ( $#kids >= 0 ) {
***************
*** 349,352 ****
--- 392,399 ----
# PARENT THAT WILL SEND COMMAND TO THE PROXY
+ close $dreader;
+ close $uwriter;
+ $dwriter->autoflush(1);
+
my $client = IO::Socket::INET->new(
Proto => "tcp",
***************
*** 634,641 ****
test_assert_equal( $magnet, '' );
- # TODO Test basic TOP capability with toptoo gets classification
- # TODO Test RETR after TOP comes from cache
- # TODO Test TOP after TOP comes from cache
-
# Check that we echo the remote servers QUIT response
--- 681,684 ----
***************
*** 646,649 ****
--- 689,879 ----
close $client;
+ # Test basic TOP capability with toptoo gets classification
+
+ print $dwriter "__TOPTOO\n";
+ my $line = <$ureader>;
+ test_assert_equal( $line, "OK\n" );
+
+
+ my $client = IO::Socket::INET->new(
+ Proto => "tcp",
+ PeerAddr => 'localhost',
+ PeerPort => $port );
+
+ test_assert( defined( $client ) );
+ test_assert( $client->connected );
+
+ my $result = <$client>;
+ test_assert_equal( $result, "+OK POP3 POPFile (test suite) server ready$eol" );
+
+ print $client "USER 127.0.0.1:8110:gooduser$eol";
+ $result = <$client>;
+ test_assert_equal( $result, "+OK Welcome gooduser$eol" );
+
+ $countdown = 2;
+ print $client "TOP 8 $countdown$eol";
+ $result = <$client>;
+ test_assert_equal( $result, "+OK " . ( -s $messages[7] ) . "$eol" );
+
+ $cam = $messages[7];
+ $cam =~ s/msg$/cam/;
+ test_assert( open FILE, "<$cam" );
+ $headers = 1;
+ while ( ( my $line = <FILE> ) && ( $countdown > 0 ) ) {
+ $result = <$client>;
+ $result =~ s/popfile2=8/popfile0=0/;
+ test_assert_equal( $result, $line );
+ if ( $headers == 0 ) {
+ $countdown -= 1;
+ }
+ if ( $line =~ /^[\r\n]+$/ ) {
+ $headers = 0;
+ }
+ }
+ close FILE;
+
+ $result = <$client>;
+ test_assert_equal( $result, "$eol" );
+ $result = <$client>;
+ test_assert_equal( $result, ".$eol" );
+
+ test_assert( -e 'messages/popfile2=8.msg' );
+ test_assert( -e 'messages/popfile2=8.cls' );
+
+ test_assert( open FILE, "<$messages[7]" );
+ test_assert( open HIST, "<messages/popfile2=8.msg" );
+ while ( ( my $fl = <FILE> ) && ( my $ml = <HIST> ) ) {
+ $fl =~ s/[\r\n]//g;
+ $ml =~ s/[\r\n]//g;
+ test_assert_equal( $fl, $ml );
+ }
+ test_assert( eof(FILE) );
+ test_assert( eof(HIST) );
+ close FILE;
+ close HIST;
+
+ my ( $reclassified, $bucket, $usedtobe, $magnet ) = $b->history_read_class( 'popfile2=8.msg' );
+ test_assert( !$reclassified );
+ test_assert_equal( $bucket, 'spam' );
+ test_assert( !defined( $usedtobe ) );
+ test_assert_equal( $magnet, '' );
+
+ # Test RETR after TOP comes from cache
+
+ print $client "RETR 8$eol";
+ $result = <$client>;
+ test_assert_equal( $result, "+OK " . ( -s 'messages/popfile2=8.msg' ) . " bytes from POPFile cache$eol" );
+
+ $cam = $messages[7];
+ $cam =~ s/msg$/cam/;
+ test_assert( open FILE, "<$cam" );
+ $headers = 1;
+ while ( my $line = <FILE> ) {
+ $line =~ s/[\r\n]//g;
+ $result = <$client>;
+ $result =~ s/[\r\n]//g;
+ $result =~ s/popfile2=8/popfile0=0/;
+ test_assert_equal( $result, $line );
+ }
+ close FILE;
+
+ $result = <$client>;
+ test_assert_equal( $result, ".$eol" );
+
+ # Test RETR after RETR returns cached copy
+
+ print $client "RETR 9$eol";
+ $result = <$client>;
+ test_assert_equal( $result, "+OK " . ( -s $messages[8] ) . "$eol" );
+ my $cam = $messages[8];
+ $cam =~ s/msg$/cam/;
+
+ test_assert( open FILE, "<$cam" );
+ while ( <FILE> ) {
+ my $line = $_;
+ $result = <$client>;
+ $result =~ s/popfile2=9/popfile0=0/;
+ test_assert_equal( $result, $line );
+ }
+ close FILE;
+
+ $result = <$client>;
+ test_assert_equal( $result, "$eol" );
+ $result = <$client>;
+ test_assert_equal( $result, ".$eol" );
+
+ select( undef, undef, undef, 0.1 );
+
+ test_assert( -e 'messages/popfile2=9.msg' );
+ test_assert( -e 'messages/popfile2=9.cls' );
+
+ test_assert( open FILE, "<$messages[8]" );
+ test_assert( open HIST, "<messages/popfile2=9.msg" );
+ while ( ( my $fl = <FILE> ) && ( my $ml = <HIST> ) ) {
+ $fl =~ s/[\r\n]//g;
+ $ml =~ s/[\r\n]//g;
+ test_assert_equal( $fl, $ml );
+ }
+ test_assert( eof(FILE) );
+ test_assert( eof(HIST) );
+ close FILE;
+ close HIST;
+
+ my ( $reclassified, $bucket, $usedtobe, $magnet ) = $b->history_read_class( 'popfile2=9.msg' );
+ test_assert( !$reclassified );
+ test_assert_equal( $bucket, 'spam' );
+ test_assert( !defined( $usedtobe ) );
+ test_assert_equal( $magnet, '' );
+
+ print $client "RETR 9$eol";
+ $result = <$client>;
+ test_assert_equal( $result, "+OK " . ( -s 'messages/popfile2=9.msg' ) . " bytes from POPFile cache$eol" );
+
+ $cam = $messages[8];
+ $cam =~ s/msg$/cam/;
+ test_assert( open FILE, "<$cam" );
+ $headers = 1;
+ while ( my $line = <FILE> ) {
+ $line =~ s/[\r\n]//g;
+ $result = <$client>;
+ $result =~ s/[\r\n]//g;
+ $result =~ s/popfile2=9/popfile0=0/;
+ test_assert_equal( $result, $line );
+ }
+ close FILE;
+
+ $result = <$client>;
+ test_assert_equal( $result, ".$eol" );
+
+ # TODO Test RETR after TOP/RETR with correct CLS file
+
+ unlink( 'messages/popfile2=9.cls' );
+
+ print $client "RETR 9$eol";
+ $result = <$client>;
+ test_assert_equal( $result, "+OK " . ( -s 'messages/popfile2=9.msg' ) . " bytes from POPFile cache$eol" );
+
+ $cam = $messages[8];
+ $cam =~ s/msg$/cam/;
+ test_assert( open FILE, "<$cam" );
+ $headers = 1;
+ while ( my $line = <FILE> ) {
+ $line =~ s/[\r\n]//g;
+ $result = <$client>;
+ $result =~ s/[\r\n]//g;
+ $result =~ s/popfile2=9/popfile0=0/;
+ test_assert_equal( $result, $line );
+ }
+ close FILE;
+
+ $result = <$client>;
+ test_assert_equal( $result, ".$eol" );
+
+ print $client "QUIT$eol";
+ $result = <$client>;
+ test_assert_equal( $result, "+OK Bye$eol" );
+
+ close $client;
+
# Test QUIT straight after connect
***************
*** 775,778 ****
--- 1005,1016 ----
close $client;
+
+ # Tell the proxy to die
+
+ print $dwriter "__QUIT\n";
+ $line = <$ureader>;
+ test_assert_equal( $line, "OK\n" );
+ close $dwriter;
+ close $ureader;
while ( waitpid( $pid, &WNOHANG ) != $pid ) {
|