Merge branch 'master' of github.com:phpmyadmin/phpmyadmin

This commit is contained in:
Madhura Jayaratne 2013-07-17 17:06:06 +05:30
commit 1dc03b6702
8 changed files with 1368 additions and 92 deletions

View File

@ -36,6 +36,7 @@ phpMyAdmin - ChangeLog
- bug #3985 Call to undefined function mb_detect_encoding
- bug #4007 Analyze option not shown for InnoDB tables
- bug #4015 Forcing a storage engine for configuration storage
- bug Incorrect Drizzle 7 detection
4.0.4.1 (2013-06-30)
- [security] Global variables scope injection vulnerability (see PMASA-2013-7)

View File

@ -153,7 +153,9 @@ class AuthenticationConfig extends AuthenticationPlugin
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
exit;
if (!defined('TESTSUITE')) {
exit;
}
return true;
}

View File

@ -102,7 +102,11 @@ class AuthenticationCookie extends AuthenticationPlugin
)
);
}
exit;
if (defined('TESTSUITE')) {
return true;
} else {
exit;
}
}
/* Perform logout to custom URL */
@ -110,7 +114,11 @@ class AuthenticationCookie extends AuthenticationPlugin
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
) {
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
exit;
if (defined('TESTSUITE')) {
return true;
} else {
exit;
}
}
// No recall if blowfish secret is not configured as it would produce
@ -301,7 +309,11 @@ class AuthenticationCookie extends AuthenticationPlugin
if (file_exists(CUSTOM_FOOTER_FILE)) {
include CUSTOM_FOOTER_FILE;
}
exit;
if (! defined('TESTSUITE')) {
exit;
} else {
return true;
}
}
/**
@ -408,7 +420,9 @@ class AuthenticationCookie extends AuthenticationPlugin
// according to the PHP manual we should do this before the destroy:
//$_SESSION = array();
session_destroy();
if (! defined('TESTSUITE')) {
session_destroy();
}
// -> delete password cookie(s)
if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
@ -478,7 +492,11 @@ class AuthenticationCookie extends AuthenticationPlugin
PMA_Util::cacheUnset('dbs_where_create_table_allowed', true);
$GLOBALS['no_activity'] = true;
$this->authFails();
exit;
if (! defined('TESTSUITE')) {
exit;
} else {
return false;
}
}
// password
@ -625,7 +643,11 @@ class AuthenticationCookie extends AuthenticationPlugin
$redirect_url . PMA_generate_common_url($url_params, '&'),
true
);
exit;
if (! defined('TESTSUITE')) {
exit;
} else {
return false;
}
} // end if
return true;

View File

@ -71,4 +71,31 @@ if (PMA_HAS_RUNKIT && $GLOBALS['runkit_internal_override']) {
echo "Please install runkit and enable runkit.internal_override!\n";
}
/**
* Return the tag array to be used with assertTag by parsing
* a given HTML element
*
* @param string $elementHTML HTML for element to be parsed
* @param array $arr Additional array elements like content, parent
*
* @return array Tag array to be used with assertTag
*/
function PMA_getTagArray($elementHTML, $arr = array())
{
// get attributes
preg_match_all("/\s+(.*?)\=\s*\"(.*?)\"/is", $elementHTML, $matches);
foreach ($matches[1] as $key => $val) {
$arr['attributes'][trim($val)] = trim($matches[2][$key]);
}
$matches = array();
// get tag
preg_match("/^\<(.*?)(\s|\>)/i", $elementHTML, $matches);
if (isset($matches[1])) {
$arr['tag'] = trim($matches[1]);
}
return $arr;
}
?>

View File

@ -0,0 +1,143 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for AuthenticationConfig class
*
* @package PhpMyAdmin-test
*/
require_once 'libraries/plugins/auth/AuthenticationConfig.class.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/Config.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/config.default.php';
require_once 'libraries/Error_Handler.class.php';
/**
* tests for AuthenticationConfig class
*
* @package PhpMyAdmin-test
*/
class PMA_AuthenticationConfig_Test extends PHPUnit_Framework_TestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['PMA_Config'] = new PMA_Config();
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['server'] = 0;
$this->object = new AuthenticationConfig(null);
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for AuthenticationConfig::auth
*
* @return void
*/
public function testAuth()
{
$this->assertTrue(
$this->object->auth()
);
}
/**
* Test for AuthenticationConfig::authCheck
*
* @return void
*/
public function testAuthCheck()
{
$this->assertTrue(
$this->object->authCheck()
);
}
/**
* Test for AuthenticationConfig::authSetUser
*
* @return void
*/
public function testAuthSetUser()
{
$this->assertTrue(
$this->object->authSetUser()
);
}
/**
* Test for AuthenticationConfig::authFails
*
* @return void
*/
public function testAuthFails()
{
$removeConstant = false;
$GLOBALS['error_handler'] = new PMA_Error_Handler;
$GLOBALS['cfg']['Servers'] = array(1);
$GLOBALS['allowDeny_forbidden'] = false;
if (!defined('PMA_USR_BROWSER_AGENT')) {
define('PMA_USR_BROWSER_AGENT', 'chrome');
$removeConstant = true;
if (! PMA_HAS_RUNKIT) {
$this->markTestSkipped('Cannot remove constant');
}
}
ob_start();
$result = $this->object->authFails();
$html = ob_get_clean();
$this->assertTrue(
$result
);
$this->assertContains(
'You probably did not create a configuration file. You might want ' .
'to use the <a href="setup/">setup script</a> to create one.',
$html
);
$this->assertContains(
'<strong>MySQL said: </strong><a href="./url.php?url=http%3A%2F%2F' .
'dev.mysql.com%2Fdoc%2Frefman%2F5.6%2Fen%2Ferror-messages-server.html' .
'&amp;server=0&amp;lang=en&amp;token=token" target="mysql_doc">' .
'<img src="themes/dot.gif" title="Documentation" alt="Documentation" ' .
'class="icon ic_b_help" /></a>',
$html
);
$this->assertContains(
'Cannot connect: invalid settings.',
$html
);
$this->assertContains(
'<a href="index.php?server=0&amp;lang=en&amp;token=token" ' .
'class="button disableAjax">Retry to connect</a>',
$html
);
if ($removeConstant) {
runkit_constant_remove('PMA_USR_BROWSER_AGENT');
}
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -21,34 +21,6 @@ require_once 'libraries/user_preferences.lib.php';
*/
class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
{
/**
* Return the tag array to be used with assertTag by parsing
* a given HTML element
*
* @param string $elementHTML HTML for element to be parsed
* @param array $arr Additional array elements like content, parent
*
* @return array Tag array to be used with assertTag
*/
private function _getTagArray($elementHTML, $arr = array())
{
// get attributes
preg_match_all("/\s+(.*?)\=\s*\"(.*?)\"/is", $elementHTML, $matches);
foreach ($matches[1] as $key => $val) {
$arr['attributes'][trim($val)] = trim($matches[2][$key]);
}
$matches = array();
// get tag
preg_match("/^\<(.*?)(\s|\>)/i", $elementHTML, $matches);
if (isset($matches[1])) {
$arr['tag'] = trim($matches[1]);
}
return $arr;
}
/**
* Test for PMA_displayFormTop()
*
@ -63,7 +35,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<form method="get" action="http://www.phpmyadmin.net" ' .
'class="config-form disableAjax">'
),
@ -71,14 +43,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="tab_hash" value="" />'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="check_page_refresh" ' .
'id="check_page_refresh" value="" />'
),
@ -86,21 +58,21 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="lang" value="en" />'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="token" value="token" />'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="0" value="1" />'
),
$result
@ -119,22 +91,22 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray('<ul class="tabs">'),
PMA_getTagArray('<ul class="tabs">'),
$result
);
$this->assertTag(
$this->_getTagArray('<a href="#0">', array('content' => 'one')),
PMA_getTagArray('<a href="#0">', array('content' => 'one')),
$result
);
$this->assertTag(
$this->_getTagArray('<a href="#1">', array('content' => 'two')),
PMA_getTagArray('<a href="#1">', array('content' => 'two')),
$result
);
$this->assertTag(
$this->_getTagArray('<div class="tabs_contents">'),
PMA_getTagArray('<div class="tabs_contents">'),
$result
);
}
@ -154,14 +126,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<fieldset class="optbox" name="attrname">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<legend>',
array(
'content' => 'TitleTest',
@ -172,7 +144,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<p>',
array(
'content' => 'DescTest',
@ -182,14 +154,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<dl class="errors">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<dd>',
array('content' => 'e1', 'parent' => array('tag' => 'dl'))
),
@ -197,7 +169,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<dd>',
array('content' => 'e2', 'parent' => array('tag' => 'dl'))
),
@ -205,7 +177,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<table width="100%" cellspacing="0">'
),
$result
@ -243,14 +215,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<tr class="group-header-field group-header-1 disabled-field">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<label for="test/path">',
array('content' => 'testName')
),
@ -258,7 +230,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<a href="http://doclink" target="documentation">',
array(
'parent' => array(
@ -271,7 +243,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<img src="testImageb_help.png" title="Documentation" ' .
'alt="Documentation" />',
array(
@ -282,28 +254,28 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<a href="http://wikilink" target="wiki">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<img src="testImageb_info.png" title="Wiki" alt="Wiki" />'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<span class="disabled-notice">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<small>',
array('content' => 'desc')
),
@ -311,7 +283,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="text" size="60" name="test/path" id="test/path" ' .
'class="custom field-error" value="val" />'
),
@ -319,7 +291,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<span class="field-comment-mark field-comment-warning" title="testComment">',
array('content' => 'i')
),
@ -327,7 +299,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<a class="restore-default" href="#test/path" ' .
'style="display:none">'
),
@ -360,14 +332,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<tr class="group-field group-field-1">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="checkbox" name="test/path" id="test/path" ' .
'checked="checked" />',
array(
@ -381,7 +353,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<a class="userprefs-comment" title="userprefsComment">',
array('child' => array('tag' => 'img'))
),
@ -389,11 +361,11 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<td class="userprefs-allow" title="Allow users to customize ' .
'this value">',
array(
'child' => $this->_getTagArray(
'child' => PMA_getTagArray(
'<input type="checkbox" name="test/path-userprefs-allow" ' .
'checked="checked"/>'
)
@ -403,7 +375,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<a class="set-value" href="#test/path=setVal" ' .
'title="Set value: setVal" style="display:none">',
array('child' => array('tag' => 'img'))
@ -425,7 +397,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="text" size="25" name="test/path" id="test/path" ' .
'value="val" />'
),
@ -441,7 +413,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="text" size="15" name="test/path" ' .
'id="test/path" value="val" />'
),
@ -463,21 +435,21 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<select name="test/path" id="test/path">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<select name="test/path" id="test/path">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<option value="1" selected="selected" disabled="disabled">',
array(
'parent' => array('tag' => 'select'),
@ -488,7 +460,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<option value="key1">',
array(
'parent' => array('tag' => 'select'),
@ -499,7 +471,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<option value="key2">',
array(
'parent' => array('tag' => 'select'),
@ -525,14 +497,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<select name="test/path" id="test/path">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<select name="test/path" id="test/path">'
),
$result
@ -554,7 +526,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<textarea cols="40" rows="5" name="test/path" id="test/path">',
array(
'content' => "foo\nbar"
@ -591,10 +563,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<tr class="group-header group-header-4">',
array(
'child' => $this->_getTagArray(
'child' => PMA_getTagArray(
'<th colspan="3">',
array(
'content' => 'headerText'
@ -615,10 +587,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<tr class="group-header group-header-4">',
array(
'child' => $this->_getTagArray(
'child' => PMA_getTagArray(
'<th colspan="2">',
array(
'content' => 'headerText'
@ -668,14 +640,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<td colspan="3" class="lastrow">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="submit" name="submit_save" value="Apply"',
array(
'parent' => array('tag' => 'td')
@ -685,7 +657,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="button" name="submit_reset" value="Reset" />',
array(
'parent' => array('tag' => 'td')
@ -708,7 +680,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase
$result = ob_get_clean();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<td colspan="2" class="lastrow">'
),
$result

View File

@ -416,35 +416,35 @@ class PMA_User_Preferences_Test extends PHPUnit_Framework_TestCase
$result = PMA_userprefsAutoloadGetHeader();
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<form action="prefs_manage.php" method="post">'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="token" value="token"'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="json" value="" />'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="submit_import" value="1" />'
),
$result
);
$this->assertTag(
$this->_getTagArray(
PMA_getTagArray(
'<input type="hidden" name="return_url" value="phpunit?" />'
),
$result