2018-07-02 23:20:00 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Tests for validating and saving a filter
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
2019-08-26 13:01:09 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
|
|
|
|
2018-07-02 23:20:00 +00:00
|
|
|
/**
|
|
|
|
* @group Test
|
|
|
|
* @group AbuseFilter
|
|
|
|
* @group AbuseFilterSave
|
|
|
|
*
|
2018-08-22 11:27:50 +00:00
|
|
|
* @covers AbuseFilter
|
|
|
|
* @covers AbuseFilterViewEdit
|
2018-07-02 23:20:00 +00:00
|
|
|
*/
|
|
|
|
class AbuseFilterSaveTest extends MediaWikiTestCase {
|
2019-08-26 13:01:09 +00:00
|
|
|
private static $defaultFilterRow = [
|
|
|
|
'af_pattern' => '/**/',
|
|
|
|
'af_user' => 0,
|
|
|
|
'af_user_text' => 'FilterTester',
|
|
|
|
'af_timestamp' => '20190826000000',
|
|
|
|
'af_enabled' => 1,
|
|
|
|
'af_comments' => '',
|
|
|
|
'af_public_comments' => 'Mock filter',
|
|
|
|
'af_hidden' => 0,
|
|
|
|
'af_hit_count' => 0,
|
|
|
|
'af_throttled' => 0,
|
|
|
|
'af_deleted' => 0,
|
|
|
|
'af_actions' => '',
|
|
|
|
'af_global' => 0,
|
|
|
|
'af_group' => 'default'
|
2018-07-02 23:20:00 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2019-08-26 13:01:09 +00:00
|
|
|
* Gets an instance of AbuseFilterViewEdit ready for creating or editing filter
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @param array $params
|
|
|
|
* @param bool $existing Whether the filter already exists
|
|
|
|
* @return AbuseFilterViewEdit|MockObject
|
2018-07-02 23:20:00 +00:00
|
|
|
*/
|
2019-08-26 13:01:09 +00:00
|
|
|
private function getViewEdit( User $user, array $params, $existing ) {
|
|
|
|
$special = new SpecialAbuseFilter();
|
|
|
|
$context = new RequestContext();
|
|
|
|
$context->setRequest( $this->getRequest( $params ) );
|
|
|
|
$context->setUser( $user );
|
|
|
|
$cfgOpts = [
|
|
|
|
'LanguageCode' => 'en',
|
|
|
|
'AbuseFilterActions' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
'throttle' => true,
|
|
|
|
'warn' => true,
|
|
|
|
'disallow' => true,
|
|
|
|
'blockautopromote' => true,
|
|
|
|
'block' => true,
|
|
|
|
'rangeblock' => true,
|
|
|
|
'degroup' => true,
|
|
|
|
'tag' => true
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'AbuseFilterValidGroups' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
'default',
|
|
|
|
'flow'
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'AbuseFilterRestrictions' => [
|
|
|
|
'degroup' => true
|
|
|
|
],
|
|
|
|
'AbuseFilterIsCentral' => true,
|
|
|
|
];
|
2018-07-02 23:20:00 +00:00
|
|
|
|
2019-08-26 13:01:09 +00:00
|
|
|
$context->setConfig( new HashConfig( $cfgOpts ) );
|
2018-07-02 23:20:00 +00:00
|
|
|
|
|
|
|
$special->setContext( $context );
|
2019-08-26 13:01:09 +00:00
|
|
|
$filter = $params['id'];
|
2018-07-02 23:20:00 +00:00
|
|
|
$special->mFilter = $filter;
|
2019-08-26 13:01:09 +00:00
|
|
|
/** @var LinkRenderer|MockObject $lr */
|
|
|
|
$lr = $this->getMockBuilder( LinkRenderer::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$special->setLinkRenderer( $lr );
|
|
|
|
/** @var AbuseFilterViewEdit|MockObject $viewEdit */
|
|
|
|
$viewEdit = $this->getMockBuilder( AbuseFilterViewEdit::class )
|
|
|
|
->setConstructorArgs( [ $special, [ $filter ] ] )
|
|
|
|
->setMethods( [ 'loadFilterData' ] )
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
if ( $existing ) {
|
|
|
|
$origValues = [ (object)self::$defaultFilterRow, [] ];
|
|
|
|
} else {
|
|
|
|
$origValues = [
|
|
|
|
(object)[
|
|
|
|
'af_pattern' => '',
|
|
|
|
'af_enabled' => 1,
|
|
|
|
'af_hidden' => 0,
|
|
|
|
'af_global' => 0,
|
2019-03-01 15:05:26 +00:00
|
|
|
'af_throttled' => 0,
|
|
|
|
'af_hit_count' => 0,
|
2019-08-26 13:01:09 +00:00
|
|
|
],
|
|
|
|
[]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$viewEdit->expects( $this->once() )
|
|
|
|
->method( 'loadFilterData' )
|
|
|
|
->willReturn( $origValues );
|
|
|
|
|
2018-07-02 23:20:00 +00:00
|
|
|
return $viewEdit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a FauxRequest object
|
|
|
|
*
|
2019-08-26 13:01:09 +00:00
|
|
|
* @param array $params
|
2018-07-02 23:20:00 +00:00
|
|
|
* @return FauxRequest
|
|
|
|
*/
|
2019-08-26 13:01:09 +00:00
|
|
|
private function getRequest( array $params ) {
|
|
|
|
$reqParams = [
|
|
|
|
'wpFilterRules' => $params['rules'],
|
|
|
|
'wpFilterDescription' => $params['description'],
|
|
|
|
'wpFilterNotes' => $params['notes'] ?? '',
|
|
|
|
'wpFilterGroup' => $params['group'] ?? 'default',
|
|
|
|
'wpFilterEnabled' => $params['enabled'] ?? true,
|
|
|
|
'wpFilterHidden' => $params['hidden'] ?? false,
|
|
|
|
'wpFilterDeleted' => $params['deleted'] ?? false,
|
|
|
|
'wpFilterGlobal' => $params['global'] ?? false,
|
|
|
|
'wpFilterActionThrottle' => $params['throttleEnabled'] ?? false,
|
|
|
|
'wpFilterThrottleCount' => $params['throttleCount'] ?? 0,
|
|
|
|
'wpFilterThrottlePeriod' => $params['throttlePeriod'] ?? 0,
|
|
|
|
'wpFilterThrottleGroups' => $params['throttleGroups'] ?? '',
|
|
|
|
'wpFilterActionWarn' => $params['warnEnabled'] ?? false,
|
|
|
|
'wpFilterWarnMessage' => $params['warnMessage'] ?? 'abusefilter-warning',
|
|
|
|
'wpFilterWarnMessageOther' => $params['warnMessageOther'] ?? '',
|
|
|
|
'wpFilterActionDisallow' => $params['disallowEnabled'] ?? false,
|
|
|
|
'wpFilterDisallowMessage' => $params['disallowMessage'] ?? 'abusefilter-disallowed',
|
|
|
|
'wpFilterDisallowMessageOther' => $params['disallowMessageOther'] ?? '',
|
|
|
|
'wpFilterActionBlockautopromote' => $params['blockautopromoteEnabled'] ?? false,
|
|
|
|
'wpFilterActionDegroup' => $params['degroupEnabled'] ?? false,
|
|
|
|
'wpFilterActionBlock' => $params['blockEnabled'] ?? false,
|
|
|
|
'wpFilterBlockTalk' => $params['blockTalk'] ?? false,
|
|
|
|
'wpBlockAnonDuration' => $params['blockAnons'] ?? 'infinity',
|
|
|
|
'wpBlockUserDuration' => $params['blockUsers'] ?? 'infinity',
|
|
|
|
'wpFilterActionRangeblock' => $params['rangeblockEnabled'] ?? false,
|
|
|
|
'wpFilterActionTag' => $params['tagEnabled'] ?? false,
|
|
|
|
'wpFilterTags' => $params['tagTags'] ?? '',
|
2018-07-02 23:20:00 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Checkboxes aren't included at all if they aren't selected. We can remove them
|
|
|
|
// this way (instead of iterating a hardcoded list) since they're the only false values
|
2019-08-26 13:01:09 +00:00
|
|
|
$reqParams = array_filter( $reqParams, function ( $el ) {
|
2018-07-02 23:20:00 +00:00
|
|
|
return $el !== false;
|
|
|
|
} );
|
|
|
|
|
2019-08-26 13:01:09 +00:00
|
|
|
return new FauxRequest( $reqParams, true );
|
2018-07-02 23:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-26 13:01:09 +00:00
|
|
|
* @param array $testPerms
|
|
|
|
* @return User|MockObject
|
2018-07-02 23:20:00 +00:00
|
|
|
*/
|
2019-08-26 13:01:09 +00:00
|
|
|
private function getUserMock( $testPerms ) {
|
2019-09-18 21:48:40 +00:00
|
|
|
$perms = array_merge( $testPerms, [ 'abusefilter-modify' ] );
|
2019-08-26 13:01:09 +00:00
|
|
|
$user = $this->getMockBuilder( User::class )
|
2019-09-18 21:48:40 +00:00
|
|
|
->setMethods( [ 'getBlock', 'getName', 'getId', 'getActorId' ] )
|
2019-08-26 13:01:09 +00:00
|
|
|
->getMock();
|
2018-07-02 23:20:00 +00:00
|
|
|
|
2019-08-26 13:01:09 +00:00
|
|
|
$user->expects( $this->any() )
|
|
|
|
->method( 'getName' )
|
|
|
|
->willReturn( 'FilterUser' );
|
|
|
|
$user->expects( $this->any() )
|
|
|
|
->method( 'getId' )
|
|
|
|
->willReturn( 1 );
|
|
|
|
$user->expects( $this->any() )
|
|
|
|
->method( 'getActorId' )
|
|
|
|
->willReturn( 1 );
|
2019-09-18 21:48:40 +00:00
|
|
|
$this->overrideUserPermissions( $user, $perms );
|
2019-08-26 13:01:09 +00:00
|
|
|
return $user;
|
2018-07-02 23:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate and save a filter given its parameters
|
|
|
|
*
|
|
|
|
* @param array $args Parameters of the filter and metadata for the test
|
|
|
|
* @covers AbuseFilter::saveFilter
|
|
|
|
* @dataProvider provideFilters
|
|
|
|
*/
|
|
|
|
public function testSaveFilter( $args ) {
|
2019-08-26 13:01:09 +00:00
|
|
|
$user = $this->getUserMock( $args['testData']['userPerms'] ?? [] );
|
2018-07-02 23:20:00 +00:00
|
|
|
|
2019-08-26 13:01:09 +00:00
|
|
|
$params = $args['filterParameters'];
|
|
|
|
$filter = $params['id'] = $params['id'] ?? 'new';
|
|
|
|
$existing = isset( $args['testData']['existing'] );
|
|
|
|
$viewEdit = $this->getViewEdit( $user, $params, $existing );
|
2018-07-02 23:20:00 +00:00
|
|
|
|
|
|
|
list( $newRow, $actions ) = $viewEdit->loadRequest( $filter );
|
|
|
|
|
2019-08-26 13:01:09 +00:00
|
|
|
/** @var IDatabase|MockObject $dbw */
|
|
|
|
$dbw = $this->getMockForAbstractClass( IDatabase::class );
|
|
|
|
$dbw->expects( $this->any() )
|
|
|
|
->method( 'insertId' )
|
|
|
|
->willReturn( 1 );
|
|
|
|
$status = AbuseFilter::saveFilter( $viewEdit, $filter, $newRow, $actions, $dbw );
|
2018-07-02 23:20:00 +00:00
|
|
|
|
2019-08-26 13:01:09 +00:00
|
|
|
if ( $args['testData']['shouldFail'] ) {
|
|
|
|
$this->assertFalse( $status->isGood(), 'The filter validation returned a valid status.' );
|
|
|
|
$actual = $status->getErrors()[0]['message'];
|
|
|
|
$expected = $args['testData']['expectedMessage'];
|
|
|
|
$this->assertEquals( $expected, $actual );
|
2018-07-02 23:20:00 +00:00
|
|
|
} else {
|
2019-08-26 13:01:09 +00:00
|
|
|
if ( $args['testData']['shouldBeSaved'] ) {
|
|
|
|
$this->assertTrue(
|
|
|
|
$status->isGood(),
|
|
|
|
"Save failed with status: $status"
|
|
|
|
);
|
2018-07-02 23:20:00 +00:00
|
|
|
$value = $status->getValue();
|
2020-01-20 15:33:32 +00:00
|
|
|
$this->assertIsArray( $value );
|
2019-08-26 13:01:09 +00:00
|
|
|
$this->assertCount( 2, $value );
|
|
|
|
$this->assertContainsOnly( 'int', $value );
|
2018-07-02 23:20:00 +00:00
|
|
|
} else {
|
2019-08-26 13:01:09 +00:00
|
|
|
$this->assertTrue(
|
|
|
|
$status->isGood(),
|
|
|
|
"Got a non-good status: $status"
|
|
|
|
);
|
|
|
|
$this->assertFalse( $status->getValue(), 'Status value should be false' );
|
2018-07-02 23:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data provider for creating and editing filters.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function provideFilters() {
|
|
|
|
return [
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to empty description and rules' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '',
|
|
|
|
'description' => '',
|
|
|
|
'blockautopromoteEnabled' => true,
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-missingfields',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Success for only rules and description' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '/* My rules */',
|
|
|
|
'description' => 'Some new filter',
|
|
|
|
'enabled' => false,
|
|
|
|
'deleted' => true,
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'shouldFail' => false,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => true
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to syntax error' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => 'rlike',
|
|
|
|
'description' => 'This syntax aint good',
|
|
|
|
'blockEnabled' => true,
|
|
|
|
'blockTalk' => true,
|
|
|
|
'blockAnons' => '8 hours',
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-badsyntax',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to both "enabled" and "deleted" selected' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Enabled and deleted',
|
|
|
|
'deleted' => true,
|
|
|
|
'blockEnabled' => true,
|
|
|
|
'blockTalk' => true,
|
|
|
|
'blockAnons' => '8 hours',
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-deleting-enabled',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to a reserved tag' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Reserved tag',
|
|
|
|
'notes' => 'Some notes',
|
|
|
|
'hidden' => true,
|
|
|
|
'tagEnabled' => true,
|
|
|
|
'tagTags' => 'mw-undo'
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-bad-tags',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to an invalid tag' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Invalid tag',
|
|
|
|
'notes' => 'Some notes',
|
|
|
|
'tagEnabled' => true,
|
|
|
|
'tagTags' => 'some|tag'
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'tags-create-invalid-chars',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-09-03 12:03:33 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to an empty tag' => [
|
2018-09-03 12:03:33 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1!=0',
|
|
|
|
'description' => 'Empty tag',
|
|
|
|
'notes' => '',
|
|
|
|
'tagEnabled' => true,
|
|
|
|
'tagTags' => ''
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'tags-create-no-name',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to lack of modify-global right' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Global without perms',
|
|
|
|
'global' => true,
|
|
|
|
'disallowEnabled' => true,
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-notallowed-global',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to custom warn message on global filter' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Global with invalid warn message',
|
|
|
|
'global' => true,
|
|
|
|
'warnEnabled' => true,
|
|
|
|
'warnMessage' => 'abusefilter-beautiful-warning',
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-notallowed-global-custom-msg',
|
|
|
|
'shouldFail' => true,
|
2018-10-12 08:51:45 +00:00
|
|
|
'shouldBeSaved' => false,
|
2019-09-18 21:48:40 +00:00
|
|
|
'userPerms' => [ 'abusefilter-modify-global' ]
|
2018-10-12 08:51:45 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to custom disallow message on global filter' => [
|
2018-10-12 08:51:45 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Global with invalid disallow message',
|
|
|
|
'global' => true,
|
|
|
|
'disallowEnabled' => true,
|
|
|
|
'disallowMessage' => 'abusefilter-disallowed-something',
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-notallowed-global-custom-msg',
|
|
|
|
'shouldFail' => true,
|
2018-07-02 23:20:00 +00:00
|
|
|
'shouldBeSaved' => false,
|
2019-09-18 21:48:40 +00:00
|
|
|
'userPerms' => [ 'abusefilter-modify-global' ]
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to a restricted action' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Restricted action',
|
|
|
|
'degroupEnabled' => true,
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-restricted',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Pass validation but do not save when there are no changes' => [
|
2018-07-02 23:20:00 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'id' => '1',
|
|
|
|
'rules' => '/**/',
|
|
|
|
'description' => 'Mock filter',
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'shouldFail' => false,
|
|
|
|
'shouldBeSaved' => false,
|
2019-08-26 13:01:09 +00:00
|
|
|
'existing' => true
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
]
|
2018-09-09 10:14:31 +00:00
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to invalid throttle groups' => [
|
2018-09-09 10:14:31 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Invalid throttle groups',
|
|
|
|
'notes' => 'Throttle... Again',
|
|
|
|
'throttleEnabled' => true,
|
|
|
|
'throttleCount' => 11,
|
|
|
|
'throttlePeriod' => 111,
|
|
|
|
'throttleGroups' => 'user\nfoo'
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-invalid-throttlegroups',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-09-09 10:14:31 +00:00
|
|
|
]
|
|
|
|
]
|
2018-09-03 09:22:41 +00:00
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to empty warning message' => [
|
2018-09-03 09:22:41 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Empty warning message',
|
|
|
|
'warnEnabled' => true,
|
|
|
|
'warnMessage' => '',
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-invalid-warn-message',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-09-03 09:22:41 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-08-26 13:01:09 +00:00
|
|
|
'Fail due to empty disallow message' => [
|
2018-09-03 09:22:41 +00:00
|
|
|
[
|
|
|
|
'filterParameters' => [
|
|
|
|
'rules' => '1==1',
|
|
|
|
'description' => 'Empty disallow message',
|
|
|
|
'disallowEnabled' => true,
|
|
|
|
'disallowMessage' => '',
|
|
|
|
],
|
|
|
|
'testData' => [
|
|
|
|
'expectedMessage' => 'abusefilter-edit-invalid-disallow-message',
|
|
|
|
'shouldFail' => true,
|
2019-08-26 13:01:09 +00:00
|
|
|
'shouldBeSaved' => false
|
2018-09-03 09:22:41 +00:00
|
|
|
]
|
|
|
|
]
|
2018-07-02 23:20:00 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|