From 14951326e238e95d12a6d05d13a599a37ad992b0 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 8 Aug 2019 16:54:30 +0100 Subject: [PATCH 1/4] Test & changes to CurlFactory --- src/Handler/CurlFactory.php | 9 +++++---- tests/Handler/CurlFactoryTest.php | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Handler/CurlFactory.php b/src/Handler/CurlFactory.php index e349bb4c4..80f48e49c 100644 --- a/src/Handler/CurlFactory.php +++ b/src/Handler/CurlFactory.php @@ -454,11 +454,12 @@ private function applyHandlerOptions(EasyHandle $easy, array &$conf) } if (isset($options['ssl_key'])) { - $sslKey = $options['ssl_key']; - if (is_array($sslKey)) { - $conf[CURLOPT_SSLKEYPASSWD] = $sslKey[1]; - $sslKey = $sslKey[0]; + if (is_array($options['ssl_key']) && count($options['ssl_key']) === 2) { + list($sslKey, $conf[CURLOPT_SSLKEYPASSWD]) = $options['ssl_key']; } + + $sslKey = isset($sslKey) ? $sslKey: $options['ssl_key']; + if (!file_exists($sslKey)) { throw new \InvalidArgumentException( "SSL private key not found: {$sslKey}" diff --git a/tests/Handler/CurlFactoryTest.php b/tests/Handler/CurlFactoryTest.php index d1e4e9980..90228d9ad 100644 --- a/tests/Handler/CurlFactoryTest.php +++ b/tests/Handler/CurlFactoryTest.php @@ -7,6 +7,7 @@ use GuzzleHttp\Handler; use GuzzleHttp\Psr7; use GuzzleHttp\TransferStats; +use PHPUnit\Framework\Error\Notice; use Psr\Http\Message\ResponseInterface; use PHPUnit\Framework\TestCase; @@ -216,6 +217,14 @@ public function testAddsSslKeyWithPassword() $this->assertEquals('test', $_SERVER['_curl'][CURLOPT_SSLKEYPASSWD]); } + public function testAddsSslKeyWhenUsingArraySyntaxButNoPassword() + { + $f = new Handler\CurlFactory(3); + $f->create(new Psr7\Request('GET', Server::$url), ['ssl_key' => [__FILE__]]); + + $this->assertEquals(__FILE__, $_SERVER['_curl'][CURLOPT_SSLKEY]); + } + /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage SSL certificate not found: /does/not/exist From 9c71320ed0766bf75e422a6e70544d533e1fff24 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 8 Aug 2019 17:20:23 +0100 Subject: [PATCH 2/4] Code style and cleanup --- src/Handler/CurlFactory.php | 8 ++++---- tests/Handler/CurlFactoryTest.php | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Handler/CurlFactory.php b/src/Handler/CurlFactory.php index 80f48e49c..9e956df58 100644 --- a/src/Handler/CurlFactory.php +++ b/src/Handler/CurlFactory.php @@ -1,13 +1,13 @@ Date: Wed, 23 Oct 2019 21:46:45 +0200 Subject: [PATCH 3/4] Restore import order --- src/Handler/CurlFactory.php | 8 ++++---- tests/Handler/CurlFactoryTest.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Handler/CurlFactory.php b/src/Handler/CurlFactory.php index 9e956df58..80f48e49c 100644 --- a/src/Handler/CurlFactory.php +++ b/src/Handler/CurlFactory.php @@ -1,13 +1,13 @@ Date: Wed, 23 Oct 2019 21:53:33 +0200 Subject: [PATCH 4/4] Bugfix --- src/Handler/CurlFactory.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Handler/CurlFactory.php b/src/Handler/CurlFactory.php index 80f48e49c..66c952c04 100644 --- a/src/Handler/CurlFactory.php +++ b/src/Handler/CurlFactory.php @@ -454,8 +454,12 @@ private function applyHandlerOptions(EasyHandle $easy, array &$conf) } if (isset($options['ssl_key'])) { - if (is_array($options['ssl_key']) && count($options['ssl_key']) === 2) { - list($sslKey, $conf[CURLOPT_SSLKEYPASSWD]) = $options['ssl_key']; + if (is_array($options['ssl_key'])) { + if (count($options['ssl_key']) === 2) { + list($sslKey, $conf[CURLOPT_SSLKEYPASSWD]) = $options['ssl_key']; + } else { + list($sslKey) = $options['ssl_key']; + } } $sslKey = isset($sslKey) ? $sslKey: $options['ssl_key'];