CSteipp has uploaded a new change for review.
https://gerrit.wikimedia.org/r/56720
Change subject: Use a provider for Xff blocking tests
......................................................................
Use a provider for Xff blocking tests
Move the block insertion to addDBData(), and use a provider to
itterate through the test strings.
This seems like the more correct way to run these tests, although it
still seems hacky, since the db isn't cleaned up after each test.
Change-Id: Ib22ce69797ec03a61b0cc330e8572865290ebd31
---
M tests/phpunit/includes/BlockTest.php
1 file changed, 23 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/20/56720/1
diff --git a/tests/phpunit/includes/BlockTest.php
b/tests/phpunit/includes/BlockTest.php
index 0f37182..e2cce8c 100644
--- a/tests/phpunit/includes/BlockTest.php
+++ b/tests/phpunit/includes/BlockTest.php
@@ -51,6 +51,8 @@
} else {
throw new MWException( "Failed to insert block for
BlockTest; old leftover block remaining?" );
}
+
+ $this->addXffBlocks();
}
/**
@@ -229,7 +231,14 @@
$this->assertEquals( 0, $block->getBy(), 'Correct blocker id' );
}
- function testBlocksOnXff() {
+ protected function addXffBlocks() {
+ static $inited = false;
+
+ if ( $inited ) {
+ return;
+ }
+
+ $inited = true;
$blockList = array(
array( 'target' => '70.2.0.0/16',
@@ -288,8 +297,10 @@
$block->isAutoblocking( $insBlock['isAutoBlocking'] );
$block->insert();
}
+ }
- $xffHeaders = array(
+ public static function providerXff() {
+ return array(
array( 'xff' => '1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5',
'count' => 2,
'result' => 'Range Hardblock'
@@ -331,14 +342,16 @@
'result' => 'Range6 Hardblock'
),
);
+ }
- foreach ( $xffHeaders as $test ) {
- $list = array_map( 'trim', explode( ',', $test['xff'] )
);
- $xffblocks = Block::getBlocksForIPList( $list, true );
- $this->assertEquals( $test['count'], count( $xffblocks
), 'Number of blocks for ' . $test['xff'] );
- $block = Block::chooseBlock( $xffblocks, $list );
- $this->assertEquals( $test['result'], $block->mReason,
'Correct block type for XFF header ' . $test['xff'] );
- }
-
+ /**
+ * @dataProvider providerXff
+ */
+ function testBlocksOnXff( $xff, $exCount, $exResult ) {
+ $list = array_map( 'trim', explode( ',', $xff ) );
+ $xffblocks = Block::getBlocksForIPList( $list, true );
+ $this->assertEquals( $exCount, count( $xffblocks ), 'Number of
blocks for ' . $xff );
+ $block = Block::chooseBlock( $xffblocks, $list );
+ $this->assertEquals( $exResult, $block->mReason, 'Correct block
type for XFF header ' . $xff );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/56720
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib22ce69797ec03a61b0cc330e8572865290ebd31
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits