From 586fbdb1918b593d2fd737b3a9aceb148199b195 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Mon, 12 Sep 2016 12:34:54 -0400 Subject: [PATCH] [BWC] Add getUserPass() method to ConnectionInterface --- src/Elasticsearch/Connections/Connection.php | 11 +++++++++++ src/Elasticsearch/Connections/ConnectionInterface.php | 7 +++++++ tests/Elasticsearch/Tests/ClientTest.php | 8 +++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Elasticsearch/Connections/Connection.php b/src/Elasticsearch/Connections/Connection.php index 6f2e6488d..81067fa16 100644 --- a/src/Elasticsearch/Connections/Connection.php +++ b/src/Elasticsearch/Connections/Connection.php @@ -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 diff --git a/src/Elasticsearch/Connections/ConnectionInterface.php b/src/Elasticsearch/Connections/ConnectionInterface.php index 229000718..98b14df0e 100644 --- a/src/Elasticsearch/Connections/ConnectionInterface.php +++ b/src/Elasticsearch/Connections/ConnectionInterface.php @@ -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' * diff --git a/tests/Elasticsearch/Tests/ClientTest.php b/tests/Elasticsearch/Tests/ClientTest.php index d73b3f16b..673c6d7af 100644 --- a/tests/Elasticsearch/Tests/ClientTest.php +++ b/tests/Elasticsearch/Tests/ClientTest.php @@ -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() @@ -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()); } }