Skip to content

Commit

Permalink
checks if ssl param is set (#1457)
Browse files Browse the repository at this point in the history
* checks if ssl param is set

* add test-cases

* update changelog

* remove dev-requirement
  • Loading branch information
floriansemm authored and ruflin committed Feb 16, 2018
1 parent 0d7f93c commit 95ce388
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file based on the
- Characters "<" and ">" will be removed when a query term is passed to [`Util::escapeTerm`](https://github.com/ruflin/Elastica/pull/1415/files). Since v5.1 the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-query-string-query.html#_reserved_characters) states that these symbols cannot be escaped ever.
- Remove [`each()`](http://www.php.net/each) usage to fix PHP 7.2 compatibility
- Fix [#1435](https://github.com/ruflin/Elastica/issues/1435) forcing `doc_as_upsert` to be boolean, acording [Elastic doc-update documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_literal_doc_as_upsert_literal)
- Fix [#1456](https://github.com/ruflin/Elastica/issues/1456) set SSL as connection scheme if it is required

### Added

Expand Down
14 changes: 10 additions & 4 deletions lib/Elastica/Transport/AwsAuthV4.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private function getCredentialProvider()
private function initializePortAndScheme()
{
$connection = $this->getConnection();
if (true === $this->getConfig($connection, 'ssl')) {
if (true === $this->isSslRequired($connection)) {
$this->_scheme = 'https';
$connection->setPort(443);
} else {
Expand All @@ -83,10 +83,16 @@ private function initializePortAndScheme()
}
}

private function getConfig(Connection $conn, $key, $default = null)
/**
* @param Connection $conn
* @param bool $default
*
* @return bool
*/
private function isSslRequired(Connection $conn, $default = false)
{
return $conn->hasConfig($key)
? $conn->getConfig($key)
return $conn->hasParam('ssl')
? (bool) $conn->getParam('ssl')
: $default;
}
}
51 changes: 51 additions & 0 deletions test/Elastica/Transport/AwsAuthV4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function testSignsWithProvidedCredentials()
];

$client = $this->_getClient($config);

try {
$client->request('_status', 'GET');
} catch (GuzzleException $e) {
Expand All @@ -50,6 +51,56 @@ public function testSignsWithProvidedCredentials()
}
}

public function testUseHttpAsDefaultProtocol()
{
$config = [
'persistent' => false,
'transport' => 'AwsAuthV4',
'aws_access_key_id' => 'foo',
'aws_secret_access_key' => 'bar',
'aws_session_token' => 'baz',
'aws_region' => 'us-east-1',
];
$client = $this->_getClient($config);

try {
$client->request('_status', 'GET');

$this->assertEquals(80, $client->getLastRequest()->toArray()['port']);
} catch (GuzzleException $e) {
$guzzleException = $e->getGuzzleException();
if ($guzzleException instanceof RequestException) {
$request = $guzzleException->getRequest();
}
}
}

public function testSetHttpsIfItIsRequired()
{
$config = [
'persistent' => false,
'transport' => 'AwsAuthV4',
'aws_access_key_id' => 'foo',
'aws_secret_access_key' => 'bar',
'aws_session_token' => 'baz',
'aws_region' => 'us-east-1',
'ssl' => true
];
$client = $this->_getClient($config);

try {
$client->request('_status', 'GET');

} catch (GuzzleException $e) {
$guzzleException = $e->getGuzzleException();
if ($guzzleException instanceof RequestException) {
$request = $guzzleException->getRequest();

$this->assertEquals('https', $request->getUri()->getScheme());
}
}
}

public function testSignsWithEnvironmentalCredentials()
{
$config = [
Expand Down

0 comments on commit 95ce388

Please sign in to comment.