Skip to content

Commit

Permalink
Adds a test for the signing client decorator (#252)
Browse files Browse the repository at this point in the history
Signed-off-by: Kim Pepper <[email protected]>
  • Loading branch information
kimpepper authored Jan 10, 2025
1 parent 6ed0301 commit 887df5e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added samples ([#218](https://github.com/opensearch-project/opensearch-php/pull/218))
- Added support for PHP 8.3 and 8.4 ([#229](https://github.com/opensearch-project/opensearch-php/pull/229))
- Added a Docker Compose config file for local development.
- Added a test for the AWS signing client decorator
### Changed
- Switched to PSR Interfaces
- Increased PHP min version to 8.1
Expand Down
53 changes: 53 additions & 0 deletions tests/Aws/SigningClientDecoratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace OpenSearch\Tests\Aws;

use Aws\Credentials\CredentialsInterface;
use Aws\Signature\SignatureV4;
use GuzzleHttp\Psr7\Request;
use OpenSearch\Aws\SigningClientDecorator;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\ResponseInterface;

/**
* Tests the signing client decorator.
*
* @coversDefaultClass \OpenSearch\Aws\SigningClientDecorator
*/
class SigningClientDecoratorTest extends TestCase
{

/**
* Test that the decorator signs the request.
*
* @covers ::sendRequest
*/
public function testSendRequest()
{
$client = $this->createMock(ClientInterface::class);
$credentials = $this->createMock(CredentialsInterface::class);
$signer = new SignatureV4('es', 'us-east-1');

$client->expects($this->once())
->method('sendRequest')
->with(
$this->callback(function (Request $req): bool {
$this->assertEquals('localhost:9200', $req->getHeaderLine('Host'));
$this->assertEquals('GET', $req->getMethod());
$this->assertTrue($req->hasHeader('Authorization'));
$this->assertTrue($req->hasHeader('x-amz-content-sha256'));
$this->assertTrue($req->hasHeader('x-amz-date'));
return true;
})
)
->willReturn($this->createMock(ResponseInterface::class));


$decorator = new SigningClientDecorator($client, $credentials, $signer);
$request = new Request('GET', 'http://localhost:9200/_search');
$decorator->sendRequest($request);
}
}

0 comments on commit 887df5e

Please sign in to comment.