Merge pull request #7836 from RichieB2B/fix-proxy-auth-via-ssl

Fix proxy authentication when SSL is used
This commit is contained in:
Mark Story 2015-12-15 21:56:40 -05:00
commit 4faf31e60a
3 changed files with 51 additions and 0 deletions

View file

@ -192,6 +192,9 @@ class CakeSocket {
$this->config['request']['uri']['port'] . ' HTTP/1.1'; $this->config['request']['uri']['port'] . ' HTTP/1.1';
$req[] = 'Host: ' . $this->config['host']; $req[] = 'Host: ' . $this->config['host'];
$req[] = 'User-Agent: php proxy'; $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"); fwrite($this->connection, implode("\r\n", $req) . "\r\n\r\n");

View file

@ -668,6 +668,13 @@ class HttpSocket extends CakeSocket {
throw new SocketException(__d('cake_dev', 'The %s does not support proxy authentication.', $authClass)); throw new SocketException(__d('cake_dev', 'The %s does not support proxy authentication.', $authClass));
} }
call_user_func_array("$authClass::proxyAuthentication", array($this, &$this->_proxy)); 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');
}
}
} }
/** /**

View file

@ -19,6 +19,25 @@
App::uses('HttpSocket', 'Network/Http'); App::uses('HttpSocket', 'Network/Http');
App::uses('BasicAuthentication', '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 * BasicMethodTest class
* *
@ -60,4 +79,26 @@ class BasicAuthenticationTest extends CakeTestCase {
$this->assertEquals('Basic bWFyazpzZWNyZXQ=', $http->request['header']['Proxy-Authorization']); $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']));
}
} }