1, "str" => "str_val", "arr" => ['val1', 'val2', 'val3'], "sarr" => [ 'arr1' => [1, 2, 3], [3, ['a', 'b', 'c'], 4] ] ]; $this->assertEquals( Core::arrayRead('int', $arr), $arr['int'] ); $this->assertEquals( Core::arrayRead('str', $arr), $arr['str'] ); $this->assertEquals( Core::arrayRead('arr/0', $arr), $arr['arr'][0] ); $this->assertEquals( Core::arrayRead('arr/1', $arr), $arr['arr'][1] ); $this->assertEquals( Core::arrayRead('arr/2', $arr), $arr['arr'][2] ); $this->assertEquals( Core::arrayRead('sarr/arr1/0', $arr), $arr['sarr']['arr1'][0] ); $this->assertEquals( Core::arrayRead('sarr/arr1/1', $arr), $arr['sarr']['arr1'][1] ); $this->assertEquals( Core::arrayRead('sarr/arr1/2', $arr), $arr['sarr']['arr1'][2] ); $this->assertEquals( Core::arrayRead('sarr/0/0', $arr), $arr['sarr'][0][0] ); $this->assertEquals( Core::arrayRead('sarr/0/1', $arr), $arr['sarr'][0][1] ); $this->assertEquals( Core::arrayRead('sarr/0/1/2', $arr), $arr['sarr'][0][1][2] ); $this->assertEquals( Core::arrayRead('sarr/not_exiting/1', $arr), null ); $this->assertEquals( Core::arrayRead('sarr/not_exiting/1', $arr, 0), 0 ); $this->assertEquals( Core::arrayRead('sarr/not_exiting/1', $arr, 'default_val'), 'default_val' ); } /** * Test for Core::arrayWrite * * @return void */ public function testArrayWrite() { $arr = [ "int" => 1, "str" => "str_val", "arr" => ['val1', 'val2', 'val3'], "sarr" => [ 'arr1' => [1, 2, 3], [3, ['a', 'b', 'c'], 4] ] ]; Core::arrayWrite('int', $arr, 5); $this->assertEquals($arr['int'], 5); Core::arrayWrite('str', $arr, '_str'); $this->assertEquals($arr['str'], '_str'); Core::arrayWrite('arr/0', $arr, 'val_arr_0'); $this->assertEquals($arr['arr'][0], 'val_arr_0'); Core::arrayWrite('arr/1', $arr, 'val_arr_1'); $this->assertEquals($arr['arr'][1], 'val_arr_1'); Core::arrayWrite('arr/2', $arr, 'val_arr_2'); $this->assertEquals($arr['arr'][2], 'val_arr_2'); Core::arrayWrite('sarr/arr1/0', $arr, 'val_sarr_arr_0'); $this->assertEquals($arr['sarr']['arr1'][0], 'val_sarr_arr_0'); Core::arrayWrite('sarr/arr1/1', $arr, 'val_sarr_arr_1'); $this->assertEquals($arr['sarr']['arr1'][1], 'val_sarr_arr_1'); Core::arrayWrite('sarr/arr1/2', $arr, 'val_sarr_arr_2'); $this->assertEquals($arr['sarr']['arr1'][2], 'val_sarr_arr_2'); Core::arrayWrite('sarr/0/0', $arr, 5); $this->assertEquals($arr['sarr'][0][0], 5); Core::arrayWrite('sarr/0/1/0', $arr, 'e'); $this->assertEquals($arr['sarr'][0][1][0], 'e'); Core::arrayWrite('sarr/not_existing/1', $arr, 'some_val'); $this->assertEquals($arr['sarr']['not_existing'][1], 'some_val'); Core::arrayWrite('sarr/0/2', $arr, null); $this->assertNull($arr['sarr'][0][2]); } /** * Test for Core::arrayRemove * * @return void */ public function testArrayRemove() { $arr = [ "int" => 1, "str" => "str_val", "arr" => ['val1', 'val2', 'val3'], "sarr" => [ 'arr1' => [1, 2, 3], [3, ['a', 'b', 'c'], 4] ] ]; Core::arrayRemove('int', $arr); $this->assertArrayNotHasKey('int', $arr); Core::arrayRemove('str', $arr); $this->assertArrayNotHasKey('str', $arr); Core::arrayRemove('arr/0', $arr); $this->assertArrayNotHasKey(0, $arr['arr']); Core::arrayRemove('arr/1', $arr); $this->assertArrayNotHasKey(1, $arr['arr']); Core::arrayRemove('arr/2', $arr); $this->assertArrayNotHasKey('arr', $arr); $tmp_arr = $arr; Core::arrayRemove('sarr/not_existing/1', $arr); $this->assertEquals($tmp_arr, $arr); Core::arrayRemove('sarr/arr1/0', $arr); $this->assertArrayNotHasKey(0, $arr['sarr']['arr1']); Core::arrayRemove('sarr/arr1/1', $arr); $this->assertArrayNotHasKey(1, $arr['sarr']['arr1']); Core::arrayRemove('sarr/arr1/2', $arr); $this->assertArrayNotHasKey('arr1', $arr['sarr']); Core::arrayRemove('sarr/0/0', $arr); $this->assertArrayNotHasKey(0, $arr['sarr'][0]); Core::arrayRemove('sarr/0/1/0', $arr); $this->assertArrayNotHasKey(0, $arr['sarr'][0][1]); Core::arrayRemove('sarr/0/1/1', $arr); $this->assertArrayNotHasKey(1, $arr['sarr'][0][1]); Core::arrayRemove('sarr/0/1/2', $arr); $this->assertArrayNotHasKey(1, $arr['sarr'][0]); Core::arrayRemove('sarr/0/2', $arr); $this->assertEmpty($arr); } /** * Test for Core::checkPageValidity * * @param string $page Page * @param array|null $whiteList White list * @param int $expected Expected value * * @return void * * @dataProvider providerTestGotoNowhere */ public function testGotoNowhere($page, $whiteList, $expected) { $this->assertSame($expected, Core::checkPageValidity($page, $whiteList)); } /** * Data provider for testGotoNowhere * * @return array */ public function providerTestGotoNowhere() { return [ ['', [], false], ['', [''], false], ['export.php', [], true], ['export.php', $this->goto_whitelist, true], ['shell.php', $this->goto_whitelist, false], ['index.php?sql.php&test=true', $this->goto_whitelist, true], ['index.php%3Fsql.php%26test%3Dtrue', $this->goto_whitelist, true], ]; } /** * Test for Core::cleanupPathInfo * * @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 * * @return void * * @dataProvider providerTestPathInfo */ public function testPathInfo($php_self, $request, $path_info, $expected) { $_SERVER['PHP_SELF'] = $php_self; $_SERVER['REQUEST_URI'] = $request; $_SERVER['PATH_INFO'] = $path_info; Core::cleanupPathInfo(); $this->assertEquals( $expected, $GLOBALS['PMA_PHP_SELF'] ); } /** * Data provider for Core::cleanupPathInfo tests * * @return array */ public function providerTestPathInfo() { 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' ], ]; } /** * Test for Core::fatalError * * @return void */ public function testFatalErrorMessage() { $this->expectOutputRegex("/FatalError!/"); Core::fatalError("FatalError!"); } /** * Test for Core::fatalError * * @return void */ public function testFatalErrorMessageWithArgs() { $message = "Fatal error #%d in file %s."; $params = [1, 'error_file.php']; $this->expectOutputRegex("/Fatal error #1 in file error_file.php./"); Core::fatalError($message, $params); $message = "Fatal error in file %s."; $params = 'error_file.php'; $this->expectOutputRegex("/Fatal error in file error_file.php./"); Core::fatalError($message, $params); } /** * Test for Core::getRealSize * * @param string $size Size * @param int $expected Expected value * * @return void * * @dataProvider providerTestGetRealSize */ public function testGetRealSize($size, $expected) { $this->assertEquals($expected, Core::getRealSize($size)); } /** * Data provider for testGetRealSize * * @return array */ public function providerTestGetRealSize() { return [ ['0', 0], ['1kb', 1024], ['1024k', 1024 * 1024], ['8m', 8 * 1024 * 1024], ['12gb', 12 * 1024 * 1024 * 1024], ['1024', 1024], ]; } /** * Test for Core::getPHPDocLink * * @return void */ public function testGetPHPDocLink() { $lang = _pgettext('PHP documentation language', 'en'); $this->assertEquals( Core::getPHPDocLink('function'), './url.php?url=https%3A%2F%2Fsecure.php.net%2Fmanual%2F' . $lang . '%2Ffunction' ); } /** * Test for Core::linkURL * * @param string $link URL where to go * @param string $url Expected value * * @return void * * @dataProvider providerTestLinkURL */ public function testLinkURL($link, $url) { $this->assertEquals(Core::linkURL($link), $url); } /** * Data provider for testLinkURL * * @return array */ public function providerTestLinkURL() { return [ ['https://wiki.phpmyadmin.net', './url.php?url=https%3A%2F%2Fwiki.phpmyadmin.net'], ['https://wiki.phpmyadmin.net', './url.php?url=https%3A%2F%2Fwiki.phpmyadmin.net'], ['wiki.phpmyadmin.net', 'wiki.phpmyadmin.net'], ['index.php?db=phpmyadmin', 'index.php?db=phpmyadmin'] ]; } /** * Test for Core::sendHeaderLocation * * @return void */ public function testSendHeaderLocationWithoutSidWithIis() { $GLOBALS['server'] = 0; $GLOBALS['PMA_Config'] = new Config(); $GLOBALS['PMA_Config']->enableBc(); $GLOBALS['PMA_Config']->set('PMA_IS_IIS', true); $testUri = 'https://example.com/test.php'; $this->mockResponse('Location: ' . $testUri); Core::sendHeaderLocation($testUri); // sets $GLOBALS['header'] $this->tearDown(); $this->mockResponse('Refresh: 0; ' . $testUri); Core::sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] } /** * Test for Core::sendHeaderLocation * * @return void */ public function testSendHeaderLocationWithoutSidWithoutIis() { $GLOBALS['server'] = 0; $GLOBALS['PMA_Config'] = new Config(); $GLOBALS['PMA_Config']->enableBc(); $GLOBALS['PMA_Config']->set('PMA_IS_IIS', null); $testUri = 'https://example.com/test.php'; $this->mockResponse('Location: ' . $testUri); Core::sendHeaderLocation($testUri); // sets $GLOBALS['header'] } /** * Test for Core::sendHeaderLocation * * @return void */ public function testSendHeaderLocationIisLongUri() { $GLOBALS['server'] = 0; $GLOBALS['PMA_Config'] = new Config(); $GLOBALS['PMA_Config']->enableBc(); $GLOBALS['PMA_Config']->set('PMA_IS_IIS', true); // over 600 chars $testUri = 'https://example.com/test.php?testlonguri=over600chars&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test'; $testUri_html = htmlspecialchars($testUri); $testUri_js = Sanitize::escapeJsString($testUri); $header = "\n
\n