From 48dd778bd0eedcaaad57e81cebf74f7ebb76db9f Mon Sep 17 00:00:00 2001 From: Qing Wu Date: Wed, 2 Dec 2015 10:24:16 +1100 Subject: [PATCH] Fixed issue #7579 on the 2.7 branch --- lib/Cake/Network/CakeSocket.php | 6 +++++- lib/Cake/Test/Case/Network/CakeSocketTest.php | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index 2c8e01fa3..a8626386c 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -129,8 +129,12 @@ class CakeSocket { $this->disconnect(); } + $hasProtocol = strpos($this->config['host'], '://') !== false; + if ($hasProtocol) { + list($this->config['protocol'], $this->config['host']) = explode('://', $this->config['host']); + } $scheme = null; - if (!empty($this->config['protocol']) && strpos($this->config['host'], '://') === false && empty($this->config['proxy'])) { + if (!empty($this->config['protocol'])) { $scheme = $this->config['protocol'] . '://'; } diff --git a/lib/Cake/Test/Case/Network/CakeSocketTest.php b/lib/Cake/Test/Case/Network/CakeSocketTest.php index d68774fe0..e93882d06 100644 --- a/lib/Cake/Test/Case/Network/CakeSocketTest.php +++ b/lib/Cake/Test/Case/Network/CakeSocketTest.php @@ -265,6 +265,24 @@ class CakeSocketTest extends CakeTestCase { $this->Socket->enableCrypto('tls', 'client'); } +/** + * Test that protocol in the host doesn't cause cert errors. + * + * @return void + */ + public function testConnectProtocolInHost() { + $this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); + $configSslTls = array('host' => 'ssl://smtp.gmail.com', 'port' => 465, 'timeout' => 5); + $socket = new CakeSocket($configSslTls); + try { + $socket->connect(); + $this->assertEquals('smtp.gmail.com', $socket->config['host']); + $this->assertEquals('ssl', $socket->config['protocol']); + } catch (SocketException $e) { + $this->markTestSkipped('Cannot test network, skipping.'); + } + } + /** * _connectSocketToSslTls *