X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2Ffuzz-tester.php;h=1c96a57161dccd1940e2a0d4d892a3056f1fffea;hb=658eb79dc10fbbceec1a6bee3ab078aca06c424e;hp=89a88e66fcf4e531754fd7f0655c2c59db3d028e;hpb=fb69d76ae010be9a69c4553437ab992cf2bdf5ad;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/fuzz-tester.php b/maintenance/fuzz-tester.php index 89a88e66fc..1c96a57161 100644 --- a/maintenance/fuzz-tester.php +++ b/maintenance/fuzz-tester.php @@ -108,7 +108,6 @@ Wiki configuration for testing: $wgGroupPermissions['*']['reupload-shared'] = true; $wgGroupPermissions['*']['rollback'] = true; $wgGroupPermissions['*']['siteadmin'] = true; - $wgGroupPermissions['*']['trackback'] = true; $wgGroupPermissions['*']['unwatchedpages'] = true; $wgGroupPermissions['*']['upload'] = true; $wgGroupPermissions['*']['userrights'] = true; @@ -121,7 +120,6 @@ Wiki configuration for testing: error_reporting (E_ALL); // At a later date could be increased to E_ALL | E_STRICT $wgBlockOpenProxies = true; // Some block pages require this to be true in order to test. $wgEnableUploads = true; // enable uploads. - //$wgUseTrackbacks = true; // enable trackbacks; However this breaks the viewPageTest, so currently disabled. $wgDBerrorLog = "/root/mediawiki-db-error-log.txt"; // log DB errors, replace with suitable path. $wgShowSQLErrors = true; // Show SQL errors (instead of saying the query was hidden). $wgShowExceptionDetails = true; // want backtraces. @@ -183,7 +181,7 @@ TODO: // ///////////////////////// COMMAND LINE HELP //////////////////////////////////// // This is a command line script, load MediaWiki env (gives command line options); -require_once( dirname( __FILE__ ) . '/commandLine.inc' ); +require_once( __DIR__ . '/commandLine.inc' ); // if the user asked for an explanation of command line options. if ( isset( $options["help"] ) ) { @@ -383,7 +381,6 @@ class wikiFuzz { "br" => array( "CLASS", "ID", "STYLE", "title", "clear" ), "cite" => array( "CLASS", "ID", "STYLE", "lang", "dir", "title" ), "var" => array( "CLASS", "ID", "STYLE", "lang", "dir", "title" ), - "dl" => array( "CLASS", "ID", "STYLE", "lang", "dir", "title" ), "ruby" => array( "CLASS", "ID", "STYLE", "lang", "dir", "title" ), "rt" => array( "CLASS", "ID", "STYLE", "lang", "dir", "title" ), "rp" => array( "CLASS", "ID", "STYLE", "lang", "dir", "title" ), @@ -759,14 +756,18 @@ class wikiFuzz { static private $maxparams = 10; /** - ** Returns random number between finish and start. + * Returns random number between finish and start. + * @param $finish + * @param $start int + * @return int */ static public function randnum( $finish, $start = 0 ) { return mt_rand( $start, $finish ); } /** - ** Returns a mix of random text and random wiki syntax. + * Returns a mix of random text and random wiki syntax. + * @return string */ static private function randstring() { $thestring = ""; @@ -796,18 +797,17 @@ class wikiFuzz { } /** - ** Returns either random text, or random wiki syntax, or random data from "ints", - ** or random data from "other". + * Returns either random text, or random wiki syntax, or random data from "ints", + * or random data from "other". + * @return string */ static private function makestring() { $what = wikiFuzz::randnum( 2 ); if ( $what == 0 ) { return wikiFuzz::randstring(); - } - elseif ( $what == 1 ) { + } elseif ( $what == 1 ) { return wikiFuzz::$ints[wikiFuzz::randnum( count( wikiFuzz::$ints ) - 1 )]; - } - else { + } else { return wikiFuzz::$other[wikiFuzz::randnum( count( wikiFuzz::$other ) - 1 )]; } } @@ -815,6 +815,8 @@ class wikiFuzz { /** * Returns the matched character slash-escaped as in a C string * Helper for makeTitleSafe callback + * @param $matches + * @return string */ static private function stringEscape( $matches ) { return sprintf( "\\x%02x", ord( $matches[1] ) ); @@ -823,6 +825,8 @@ class wikiFuzz { /** ** Strips out the stuff that Mediawiki balks at in a page's title. ** Implementation copied/pasted from cleanupTable.inc & cleanupImages.php + * @param $str string + * @return string */ static public function makeTitleSafe( $str ) { $legalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF"; @@ -833,6 +837,7 @@ class wikiFuzz { /** ** Returns a string of fuzz text. + * @return string */ static private function loop() { switch ( wikiFuzz::randnum( 3 ) ) { @@ -860,7 +865,8 @@ class wikiFuzz { } /** - ** Returns one of the three styles of random quote: ', ", and nothing. + * Returns one of the three styles of random quote: ', ", and nothing. + * @return string */ static private function getRandQuote() { switch ( wikiFuzz::randnum( 3 ) ) { @@ -872,6 +878,8 @@ class wikiFuzz { /** ** Returns fuzz text, with the parameter indicating approximately how many lines of text you want. + * @param $maxtypes int + * @return string */ static public function makeFuzz( $maxtypes = 2 ) { $page = ""; @@ -1351,6 +1359,7 @@ class viewPageTest extends pageTest { "rdfrom" => wikiFuzz::makeFuzz( 2 ), // things from Article.php from here on: "token" => wikiFuzz::makeFuzz( 2 ), "tbid" => wikiFuzz::makeFuzz( 2 ), + // @todo FIXME: Duplicate array key. "action" => wikiFuzz::chooseInput( array( "purge", wikiFuzz::makeFuzz( 2 ) ) ), "wpReason" => wikiFuzz::makeFuzz( 2 ), "wpEditToken" => wikiFuzz::makeFuzz( 2 ), @@ -1808,32 +1817,6 @@ class thumbTest extends pageTest { } } - -/** - ** a test for trackback.php - */ -class trackbackTest extends pageTest { - function __construct() { - $this->pagePath = "trackback.php"; - - $this->params = array ( - "url" => wikiFuzz::makeFuzz( 2 ), - "blog_name" => wikiFuzz::chooseInput( array( "80", wikiFuzz::randnum( 6000, -200 ), wikiFuzz::makeFuzz( 2 ) ) ), - "article" => wikiFuzz::chooseInput( array( "Main Page", wikiFuzz::makeFuzz( 2 ) ) ), - "title" => wikiFuzz::chooseInput( array( "Main Page", wikiFuzz::makeFuzz( 2 ) ) ), - "excerpt" => wikiFuzz::makeFuzz( 2 ), - ); - - // sometimes we don't want to specify certain parameters. - if ( wikiFuzz::randnum( 3 ) == 0 ) unset( $this->params["title"] ); - if ( wikiFuzz::randnum( 3 ) == 0 ) unset( $this->params["excerpt"] ); - - // page does not produce HTML. - $this->tidyValidate = false; - } -} - - /** ** a test for profileinfo.php */ @@ -2174,9 +2157,10 @@ class GeSHi_Test extends pageTest { } } - /** ** selects a page test to run. + * @param $count + * @return \api|\confirmEmail|\contributionsTest|\editPageTest|\imagelistTest|\imagepageTest|\ipblocklistTest|\listusersTest|\mimeSearchTest|\newImagesTest|\pageDeletion|\pageHistoryTest|\pageProtectionForm|\prefixindexTest|\profileInfo|\recentchangesTest|\redirectTest|\searchTest|\specialAllmessagesTest|\specialAllpagesTest|\specialBlockip|\specialBlockmeTest|\specialBooksourcesTest|\specialCategoryTree|\specialChemicalsourcesTest|\specialCitePageTest|\specialExportTest|\specialFilepathPageTest|\specialImportPageTest|\specialLinksearch|\specialLockdbPageTest|\specialLogTest|\specialMovePage|\specialNewpagesPageTest|\specialRenameuserPageTest|\specialRevisionDeletePageTest|\specialUndeletePageTest|\specialUnlockdbPageTest|\specialUserrights|\successfulUserLoginTest|\thumbTest|\userLoginTest|\viewPageTest|\watchlistTest */ function selectPageTest( $count ) { @@ -2225,7 +2209,6 @@ function selectPageTest( $count ) { case 33: return new specialRevisionDeletePageTest(); case 34: return new specialImportPageTest(); case 35: return new thumbTest(); - case 36: return new trackbackTest(); case 37: return new profileInfo(); case 38: return new specialCitePageTest(); case 39: return new specialFilepathPageTest(); @@ -2248,11 +2231,12 @@ function saveFile( $data, $name ) { file_put_contents( $name, $data ); } - /** ** Returns a test as an experimental GET-to-POST URL. ** This doesn't seem to always work though, and sometimes the output is too long ** to be a valid GET URL, so we also save in other formats. + * @param $test pageTest + * @return string */ function getAsURL( pageTest $test ) { $used_question_mark = ( strpos( $test->getPagePath(), "?" ) !== false ); @@ -2304,11 +2288,12 @@ function saveTestAsPHP( pageTest $test, $filename ) { saveFile( $str, $filename ); } - /** - ** Escapes a value so that it can be used on the command line by Curl. - ** Specifically, "<" and "@" need to be escaped if they are the first character, - ** otherwise curl interprets these as meaning that we want to insert a file. + * Escapes a value so that it can be used on the command line by Curl. + * Specifically, "<" and "@" need to be escaped if they are the first character, + * otherwise curl interprets these as meaning that we want to insert a file. + * @param $input_params array + * @return array */ function escapeForCurl( array $input_params ) { $output_params = array(); @@ -2359,18 +2344,21 @@ function saveTest( pageTest $test, $testname ) { saveTestData ( $test, $base_name . DATA_FILE ); } - // ////////////////// MEDIAWIKI OUTPUT ///////////////////////// /** - ** Asks MediaWiki for the HTML output of a test. + * Asks MediaWiki for the HTML output of a test. + * @param $test pageTest + * @return string */ function wikiTestOutput( pageTest $test ) { $ch = curl_init(); // specify the cookie, if required. - if ( $test->getCookie() ) curl_setopt( $ch, CURLOPT_COOKIE, $test->getCookie() ); + if ( $test->getCookie() ) { + curl_setopt( $ch, CURLOPT_COOKIE, $test->getCookie() ); + } curl_setopt( $ch, CURLOPT_POST, 1 ); // save form using a POST $params = escapeForCurl( $test->getParams() ); @@ -2395,8 +2383,10 @@ function wikiTestOutput( pageTest $test ) { // ////////////////// HTML VALIDATION ///////////////////////// -/* - ** Asks the validator whether this is valid HTML, or not. +/** + * Asks the validator whether this is valid HTML, or not. + * @param $text string + * @return array */ function validateHTML( $text ) { @@ -2425,9 +2415,10 @@ function validateHTML( $text ) { return array( $valid, $result ); } - /** - ** Get tidy to check for no HTML errors in the output file (e.g. unescaped strings). + * Get tidy to check for no HTML errors in the output file (e.g. unescaped strings). + * @param $name + * @return bool */ function tidyCheckFile( $name ) { $file = DIRECTORY . "/" . $name; @@ -2446,10 +2437,10 @@ function tidyCheckFile( $name ) { } } - /** ** Returns whether or not an database error log file has changed in size since ** the last time this was run. This is used to tell if a test caused a DB error. + * @return bool */ function dbErrorLogged() { static $filesize; @@ -2477,8 +2468,12 @@ function dbErrorLogged() { // //////////////// TOP-LEVEL PROBLEM-FINDING FUNCTION //////////////////////// /** - ** takes a page test, and runs it and tests it for problems in the output. - ** Returns: False on finding a problem, or True on no problems being found. + * takes a page test, and runs it and tests it for problems in the output. + * Returns: False on finding a problem, or True on no problems being found. + * @param $test pageTest + * @param $testname + * @param $can_overwrite bool + * @return bool */ function runWikiTest( pageTest $test, &$testname, $can_overwrite = false ) {