1010
1111use Nexmo \Client \Signature ;
1212use PHPUnit \Framework \TestCase ;
13+ use Nexmo \Client \Exception \Exception ;
1314
1415
1516class SignatureTest extends TestCase
1617{
18+ public function testInvalidSignatureMethod () {
19+ $ this ->expectException (Exception::class);
20+ $ this ->expectExceptionMessage ('Unknown signature algorithm: fake_algo. Expected: md5hash, md5, sha1, sha256, or sha512 ' );
21+ $ signature = new Signature (['foo ' => 'bar ' ], 'sig_secret ' , 'fake_algo ' );
22+ }
23+
24+ /**
25+ * @dataProvider hmacSignatureProvider
26+ */
27+ public function testHmacSignature ($ algorithm , $ expected ){
28+ $ data = [
29+ 'api_key ' => 'fake_api_key ' ,
30+ 'to ' => '14155550100 ' ,
31+ 'from ' => 'AcmeInc ' ,
32+ 'text ' => 'Test From Nexmo ' ,
33+ 'type ' => 'text ' ,
34+ 'timestamp ' => '1540924779 '
35+ ];
36+ $ secret = '71efab63122f1d179f51c46bac838fb5 ' ;
37+ $ signature = new Signature ($ data , $ secret , $ algorithm );
38+
39+ $ this ->assertEquals ($ expected , $ signature ->getSignature ());
40+ }
41+
42+ public function hmacSignatureProvider () {
43+ $ data = [];
44+
45+ $ data ['md5 ' ] = ['md5 ' , '51cdafebb4bbce9525b195c1617cb8d2 ' ];
46+ $ data ['sha1 ' ] = ['sha1 ' , '0162aec64bc183b2e1256545951fe5639dc98020 ' ];
47+ $ data ['sha256 ' ] = ['sha256 ' , '9fec5ef6d0f2b3d2bb7558b6e4042569823cab9ea0dd30503472b7b304601975 ' ];
48+ $ data ['sha512 ' ] = ['sha512 ' , '40bd12b9a4b6000ad1138eefd24ffe9fbd72aee13c3fa04b32bb69dbc256ad0a04a463b1a9af6660d10f6e1e769ee14b9cff6a635502e93afcd0bfab29f38f87 ' ];
49+
50+ return $ data ;
51+ }
52+
1753 /**
1854 * @dataProvider signatures
1955 * @param $sig
@@ -23,7 +59,7 @@ class SignatureTest extends TestCase
2359 public function testSignature ($ sig , $ params , $ secret )
2460 {
2561 //a signature is created from a set of parameters and a secret
26- $ signature = new Signature ($ params , $ secret );
62+ $ signature = new Signature ($ params , $ secret, ' md5hash ' );
2763
2864 //the parameters should ne be changed
2965 $ this ->assertEquals ($ params , $ signature ->getParams ());
0 commit comments