Page MenuHomePhabricator

ApiBlockTest::testMakeNormalBlock() broken
Closed, ResolvedPublic


Since the security patch,3434 , the API has a broken test :

php tests/phpunit/phpunit.php tests/phpunit/includes/api/ApiBlockTest.php

  1. ApiBlockTest::testMakeNormalBlock UsageException: Invalid token

Version: unspecified
Severity: major



Related Objects

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 12:17 AM
bzimport set Reference to bz35646.
bzimport added a subscriber: Unknown Object (MLST).

Marking high priority since that makes the API tests job to always be failing.

User.php, it's the request specific tokens at fault


  • Check given value against the token value stored in the session.
  • A match should confirm that the form was submitted from the
  • user's own login session, not a form submission from a third-party
  • site. *
  • @param $val String Input value to compare
  • @param $salt String Optional function-specific data for hashing
  • @param $request WebRequest object to use or null to use $wgRequest
  • @return Boolean: Whether the token matches

public function matchEditToken( $val, $salt = '', $request = null ) {

		$sessionToken = $this->getEditToken( $salt, $request );
		if ( $val != $sessionToken ) {
			wfDebug( "User::matchEditToken: broken session data\n" );
		return $val == $sessionToken;


Commenting out the pass of $request (so it falls back to null) fixes the issue.

We've got discrepancy between code - the gettoken part of block passes the request, but prop=info doesn't, but the api itself does

		// Die if token required, but not provided (unless there is a gettoken parameter)
		$salt = $module->getTokenSalt();
		if ( $salt !== false && !isset( $moduleParams['gettoken'] ) ) {
			if ( !isset( $moduleParams['token'] ) ) {
				$this->dieUsageMsg( array( 'missingparam', 'token' ) );
			} else {
				if ( !$this->getUser()->matchEditToken( $moduleParams['token'], $salt, $this->getRequest() ) ) {
					$this->dieUsageMsg( 'sessionfailure' );

So the question is about the requests. Where should we be passing it, and where shouldn't we?

I guess the request in the block/unblock should be removed to normalise them with the prop=info one. And then do the same in ApiMain::setupModule (ie not pass $this->request)

reopening, still happening on gallium :(

ssh gallium
sudo -s -u jenkins
cd /var/lib/jenkins/jobs/MediaWiki-Tests-API
ant phpunit-api


[exec] PHPUnit 3.5.15 by Sebastian Bergmann.
[exec] ........I..E...
[exec] Time: 1 second, Memory: 95.25Mb
[exec] There was 1 error:
[exec] 1) ApiBlockTest::testMakeNormalBlock
[exec] UsageException: Invalid token
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/includes/api/ApiBase.php:1087
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/includes/api/ApiBase.php:1266
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/includes/api/ApiMain.php:603
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/includes/api/ApiMain.php:691
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/includes/api/ApiMain.php:342
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/includes/api/ApiTestCase.php:53
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/includes/api/ApiBlockTest.php:51
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/MediaWikiTestCase.php:66
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/MediaWikiPHPUnitCommand.php:45
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/phpunit.php:60
[exec] There was 1 incomplete test:
[exec] 1) ApiTest::testApiListPages
[exec] Somebody needs to finish loving me
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/includes/api/ApiTest.php:215
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/MediaWikiTestCase.php:66
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/MediaWikiPHPUnitCommand.php:45
[exec] /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace/tests/phpunit/phpunit.php:60
       Tests: 15, Assertions: 45, Errors: 1, Incomplete: 1.

Another way, which only run the ApiBlockTest::testMakeNormalBlock test :

ssh gallium
sudo -s -u jenkins
cd /var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace


php tests/phpunit/phpunit.php \

--conf /var/lib/jenkins/jobs/MediaWiki-Tests-API/workspace/LocalSettings.php \
  1. ApiBlockTest::testMakeNormalBlock

UsageException: Invalid token

Test marked as broken with so I can continue the Jenkins/Gerrit integration.


reedy@ubuntu64-web-esxi:/var/www/wiki/w$ php tests/phpunit/phpunit.php tests/phpunit/includes/api/ApiBlockTest.php
PHPUnit 3.6.10 by Sebastian Bergmann.

Configuration read from /var/www/wiki/w/tests/phpunit/suite.xml


Time: 10 seconds, Memory: 70.25Mb

OK (1 test, 4 assertions)

I am not sure what is the issue there, but it is certainly reproducible on gallium :/

jenkins@gallium:/var/lib/jenkins/jobs/MediaWiki-GIT-Fetching/workspace$ php tests/phpunit/phpunit.php --conf /var/lib/jenkins/jobs/MediaWiki-Tests-API/workspace/LocalSettings.php tests/phpunit/includes/api/ApiBlockTest.php
PHPUnit 3.5.15 by Sebastian Bergmann.

string(34) "1ebf829d30b805f7ed7a081c81d15c02+\"
string(0) ""
string(34) "1ebf829d30b805f7ed7a081c81d15c02+\"

Time: 0 seconds, Memory: 34.25Mb

OK (1 test, 4 assertions

The test has been enabled again by . I have had PHPUnit upgraded from 3.5.x to 3.6.10, maybe that helped fixing the issue we had. Or another changed fixed it.