OAuthTestUnitOAuth1SignatureSignatureTest

The Gravity Forms Salesforce Add-On OAuthTest Unit OAuth1 Signature SignatureTest class.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/tests/Unit/OAuth1/Signature/SignatureTest.php  
  1. class SignatureTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  4. */ 
  5. public function testConstructCorrectInterface() 
  6. $signature = new Signature($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface')); 
  7.  
  8. $this->assertInstanceOf('\\OAuth\\OAuth1\\Signature\\SignatureInterface', $signature); 
  9.  
  10. /** 
  11. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  12. * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm 
  13. */ 
  14. public function testSetHashingAlgorithm() 
  15. $signature = new Signature($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface')); 
  16.  
  17. $this->assertNull($signature->setHashingAlgorithm('foo')); 
  18.  
  19. /** 
  20. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  21. * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret 
  22. */ 
  23. public function testSetTokenSecret() 
  24. $signature = new Signature($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface')); 
  25.  
  26. $this->assertNull($signature->setTokenSecret('foo')); 
  27.  
  28. /** 
  29. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  30. * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm 
  31. * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret 
  32. * @covers OAuth\OAuth1\Signature\Signature::getSignature 
  33. * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString 
  34. * @covers OAuth\OAuth1\Signature\Signature::hash 
  35. * @covers OAuth\OAuth1\Signature\Signature::getSigningKey 
  36. */ 
  37. public function testGetSignatureBareUri() 
  38. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  39. $credentials->expects($this->any()) 
  40. ->method('getConsumerSecret') 
  41. ->will($this->returnValue('foo')); 
  42.  
  43.  
  44. $signature = new Signature($credentials); 
  45.  
  46. $signature->setHashingAlgorithm('HMAC-SHA1'); 
  47. $signature->setTokenSecret('foo'); 
  48.  
  49. $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); 
  50. $uri->expects($this->any()) 
  51. ->method('getQuery') 
  52. ->will($this->returnValue('')); 
  53. $uri->expects($this->any()) 
  54. ->method('getScheme') 
  55. ->will($this->returnValue('http')); 
  56. $uri->expects($this->any()) 
  57. ->method('getRawAuthority') 
  58. ->will($this->returnValue('')); 
  59. $uri->expects($this->any()) 
  60. ->method('getPath') 
  61. ->will($this->returnValue('/foo')); 
  62.  
  63. $this->assertSame('uoCpiII/Lg/cPiF0XrU2pj4eGFQ=', $signature->getSignature($uri, array('pee' => 'haa'))); 
  64.  
  65. /** 
  66. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  67. * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm 
  68. * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret 
  69. * @covers OAuth\OAuth1\Signature\Signature::getSignature 
  70. * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString 
  71. * @covers OAuth\OAuth1\Signature\Signature::hash 
  72. * @covers OAuth\OAuth1\Signature\Signature::getSigningKey 
  73. */ 
  74. public function testGetSignatureWithQueryString() 
  75. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  76. $credentials->expects($this->any()) 
  77. ->method('getConsumerSecret') 
  78. ->will($this->returnValue('foo')); 
  79.  
  80.  
  81. $signature = new Signature($credentials); 
  82.  
  83. $signature->setHashingAlgorithm('HMAC-SHA1'); 
  84. $signature->setTokenSecret('foo'); 
  85.  
  86. $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); 
  87. $uri->expects($this->any()) 
  88. ->method('getQuery') 
  89. ->will($this->returnValue('param1=value1')); 
  90. $uri->expects($this->any()) 
  91. ->method('getScheme') 
  92. ->will($this->returnValue('http')); 
  93. $uri->expects($this->any()) 
  94. ->method('getRawAuthority') 
  95. ->will($this->returnValue('')); 
  96. $uri->expects($this->any()) 
  97. ->method('getPath') 
  98. ->will($this->returnValue('/foo')); 
  99.  
  100. $this->assertSame('LxtD+WjJBRppIUvEI79iQ7I0hSo=', $signature->getSignature($uri, array('pee' => 'haa'))); 
  101.  
  102. /** 
  103. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  104. * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm 
  105. * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret 
  106. * @covers OAuth\OAuth1\Signature\Signature::getSignature 
  107. * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString 
  108. * @covers OAuth\OAuth1\Signature\Signature::hash 
  109. * @covers OAuth\OAuth1\Signature\Signature::getSigningKey 
  110. */ 
  111. public function testGetSignatureWithAuthority() 
  112. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  113. $credentials->expects($this->any()) 
  114. ->method('getConsumerSecret') 
  115. ->will($this->returnValue('foo')); 
  116.  
  117.  
  118. $signature = new Signature($credentials); 
  119.  
  120. $signature->setHashingAlgorithm('HMAC-SHA1'); 
  121. $signature->setTokenSecret('foo'); 
  122.  
  123. $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); 
  124. $uri->expects($this->any()) 
  125. ->method('getQuery') 
  126. ->will($this->returnValue('param1=value1')); 
  127. $uri->expects($this->any()) 
  128. ->method('getScheme') 
  129. ->will($this->returnValue('http')); 
  130. $uri->expects($this->any()) 
  131. ->method('getRawAuthority') 
  132. ->will($this->returnValue('peehaa:pass')); 
  133. $uri->expects($this->any()) 
  134. ->method('getPath') 
  135. ->will($this->returnValue('/foo')); 
  136.  
  137. $this->assertSame('MHvkRndIntLrxiPkjkiCNsMEqv4=', $signature->getSignature($uri, array('pee' => 'haa'))); 
  138.  
  139. /** 
  140. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  141. * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm 
  142. * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret 
  143. * @covers OAuth\OAuth1\Signature\Signature::getSignature 
  144. * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString 
  145. * @covers OAuth\OAuth1\Signature\Signature::hash 
  146. * @covers OAuth\OAuth1\Signature\Signature::getSigningKey 
  147. */ 
  148. public function testGetSignatureWithBarePathNonExplicitTrailingHostSlash() 
  149. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  150. $credentials->expects($this->any()) 
  151. ->method('getConsumerSecret') 
  152. ->will($this->returnValue('foo')); 
  153.  
  154.  
  155. $signature = new Signature($credentials); 
  156.  
  157. $signature->setHashingAlgorithm('HMAC-SHA1'); 
  158. $signature->setTokenSecret('foo'); 
  159.  
  160. $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); 
  161. $uri->expects($this->any()) 
  162. ->method('getQuery') 
  163. ->will($this->returnValue('param1=value1')); 
  164. $uri->expects($this->any()) 
  165. ->method('getScheme') 
  166. ->will($this->returnValue('http')); 
  167. $uri->expects($this->any()) 
  168. ->method('getRawAuthority') 
  169. ->will($this->returnValue('peehaa:pass')); 
  170. $uri->expects($this->any()) 
  171. ->method('getPath') 
  172. ->will($this->returnValue('/')); 
  173. $uri->expects($this->any()) 
  174. ->method('hasExplicitTrailingHostSlash') 
  175. ->will($this->returnValue(false)); 
  176.  
  177. $this->assertSame('iFELDoiI5Oj9ixB3kHzoPvBpq0w=', $signature->getSignature($uri, array('pee' => 'haa'))); 
  178.  
  179. /** 
  180. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  181. * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm 
  182. * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret 
  183. * @covers OAuth\OAuth1\Signature\Signature::getSignature 
  184. * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString 
  185. * @covers OAuth\OAuth1\Signature\Signature::hash 
  186. * @covers OAuth\OAuth1\Signature\Signature::getSigningKey 
  187. */ 
  188. public function testGetSignatureWithBarePathWithExplicitTrailingHostSlash() 
  189. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  190. $credentials->expects($this->any()) 
  191. ->method('getConsumerSecret') 
  192. ->will($this->returnValue('foo')); 
  193.  
  194.  
  195. $signature = new Signature($credentials); 
  196.  
  197. $signature->setHashingAlgorithm('HMAC-SHA1'); 
  198. $signature->setTokenSecret('foo'); 
  199.  
  200. $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); 
  201. $uri->expects($this->any()) 
  202. ->method('getQuery') 
  203. ->will($this->returnValue('param1=value1')); 
  204. $uri->expects($this->any()) 
  205. ->method('getScheme') 
  206. ->will($this->returnValue('http')); 
  207. $uri->expects($this->any()) 
  208. ->method('getRawAuthority') 
  209. ->will($this->returnValue('peehaa:pass')); 
  210. $uri->expects($this->any()) 
  211. ->method('getPath') 
  212. ->will($this->returnValue('/')); 
  213. $uri->expects($this->any()) 
  214. ->method('hasExplicitTrailingHostSlash') 
  215. ->will($this->returnValue(true)); 
  216.  
  217. $this->assertSame('IEhUsArSTLvbQ3QYr0zzn+Rxpjg=', $signature->getSignature($uri, array('pee' => 'haa'))); 
  218.  
  219. /** 
  220. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  221. * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm 
  222. * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret 
  223. * @covers OAuth\OAuth1\Signature\Signature::getSignature 
  224. * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString 
  225. * @covers OAuth\OAuth1\Signature\Signature::hash 
  226. * @covers OAuth\OAuth1\Signature\Signature::getSigningKey 
  227. */ 
  228. public function testGetSignatureNoTokenSecretSet() 
  229. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  230. $credentials->expects($this->any()) 
  231. ->method('getConsumerSecret') 
  232. ->will($this->returnValue('foo')); 
  233.  
  234.  
  235. $signature = new Signature($credentials); 
  236.  
  237. $signature->setHashingAlgorithm('HMAC-SHA1'); 
  238.  
  239. $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); 
  240. $uri->expects($this->any()) 
  241. ->method('getQuery') 
  242. ->will($this->returnValue('param1=value1')); 
  243. $uri->expects($this->any()) 
  244. ->method('getScheme') 
  245. ->will($this->returnValue('http')); 
  246. $uri->expects($this->any()) 
  247. ->method('getRawAuthority') 
  248. ->will($this->returnValue('peehaa:pass')); 
  249. $uri->expects($this->any()) 
  250. ->method('getPath') 
  251. ->will($this->returnValue('/')); 
  252. $uri->expects($this->any()) 
  253. ->method('hasExplicitTrailingHostSlash') 
  254. ->will($this->returnValue(true)); 
  255.  
  256. $this->assertSame('YMHF7FYmLq7wzGnnHWYtd1VoBBE=', $signature->getSignature($uri, array('pee' => 'haa'))); 
  257.  
  258. /** 
  259. * @covers OAuth\OAuth1\Signature\Signature::__construct 
  260. * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm 
  261. * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret 
  262. * @covers OAuth\OAuth1\Signature\Signature::getSignature 
  263. * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString 
  264. * @covers OAuth\OAuth1\Signature\Signature::hash 
  265. * @covers OAuth\OAuth1\Signature\Signature::getSigningKey 
  266. */ 
  267. public function testGetSignatureThrowsExceptionOnUnsupportedAlgo() 
  268. $this->setExpectedException('\\OAuth\\OAuth1\\Signature\\Exception\\UnsupportedHashAlgorithmException'); 
  269.  
  270. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  271. $credentials->expects($this->any()) 
  272. ->method('getConsumerSecret') 
  273. ->will($this->returnValue('foo')); 
  274.  
  275.  
  276. $signature = new Signature($credentials); 
  277.  
  278. $signature->setHashingAlgorithm('UnsupportedAlgo'); 
  279.  
  280. $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); 
  281. $uri->expects($this->any()) 
  282. ->method('getQuery') 
  283. ->will($this->returnValue('param1=value1')); 
  284. $uri->expects($this->any()) 
  285. ->method('getScheme') 
  286. ->will($this->returnValue('http')); 
  287. $uri->expects($this->any()) 
  288. ->method('getRawAuthority') 
  289. ->will($this->returnValue('peehaa:pass')); 
  290. $uri->expects($this->any()) 
  291. ->method('getPath') 
  292. ->will($this->returnValue('/')); 
  293. $uri->expects($this->any()) 
  294. ->method('hasExplicitTrailingHostSlash') 
  295. ->will($this->returnValue(true)); 
  296.  
  297. $signature->getSignature($uri, array('pee' => 'haa'));