aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiBlockTest.php
diff options
context:
space:
mode:
authorPetr Pchelko <ppchelko@wikimedia.org>2021-04-20 06:42:53 -0700
committerPpchelko <ppchelko@wikimedia.org>2021-09-13 15:22:16 +0000
commit8d7201894ce2ad2b41a7672280d50d327f62cef1 (patch)
tree4582c30e97017e8e77868635e7279d3c3b278492 /tests/phpunit/includes/api/ApiBlockTest.php
parent003af60ae63e99e63e2eb8d958ae822f8293172a (diff)
downloadmediawikicore-8d7201894ce2ad2b41a7672280d50d327f62cef1.tar.gz
mediawikicore-8d7201894ce2ad2b41a7672280d50d327f62cef1.zip
Drop action api token methods deprecated in 1.24
Removes deprecated API endpoints and modules for dealing with CSRF tokens. Note: i18n messages are removed in a followup for ease of revert. Bug: T280806 Depends-On: Ic83f44587db119ff2e3e6d5ff33a10894e0695e7 Change-Id: I58aedec6942ac5d3c21574cb0072f00ef365098c
Diffstat (limited to 'tests/phpunit/includes/api/ApiBlockTest.php')
-rw-r--r--tests/phpunit/includes/api/ApiBlockTest.php37
1 files changed, 12 insertions, 25 deletions
diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php
index c7a9eab439ac..7e769bf69330 100644
--- a/tests/phpunit/includes/api/ApiBlockTest.php
+++ b/tests/phpunit/includes/api/ApiBlockTest.php
@@ -5,7 +5,6 @@ use MediaWiki\Block\Restriction\ActionRestriction;
use MediaWiki\Block\Restriction\NamespaceRestriction;
use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\MediaWikiServices;
-use MediaWiki\Permissions\Authority;
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
/**
@@ -34,34 +33,24 @@ class ApiBlockTest extends ApiTestCase {
] );
}
- protected function getTokens() {
- return $this->getTokenList( self::$users['sysop'] );
- }
-
/**
* @param array $extraParams Extra API parameters to pass to doApiRequest
- * @param Authority|null $blocker User to do the blocking, null to pick arbitrarily
+ * @param User|null $blocker User to do the blocking, null to pick arbitrarily
* @return array result of doApiRequest
*/
- private function doBlock( array $extraParams = [], Authority $blocker = null ) {
- $tokens = $this->getTokens();
-
+ private function doBlock( array $extraParams = [], User $blocker = null ) {
$this->assertNotNull( $this->mUser, 'Sanity check' );
- $this->assertArrayHasKey( 'blocktoken', $tokens, 'Sanity check' );
-
$params = [
'action' => 'block',
'user' => $this->mUser->getName(),
'reason' => 'Some reason',
- 'token' => $tokens['blocktoken'],
];
if ( array_key_exists( 'userid', $extraParams ) ) {
// Make sure we don't have both user and userid
unset( $params['user'] );
}
- $ret = $this->doApiRequest( array_merge( $params, $extraParams ), null,
- false, $blocker );
+ $ret = $this->doApiRequestWithToken( array_merge( $params, $extraParams ), null, $blocker );
$block = DatabaseBlock::newFromTarget( $this->mUser->getName() );
@@ -162,9 +151,15 @@ class ApiBlockTest extends ApiTestCase {
}
public function testBlockWithHide() {
+ global $wgGroupPermissions;
+ $newPermissions = $wgGroupPermissions['sysop'];
+ $newPermissions['hideuser'] = true;
+ $this->mergeMwGlobalArrayValue( 'wgGroupPermissions',
+ [ 'sysop' => $newPermissions ] );
+
$res = $this->doBlock(
[ 'hidename' => '' ],
- $this->mockRegisteredAuthorityWithPermissions( [ 'hideuser', 'writeapi', 'block' ] )
+ self::$users['sysop']->getUser()
);
$this->assertSame( '1', $this->db->selectField(
@@ -318,40 +313,32 @@ class ApiBlockTest extends ApiTestCase {
}
public function testBlockWithLargeRange() {
- $tokens = $this->getTokens();
-
$this->expectException( ApiUsageException::class );
$this->expectExceptionMessage( 'Invalid value "127.0.0.1/64" for user parameter "user".' );
- $this->doApiRequest(
+ $this->doApiRequestWithToken(
[
'action' => 'block',
'user' => '127.0.0.1/64',
'reason' => 'Some reason',
- 'token' => $tokens['blocktoken'],
],
null,
- false,
self::$users['sysop']->getUser()
);
}
public function testBlockingTooManyPageRestrictions() {
- $tokens = $this->getTokens();
-
$this->expectException( ApiUsageException::class );
$this->expectExceptionMessage(
"Too many values supplied for parameter \"pagerestrictions\". The limit is 10." );
- $this->doApiRequest(
+ $this->doApiRequestWithToken(
[
'action' => 'block',
'user' => $this->mUser->getName(),
'reason' => 'Some reason',
'partial' => true,
'pagerestrictions' => 'One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven',
- 'token' => $tokens['blocktoken'],
],
null,
- false,
self::$users['sysop']->getUser()
);
}