2017-05-01 22:33:21 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Flow
|
|
|
|
|
*/
|
|
|
|
|
class SpamBlacklistTest extends MediaWikiTestCase {
|
|
|
|
|
/**
|
|
|
|
|
* @var SpamBlacklist
|
|
|
|
|
*/
|
|
|
|
|
protected $spamFilter;
|
|
|
|
|
|
|
|
|
|
/**
|
2017-06-29 17:39:54 +00:00
|
|
|
|
* Spam blacklist regexes. Examples taken from:
|
2017-05-01 22:33:21 +00:00
|
|
|
|
*
|
|
|
|
|
* @see http://meta.wikimedia.org/wiki/Spam_blacklist
|
|
|
|
|
* @see http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist
|
2017-06-29 17:39:54 +00:00
|
|
|
|
*
|
|
|
|
|
* via Flow extension
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $blacklist = [ '\b01bags\.com\b', 'sytes\.net' ];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Spam whitelist regexes. Examples taken from:
|
|
|
|
|
*
|
2017-05-01 22:33:21 +00:00
|
|
|
|
* @see http://en.wikipedia.org/wiki/MediaWiki:Spam-whitelist
|
|
|
|
|
*
|
|
|
|
|
* via Flow extension
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2017-06-29 17:39:54 +00:00
|
|
|
|
protected $whitelist = [ 'a5b\.sytes\.net' ];
|
2017-05-01 22:33:21 +00:00
|
|
|
|
|
|
|
|
|
public function spamProvider() {
|
2017-06-06 16:29:27 +00:00
|
|
|
|
return [
|
|
|
|
|
'no spam' => [
|
2017-05-01 22:33:21 +00:00
|
|
|
|
[ 'https://example.com' ],
|
|
|
|
|
false,
|
2017-06-06 16:29:27 +00:00
|
|
|
|
],
|
|
|
|
|
'revision with spam, with additional non-spam' => [
|
2017-05-01 22:33:21 +00:00
|
|
|
|
[ 'https://foo.com', 'http://01bags.com', 'http://bar.com' ],
|
|
|
|
|
[ '01bags.com' ],
|
2017-06-06 16:29:27 +00:00
|
|
|
|
],
|
2017-05-01 22:33:21 +00:00
|
|
|
|
|
2017-06-06 16:29:27 +00:00
|
|
|
|
'revision with spam using full width stop normalization' => [
|
2017-05-01 22:33:21 +00:00
|
|
|
|
[ 'http://01bags.com' ],
|
|
|
|
|
[ '01bags.com' ],
|
2017-06-06 16:29:27 +00:00
|
|
|
|
],
|
2017-05-01 22:33:21 +00:00
|
|
|
|
|
2017-06-06 16:29:27 +00:00
|
|
|
|
'revision with domain blacklisted as spam, but subdomain whitelisted' => [
|
2017-05-01 22:33:21 +00:00
|
|
|
|
[ 'http://a5b.sytes.net' ],
|
|
|
|
|
false,
|
2017-06-06 16:29:27 +00:00
|
|
|
|
],
|
|
|
|
|
];
|
2017-05-01 22:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider spamProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testSpam( $links, $expected ) {
|
|
|
|
|
$returnValue = $this->spamFilter->filter( $links, Title::newMainPage() );
|
|
|
|
|
$this->assertEquals( $expected, $returnValue );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
// create spam filter
|
|
|
|
|
$this->spamFilter = new SpamBlacklist;
|
|
|
|
|
|
2017-06-06 16:29:27 +00:00
|
|
|
|
$this->setMwGlobals( 'wgBlacklistSettings', [
|
|
|
|
|
'files' => [],
|
|
|
|
|
] );
|
2017-05-01 22:33:21 +00:00
|
|
|
|
|
|
|
|
|
\MessageCache::singleton()->enable();
|
|
|
|
|
$this->insertPage( 'MediaWiki:Spam-blacklist', implode( "\n", $this->blacklist ) );
|
|
|
|
|
$this->insertPage( 'MediaWiki:Spam-whitelist', implode( "\n", $this->whitelist ) );
|
|
|
|
|
|
|
|
|
|
// That only works if the spam blacklist is really reset
|
|
|
|
|
$instance = BaseBlacklist::getInstance( 'spam' );
|
|
|
|
|
$reflProp = new \ReflectionProperty( $instance, 'regexes' );
|
|
|
|
|
$reflProp->setAccessible( true );
|
|
|
|
|
$reflProp->setValue( $instance, false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tearDown() {
|
|
|
|
|
\MessageCache::singleton()->disable();
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
}
|