2011-07-21 22:08:44 +00:00
|
|
|
<?php
|
2011-10-14 21:30:16 +00:00
|
|
|
/**
|
2012-08-29 13:35:12 +00:00
|
|
|
* Test the TitleBlacklist API.
|
2011-07-21 22:08:44 +00:00
|
|
|
*
|
|
|
|
* This wants to run with phpunit.php, like so:
|
|
|
|
* cd $IP/tests/phpunit
|
|
|
|
* php phpunit.php ../../extensions/TitleBlacklist/tests/ApiQueryTitleBlacklistTest.php
|
|
|
|
*
|
2012-08-29 13:35:12 +00:00
|
|
|
* The blacklist file is `testSource` and shared by all tests.
|
|
|
|
*
|
2011-07-21 22:08:44 +00:00
|
|
|
* Ian Baker <ian@wikimedia.org>
|
|
|
|
*/
|
|
|
|
|
2012-05-24 23:55:22 +00:00
|
|
|
/**
|
|
|
|
* @group medium
|
2018-02-16 08:01:34 +00:00
|
|
|
* @covers ApiQueryTitleBlacklist
|
|
|
|
*/
|
2011-07-21 22:08:44 +00:00
|
|
|
class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|
|
|
|
2018-11-01 19:27:32 +00:00
|
|
|
public function setUp() {
|
2011-07-21 22:08:44 +00:00
|
|
|
parent::setUp();
|
|
|
|
$this->doLogin();
|
2011-10-14 21:30:16 +00:00
|
|
|
|
2017-01-23 10:58:52 +00:00
|
|
|
TitleBlacklist::destroySingleton();
|
2017-06-06 16:18:36 +00:00
|
|
|
$this->setMwGlobals( 'wgTitleBlacklistSources', [
|
|
|
|
[
|
2015-05-19 16:05:32 +00:00
|
|
|
'type' => 'file',
|
2015-01-06 16:33:36 +00:00
|
|
|
'src' => __DIR__ . '/testSource',
|
2017-06-06 16:18:36 +00:00
|
|
|
],
|
|
|
|
] );
|
2012-08-29 13:35:12 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 19:27:32 +00:00
|
|
|
public function tearDown() {
|
2017-01-23 10:58:52 +00:00
|
|
|
TitleBlacklist::destroySingleton();
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2012-08-29 13:35:12 +00:00
|
|
|
/**
|
2012-10-17 21:52:05 +00:00
|
|
|
* Verify we allow a title which is not blacklisted
|
2012-08-29 13:35:12 +00:00
|
|
|
*/
|
2018-11-01 19:27:32 +00:00
|
|
|
public function testCheckingUnlistedTitle() {
|
2017-06-06 16:18:36 +00:00
|
|
|
$unlisted = $this->doApiRequest( [
|
2011-07-21 22:08:44 +00:00
|
|
|
'action' => 'titleblacklist',
|
2012-10-17 21:52:05 +00:00
|
|
|
// evil_acc is blacklisted as <newaccountonly>
|
|
|
|
'tbtitle' => 'evil_acc',
|
|
|
|
'tbaction' => 'create',
|
|
|
|
'tbnooverride' => true,
|
2017-06-06 16:18:36 +00:00
|
|
|
] );
|
2012-10-17 21:52:05 +00:00
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'ok',
|
|
|
|
$unlisted[0]['titleblacklist']['result'],
|
|
|
|
'Not blacklisted title returns ok'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify tboverride works
|
|
|
|
*/
|
2018-11-01 19:27:32 +00:00
|
|
|
public function testTboverride() {
|
2012-10-17 21:52:05 +00:00
|
|
|
// Allow all users to override the titleblacklist
|
2018-10-07 12:45:41 +00:00
|
|
|
$this->setGroupPermissions( '*', 'tboverride', true );
|
2012-10-17 21:52:05 +00:00
|
|
|
|
2017-06-06 16:18:36 +00:00
|
|
|
$unlisted = $this->doApiRequest( [
|
2012-10-17 21:52:05 +00:00
|
|
|
'action' => 'titleblacklist',
|
|
|
|
'tbtitle' => 'bar',
|
2011-07-21 22:08:44 +00:00
|
|
|
'tbaction' => 'create',
|
2017-06-06 16:18:36 +00:00
|
|
|
] );
|
2011-07-21 22:08:44 +00:00
|
|
|
|
2012-08-29 13:17:27 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
'ok',
|
|
|
|
$unlisted[0]['titleblacklist']['result'],
|
2012-10-17 21:52:05 +00:00
|
|
|
'Blacklisted title returns ok if the user is allowd to tboverride'
|
2012-08-29 13:17:27 +00:00
|
|
|
);
|
2012-08-29 13:35:12 +00:00
|
|
|
}
|
2011-07-21 22:08:44 +00:00
|
|
|
|
2012-08-29 13:35:12 +00:00
|
|
|
/**
|
2012-10-17 21:52:05 +00:00
|
|
|
* Verify a blacklisted title gives out an error.
|
2012-08-29 13:35:12 +00:00
|
|
|
*/
|
2018-11-01 19:27:32 +00:00
|
|
|
public function testCheckingBlackListedTitle() {
|
2017-06-06 16:18:36 +00:00
|
|
|
$listed = $this->doApiRequest( [
|
2011-07-21 22:08:44 +00:00
|
|
|
'action' => 'titleblacklist',
|
|
|
|
'tbtitle' => 'bar',
|
|
|
|
'tbaction' => 'create',
|
2012-10-17 21:52:05 +00:00
|
|
|
'tbnooverride' => true,
|
2017-06-06 16:18:36 +00:00
|
|
|
] );
|
2011-07-21 22:08:44 +00:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2012-08-29 13:17:27 +00:00
|
|
|
'blacklisted',
|
|
|
|
$listed[0]['titleblacklist']['result'],
|
|
|
|
'Listed title returns error'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2017-06-02 15:43:58 +00:00
|
|
|
"The title \"bar\" has been banned from creation.\nIt matches the following " .
|
|
|
|
"blacklist entry: <code>[Bb]ar #example blacklist entry</code>",
|
2012-08-29 13:17:27 +00:00
|
|
|
$listed[0]['titleblacklist']['reason'],
|
2011-07-29 17:19:51 +00:00
|
|
|
'Listed title error text is as expected'
|
2011-07-21 22:08:44 +00:00
|
|
|
);
|
2011-10-14 21:30:16 +00:00
|
|
|
|
2011-08-01 22:44:54 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
"titleblacklist-forbidden-edit",
|
2012-08-29 13:17:27 +00:00
|
|
|
$listed[0]['titleblacklist']['message'],
|
2011-08-01 22:44:54 +00:00
|
|
|
'Correct blacklist message name is returned'
|
|
|
|
);
|
2011-10-14 21:30:16 +00:00
|
|
|
|
2011-07-29 17:19:51 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
"[Bb]ar #example blacklist entry",
|
2012-08-29 13:17:27 +00:00
|
|
|
$listed[0]['titleblacklist']['line'],
|
2011-07-29 17:19:51 +00:00
|
|
|
'Correct blacklist line is returned'
|
|
|
|
);
|
2013-09-08 04:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests integration with the AntiSpoof extension
|
|
|
|
*/
|
2018-11-01 19:27:32 +00:00
|
|
|
public function testAntiSpoofIntegration() {
|
2019-03-03 01:36:14 +00:00
|
|
|
if ( !ExtensionRegistry::getInstance()->isLoaded( 'AntiSpoof' ) ) {
|
2013-09-08 04:24:56 +00:00
|
|
|
$this->markTestSkipped( "This test requires the AntiSpoof extension" );
|
|
|
|
}
|
|
|
|
|
2017-06-06 16:18:36 +00:00
|
|
|
$listed = $this->doApiRequest( [
|
2013-09-08 04:24:56 +00:00
|
|
|
'action' => 'titleblacklist',
|
|
|
|
'tbtitle' => 'AVVVV',
|
|
|
|
'tbaction' => 'create',
|
|
|
|
'tbnooverride' => true,
|
2017-06-06 16:18:36 +00:00
|
|
|
] );
|
2013-09-08 04:24:56 +00:00
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'blacklisted',
|
|
|
|
$listed[0]['titleblacklist']['result'],
|
|
|
|
'Spoofed title is blacklisted'
|
|
|
|
);
|
2011-07-21 22:08:44 +00:00
|
|
|
}
|
2011-10-14 21:30:16 +00:00
|
|
|
}
|