From: naoki i. <am...@us...> - 2008-04-16 13:08:03
|
Update of /cvsroot/popfile/engine/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22400/tests Modified Files: TestBayes.tst TestHistory.tst TestXMLRPC.tst Log Message: Change Log 1. Added the UI to rename user's name UI/HTML.pm Classifier/Bayes.pm POPFile/API.pm skins/default/users-page.thtml languages/English.msg languages/Nihongo.msg tests/TestBayes.tst 2. Save the current piddir and restore in the utility scripts bayes.pl insert.pl pipe.pl 3. TestXMLRPC's child process (xmlrpc server) now terminates tests/TestXMLRPC.tst 4. Use the place holders in preparing SQL statements UI/HTML.pm POPFile/History.pm 5. Copy the global language setting to the new user's default language Classifier/Bayes.pm 6. New script to import old database to new database import.pl import.pl - import user data into the new database Usage: import.pl <old_user_dir> <user> [<newuser>] <old_user_dir> The path to the user data to import <user> The name of the user to import from Use 'admin' when upgrading from v1 <newuser> The name of the user to import into (optional) If not specified, assume newuser=user 7. Added multi user support tests tests/TestHistory.tst Current state of the test suite: TestBayesScript PASS TestBayes PASS TestConfiguration PASS * TestHistory PASS TestHTML PASS * TestHTTP PASS TestIMAP PASS TestInsertScript PASS * TestLogger PASS TestMailParse PASS TestModule PASS TestMQ PASS TestMutex PASS TestPipeScript PASS TestPOP3 PASS TestProxy PASS TestWordMangle PASS TestXMLRPC PASS * : TODO : needs to add tests for multi user support Index: TestHistory.tst =================================================================== RCS file: /cvsroot/popfile/engine/tests/TestHistory.tst,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** TestHistory.tst 9 Apr 2008 17:20:48 -0000 1.18 --- TestHistory.tst 16 Apr 2008 13:08:05 -0000 1.19 *************** *** 22,25 **** --- 22,27 ---- # --------------------------------------------------------------------------- + use strict; + rmtree( 'messages' ); rmtree( 'corpus' ); *************** *** 63,107 **** my $session = $h->classifier_()->get_administrator_session_key(); ! my ( $slot, $file ) = $h->reserve_slot( $session, 1 ); ! test_assert( defined( $slot ) ); ! test_assert( !( -e $file ) ); ! test_assert_equal( $file, $h->get_slot_file( $slot ) ); ! my $path = $file; ! $path =~ s/popfile..\.msg//; ! test_assert( ( -e $path ) ); ! test_assert( ( -d $path ) ); ! open FILE, ">$file"; ! print FILE "test\n"; ! close FILE; ! # Check that there is an entry and that it has not yet ! # been committed ! my @result = $h->db_()->selectrow_array( "select committed from history where id = $slot;" ); ! test_assert_equal( $#result, 0 ); ! test_assert( $result[0] != 1 ); ! # Check that release_slot removes the entry from the database ! # and deletes the file, and does clean up the directory ! $h->release_slot( $slot ); ! test_assert( !( -e $file ) ); ! test_assert( !( -e $path ) ); ! @result = $h->db_()->selectrow_array( "select committed from history where id = $slot;" ); ! test_assert_equal( $#result, -1 ); ! # Now try actually adding an element to the history. Reserve a slot ! # then commit it and call service to get it added. Ensure that the ! # slot is now committed and has the right fields ! ( $slot, $file ) = $h->reserve_slot( $session, 1 ); ! open FILE, ">$file"; ! print FILE <<EOF; Received: Today From: John Graham-Cumming <nospam\@jgc.org> --- 65,154 ---- my $session = $h->classifier_()->get_administrator_session_key(); ! history_test( $session ); ! # Check that the directories are gone too ! test_assert( !( -e 'messages/00' ) ); ! test_assert( !( -e 'messages/00/00' ) ); ! test_assert( !( -e 'messages/00/00/00' ) ); ! # Multi user mode tests ! $h->global_config_( 'single_user', 0 ); ! my ( $result, $password ) = $h->classifier_()->create_user( $session, 'test' ); ! test_assert( defined( $result ) ); ! test_assert_equal( $result, 0 ); ! test_assert( defined( $password ) ); ! my $user_session = $h->classifier_()->get_session_key( 'test', $password ); ! test_assert( defined( $user_session ) ); ! $h->classifier_()->create_bucket( $user_session, 'spam' ); ! $h->classifier_()->create_bucket( $user_session, 'personal' ); ! $h->classifier_()->create_bucket( $user_session, 'other' ); ! history_test( $user_session ); ! $h->classifier_()->release_session_key( $user_session ); ! $h->classifier_()->release_session_key( $session ); ! $POPFile->CORE_stop(); ! 1; ! ! sub history_test ! { ! my ( $session ) = @_; ! ! my $userid = $h->classifier_()->get_user_id_from_session( $session ); ! test_assert( defined( $userid ) ); ! ! my %bucketids; ! $bucketids{spam} = $h->classifier_()->get_bucket_id( $session, 'spam' ); ! $bucketids{personal} = $h->classifier_()->get_bucket_id( $session, 'personal' ); ! ! my ( $slot, $file ) = $h->reserve_slot( $session ); ! ! test_assert( defined( $slot ) ); ! test_assert( !( -e $file ) ); ! test_assert_equal( $file, $h->get_slot_file( $slot ) ); ! ! my $path = $file; ! $path =~ s/popfile..\.msg//; ! test_assert( ( -e $path ) ); ! test_assert( ( -d $path ) ); ! ! open FILE, ">$file"; ! print FILE "test\n"; ! close FILE; ! ! # Check that there is an entry and that it has not yet ! # been committed ! ! my @result = $h->db_()->selectrow_array( "select committed from history where id = $slot;" ); ! test_assert_equal( $#result, 0 ); ! test_assert( $result[0] != 1 ); ! ! # Check that release_slot removes the entry from the database ! # and deletes the file, and does clean up the directory ! ! $h->release_slot( $slot ); ! ! test_assert( !( -e $file ) ); ! test_assert( !( -e $path ) ); ! ! @result = $h->db_()->selectrow_array( "select committed from history where id = $slot;" ); ! test_assert_equal( $#result, -1 ); ! ! # Now try actually adding an element to the history. Reserve a slot ! # then commit it and call service to get it added. Ensure that the ! # slot is now committed and has the right fields ! ! ( $slot, $file ) = $h->reserve_slot( $session ); ! ! open FILE, ">$file"; ! print FILE <<EOF; Received: Today From: John Graham-Cumming <nospam\@jgc.org> *************** *** 114,126 **** This is the message body EOF ! close FILE; ! my $size = -s $file; ! my $slot1 = $slot; ! sleep(2); ! ( $slot, $file ) = $h->reserve_slot( $session, 1 ); ! open FILE, ">$file"; print FILE <<EOF; From: Evil Spammer <nospam\@jgc.org> --- 161,173 ---- This is the message body EOF ! close FILE; ! my $size = -s $file; ! my $slot1; ! sleep(2); ! ( $slot1, $file ) = $h->reserve_slot( $session ); ! open FILE, ">$file"; print FILE <<EOF; From: Evil Spammer <nospam\@jgc.org> *************** *** 132,159 **** This is the message body EOF ! close FILE; ! my $size2 = -s $file; ! sleep(2); ! # This is a message for testing evil spammer header tricks or ! # unusual header malformations that may end up parsed into our ! # history database ! # Please list tricks or malformations here ! # Subject: =?UNKNOWN?B??= (Should produce a "header missing" string in the ! # database rather than an empty string) ! # ! # To: =?utf-8?q?Do you covet to perc?= ! # =?utf-8?q?eive precious follo?= ! # =?utf-8?q?wing day ??= ! # ! # (This should decode to "Do you covet to perceive precious following day ?" ! my $slot2; ! ( $slot2, $file ) = $h->reserve_slot( $session, 1 ); ! open FILE, ">$file"; ! print FILE <<EOF; From: Evil Spammer who does tricks <nospam\@jgc.org> To: =?utf-8?q?Do you covet to perc?= --- 179,206 ---- This is the message body EOF ! close FILE; ! my $size2 = -s $file; ! sleep(2); ! # This is a message for testing evil spammer header tricks or ! # unusual header malformations that may end up parsed into our ! # history database ! # Please list tricks or malformations here ! # Subject: =?UNKNOWN?B??= (Should produce a "header missing" string in the ! # database rather than an empty string) ! # ! # To: =?utf-8?q?Do you covet to perc?= ! # =?utf-8?q?eive precious follo?= ! # =?utf-8?q?wing day ??= ! # ! # (This should decode to "Do you covet to perceive precious following day ?" ! my $slot2; ! ( $slot2, $file ) = $h->reserve_slot( $session ); ! open FILE, ">$file"; ! print FILE <<EOF; From: Evil Spammer who does tricks <nospam\@jgc.org> To: =?utf-8?q?Do you covet to perc?= *************** *** 166,424 **** This is the message body EOF ! close FILE; ! my $size3 = -s $file; ! $h->commit_slot( $session, $slot, 'spam', 0 ); ! $POPFile->CORE_service( 1 ); ! $h->commit_slot( $session, $slot1, 'personal', 0 ); ! $POPFile->CORE_service( 1 ); ! $h->commit_slot( $session, $slot2, 'spam', 0 ); ! $POPFile->CORE_service( 1 ); ! $POPFile->CORE_service( 1 ); ! $POPFile->CORE_service( 1 ); ! # Check that the message hash mechanism works ! my $hash = $h->get_message_hash( '1234', ! 'Sun, 25 Jul 2020 03:46:32 -0700', ! 're: his is the subject line', ! 'Today' ); ! test_assert_equal( $hash, '79499c2f056a026ef7bb4ab6c1f51a18' ); ! test_assert_equal( $slot1, $h->get_slot_from_hash( $hash ) ); ! # Check that the three messages were correctly inserted into ! # the database ! @result = $h->db_()->selectrow_array( "select * from history where id = 1;" ); ! test_assert_equal( $#result, 17 ); ! test_assert_equal( $result[0], 1 ); # id ! test_assert_equal( $result[1], 1 ); # userid ! test_assert_equal( $result[2], 1 ); # committed ! test_assert_equal( $result[3], 'John Graham-Cumming <no...@jg...>' ); # From ! test_assert_equal( $result[4], 'Everyone <nos...@jg...>' ); # To ! test_assert_equal( $result[5], 'People <no-...@jg...>' ); # Cc ! test_assert_equal( $result[6], 're: his is the subject line' ); # Subject ! test_assert_equal( $result[7], 1595673992 ); ! test_assert_equal( $result[10], 3 ); # bucketid ! test_assert_equal( $result[11], 0 ); # usedtobe ! test_assert_equal( $result[13], 'john graham-cumming no...@jg...' ); ! test_assert_equal( $result[14], 'everyone nos...@jg...' ); # To ! test_assert_equal( $result[15], 'people no-...@jg...' ); # Cc ! test_assert_equal( $result[16], 'his is the subject line' ); # Subject ! test_assert_equal( $result[17], $size ); # size ! @result = $h->db_()->selectrow_array( "select * from history where id = 2;" ); ! test_assert_equal( $#result, 17 ); ! test_assert_equal( $result[0], 2 ); # id ! test_assert_equal( $result[1], 1 ); # userid ! test_assert_equal( $result[2], 1 ); # committed ! test_assert_equal( $result[3], 'Evil Spammer <no...@jg...>' ); # From ! test_assert_equal( $result[4], 'Someone Else <nos...@jg...>' ); # To ! test_assert_equal( $result[5], '' ); # Cc ! test_assert_equal( $result[6], 'Hot Teen Mortgage Enlargers' ); # Subject ! test_assert_equal( $result[7], 1595587592 ); ! test_assert_equal( $result[10], 4 ); # bucketid ! test_assert_equal( $result[11], 0 ); # usedtobe ! test_assert_equal( $result[13], 'evil spammer no...@jg...' ); # From ! test_assert_equal( $result[14], 'someone else nos...@jg...' ); ! test_assert_equal( $result[15], '' ); # Cc ! test_assert_equal( $result[16], 'hot teen mortgage enlargers' ); # Subject ! test_assert_equal( $result[17], $size2 ); # size ! @result = $h->db_()->selectrow_array( "select * from history where id = 3;" ); ! test_assert_equal( $#result, 17 ); ! test_assert_equal( $result[0], 3 ); # id ! test_assert_equal( $result[1], 1 ); # userid ! test_assert_equal( $result[2], 1 ); # committed ! test_assert_equal( $result[3], 'Evil Spammer who does tricks <no...@jg...>' ); # From ! test_assert_equal( $result[4], 'Do you covet to perceive precious following day ?' ); # To ! test_assert_equal( $result[5], '' ); # Cc ! test_assert_equal( $result[6], '<subject header missing>' ); # Subject ! test_assert_equal( $result[7], 1595587592 ); ! test_assert_equal( $result[10], 4 ); # bucketid ! test_assert_equal( $result[11], 0 ); # usedtobe ! test_assert_equal( $result[13], 'evil spammer who does tricks no...@jg...' ); # From ! test_assert_equal( $result[14], 'do you covet to perceive precious following day ?' ); ! test_assert_equal( $result[15], '' ); # Cc ! test_assert_equal( $result[16], '' ); # subject ! test_assert_equal( $result[17], $size3 ); # size ! # Try a reclassification and undo ! $h->change_slot_classification( 1, 'spam', $session ); ! my @fields = $h->get_slot_fields( 1, $session ); ! test_assert_equal( $fields[10], 4 ); ! test_assert_equal( $fields[9], 3 ); ! test_assert_equal( $fields[8], 'spam' ); ! $h->revert_slot_classification( 1, $session ); ! @fields = $h->get_slot_fields( 1, $session ); ! test_assert_equal( $fields[10], 3 ); ! test_assert_equal( $fields[9], 0 ); ! test_assert_equal( $fields[8], 'personal' ); ! # Check is_valid_slot ! test_assert( $h->is_valid_slot( 1, $session ) ); ! test_assert( !$h->is_valid_slot( 100, $session ) ); ! # Now that we've got some data in the history test the query ! # interface ! my $q = $h->start_query( $session ); ! test_assert( defined( $q ) ); ! test_assert_regexp( $q, '[0-9a-f]{8}' ); ! test_assert( defined( $h->{queries__}{$q} ) ); ! # Unsorted returns in inserted order ! $h->set_query( $q, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! my @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'John Graham-Cumming <no...@jg...>' ); ! my @slot_row = $h->get_slot_fields( $rows[0][0], $session ); ! test_assert_equal( join(':',@{$rows[0]}), join(':',@slot_row) ); ! # Start with the most basic, give me everything query ! # sorted by from/to address ! $h->set_query( $q, '', '', 'from', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'John Graham-Cumming <no...@jg...>' ); ! $h->set_query( $q, '', '', 'to' ,0 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'John Graham-Cumming <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'Evil Spammer <no...@jg...>' ); ! $h->set_query( $q, '', '', 'from', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer <no...@jg...>' ); ! $h->set_query( $q, '', '', 'to', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 2, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'John Graham-Cumming <no...@jg...>' ); ! $h->set_query( $q, '', '', 'subject', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'John Graham-Cumming <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'Evil Spammer <no...@jg...>' ); ! # Now try unsorted and filtered on a specific bucket ! $h->set_query( $q, 'spam', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 2 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[0][8], 'spam' ); ! $h->set_query( $q, 'personal', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 1 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'John Graham-Cumming <no...@jg...>' ); ! test_assert_equal( $rows[0][8], 'personal' ); ! # Try a negated bucket filter ! $h->set_query( $q, 'personal', '', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 2 ); ! @rows = $h->get_query_rows( $q, 1, 2 ); ! test_assert_equal( $#rows, 1 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[0][8], 'spam' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer <no...@jg...>' ); ! test_assert_equal( $rows[1][8], 'spam' ); ! # Now try a search ! $h->set_query( $q, '', 'john', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 1 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'John Graham-Cumming <no...@jg...>' ); ! $h->set_query( $q, '', 's', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'John Graham-Cumming <no...@jg...>' ); ! $h->set_query( $q, '', 'subject line', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 1 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'John Graham-Cumming <no...@jg...>' ); ! # Try negated search ! $h->set_query( $q, '', 's', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 0 ); ! $h->set_query( $q, '', 'john', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 2 ); ! @rows = $h->get_query_rows( $q, 1, 2 ); ! test_assert_equal( $#rows, 1 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer <no...@jg...>' ); ! # Now try cases that return nothing ! $h->set_query( $q, '', 'zzz', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 0 ); ! $h->set_query( $q, '', 'zzz', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! $h->set_query( $q, 'other', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 0 ); ! $h->set_query( $q, 'other', '', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! # Make sure that we don't requery unless necessary ! $h->set_query( $q, '', 's', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 2 ); ! $h->set_query( $q, '', 's', '', 0 ); ! test_assert_equal( $#{$h->{queries__}{$q}{cache}}, 1 ); ! $h->set_query( $q, '', 't', '', 0 ); ! test_assert_equal( $#{$h->{queries__}{$q}{cache}}, -1 ); ! # Make sure that we can upgrade an existing file with a specific ! # classification ! open MSG, '>' . $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.msg' ); ! print MSG <<EOF; From: Another Person To: Someone Else --- 213,472 ---- This is the message body EOF ! close FILE; ! my $size3 = -s $file; ! $h->commit_slot( $session, $slot1, 'spam', 0 ); ! $POPFile->CORE_service( 1 ); ! $h->commit_slot( $session, $slot, 'personal', 0 ); ! $POPFile->CORE_service( 1 ); ! $h->commit_slot( $session, $slot2, 'spam', 0 ); ! $POPFile->CORE_service( 1 ); ! $POPFile->CORE_service( 1 ); ! $POPFile->CORE_service( 1 ); ! # Check that the message hash mechanism works ! my $hash = $h->get_message_hash( '1234', ! 'Sun, 25 Jul 2020 03:46:32 -0700', ! 're: his is the subject line', ! 'Today' ); ! test_assert_equal( $hash, '79499c2f056a026ef7bb4ab6c1f51a18' ); ! test_assert_equal( $slot, $h->get_slot_from_hash( $hash ) ); ! # Check that the three messages were correctly inserted into ! # the database ! @result = $h->db_()->selectrow_array( "select * from history where id = $slot;" ); ! test_assert_equal( $#result, 17 ); ! test_assert_equal( $result[0], $slot ); # id ! test_assert_equal( $result[1], $userid ); # userid ! test_assert_equal( $result[2], 1 ); # committed ! test_assert_equal( $result[3], 'John Graham-Cumming <no...@jg...>' ); # From ! test_assert_equal( $result[4], 'Everyone <nos...@jg...>' ); # To ! test_assert_equal( $result[5], 'People <no-...@jg...>' ); # Cc ! test_assert_equal( $result[6], 're: his is the subject line' ); # Subject ! test_assert_equal( $result[7], 1595673992 ); ! test_assert_equal( $result[10], $bucketids{personal} ); # bucketid ! test_assert_equal( $result[11], 0 ); # usedtobe ! test_assert_equal( $result[13], 'john graham-cumming no...@jg...' ); ! test_assert_equal( $result[14], 'everyone nos...@jg...' ); # To ! test_assert_equal( $result[15], 'people no-...@jg...' ); # Cc ! test_assert_equal( $result[16], 'his is the subject line' ); # Subject ! test_assert_equal( $result[17], $size ); # size ! @result = $h->db_()->selectrow_array( "select * from history where id = $slot1;" ); ! test_assert_equal( $#result, 17 ); ! test_assert_equal( $result[0], $slot1 ); # id ! test_assert_equal( $result[1], $userid ); # userid ! test_assert_equal( $result[2], 1 ); # committed ! test_assert_equal( $result[3], 'Evil Spammer <no...@jg...>' ); # From ! test_assert_equal( $result[4], 'Someone Else <nos...@jg...>' ); # To ! test_assert_equal( $result[5], '' ); # Cc ! test_assert_equal( $result[6], 'Hot Teen Mortgage Enlargers' ); # Subject ! test_assert_equal( $result[7], 1595587592 ); ! test_assert_equal( $result[10], $bucketids{spam} ); # bucketid ! test_assert_equal( $result[11], 0 ); # usedtobe ! test_assert_equal( $result[13], 'evil spammer no...@jg...' ); # From ! test_assert_equal( $result[14], 'someone else nos...@jg...' ); ! test_assert_equal( $result[15], '' ); # Cc ! test_assert_equal( $result[16], 'hot teen mortgage enlargers' ); # Subject ! test_assert_equal( $result[17], $size2 ); # size ! @result = $h->db_()->selectrow_array( "select * from history where id = $slot2;" ); ! test_assert_equal( $#result, 17 ); ! test_assert_equal( $result[0], $slot2 ); # id ! test_assert_equal( $result[1], $userid ); # userid ! test_assert_equal( $result[2], 1 ); # committed ! test_assert_equal( $result[3], 'Evil Spammer who does tricks <no...@jg...>' ); # From ! test_assert_equal( $result[4], 'Do you covet to perceive precious following day ?' ); # To ! test_assert_equal( $result[5], '' ); # Cc ! test_assert_equal( $result[6], '<subject header missing>' ); # Subject ! test_assert_equal( $result[7], 1595587592 ); ! test_assert_equal( $result[10], $bucketids{spam} ); # bucketid ! test_assert_equal( $result[11], 0 ); # usedtobe ! test_assert_equal( $result[13], 'evil spammer who does tricks no...@jg...' ); # From ! test_assert_equal( $result[14], 'do you covet to perceive precious following day ?' ); ! test_assert_equal( $result[15], '' ); # Cc ! test_assert_equal( $result[16], '' ); # subject ! test_assert_equal( $result[17], $size3 ); # size ! # Try a reclassification and undo ! $h->change_slot_classification( 1, 'spam', $session ); ! my @fields = $h->get_slot_fields( 1, $session ); ! test_assert_equal( $fields[10], $bucketids{spam} ); ! test_assert_equal( $fields[9], $bucketids{personal} ); ! test_assert_equal( $fields[8], 'spam' ); ! $h->revert_slot_classification( 1, $session ); ! @fields = $h->get_slot_fields( 1, $session ); ! test_assert_equal( $fields[10], $bucketids{personal} ); ! test_assert_equal( $fields[9], 0 ); ! test_assert_equal( $fields[8], 'personal' ); ! # Check is_valid_slot ! test_assert( $h->is_valid_slot( 1, $session ) ); ! test_assert( !$h->is_valid_slot( 100, $session ) ); ! # Now that we've got some data in the history test the query ! # interface ! my $q = $h->start_query( $session ); ! test_assert( defined( $q ) ); ! test_assert_regexp( $q, '[0-9a-f]{8}' ); ! test_assert( defined( $h->{queries__}{$q} ) ); ! # Unsorted returns in inserted order ! $h->set_query( $q, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! my @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'John Graham-Cumming <no...@jg...>' ); ! my @slot_row = $h->get_slot_fields( $rows[0][0], $session ); ! test_assert_equal( join(':',@{$rows[0]}), join(':',@slot_row) ); ! # Start with the most basic, give me everything query ! # sorted by from/to address ! $h->set_query( $q, '', '', 'from', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'John Graham-Cumming <no...@jg...>' ); ! $h->set_query( $q, '', '', 'to' ,0 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'John Graham-Cumming <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'Evil Spammer <no...@jg...>' ); ! $h->set_query( $q, '', '', 'from', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer <no...@jg...>' ); ! $h->set_query( $q, '', '', 'to', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 2, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'John Graham-Cumming <no...@jg...>' ); ! $h->set_query( $q, '', '', 'subject', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'John Graham-Cumming <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'Evil Spammer <no...@jg...>' ); ! # Now try unsorted and filtered on a specific bucket ! $h->set_query( $q, 'spam', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 2 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[0][8], 'spam' ); ! $h->set_query( $q, 'personal', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 1 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'John Graham-Cumming <no...@jg...>' ); ! test_assert_equal( $rows[0][8], 'personal' ); ! # Try a negated bucket filter ! $h->set_query( $q, 'personal', '', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 2 ); ! @rows = $h->get_query_rows( $q, 1, 2 ); ! test_assert_equal( $#rows, 1 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[0][8], 'spam' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer <no...@jg...>' ); ! test_assert_equal( $rows[1][8], 'spam' ); ! # Now try a search ! $h->set_query( $q, '', 'john', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 1 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'John Graham-Cumming <no...@jg...>' ); ! $h->set_query( $q, '', 's', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'John Graham-Cumming <no...@jg...>' ); ! $h->set_query( $q, '', 'subject line', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 1 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'John Graham-Cumming <no...@jg...>' ); ! # Try negated search ! $h->set_query( $q, '', 's', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 0 ); ! $h->set_query( $q, '', 'john', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 2 ); ! @rows = $h->get_query_rows( $q, 1, 2 ); ! test_assert_equal( $#rows, 1 ); ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer <no...@jg...>' ); ! # Now try cases that return nothing ! $h->set_query( $q, '', 'zzz', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 0 ); ! $h->set_query( $q, '', 'zzz', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! $h->set_query( $q, 'other', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 0 ); ! $h->set_query( $q, 'other', '', '', 1 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! # Make sure that we don't requery unless necessary ! $h->set_query( $q, '', 's', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 2 ); ! $h->set_query( $q, '', 's', '', 0 ); ! test_assert_equal( $#{$h->{queries__}{$q}{cache}}, 1 ); ! $h->set_query( $q, '', 't', '', 0 ); ! test_assert_equal( $#{$h->{queries__}{$q}{cache}}, -1 ); ! if ( $userid eq 1 ) { ! # Make sure that we can upgrade an existing file with a specific ! # classification ! open MSG, '>' . $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.msg' ); ! print MSG <<EOF; From: Another Person To: Someone Else *************** *** 428,509 **** This is the body of the message EOF ! close MSG; ! $size = -s $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.msg' ); ! open CLS, '>' . $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.cls' ); ! print CLS <<EOF; RECLASSIFIED other personal EOF ! close CLS; ! ! $h->upgrade_history_files__(); ! ! test_assert( !(-e $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.cls' ) ) ); ! test_assert( !(-e $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.msg' ) ) ); ! ! $POPFile->CORE_service( 1 ); ! ! $h->set_query( $q, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 4 ); ! ! $h->set_query( $q, 'other', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 1 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'Another Person' ); ! test_assert_equal( $rows[0][2], 'Someone Else' ); ! test_assert_equal( $rows[0][4], 'Something' ); ! test_assert_equal( $rows[0][5], 964521991 ); ! test_assert_equal( $rows[0][12], $size ); ! # Now check that deletion works ! $h->set_query( $q, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 4 ); ! $file = $h->get_slot_file( 2 ); ! test_assert( ( -e $file ) ); ! $h->start_deleting(); ! $h->delete_slot( 2, 0, $session, 0 ); ! $h->stop_deleting(); ! test_assert( !( -e $file ) ); ! $h->set_query( $q, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 3 ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! test_assert_equal( $rows[0][1], 'Another Person' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'John Graham-Cumming <no...@jg...>' ); ! # Now try history cleanup, should leave nothing ! $h->stop_query( $q ); ! $h->user_config_( 1, 'history_days', 0 ); ! sleep( 2 ); ! $h->cleanup_history(); ! my $qq = $h->start_query( $session ); ! $h->set_query( $qq, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $qq ), 0 ); ! $h->stop_query( $qq ); ! test_assert( !defined( $h->{queries__}{$q} ) ); ! # Check that the directories are gone too ! test_assert( !( -e 'messages/00' ) ); ! test_assert( !( -e 'messages/00/00' ) ); ! test_assert( !( -e 'messages/00/00/00' ) ); ! $h->classifier_()->release_session_key( $session ); ! $POPFile->CORE_stop(); ! 1; --- 476,552 ---- This is the body of the message EOF ! close MSG; ! $size = -s $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.msg' ); ! open CLS, '>' . $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.cls' ); ! print CLS <<EOF; RECLASSIFIED other personal EOF ! close CLS; ! $h->upgrade_history_files__(); ! test_assert( !(-e $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.cls' ) ) ); ! test_assert( !(-e $h->get_user_path_( $h->global_config_( 'msgdir' ) . 'popfile1=1.msg' ) ) ); ! $POPFile->CORE_service( 1 ); ! $h->set_query( $q, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 4 ); ! $h->set_query( $q, 'other', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), 1 ); ! @rows = $h->get_query_rows( $q, 1, 1 ); ! test_assert_equal( $#rows, 0 ); ! test_assert_equal( $rows[0][1], 'Another Person' ); ! test_assert_equal( $rows[0][2], 'Someone Else' ); ! test_assert_equal( $rows[0][4], 'Something' ); ! test_assert_equal( $rows[0][5], 964521991 ); ! test_assert_equal( $rows[0][12], $size ); ! } ! # Now check that deletion works ! $h->set_query( $q, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), ($userid eq 1?4:3) ); ! $file = $h->get_slot_file( $slot1 ); ! test_assert( ( -e $file ) ); ! $h->start_deleting(); ! $h->delete_slot( 2, 0, $session, 0 ); ! $h->stop_deleting(); ! test_assert( !( -e $file ) ); ! $h->set_query( $q, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $q ), ($userid eq 1?3:2) ); ! @rows = $h->get_query_rows( $q, 1, 3 ); ! test_assert_equal( $#rows, 2 ); ! if ( $userid eq 1 ) { ! test_assert_equal( $rows[0][1], 'Another Person' ); ! test_assert_equal( $rows[1][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[2][1], 'John Graham-Cumming <no...@jg...>' ); ! } else { ! test_assert_equal( $rows[0][1], 'Evil Spammer who does tricks <no...@jg...>' ); ! test_assert_equal( $rows[1][1], 'John Graham-Cumming <no...@jg...>' ); ! } ! # Now try history cleanup, should leave nothing ! $h->stop_query( $q ); ! $h->user_config_( 1, 'history_days', 0 ); # Clean up userid = 1 only ! sleep( 2 ); ! $h->cleanup_history(); ! my $qq = $h->start_query( $session ); ! $h->set_query( $qq, '', '', '', 0 ); ! test_assert_equal( $h->get_query_size( $qq ), ($userid eq 1?0:2) ); ! $h->stop_query( $qq ); ! test_assert( !defined( $h->{queries__}{$q} ) ); ! } \ No newline at end of file Index: TestXMLRPC.tst =================================================================== RCS file: /cvsroot/popfile/engine/tests/TestXMLRPC.tst,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TestXMLRPC.tst 5 Apr 2008 16:50:49 -0000 1.11 --- TestXMLRPC.tst 16 Apr 2008 13:08:05 -0000 1.12 *************** *** 67,72 **** --- 67,74 ---- if ( $x->start() == 1 ) { + my $count = 100; while ( $x->service() && $POPFile->CORE_service( 1 ) ) { select( undef, undef, undef, 0.1 ); + last if ( $count-- <= 0 ); } $x->stop(); *************** *** 75,78 **** --- 77,83 ---- } + $x->stop(); + $POPFile->CORE_stop(); + exit(0); } else { *************** *** 82,86 **** use XMLRPC::Lite; ! print "Testing $xport\n"; my $session = XMLRPC::Lite --- 87,91 ---- use XMLRPC::Lite; ! print "Testing $xport\n"; my $session = XMLRPC::Lite *************** *** 123,130 **** -> proxy("http://127.0.0.1:" . $xport . "/RPC2") -> call('POPFile/API.release_session_key', $session ); - } ! $x->stop(); ! $POPFile->CORE_stop(); # TODO : terminate child process --- 128,134 ---- -> proxy("http://127.0.0.1:" . $xport . "/RPC2") -> call('POPFile/API.release_session_key', $session ); ! wait(); ! } # TODO : terminate child process Index: TestBayes.tst =================================================================== RCS file: /cvsroot/popfile/engine/tests/TestBayes.tst,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** TestBayes.tst 9 Apr 2008 17:20:48 -0000 1.63 --- TestBayes.tst 16 Apr 2008 13:08:05 -0000 1.64 *************** *** 27,30 **** --- 27,31 ---- rmtree( 'corpus/CVS' ); + unlink 'popfile.cfg'; unlink 'popfile.db'; unlink 'popfile.pid'; *************** *** 112,116 **** test_assert( $password2 ne '' ); ! my ( $success3, $password3 ) = $b->create_user( $session, 'testuser' ); test_assert_equal( $success3, 1 ); test_assert( !defined( $password3 ) ); --- 113,117 ---- test_assert( $password2 ne '' ); ! my ( $success3, $password3 ) = $b->create_user( $session, 'testuser' ); test_assert_equal( $success3, 1 ); test_assert( !defined( $password3 ) ); *************** *** 224,231 **** test_assert_equal( $def, 1 ); test_assert_equal( $b->validate_password( $session1, '1234' ), 0 ); test_assert_equal( $b->validate_password( $session1, $password ), 1 ); ! test_assert_equal( $b->validate_password( $session, '1234' ), 0 ); ! test_assert_equal( $b->validate_password( $session, '' ), 1 ); test_assert_equal( $b->set_password( $session1, '' ), 1 ); --- 225,234 ---- test_assert_equal( $def, 1 ); + # validate_password and set_password + test_assert_equal( $b->validate_password( $session1, '1234' ), 0 ); test_assert_equal( $b->validate_password( $session1, $password ), 1 ); ! test_assert_equal( $b->validate_password( $session, '1234' ), 0 ); ! test_assert_equal( $b->validate_password( $session, '' ), 1 ); test_assert_equal( $b->set_password( $session1, '' ), 1 ); *************** *** 248,252 **** test_assert( !defined($b->create_user( $session1, 'testuser3' )) ); ! test_assert( !defined($b->remove_user( $session1, 'testuser' )) ); test_assert( !defined($b->get_user_list( $session1 )) ); --- 251,255 ---- test_assert( !defined($b->create_user( $session1, 'testuser3' )) ); ! test_assert( !defined($b->remove_user( $session1, 'testuser' )) ); test_assert( !defined($b->get_user_list( $session1 )) ); *************** *** 254,259 **** test_assert( !defined($b->get_accounts( $session1, $id1 )) ); ! test_assert_equal( $b->add_account( $session1, $id1, 'pop3', 'foo:bar2' ), 0 ); ! test_assert_equal( $b->remove_account( $session1, $id1, 'pop3', 'foo:bar' ), 0 ); test_assert( !defined($b->get_session_key_from_token( $session1, 'smtp', 'token' )) ); --- 257,262 ---- test_assert( !defined($b->get_accounts( $session1, $id1 )) ); ! test_assert_equal( $b->add_account( $session1, $id1, 'pop3', 'foo:bar2' ), 0 ); ! test_assert_equal( $b->remove_account( $session1, $id1, 'pop3', 'foo:bar' ), 0 ); test_assert( !defined($b->get_session_key_from_token( $session1, 'smtp', 'token' )) ); *************** *** 337,340 **** --- 340,345 ---- $b->release_session_key( $session4 ); + # TODO : cloning with magnets and corpus option + # initialize_users_password *************** *** 361,364 **** --- 366,387 ---- test_assert_equal( $b->change_users_password( $session, 'baduser', 'badpassword' ), 1 ); + # rename_user + + my ( $success7, $password7 ) = $b->rename_user( $session, 'testuser', 'changeduser' ); + test_assert_equal( $success7, 0 ); + test_assert( defined($password7) ); + + my $session7 = $b->get_session_key( 'changeduser', $password7 ); + test_assert( defined($session7) ); + $b->release_session_key( $session7 ); + + ( $success7, $password7 ) = $b->rename_user( $session, 'admin', 'admincannotberenamed' ); + test_assert_equal( $success7, 2 ); + test_assert( !defined($password7) ); + + ( $success7, $password7 ) = $b->rename_user( $session, 'changeduser', 'admin' ); + test_assert_equal( $success7, 1 ); + test_assert( !defined($password7) ); + # get_user_name_from_id |