OAuthSignatureMethodHmacSha1Test.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require_once 'common.php';
  3. require_once 'Mock_OAuthBaseStringRequest.php';
  4. class OAuthSignatureMethodHmacSha1Test extends PHPUnit_Framework_TestCase {
  5. private $method;
  6. public function setUp() {
  7. $this->method = new OAuthSignatureMethod_HMAC_SHA1();
  8. }
  9. public function testIdentifyAsHmacSha1() {
  10. $this->assertEquals('HMAC-SHA1', $this->method->get_name());
  11. }
  12. public function testBuildSignature() {
  13. // Tests taken from http://wiki.oauth.net/TestCases section 9.2 ("HMAC-SHA1")
  14. $request = new Mock_OAuthBaseStringRequest('bs');
  15. $consumer = new OAuthConsumer('__unused__', 'cs');
  16. $token = NULL;
  17. $this->assertEquals('egQqG5AJep5sJ7anhXju1unge2I=', $this->method->build_signature( $request, $consumer, $token) );
  18. $request = new Mock_OAuthBaseStringRequest('bs');
  19. $consumer = new OAuthConsumer('__unused__', 'cs');
  20. $token = new OAuthToken('__unused__', 'ts');
  21. $this->assertEquals('VZVjXceV7JgPq/dOTnNmEfO0Fv8=', $this->method->build_signature( $request, $consumer, $token) );
  22. $request = new Mock_OAuthBaseStringRequest('GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26'
  23. . 'oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26'
  24. . 'oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal');
  25. $consumer = new OAuthConsumer('__unused__', 'kd94hf93k423kf44');
  26. $token = new OAuthToken('__unused__', 'pfkkdhi9sl3r4s00');
  27. $this->assertEquals('tR3+Ty81lMeYAr/Fid0kMTYa/WM=', $this->method->build_signature( $request, $consumer, $token) );
  28. }
  29. public function testVerifySignature() {
  30. // Tests taken from http://wiki.oauth.net/TestCases section 9.2 ("HMAC-SHA1")
  31. $request = new Mock_OAuthBaseStringRequest('bs');
  32. $consumer = new OAuthConsumer('__unused__', 'cs');
  33. $token = NULL;
  34. $signature = 'egQqG5AJep5sJ7anhXju1unge2I=';
  35. $this->assertTrue( $this->method->check_signature( $request, $consumer, $token, $signature) );
  36. $request = new Mock_OAuthBaseStringRequest('bs');
  37. $consumer = new OAuthConsumer('__unused__', 'cs');
  38. $token = new OAuthToken('__unused__', 'ts');
  39. $signature = 'VZVjXceV7JgPq/dOTnNmEfO0Fv8=';
  40. $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
  41. $request = new Mock_OAuthBaseStringRequest('GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26'
  42. . 'oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26'
  43. . 'oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal');
  44. $consumer = new OAuthConsumer('__unused__', 'kd94hf93k423kf44');
  45. $token = new OAuthToken('__unused__', 'pfkkdhi9sl3r4s00');
  46. $signature = 'tR3+Ty81lMeYAr/Fid0kMTYa/WM=';
  47. $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
  48. }
  49. }