mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge pull request #7836 from RichieB2B/fix-proxy-auth-via-ssl
Fix proxy authentication when SSL is used
This commit is contained in:
commit
4faf31e60a
3 changed files with 51 additions and 0 deletions
|
@ -192,6 +192,9 @@ class CakeSocket {
|
|||
$this->config['request']['uri']['port'] . ' HTTP/1.1';
|
||||
$req[] = 'Host: ' . $this->config['host'];
|
||||
$req[] = 'User-Agent: php proxy';
|
||||
if (!empty($this->config['proxyauth'])) {
|
||||
$req[] = 'Proxy-Authorization: ' . $this->config['proxyauth'];
|
||||
}
|
||||
|
||||
fwrite($this->connection, implode("\r\n", $req) . "\r\n\r\n");
|
||||
|
||||
|
|
|
@ -668,6 +668,13 @@ class HttpSocket extends CakeSocket {
|
|||
throw new SocketException(__d('cake_dev', 'The %s does not support proxy authentication.', $authClass));
|
||||
}
|
||||
call_user_func_array("$authClass::proxyAuthentication", array($this, &$this->_proxy));
|
||||
|
||||
if (!empty($this->request['header']['Proxy-Authorization'])) {
|
||||
$this->config['proxyauth'] = $this->request['header']['Proxy-Authorization'];
|
||||
if ($this->request['uri']['scheme'] === 'https') {
|
||||
$this->request['header'] = Hash::remove($this->request['header'], 'Proxy-Authorization');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,25 @@
|
|||
App::uses('HttpSocket', 'Network/Http');
|
||||
App::uses('BasicAuthentication', 'Network/Http');
|
||||
|
||||
/**
|
||||
* class TestSslHttpSocket
|
||||
*
|
||||
* @package Cake.Test.Case.Network.Http
|
||||
*/
|
||||
class TestSslHttpSocket extends HttpSocket {
|
||||
|
||||
/**
|
||||
* testSetProxy method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetProxy($proxy = null) {
|
||||
$this->_proxy = $proxy;
|
||||
$this->_setProxy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* BasicMethodTest class
|
||||
*
|
||||
|
@ -60,4 +79,26 @@ class BasicAuthenticationTest extends CakeTestCase {
|
|||
$this->assertEquals('Basic bWFyazpzZWNyZXQ=', $http->request['header']['Proxy-Authorization']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testProxyAuthenticationSsl method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testProxyAuthenticationSsl() {
|
||||
$http = new TestSslHttpSocket();
|
||||
$http->request['uri']['scheme'] = 'https';
|
||||
$proxy = array(
|
||||
'host' => 'localhost',
|
||||
'port' => 3128,
|
||||
'method' => 'Basic',
|
||||
'user' => 'mark',
|
||||
'pass' => 'secret'
|
||||
);
|
||||
|
||||
$http->testSetProxy($proxy);
|
||||
|
||||
$this->assertEquals('Basic bWFyazpzZWNyZXQ=', $http->config['proxyauth']);
|
||||
$this->assertFalse(isset($http->request['header']['Proxy-Authorization']));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue