-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a test for the signing client decorator (#252)
Signed-off-by: Kim Pepper <[email protected]>
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |