Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
7c25ca7967
@ -456,4 +456,87 @@ class Response
|
||||
{
|
||||
return headers_sent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around PHP's http_response_code() function.
|
||||
*
|
||||
* @param int $response_code will set the response code.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function http_response_code($response_code)
|
||||
{
|
||||
http_response_code($response_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets http response code.
|
||||
*
|
||||
* @param int $response_code will set the response code.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_http_response_code($response_code)
|
||||
{
|
||||
$this->http_response_code($response_code);
|
||||
switch ($response_code) {
|
||||
case 100: $httpStatusMsg = ' Continue'; break;
|
||||
case 101: $httpStatusMsg = ' Switching Protocols'; break;
|
||||
case 200: $httpStatusMsg = ' OK'; break;
|
||||
case 201: $httpStatusMsg = ' Created'; break;
|
||||
case 202: $httpStatusMsg = ' Accepted'; break;
|
||||
case 203: $httpStatusMsg = ' Non-Authoritative Information'; break;
|
||||
case 204: $httpStatusMsg = ' No Content'; break;
|
||||
case 205: $httpStatusMsg = ' Reset Content'; break;
|
||||
case 206: $httpStatusMsg = ' Partial Content'; break;
|
||||
case 300: $httpStatusMsg = ' Multiple Choices'; break;
|
||||
case 301: $httpStatusMsg = ' Moved Permanently'; break;
|
||||
case 302: $httpStatusMsg = ' Moved Temporarily'; break;
|
||||
case 303: $httpStatusMsg = ' See Other'; break;
|
||||
case 304: $httpStatusMsg = ' Not Modified'; break;
|
||||
case 305: $httpStatusMsg = ' Use Proxy'; break;
|
||||
case 400: $httpStatusMsg = ' Bad Request'; break;
|
||||
case 401: $httpStatusMsg = ' Unauthorized'; break;
|
||||
case 402: $httpStatusMsg = ' Payment Required'; break;
|
||||
case 403: $httpStatusMsg = ' Forbidden'; break;
|
||||
case 404: $httpStatusMsg = ' Not Found'; break;
|
||||
case 405: $httpStatusMsg = ' Method Not Allowed'; break;
|
||||
case 406: $httpStatusMsg = ' Not Acceptable'; break;
|
||||
case 407: $httpStatusMsg = ' Proxy Authentication Required'; break;
|
||||
case 408: $httpStatusMsg = ' Request Time-out'; break;
|
||||
case 409: $httpStatusMsg = ' Conflict'; break;
|
||||
case 410: $httpStatusMsg = ' Gone'; break;
|
||||
case 411: $httpStatusMsg = ' Length Required'; break;
|
||||
case 412: $httpStatusMsg = ' Precondition Failed'; break;
|
||||
case 413: $httpStatusMsg = ' Request Entity Too Large'; break;
|
||||
case 414: $httpStatusMsg = ' Request-URI Too Large'; break;
|
||||
case 415: $httpStatusMsg = ' Unsupported Media Type'; break;
|
||||
case 500: $httpStatusMsg = ' Internal Server Error'; break;
|
||||
case 501: $httpStatusMsg = ' Not Implemented'; break;
|
||||
case 502: $httpStatusMsg = ' Bad Gateway'; break;
|
||||
case 503: $httpStatusMsg = ' Service Unavailable'; break;
|
||||
case 504: $httpStatusMsg = ' Gateway Time-out'; break;
|
||||
case 505: $httpStatusMsg = ' HTTP Version not supported'; break;
|
||||
default: $httpStatusMsg = ' Web server is down'; break;
|
||||
}
|
||||
if (php_sapi_name() !== 'cgi-fcgi') {
|
||||
$this->header('status: ' . $response_code . $httpStatusMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate header for 303
|
||||
*
|
||||
* @param string $location will set location to redirect.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generateHeader303($location)
|
||||
{
|
||||
$this->set_http_response_code(303);
|
||||
$this->header('Location: '.$location);
|
||||
if (!defined('TESTSUITE')) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,10 +66,7 @@ class AuthenticationHttp extends AuthenticationPlugin
|
||||
// remove non US-ASCII to respect RFC2616
|
||||
$realm_message = preg_replace('/[^\x20-\x7e]/i', '', $realm_message);
|
||||
$response->header('WWW-Authenticate: Basic realm="' . $realm_message . '"');
|
||||
$response->header('HTTP/1.0 401 Unauthorized');
|
||||
if (php_sapi_name() !== 'cgi-fcgi') {
|
||||
$response->header('status: 401 Unauthorized');
|
||||
}
|
||||
$response->set_http_response_code(401);
|
||||
|
||||
/* HTML header */
|
||||
$footer = $response->getFooter();
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
use PMA\libraries\config\FormDisplay;
|
||||
use PMA\setup\lib\ConfigGenerator;
|
||||
use PMA\libraries\URL;
|
||||
use PMA\libraries\Response;
|
||||
|
||||
/**
|
||||
* Core libraries.
|
||||
@ -20,6 +21,8 @@ $form_display = new FormDisplay($GLOBALS['ConfigFile']);
|
||||
$form_display->registerForm('_config.php', $forms['_config.php']);
|
||||
$form_display->save('_config.php');
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
if (isset($_POST['eol'])) {
|
||||
$_SESSION['eol'] = ($_POST['eol'] == 'unix') ? 'unix' : 'win';
|
||||
}
|
||||
@ -30,8 +33,7 @@ if (PMA_ifSetOr($_POST['submit_clear'], '')) {
|
||||
//
|
||||
$GLOBALS['ConfigFile']->resetConfigData();
|
||||
// drop post data
|
||||
header('HTTP/1.1 303 See Other');
|
||||
header('Location: index.php' . URL::getCommonRaw());
|
||||
$response->generateHeader303('index.php' . URL::getCommonRaw());
|
||||
exit;
|
||||
} elseif (PMA_ifSetOr($_POST['submit_download'], '')) {
|
||||
//
|
||||
@ -44,7 +46,6 @@ if (PMA_ifSetOr($_POST['submit_clear'], '')) {
|
||||
//
|
||||
// Show generated config file in a <textarea>
|
||||
//
|
||||
header('HTTP/1.1 303 See Other');
|
||||
header('Location: index.php' . URL::getCommonRaw() . '&page=config');
|
||||
$response->generateHeader303('index.php' . URL::getCommonRaw() . '&page=config');
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -21,7 +21,8 @@ function PMA_Process_formset(FormDisplay $form_display)
|
||||
if (isset($_GET['mode']) && $_GET['mode'] == 'revert') {
|
||||
// revert erroneous fields to their default values
|
||||
$form_display->fixErrors();
|
||||
PMA_generateHeader303();
|
||||
$response = Response::getInstance();
|
||||
$response->generateHeader303('index.php' . URL::getCommonRaw());
|
||||
}
|
||||
|
||||
if (!$form_display->process(false)) {
|
||||
@ -32,7 +33,8 @@ function PMA_Process_formset(FormDisplay $form_display)
|
||||
|
||||
// check for form errors
|
||||
if (!$form_display->hasErrors()) {
|
||||
PMA_generateHeader303();
|
||||
$response = Response::getInstance();
|
||||
$response->generateHeader303('index.php' . URL::getCommonRaw());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -64,22 +66,4 @@ function PMA_Process_formset(FormDisplay $form_display)
|
||||
<?php echo __('Show form') ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate header for 303
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_generateHeader303()
|
||||
{
|
||||
$response = Response::getInstance();
|
||||
|
||||
// drop post data
|
||||
$response->header('HTTP/1.1 303 See Other');
|
||||
$response->header('Location: index.php' . URL::getCommonRaw());
|
||||
|
||||
if (!defined('TESTSUITE')) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@ -36,7 +36,7 @@ class PMATestCase extends PHPUnit_Framework_TestCase
|
||||
->setMethods(array(
|
||||
'header', 'headersSent', 'disable', 'isAjax',
|
||||
'setRequestStatus', 'addJSON', 'addHTML',
|
||||
'getFooter', 'getHeader',
|
||||
'getFooter', 'getHeader','http_response_code',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
@ -51,11 +51,20 @@ class PMATestCase extends PHPUnit_Framework_TestCase
|
||||
if (is_array($param[0])) {
|
||||
if (is_array($param[0][0]) && count($param) == 1) {
|
||||
$param = $param[0];
|
||||
if(is_int(end($param))){
|
||||
$http_response_code_param = end($param);
|
||||
$param = array_slice($param, 0, -1);
|
||||
|
||||
$header_method = $mockResponse->expects($this->once())
|
||||
->method('http_response_code')->with($http_response_code_param);
|
||||
}
|
||||
}
|
||||
|
||||
$header_method = $mockResponse->expects($this->exactly(count($param)))
|
||||
->method('header');
|
||||
|
||||
call_user_func_array(array($header_method, 'withConsecutive'), $param);
|
||||
|
||||
} else {
|
||||
$mockResponse->expects($this->once())
|
||||
->method('header')
|
||||
|
||||
@ -136,8 +136,8 @@ class AuthenticationHttpTest extends PMATestCase
|
||||
$this->doMockResponse(
|
||||
1, 1, 1,
|
||||
array('WWW-Authenticate: Basic realm="phpMyAdmin verboseMessag"'),
|
||||
array('HTTP/1.0 401 Unauthorized'),
|
||||
array('status: 401 Unauthorized')
|
||||
array('status: 401 Unauthorized'),
|
||||
401
|
||||
);
|
||||
}
|
||||
|
||||
@ -149,8 +149,8 @@ class AuthenticationHttpTest extends PMATestCase
|
||||
$this->doMockResponse(
|
||||
1, 1, 1,
|
||||
array('WWW-Authenticate: Basic realm="phpMyAdmin hst"'),
|
||||
array('HTTP/1.0 401 Unauthorized'),
|
||||
array('status: 401 Unauthorized')
|
||||
array('status: 401 Unauthorized'),
|
||||
401
|
||||
);
|
||||
}
|
||||
|
||||
@ -162,8 +162,8 @@ class AuthenticationHttpTest extends PMATestCase
|
||||
$this->doMockResponse(
|
||||
1, 1, 1,
|
||||
array('WWW-Authenticate: Basic realm="realmmessage"'),
|
||||
array('HTTP/1.0 401 Unauthorized'),
|
||||
array('status: 401 Unauthorized')
|
||||
array('status: 401 Unauthorized'),
|
||||
401
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -38,8 +38,11 @@ class PMA_Form_Processing_Test extends PMATestCase
|
||||
public function testProcessFormSet()
|
||||
{
|
||||
$this->mockResponse(
|
||||
array('HTTP/1.1 303 See Other'),
|
||||
array('Location: index.php?lang=en')
|
||||
array(
|
||||
array('status: 303 See Other'),
|
||||
array('Location: index.php?lang=en'),
|
||||
303
|
||||
)
|
||||
);
|
||||
|
||||
// case 1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user