OAuthSignatureMethodRsaSha1Test.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. require_once 'common.php';
  3. require_once 'Mock_OAuthBaseStringRequest.php';
  4. require_once 'Mock_OAuthSignatureMethod_RSA_SHA1.php';
  5. class OAuthSignatureMethodRsaSha1Test extends PHPUnit_Framework_TestCase {
  6. private $method;
  7. public function setUp() {
  8. $this->method = new Mock_OAuthSignatureMethod_RSA_SHA1();
  9. }
  10. public function testIdentifyAsRsaSha1() {
  11. $this->assertEquals('RSA-SHA1', $this->method->get_name());
  12. }
  13. public function testBuildSignature() {
  14. if( ! function_exists('openssl_get_privatekey') ) {
  15. $this->markTestSkipped('OpenSSL not available, can\'t test RSA-SHA1 functionality');
  16. }
  17. // Tests taken from http://wiki.oauth.net/TestCases section 9.3 ("RSA-SHA1")
  18. $request = new Mock_OAuthBaseStringRequest('GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacaction.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3D13917289812797014437%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1196666512%26oauth_version%3D1.0%26size%3Doriginal');
  19. $consumer = new OAuthConsumer('dpf43f3p2l4k3l03', '__unused__');
  20. $token = NULL;
  21. $signature = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
  22. $this->assertEquals($signature, $this->method->build_signature( $request, $consumer, $token) );
  23. }
  24. public function testVerifySignature() {
  25. if( ! function_exists('openssl_get_privatekey') ) {
  26. $this->markTestSkipped('OpenSSL not available, can\'t test RSA-SHA1 functionality');
  27. }
  28. // Tests taken from http://wiki.oauth.net/TestCases section 9.3 ("RSA-SHA1")
  29. $request = new Mock_OAuthBaseStringRequest('GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacaction.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3D13917289812797014437%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1196666512%26oauth_version%3D1.0%26size%3Doriginal');
  30. $consumer = new OAuthConsumer('dpf43f3p2l4k3l03', '__unused__');
  31. $token = NULL;
  32. $signature = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
  33. $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
  34. }
  35. }