OAuthSignatureMethodPlaintextTest.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. require_once 'common.php';
  3. require_once 'Mock_OAuthBaseStringRequest.php';
  4. class OAuthSignatureMethodPlaintextTest extends PHPUnit_Framework_TestCase {
  5. private $method;
  6. public function setUp() {
  7. $this->method = new OAuthSignatureMethod_PLAINTEXT();
  8. }
  9. public function testIdentifyAsPlaintext() {
  10. $this->assertEquals('PLAINTEXT', $this->method->get_name());
  11. }
  12. public function testBuildSignature() {
  13. // Tests based on from http://wiki.oauth.net/TestCases section 9.2 ("HMAC-SHA1")
  14. $request = new Mock_OAuthBaseStringRequest('__unused__');
  15. $consumer = new OAuthConsumer('__unused__', 'cs');
  16. $token = NULL;
  17. $this->assertEquals('cs&', $this->method->build_signature( $request, $consumer, $token) );
  18. $request = new Mock_OAuthBaseStringRequest('__unused__');
  19. $consumer = new OAuthConsumer('__unused__', 'cs');
  20. $token = new OAuthToken('__unused__', 'ts');
  21. $this->assertEquals('cs&ts', $this->method->build_signature( $request, $consumer, $token) );
  22. $request = new Mock_OAuthBaseStringRequest('__unused__');
  23. $consumer = new OAuthConsumer('__unused__', 'kd94hf93k423kf44');
  24. $token = new OAuthToken('__unused__', 'pfkkdhi9sl3r4s00');
  25. $this->assertEquals('kd94hf93k423kf44&pfkkdhi9sl3r4s00', $this->method->build_signature( $request, $consumer, $token) );
  26. // Tests taken from Chapter 9.4.1 ("Generating Signature") from the spec
  27. $request = new Mock_OAuthBaseStringRequest('__unused__');
  28. $consumer = new OAuthConsumer('__unused__', 'djr9rjt0jd78jf88');
  29. $token = new OAuthToken('__unused__', 'jjd999tj88uiths3');
  30. $this->assertEquals('djr9rjt0jd78jf88&jjd999tj88uiths3', $this->method->build_signature( $request, $consumer, $token) );
  31. $request = new Mock_OAuthBaseStringRequest('__unused__');
  32. $consumer = new OAuthConsumer('__unused__', 'djr9rjt0jd78jf88');
  33. $token = new OAuthToken('__unused__', 'jjd99$tj88uiths3');
  34. $this->assertEquals('djr9rjt0jd78jf88&jjd99%24tj88uiths3', $this->method->build_signature( $request, $consumer, $token) );
  35. }
  36. public function testVerifySignature() {
  37. // Tests based on from http://wiki.oauth.net/TestCases section 9.2 ("HMAC-SHA1")
  38. $request = new Mock_OAuthBaseStringRequest('__unused__');
  39. $consumer = new OAuthConsumer('__unused__', 'cs');
  40. $token = NULL;
  41. $signature = 'cs&';
  42. $this->assertTrue( $this->method->check_signature( $request, $consumer, $token, $signature) );
  43. $request = new Mock_OAuthBaseStringRequest('__unused__');
  44. $consumer = new OAuthConsumer('__unused__', 'cs');
  45. $token = new OAuthToken('__unused__', 'ts');
  46. $signature = 'cs&ts';
  47. $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
  48. $request = new Mock_OAuthBaseStringRequest('__unused__');
  49. $consumer = new OAuthConsumer('__unused__', 'kd94hf93k423kf44');
  50. $token = new OAuthToken('__unused__', 'pfkkdhi9sl3r4s00');
  51. $signature = 'kd94hf93k423kf44&pfkkdhi9sl3r4s00';
  52. $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
  53. // Tests taken from Chapter 9.4.1 ("Generating Signature") from the spec
  54. $request = new Mock_OAuthBaseStringRequest('__unused__');
  55. $consumer = new OAuthConsumer('__unused__', 'djr9rjt0jd78jf88');
  56. $token = new OAuthToken('__unused__', 'jjd999tj88uiths3');
  57. $signature = 'djr9rjt0jd78jf88&jjd999tj88uiths3';
  58. $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
  59. $request = new Mock_OAuthBaseStringRequest('__unused__');
  60. $consumer = new OAuthConsumer('__unused__', 'djr9rjt0jd78jf88');
  61. $token = new OAuthToken('__unused__', 'jjd99$tj88uiths3');
  62. $signature = 'djr9rjt0jd78jf88&jjd99%24tj88uiths3';
  63. $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
  64. }
  65. }