Initial commit
This commit is contained in:
53
tests/GuzzleSignerTest.php
Normal file
53
tests/GuzzleSignerTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace HttpSignatures\Test;
|
||||
|
||||
use HttpSignatures\Guzzle\CreateRequestSubscriber;
|
||||
use HttpSignatures\Context;
|
||||
use HttpSignatures\Guzzle\Message;
|
||||
|
||||
class GuzzleSignerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->context = new Context(array(
|
||||
'keys' => array('pda' => 'secret'),
|
||||
'algorithm' => 'hmac-sha256',
|
||||
'headers' => array('(request-target)', 'date'),
|
||||
));
|
||||
|
||||
$this->client = new \Guzzle\Http\Client();
|
||||
$this->client->addSubscriber(new CreateRequestSubscriber($this->context));
|
||||
}
|
||||
|
||||
public function testGuzzleRequestHasExpectedHeaders()
|
||||
{
|
||||
$message = $this->client->get('/path?query=123', array('date' => 'today', 'accept' => 'llamas'));
|
||||
|
||||
$expectedString = implode(
|
||||
',',
|
||||
array(
|
||||
'keyId="pda"',
|
||||
'algorithm="hmac-sha256"',
|
||||
'headers="(request-target) date"',
|
||||
'signature="SFlytCGpsqb/9qYaKCQklGDvwgmrwfIERFnwt+yqPJw="',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedString,
|
||||
(string) $message->getHeader('Signature')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Signature ' . $expectedString,
|
||||
(string) $message->getHeader('Authorization')
|
||||
);
|
||||
}
|
||||
|
||||
public function testVerifyGuzzleRequest()
|
||||
{
|
||||
$message = $this->client->get('/path?query=123', array('date' => 'today', 'accept' => 'dogs'));
|
||||
$this->assertTrue($this->context->verifier()->isValid(new Message($message)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user