Skip to content

Commit ae6d565

Browse files
committed
HMAC-SHA1 signature test
1 parent 9042ddd commit ae6d565

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace ApiClients\Tests\Tools\Psr7\Oauth1\Signature;
4+
5+
use ApiClients\Tools\Psr7\Oauth1\Definition\ConsumerSecret;
6+
use ApiClients\Tools\Psr7\Oauth1\Definition\TokenSecret;
7+
use ApiClients\Tools\Psr7\Oauth1\Signature\HmacSha1Signature;
8+
use GuzzleHttp\Psr7\Uri;
9+
use Psr\Http\Message\UriInterface;
10+
11+
class HmacSha1SignatureTest extends \PHPUnit_Framework_TestCase
12+
{
13+
public function testGetMethod()
14+
{
15+
$this->assertSame('HMAC-SHA1', (new HmacSha1Signature(new ConsumerSecret('secret')))->getMethod());
16+
}
17+
18+
public function provideSign()
19+
{
20+
return [
21+
[
22+
new Uri('https://example.com/'),
23+
'T7pWk5I7re3JTz5FS3LK8rVbQ0U=',
24+
'T7pWk5I7re3JTz5FS3LK8rVbQ0U=',
25+
],
26+
[
27+
new Uri('https://example.com/thea.pot',[], 'THEAPOT'),
28+
'XyTxyDmU2s3iBMBpSX4DbZ47Ltg=',
29+
'XyTxyDmU2s3iBMBpSX4DbZ47Ltg=',
30+
],
31+
[
32+
new Uri('https://example.com/?foo=bar', ['foo' => 'bar',]),
33+
'OXZBqYIhLdj7CT6bYudGqc8OzlU=',
34+
'OXZBqYIhLdj7CT6bYudGqc8OzlU=',
35+
],
36+
[
37+
new Uri('https://example.com/',['foo' => 'bar',], 'HEAD'),
38+
'T7pWk5I7re3JTz5FS3LK8rVbQ0U=',
39+
'T7pWk5I7re3JTz5FS3LK8rVbQ0U=',
40+
],
41+
];
42+
}
43+
44+
/**
45+
* @param UriInterface $uri
46+
* @param $signedSignature
47+
* @dataProvider provideSign
48+
*/
49+
public function testSign(UriInterface $uri, $signedSignature, $signedTokenSecretSignature)
50+
{
51+
$secret = new ConsumerSecret('consumerSecret');
52+
$signature = new HmacSha1Signature($secret);
53+
$tokenSecret = new TokenSecret('tokenSecret');
54+
$this->assertSame($signedSignature, $signature->sign($uri));
55+
$signature->withTokenSecret($tokenSecret);
56+
$this->assertSame($signedTokenSecretSignature, $signature->sign($uri));
57+
}
58+
}

0 commit comments

Comments
 (0)