From ff5cccc82cddfa29699e456de293172864435047 Mon Sep 17 00:00:00 2001 From: Hiraku NAKANO Date: Sun, 26 Jun 2016 16:03:40 +0900 Subject: [PATCH 1/2] fix lint --- src/CurlRemoteFilesystem.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CurlRemoteFilesystem.php b/src/CurlRemoteFilesystem.php index 9c5f774..6f75ccb 100644 --- a/src/CurlRemoteFilesystem.php +++ b/src/CurlRemoteFilesystem.php @@ -12,7 +12,10 @@ class CurlRemoteFilesystem extends Util\RemoteFilesystem { - protected $io, $config, $options, $disableTls; + protected $io; + protected $config; + protected $options; + protected $disableTls; private $req; From 618aaead3f76ef9bfdfd4e731f24fadbf43bf29c Mon Sep 17 00:00:00 2001 From: Hiraku NAKANO Date: Sun, 26 Jun 2016 16:45:36 +0900 Subject: [PATCH 2/2] add Tests --- src/BaseRequest.php | 7 +++++- src/CopyRequest.php | 7 +++++- src/FetchRequest.php | 11 +++++++-- tests/unit/CurlRemoteFilesystemTest.php | 31 +++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 tests/unit/CurlRemoteFilesystemTest.php diff --git a/src/BaseRequest.php b/src/BaseRequest.php index cb5340d..f42258c 100644 --- a/src/BaseRequest.php +++ b/src/BaseRequest.php @@ -113,7 +113,7 @@ protected function getProxy($url) * @param $githubDomains * @param $gitlabDomains */ - protected function setupAuthentication(IO\IOInterface $io, $useRedirector, array $githubDomains = array(), array $gitlabDomains = array()) + protected function setupAuthentication(IO\IOInterface $io, $useRedirector, array $githubDomains, array $gitlabDomains) { if (preg_match('/\.github\.com$/', $this->host)) { $authKey = 'github.com'; @@ -270,4 +270,9 @@ public function setCA($path = null, $file = null) $this->capath = $path; $this->cafile = $file; } + + public function isHTTP() + { + return $this->scheme === 'http' || $this->scheme === 'https'; + } } diff --git a/src/CopyRequest.php b/src/CopyRequest.php index 443d527..72d206c 100644 --- a/src/CopyRequest.php +++ b/src/CopyRequest.php @@ -38,7 +38,12 @@ public function __construct($url, $destination, $useRedirector, IO\IOInterface $ $this->setURL($url); $this->setDestination($destination); $this->setCA($config->get('capath'), $config->get('cafile')); - $this->setupAuthentication($io, $useRedirector, $config->get('github-domains'), $config->get('gitlab-domains')); + $this->setupAuthentication( + $io, + $useRedirector, + $config->get('github-domains') ?: array(), + $config->get('gitlab-domains') ?: array() + ); } public function __destruct() diff --git a/src/FetchRequest.php b/src/FetchRequest.php index b3bc6b0..596dc98 100644 --- a/src/FetchRequest.php +++ b/src/FetchRequest.php @@ -32,7 +32,12 @@ public function __construct($url, IO\IOInterface $io, Config $config) { $this->setURL($url); $this->setCA($config->get('capath'), $config->get('cafile')); - $this->setupAuthentication($io, false, $config->get('github-domains'), $config->get('gitlab-domains')); + $this->setupAuthentication( + $io, + false, + $config->get('github-domains') ?: array(), + $config->get('gitlab-domains') ?: array() + ); } public function getCurlOptions() @@ -71,7 +76,9 @@ public function fetch() $this->error = curl_error($ch); $info = curl_getinfo($ch); - if ($errno === CURLE_OK && $info['http_code'] === 200) { + if (!$this->isHTTP()) { + return $result; + } elseif ($errno === CURLE_OK && $info['http_code'] === 200) { return $result; } else { return false; diff --git a/tests/unit/CurlRemoteFilesystemTest.php b/tests/unit/CurlRemoteFilesystemTest.php new file mode 100644 index 0000000..7c32b2b --- /dev/null +++ b/tests/unit/CurlRemoteFilesystemTest.php @@ -0,0 +1,31 @@ +iop = $this->prophesize('Composer\IO\IOInterface'); + $this->configp = $this->prophesize('Composer\Config'); + } + + public function testConstruct() + { + $rfs = new CurlRemoteFilesystem( + $this->iop->reveal(), + $this->configp->reveal() + ); + + self::assertEmpty($rfs->__debugInfo()); + + $content = $rfs->getContents('https://packagist.jp', 'https://packagist.jp/packages.json'); + self::assertInternalType('string', $content); + + $headers = $rfs->getLastHeaders(); + self::assertInternalType('array', $headers); + } +}