Skip to content

Commit

Permalink
Split the protocol out of the host name.
Browse files Browse the repository at this point in the history
This avoids issues in PHP 5.6 where certificate validation fails when
`ssl://smtp.gmail.com` is used as a host name.

Refs #7579
  • Loading branch information
markstory committed Oct 20, 2015
1 parent 9f90a04 commit 3d18f28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Network/Socket.php
Expand Up @@ -128,8 +128,12 @@ public function connect()
$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) {
if (!empty($this->_config['protocol'])) {
$scheme = $this->_config['protocol'] . '://';
}

Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase/Network/SocketTest.php
Expand Up @@ -291,6 +291,25 @@ public function testEnableCryptoSocketExceptionNoTls()
$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 = ['host' => 'ssl://smtp.gmail.com', 'port' => 465, 'timeout' => 5];
$socket = new Socket($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
*
Expand Down

0 comments on commit 3d18f28

Please sign in to comment.