From: John Graham-C. <jgr...@us...> - 2005-08-21 22:18:03
|
Update of /cvsroot/popfile/engine/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11349/tests Modified Files: TestBayes.tst TestHTML.tst TestHTTP.tst Log Message: More v0.23.0 work; mostly around the test suite and the ability to change passwords. *** NOTE: Had to run 'dos2unix' because a number of files had CRLF line endings. POPFile standard is Unix-style LF only line endings on files. *** tests/TestBayes.tst and Classifier/Bayes.pm: Add tests for APIs that had no tests (and fix the bugs that the tests showed up!). All APIs now have tests; the new tests cover: add_account create_user get_accounts get_bucket_id get_bucket_name get_user_id get_user_list get_user_parameter get_user_parameter_from_id get_user_parameter_list remove_account remove_user set_user_parameter_from_id *** Classifier/Bayes.pm, tests/TestBayes.tst, UI/HTML.pm create_user now also creates a random password for the user and the password is displayed when the user is created in the UI. *** Classifier/Bayes.pm, tests/TestBayes.tst, UI/HTML.pm, skins/default/configuration-bar.thtml Added the ability to change password for a user. This is done in the configuration bar and added new APIs and tests (validate_password and set_password) for a user. *** POPFile/API.pm: Add external access to the following new APIs: add_account create_user get_user_id get_user_id_from_session get_user_parameter get_user_parameter_from_id get_user_parameter_list remove_account remove_user set_user_parameter_from_id *** tests/TestHTTP.tst: Remove redirection tests since this is no longer handled by the HTTP module. *** Current state of the test suite: TestBayesScript fail TestBayes PASS TestConfiguration fail TestHistory fail TestHTML fail (horribly) TestHTTP PASS TestIMAP PASS TestInsertScript fail TestLogger PASS TestMailParse fail TestModule PASS TestMQ PASS TestMutex PASS TestPipeScript PASS TestPOP3 fail TestProxy PASS TestWordMangle PASS TestXMLRPC fail *** TODO tests/TestModule.tst needs updating for the user_*_config_ APIs that have been added. Look into why we get bogus complaints about the primary key not being unique when we do a database upgrade. I think some of these are caused by the fact that popfile.sql contains some INSERT statements and we are getting double inserts. Perhaps the upgrade should be using UPDATE instead. Index: TestHTML.tst =================================================================== RCS file: /cvsroot/popfile/engine/tests/TestHTML.tst,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** TestHTML.tst 23 Sep 2004 07:37:06 -0000 1.35 --- TestHTML.tst 21 Aug 2005 22:17:52 -0000 1.36 *************** *** 702,704 **** --- 702,706 ---- } + # TODO http_redirect_ + 1; Index: TestBayes.tst =================================================================== RCS file: /cvsroot/popfile/engine/tests/TestBayes.tst,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** TestBayes.tst 15 Jan 2005 08:02:57 -0000 1.58 --- TestBayes.tst 21 Aug 2005 22:17:52 -0000 1.59 *************** *** 82,85 **** --- 82,199 ---- test_assert( $session ne '' ); + # Test for getting and setting the session key from an associated + # account + + my ( $success, $password ) = $b->create_user( $session, 'testuser' ); + test_assert_equal( $success, 0 ); + test_assert( $password ne '' ); + my ( $success2, $password2 ) = $b->create_user( $session, 'testuser2' ); + test_assert_equal( $success2, 0 ); + test_assert( $password2 ne '' ); + ( $success2, $password2 ) = $b->create_user( $session, 'testuser' ); + test_assert_equal( $success2, 1 ); + test_assert( !defined( $password2 ) ); + + my @users = sort @{$b->get_user_list( $session )}; + + test_assert( $#users == 2 ); + test_assert( $users[0] eq 'admin' ); + test_assert( $users[1] eq 'testuser' ); + test_assert( $users[2] eq 'testuser2' ); + + test_assert( $b->remove_user( $session, 'testuser3' ) == 1 ); + test_assert( $b->remove_user( $session, 'testuser2' ) == 0 ); + + @users = sort @{$b->get_user_list( $session )}; + + test_assert( $#users == 1 ); + test_assert( $users[0] eq 'admin' ); + test_assert( $users[1] eq 'testuser' ); + + $b->global_config_( 'single_user', 1 ); + + my $session2 = $b->get_session_key_from_token( $session, 'smtp', 'token' ); + test_assert( $session2 eq $session ); + $session2 = $b->get_session_key_from_token( $session, 'nntp', 'token' ); + test_assert( $session2 eq $session ); + $session2 = $b->get_session_key_from_token( $session, 'pop', 'token' ); + test_assert( $session2 eq $session ); + $session2 = $b->get_session_key_from_token( $session, 'pop3', 'token' ); + test_assert( $session2 eq $session ); + + $b->global_config_( 'single_user', 0 ); + + $session2 = $b->get_session_key_from_token( $session, 'smtp', 'token' ); + test_assert( $session2 eq $session ); + $session2 = $b->get_session_key_from_token( $session, 'nntp', 'token' ); + test_assert( $session2 eq $session ); + $session2 = $b->get_session_key_from_token( $session, 'pop', 'token' ); + test_assert( $session2 eq $session ); + $session2 = $b->get_session_key_from_token( $session, 'pop3', 'token' ); + test_assert( !defined( $session2 ) ); + + my $id2 = $b->get_user_id( $session, 'testuser2' ); + test_assert( !defined( $id2 ) ); + $id2 = $b->get_user_id( $session, 'testuser' ); + test_assert( defined( $id2 ) ); + + test_assert( $b->add_account( $session, $id2, 'pop3', 'foo:bar' ) == 1 ); + test_assert( $b->add_account( $session, $id2, 'pop3', 'foo:bar' ) == -1 ); + + my $session3 = $b->get_session_key_from_token( $session, 'pop3', 'fooz:bar' ); + test_assert( !defined( $session3 ) ); + $session3 = $b->get_session_key_from_token( $session, 'pop3', 'foo:bar' ); + test_assert( defined( $session3 ) ); + + my @parameters = sort $b->get_user_parameter_list( $session ); + test_assert_equal( $#parameters, 35 ); + test_assert_equal( join( ' ', @parameters ), 'GLOBAL_can_admin GLOBAL_private_key GLOBAL_public_key bayes_subject_mod_left bayes_subject_mod_right bayes_unclassified_weight bayes_xpl_angle history_history_days html_column_characters html_columns html_date_format html_language html_last_reset html_last_update_check html_page_size html_send_stats html_session_dividers html_show_bucket_help html_show_configbars html_show_training_help html_skin html_test_language html_update_check html_wordtable_format imap_bucket_folder_mappings imap_expunge imap_hostname imap_login imap_password imap_port imap_training_mode imap_uidnexts imap_uidvalidities imap_update_interval imap_use_ssl imap_watched_folders' ); + + test_assert( $b->get_user_parameter( $session, 'GLOBAL_can_admin' ) ); + test_assert( !$b->get_user_parameter( $session3, 'GLOBAL_can_admin' ) ); + + my ( $val, $def ) = $b->get_user_parameter_from_id( 1, 'GLOBAL_can_admin' ); + test_assert_equal( $val, 1 ); + test_assert_equal( $def, 0 ); + ( $val, $def ) = $b->get_user_parameter_from_id( $id2, 'GLOBAL_can_admin' ); + test_assert_equal( $val, 0 ); + test_assert_equal( $def, 1 ); + $b->set_user_parameter_from_id( $id2, 'GLOBAL_can_admin', 1 ); + ( $val, $def ) = $b->get_user_parameter_from_id( $id2, 'GLOBAL_can_admin' ); + test_assert_equal( $val, 1 ); + test_assert_equal( $def, 0 ); + $b->set_user_parameter_from_id( $id2, 'GLOBAL_can_admin', 0 ); + ( $val, $def ) = $b->get_user_parameter_from_id( $id2, 'GLOBAL_can_admin' ); + test_assert_equal( $val, 0 ); + test_assert_equal( $def, 1 ); + + test_assert_equal( $b->validate_password( $session3, '1234' ), 0 ); + test_assert_equal( $b->validate_password( $session3, $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( $session3, '' ), 1 ); + test_assert_equal( $b->validate_password( $session3, '1234' ), 0 ); + test_assert_equal( $b->validate_password( $session3, '' ), 1 ); + + test_assert_equal( $b->set_password( $session, '1234' ), 1 ); + test_assert_equal( $b->validate_password( $session, '1234' ), 1 ); + test_assert_equal( $b->validate_password( $session, '' ), 0 ); + + test_assert_equal( $b->set_password( $session, '' ), 1 ); + + $b->release_session_key( $session3 ); + + my @accounts = $b->get_accounts( $session, 0 ); + test_assert( $#accounts == -1 ); + my @accounts = $b->get_accounts( $session, $id2 ); + test_assert( $#accounts == 0 ); + test_assert( $accounts[0] eq 'pop3:foo:bar' ); + + test_assert( $b->remove_account( $session, 'pop3', 'foo:bar' ) == 1 ); + + $session3 = $b->get_session_key_from_token( $session, 'pop3', 'foo:bar' ); + test_assert( !defined( $session3 ) ); + # get_all_buckets *************** *** 121,124 **** --- 235,245 ---- test_assert_equal( defined($buckets[3]), defined(undef) ); + # get_bucket_id, get_bucket_name + + my $spam_id = $b->get_bucket_id( $session, 'spam' ); + test_assert( defined( $spam_id ) ); + test_assert_equal( $b->get_bucket_name( $session, $spam_id ), 'spam' ); + + # get_bucket_word_count Index: TestHTTP.tst =================================================================== RCS file: /cvsroot/popfile/engine/tests/TestHTTP.tst,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TestHTTP.tst 4 Jan 2005 22:52:05 -0000 1.10 --- TestHTTP.tst 21 Aug 2005 22:17:52 -0000 1.11 *************** *** 126,146 **** test_assert_equal( $h->url_encode_( '{start' ), '%7bstart' ); - # http_redirect_ tests - - open FILE, ">temp.tmp"; - $h->http_redirect_( \*FILE, 'http://www.usethesource.com/' ); - close FILE; - open FILE, "<temp.tmp"; - my $line = <FILE>; - test_assert_equal( $line, "HTTP/1.0 302 Found$eol" ); - $line = <FILE>; - test_assert_equal( $line, "Location: http://www.usethesource.com/$eol" ); - $line = <FILE>; - test_assert( defined( $line ) ); - test_assert( $line =~ /^$eol$/ ); - $line = <FILE>; - test_assert( !defined( $line ) ); - close FILE; - # http_error_ tests --- 126,129 ---- |