Skip to content

Commit

Permalink
Merge pull request #73 from wp-cli/cacert.pem-path
Browse files Browse the repository at this point in the history
Avoid using Composer CA bundle if in phar.
  • Loading branch information
danielbachhuber authored Mar 2, 2018
2 parents d93cc0c + b96a80f commit c542be5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions features/package-install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,8 @@ Feature: Install WP-CLI packages
}
"""

When I run `{PHAR_PATH} package install path-command`
# Allow for composer/ca-bundle using `openssl_x509_parse()` which throws PHP warnings on old versions of PHP.
When I try `{PHAR_PATH} package install path-command`
Then STDOUT should contain:
"""
Success: Package installed.
Expand Down Expand Up @@ -1051,7 +1052,8 @@ Feature: Install WP-CLI packages
}
"""

When I run `{PHAR_PATH} package install path-command`
# Allow for composer/ca-bundle using `openssl_x509_parse()` which throws PHP warnings on old versions of PHP.
When I try `{PHAR_PATH} package install path-command`
Then STDOUT should contain:
"""
Success: Package installed.
Expand Down
12 changes: 12 additions & 0 deletions src/Package_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ private function is_community_package( $package ) {
* Gets a Composer instance.
*/
private function get_composer() {
$this->avoid_composer_ca_bundle();
try {
$composer_path = $this->get_composer_json_path();

Expand Down Expand Up @@ -585,6 +586,7 @@ private function get_community_packages() {
static $community_packages;

if ( null === $community_packages ) {
$this->avoid_composer_ca_bundle();
try {
$community_packages = $this->package_index()->getPackages();
} catch( Exception $e ) {
Expand Down Expand Up @@ -1060,6 +1062,16 @@ private function set_composer_auth_env_var() {
}
}

/**
* Avoid using default Composer CA bundle if in phar as we don't include it.
* See https://github.com/composer/ca-bundle/blob/1.1.0/src/CaBundle.php#L64
*/
private function avoid_composer_ca_bundle() {
if ( Utils\inside_phar() && ! getenv( 'SSL_CERT_FILE' ) && ! getenv( 'SSL_CERT_DIR' ) && ! ini_get( 'openssl.cafile' ) && ! ini_get( 'openssl.capath' ) ) {
putenv( 'SSL_CERT_FILE=phar://wp-cli.phar/vendor/rmccue/requests/library/Requests/Transport/cacert.pem' );
}
}

/**
* Reads the WP-CLI packages composer.json, checking validity and returning array containing its path, contents, and decoded contents.
*
Expand Down

0 comments on commit c542be5

Please sign in to comment.