1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Common;
/**
* @covers \PhpMyAdmin\Common
*/
class CommonTest extends AbstractTestCase
{
/**
* @param string $php_self The PHP_SELF value
* @param string $request The REQUEST_URI value
* @param string $path_info The PATH_INFO value
* @param string $expected Expected result
*
* @dataProvider providerForTestCleanupPathInfo
*/
public function testCleanupPathInfo(string $php_self, string $request, string $path_info, string $expected): void
{
$_SERVER['PHP_SELF'] = $php_self;
$_SERVER['REQUEST_URI'] = $request;
$_SERVER['PATH_INFO'] = $path_info;
Common::cleanupPathInfo();
$this->assertEquals($expected, $GLOBALS['PMA_PHP_SELF']);
}
public function providerForTestCleanupPathInfo(): array
{
return [
[
'/phpmyadmin/index.php/; cookieinj=value/',
'/phpmyadmin/index.php/;%20cookieinj=value///',
'/; cookieinj=value/',
'/phpmyadmin/index.php',
],
[
'',
'/phpmyadmin/index.php/;%20cookieinj=value///',
'/; cookieinj=value/',
'/phpmyadmin/index.php',
],
[
'',
'//example.com/../phpmyadmin/index.php',
'',
'/phpmyadmin/index.php',
],
[
'',
'//example.com/../../.././phpmyadmin/index.php',
'',
'/phpmyadmin/index.php',
],
[
'',
'/page.php/malicouspathinfo?malicouspathinfo',
'malicouspathinfo',
'/page.php',
],
[
'/phpmyadmin/./index.php',
'/phpmyadmin/./index.php',
'',
'/phpmyadmin/index.php',
],
[
'/phpmyadmin/index.php',
'/phpmyadmin/index.php',
'',
'/phpmyadmin/index.php',
],
[
'',
'/phpmyadmin/index.php',
'',
'/phpmyadmin/index.php',
],
];
}
public function testCheckTokenRequestParam(): void
{
global $token_mismatch, $token_provided;
$_SERVER['REQUEST_METHOD'] = 'GET';
Common::checkTokenRequestParam();
$this->assertTrue($token_mismatch);
$this->assertFalse($token_provided);
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['test'] = 'test';
Common::checkTokenRequestParam();
$this->assertTrue($token_mismatch);
$this->assertFalse($token_provided);
$this->assertArrayNotHasKey('test', $_POST);
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['token'] = 'token';
$_POST['test'] = 'test';
$_SESSION[' PMA_token '] = 'mismatch';
Common::checkTokenRequestParam();
$this->assertTrue($token_mismatch);
$this->assertTrue($token_provided);
$this->assertArrayNotHasKey('test', $_POST);
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['token'] = 'token';
$_POST['test'] = 'test';
$_SESSION[' PMA_token '] = 'token';
Common::checkTokenRequestParam();
$this->assertFalse($token_mismatch);
$this->assertTrue($token_provided);
$this->assertArrayHasKey('test', $_POST);
$this->assertEquals('test', $_POST['test']);
}
}
|