Skip to content

Commit 1f3e087

Browse files
committed
HMAC-SHA384 signature
1 parent 713a311 commit 1f3e087

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/Signature/HmacSha384Signature.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace ApiClients\Tools\Psr7\Oauth1\Signature;
4+
5+
class HmacSha384Signature extends HmacSignature
6+
{
7+
protected function getHashingAlgorithm()
8+
{
9+
return 'sha384';
10+
}
11+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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\HmacSha384Signature;
8+
use GuzzleHttp\Psr7\Uri;
9+
use Psr\Http\Message\UriInterface;
10+
11+
class HmacSha384SignatureTest extends \PHPUnit_Framework_TestCase
12+
{
13+
public function testGetMethod()
14+
{
15+
$this->assertSame('HMAC-SHA384', (new HmacSha384Signature(new ConsumerSecret('secret')))->getMethod());
16+
}
17+
18+
public function provideSign()
19+
{
20+
return [
21+
[
22+
new Uri('https://example.com/'),
23+
'JgaK+ORQ+mkdItwZUJgNI15mgIYHgcqEUIbp6qDbEhYrwwsrOrNxK+cgMMmY0/A7',
24+
'0Eib7qzwodDV6L4UYTOWS9G3UYPOvZCByUn02wrMMV0vNbNLGGFnA8IxnW6v1ZYN',
25+
],
26+
[
27+
new Uri('https://example.com/thea.pot',[], 'THEAPOT'),
28+
'Bm+fK6fVlejPvOcrQJcv+ZwsgQdh9W3Ok/ljmY39vy0MxymzH+I+Hntcxi90/Qfq',
29+
'mjT2JRgSTEdrMJi6/eJ6mZBh7C2bWT9HVqS1Gq6JpXJHNPze7gy7XdA4sgy3ORwE',
30+
],
31+
[
32+
new Uri('https://example.com/?foo=bar', ['foo' => 'bar',]),
33+
'+88Vdw/72CKTOJpUM42FZLkQnBakun9M9lKVzk8a9T9TpmK9Sn6MP4hp7id/VJRj',
34+
'FKV3k1/PDOZTwMO6fE74NisTlixs1qlLt5IedDWVoIyk9tyNNAUIjwOt7w1GtnHH',
35+
],
36+
[
37+
new Uri('https://example.com/',['foo' => 'bar',], 'HEAD'),
38+
'JgaK+ORQ+mkdItwZUJgNI15mgIYHgcqEUIbp6qDbEhYrwwsrOrNxK+cgMMmY0/A7',
39+
'0Eib7qzwodDV6L4UYTOWS9G3UYPOvZCByUn02wrMMV0vNbNLGGFnA8IxnW6v1ZYN',
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 HmacSha384Signature($secret);
53+
$tokenSecret = new TokenSecret('tokenSecret');
54+
$this->assertSame($signedSignature, $signature->sign($uri));
55+
$signature = $signature->withTokenSecret($tokenSecret);
56+
$this->assertSame($signedTokenSecretSignature, $signature->sign($uri));
57+
$signature = $signature->withoutTokenSecret();
58+
$this->assertSame($signedSignature, $signature->sign($uri));
59+
}
60+
}

0 commit comments

Comments
 (0)