From e315fb6688f19d6599ac2db672718184263bca25 Mon Sep 17 00:00:00 2001 From: Richard van den Berg Date: Fri, 11 Dec 2015 14:44:46 +0100 Subject: [PATCH 1/5] Fix proxy authentication when SSL is used --- lib/Cake/Network/CakeSocket.php | 3 +++ lib/Cake/Network/Http/HttpSocket.php | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index a8626386c..963456db7 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -189,6 +189,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"); diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 0356391b8..308487094 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -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'); + } + } } /** From ac50b609ac1af150670e1e702fed05fe5d741a41 Mon Sep 17 00:00:00 2001 From: Richard van den Berg Date: Fri, 11 Dec 2015 15:01:05 +0100 Subject: [PATCH 2/5] Added space --- lib/Cake/Network/CakeSocket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index 963456db7..f4b5ed2c3 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -189,7 +189,7 @@ 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'])) { + if (!empty($this->config['proxyauth'])) { $req[] = 'Proxy-Authorization: ' . $this->config['proxyauth']; } From 077f157adf9526bee8c5ffde4ecf3e2d83e51c4c Mon Sep 17 00:00:00 2001 From: Richard van den Berg Date: Sat, 12 Dec 2015 11:13:41 +0100 Subject: [PATCH 3/5] Test case for proxy authentication when request is HTTPS --- .../Network/Http/BasicAuthenticationTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php b/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php index f7b4d6109..b3e345d9f 100644 --- a/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php +++ b/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php @@ -19,6 +19,24 @@ App::uses('HttpSocket', 'Network/Http'); App::uses('BasicAuthentication', 'Network/Http'); +/** + * class TestHttpSocket + * + * @package Cake.Test.Case.Network.Http + */ +class TestHttpSocket extends HttpSocket { + +/** + * testSetProxy method + * + * @return void + */ + public function testSetProxy($proxy = null) { + $this->_proxy=$proxy; + $this->_setProxy(); + } +} + /** * BasicMethodTest class * @@ -60,4 +78,26 @@ class BasicAuthenticationTest extends CakeTestCase { $this->assertEquals('Basic bWFyazpzZWNyZXQ=', $http->request['header']['Proxy-Authorization']); } +/** + * testProxyAuthenticationSsl method + * + * @return void + */ + public function testProxyAuthenticationSsl() { + $http = new TestHttpSocket(); + $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'])); + } + } From e47b26aa6b230fb992c4408ad2cf3c07a6170c20 Mon Sep 17 00:00:00 2001 From: Richard van den Berg Date: Tue, 15 Dec 2015 16:58:12 +0100 Subject: [PATCH 4/5] Do not redefine TestHttpSocket --- lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php b/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php index b3e345d9f..741f1621b 100644 --- a/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php +++ b/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php @@ -20,11 +20,11 @@ App::uses('HttpSocket', 'Network/Http'); App::uses('BasicAuthentication', 'Network/Http'); /** - * class TestHttpSocket + * class TestSslHttpSocket * * @package Cake.Test.Case.Network.Http */ -class TestHttpSocket extends HttpSocket { +class TestSslHttpSocket extends HttpSocket { /** * testSetProxy method @@ -84,7 +84,7 @@ class BasicAuthenticationTest extends CakeTestCase { * @return void */ public function testProxyAuthenticationSsl() { - $http = new TestHttpSocket(); + $http = new TestSslHttpSocket(); $http->request['uri']['scheme'] = 'https'; $proxy = array( 'host' => 'localhost', From 2d178b7e10b54ea057f5eea27715770ae87f8353 Mon Sep 17 00:00:00 2001 From: Richard van den Berg Date: Tue, 15 Dec 2015 19:58:11 +0100 Subject: [PATCH 5/5] PHPCS fixes --- lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php b/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php index 741f1621b..7ae8349b3 100644 --- a/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php +++ b/lib/Cake/Test/Case/Network/Http/BasicAuthenticationTest.php @@ -32,9 +32,10 @@ class TestSslHttpSocket extends HttpSocket { * @return void */ public function testSetProxy($proxy = null) { - $this->_proxy=$proxy; + $this->_proxy = $proxy; $this->_setProxy(); } + } /**