Skip to content

Commit

Permalink
[BWC] Add getUserPass() method to ConnectionInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Sep 12, 2016
1 parent 445fdea commit 586fbdb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/Elasticsearch/Connections/Connection.php
Expand Up @@ -493,6 +493,17 @@ public function getHost()
return $this->host;
}

/**
* @return null|string
*/
public function getUserPass()
{
if (isset($this->connectionParams['client']['curl'][CURLOPT_USERPWD]) === true) {
return $this->connectionParams['client']['curl'][CURLOPT_USERPWD];
}
return null;
}

/**
* @param $request
* @param $response
Expand Down
7 changes: 7 additions & 0 deletions src/Elasticsearch/Connections/ConnectionInterface.php
Expand Up @@ -44,6 +44,13 @@ public function getTransportSchema();
*/
public function getHost();

/**
* Get the username:password string for this connection, null if not set
*
* @return null|string
*/
public function getUserPass();

/**
* Check to see if this instance is marked as 'alive'
*
Expand Down
8 changes: 3 additions & 5 deletions tests/Elasticsearch/Tests/ClientTest.php
Expand Up @@ -300,15 +300,13 @@ public function testInlineHosts()
$this->assertEquals("https", $host->getTransportSchema());


// Note: we can't test user/pass themselves yet, need to introduce
// breaking change to interface in master to do that
// But we can confirm it doesn't break anything
$client = Elasticsearch\ClientBuilder::create()->setHosts([
'https://user:pass@foo.com:9200'
])->build();
$host = $client->transport->getConnection();
$this->assertEquals("foo.com:9200", $host->getHost());
$this->assertEquals("https", $host->getTransportSchema());
$this->assertEquals("user:pass", $host->getUserPass());
}

public function testExtendedHosts()
Expand Down Expand Up @@ -410,12 +408,12 @@ public function testExtendedHosts()
[
'host' => 'foo.com',
'user' => 'user',
'pass' => 'abc#$%!abc'
'pass' => 'abc#$@?%!abc'
]
])->build();
$host = $client->transport->getConnection();
$this->assertEquals("foo.com:9200", $host->getHost());
$this->assertEquals("http", $host->getTransportSchema());

$this->assertEquals("user:abc#$@?%!abc", $host->getUserPass());
}
}

0 comments on commit 586fbdb

Please sign in to comment.