Skip to content

Commit

Permalink
Merge 7660602 into 4df8dfe
Browse files Browse the repository at this point in the history
  • Loading branch information
gongo committed Aug 29, 2023
2 parents 4df8dfe + 7660602 commit c431863
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -8,7 +8,7 @@
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": "^7.5 || ^4.8",
"phpunit/phpunit": "^9 || ^7.5 || ^4.8",
"php-coveralls/php-coveralls": "*"
},
"license": "MIT",
Expand Down
5 changes: 1 addition & 4 deletions test/BaseTest.php
Expand Up @@ -16,13 +16,10 @@ class BaseTest extends TestCase
{
private $object = null;

protected function setUp()
public function testIgnoringVariable()
{
$this->object = new Polluter;
}

public function testIgnoringVariable()
{
$ignores = array(
'GLOBALS',
'_SERVER',
Expand Down
25 changes: 24 additions & 1 deletion test/RequestTest.php
Expand Up @@ -11,7 +11,7 @@ class RequestTest extends TestCase
{
private $object = null;

protected function setUp()
private function setUpMethod()
{
$this->object = $this->getMockBuilder('Gongo\MercifulPolluter\Request')
->setMethods(array('getInjectVariables'))
Expand All @@ -20,6 +20,8 @@ protected function setUp()

public function testPollute()
{
$this->setUpMethod();

$_FILES['upfile'] = array(
'tmp_name' => '/tmp/aqwsedrftgyhujik.txt',
'name' => 'test.txt',
Expand Down Expand Up @@ -56,6 +58,8 @@ public function testPollute()
*/
public function testPollutePostMultipleFile()
{
$this->setUpMethod();

$_FILES['music'] = array(
'tmp_name' => array('/tmp/aqwerft', '/tmp/gyhujiko'),
'size' => array(123, 456)
Expand All @@ -80,6 +84,8 @@ public function testPollutePostMultipleFile()

public function testPolluteOverwriteVariableOrder()
{
$this->setUpMethod();

$_GET['id'] = 'get';
$_POST['id'] = 'post';

Expand All @@ -92,6 +98,8 @@ public function testPolluteOverwriteVariableOrder()

public function testPolluteOverwriteArrayToArray()
{
$this->setUpMethod();

$_GET['foo'] = array('bar' => 'baz');
$_POST['foo'] = array('spam' => 'ham');

Expand All @@ -104,6 +112,8 @@ public function testPolluteOverwriteArrayToArray()

public function testPolluteOverwriteNestedArrayToNestedArray()
{
$this->setUpMethod();

$_GET['foo'] = array('bar' => array('baz' => '123'));
$_POST['foo'] = array('bar' => array('spam' => 'ham'));

Expand All @@ -124,6 +134,8 @@ public function testPolluteOverwriteNestedArrayToNestedArray()

public function testPolluteOverwriteScalarToArray()
{
$this->setUpMethod();

$_GET['foo'] = 'bar';
$_POST['foo'] = array('spam' => 'ham');

Expand All @@ -136,6 +148,8 @@ public function testPolluteOverwriteScalarToArray()

public function testPolluteOverwriteArrayToScalar()
{
$this->setUpMethod();

$_GET['foo'] = array('bar' => 'baz');
$_POST['foo'] = 'ham';

Expand All @@ -148,6 +162,8 @@ public function testPolluteOverwriteArrayToScalar()

public function testPolluteOverwriteArrayToScalarToArray()
{
$this->setUpMethod();

$_GET['foo'] = array('bar' => 'baz');
$_POST['foo'] = 'ham';
$_COOKIE['foo'] = array('spam' => 'ham');
Expand All @@ -161,6 +177,7 @@ public function testPolluteOverwriteArrayToScalarToArray()

public function testPolluteOverwriteArrayToArrayToScalar()
{
$this->setUpMethod();
$_GET['foo'] = array('bar' => 'baz');
$_POST['foo'] = array('spam' => 'ham');
$_COOKIE['foo'] = 'ham';
Expand All @@ -174,6 +191,8 @@ public function testPolluteOverwriteArrayToArrayToScalar()

public function testPolluteEnableMagicQuotesGpc()
{
$this->setUpMethod();

$_ENV['TOKEN'] = "foo'bar";
$_GET['name_1'] = "baz'piyo_get";
$_GET['personal_info_1'] = array('address' => "'Okinawa'");
Expand Down Expand Up @@ -222,6 +241,8 @@ public function testPolluteEnableMagicQuotesGpc()
*/
public function testPolluteSpecifiedBlacklist()
{
$this->setUpMethod();

$_GET['foo'] = '123';
$_GET['bar'] = 'baz';
$_GET['_GET'] = array(
Expand All @@ -243,6 +264,8 @@ public function testPolluteSpecifiedBlacklist()

private function setVariablesOrder($value)
{
$this->setUpMethod();

$this->object->method('getInjectVariables')
->willReturn(str_split(strtolower($value)));
}
Expand Down
16 changes: 12 additions & 4 deletions test/SessionTest.php
Expand Up @@ -11,13 +11,10 @@ class SessionTest extends TestCase
{
private $object = null;

protected function setUp()
public function testPollute()
{
$this->object = new Session;
}

public function testPollute()
{
session_start();

$_SESSION['userId'] = '1234';
Expand All @@ -35,11 +32,20 @@ public function testPollute()
}

/**
* Below annotations are for PHPUnit < 9.0
*
* @expectedException PHPUnit_Framework_Error_Warning
* @expectedExceptionMessage The session not yet started (Ignoring)
*/
public function testPolluteSessionNotStarted()
{
// For PHPUnit >= 9.0
if (method_exists($this, 'expectWarning')) {
$this->expectWarning();
$this->expectWarningMessage('The session not yet started (Ignoring)');
}

$this->object = new Session;
$this->object->pollute();
}

Expand All @@ -48,6 +54,8 @@ public function testPolluteSessionNotStarted()
*/
public function testPolluteSpecifiedBlacklist()
{
$this->object = new Session;

session_start();

$_SESSION['_GET'] = '1234';
Expand Down

0 comments on commit c431863

Please sign in to comment.