opensearch-project / opensearch-php

Official PHP Client for OpenSearch
Other
109 stars 58 forks source link

[BUG] ClientBuilder::fromConfig overrides basic authentication #159

Closed CSalih closed 1 year ago

CSalih commented 1 year ago

What is the bug?

Creating the Client with ClientBuilder::fromConfig may overrides basic authentication depending on the order of the given $config array.

How can one reproduce the bug?

$client = [
    'basicAuthentication' => [...],
    'connectionParams' => [
        'client' => [
            'curl' => [...],
        ],
    ],
];

// The call ClientBuilder->setConnectionParams() will override basic authentication
$this->client = ClientBuilder::fromConfig($client);

fromConfig will call ClientBuilder->setConnectionParams() after ClientBuilder->setBasicAuthentication() and the basic authentication will be overridden, therefore the performed requests will result to status code 401. The same behavior would also happen when someone calls $clientBuilder->setBasicAuthentication() before $clientBuilder->setConnectionParams().

What is the expected behavior?

The order of the $client properties should be in depended. ClientBuilder->setConnectionParams() needs to merge the given params with $this->connectionParams instead of overriding it.

What is your host/environment?


Do you have any screenshots?


Do you have any additional context?

opensearch-project/opensearch-php Version 2.2.0

I am ready to create a PR for this issue.