OauthTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @link https://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Test\TestCase\Http\Client\Auth;
  15. use Cake\Http\Client\Auth\Oauth;
  16. use Cake\Http\Client\Request;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * Oauth test.
  20. */
  21. class OauthTest extends TestCase
  22. {
  23. private $privateKeyString = '-----BEGIN RSA PRIVATE KEY-----
  24. MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V
  25. A7qVvdqxevEuUkW4K+2KdMXmnQbG9Aa7k7eBjK1S+0LYmVjPKlJGNXHDGuy5Fw/d
  26. 7rjVJ0BLB+ubPK8iA/Tw3hLQgXMRRGRXXCn8ikfuQfjUS1uZSatdLB81mydBETlJ
  27. hI6GH4twrbDJCR2Bwy/XWXgqgGRzAgMBAAECgYBYWVtleUzavkbrPjy0T5FMou8H
  28. X9u2AC2ry8vD/l7cqedtwMPp9k7TubgNFo+NGvKsl2ynyprOZR1xjQ7WgrgVB+mm
  29. uScOM/5HVceFuGRDhYTCObE+y1kxRloNYXnx3ei1zbeYLPCHdhxRYW7T0qcynNmw
  30. rn05/KO2RLjgQNalsQJBANeA3Q4Nugqy4QBUCEC09SqylT2K9FrrItqL2QKc9v0Z
  31. zO2uwllCbg0dwpVuYPYXYvikNHHg+aCWF+VXsb9rpPsCQQDWR9TT4ORdzoj+Nccn
  32. qkMsDmzt0EfNaAOwHOmVJ2RVBspPcxt5iN4HI7HNeG6U5YsFBb+/GZbgfBT3kpNG
  33. WPTpAkBI+gFhjfJvRw38n3g/+UeAkwMI2TJQS4n8+hid0uus3/zOjDySH3XHCUno
  34. cn1xOJAyZODBo47E+67R4jV1/gzbAkEAklJaspRPXP877NssM5nAZMU0/O/NGCZ+
  35. 3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT898jusgQJAd5Zrr6Q8
  36. AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54
  37. Lw03eHTNQghS0A==
  38. -----END RSA PRIVATE KEY-----';
  39. private $privateKeyStringEnc = '-----BEGIN RSA PRIVATE KEY-----
  40. Proc-Type: 4,ENCRYPTED
  41. DEK-Info: DES-CBC,E65DB7AE7A05EF23
  42. QCXAQ/Uj1+7uQp0MyDUPlKvW/28PhbT4GxflBYmU6SxKZ2CVFPk0M8RgB6gkJyVv
  43. mwjo1Ch2Tlt7/VrNfLWGIh1XPhsC3gatv8Wv+g0keWWifaHlhXulgMGREJ7QeJg0
  44. 5THvdFuIs2qQnOzPCAwONjM6yMxPb2qxvwq0UKAL5V/CYVFWS6PYdR25f9ogXxBz
  45. c3QjvvnhQ7ipNjpjVp/XKYMYnZPCYkNYvRX+BcsWlqYtclO3m+xPG+mPAFs9hnBI
  46. wHI4yC2fl52giRc7XnSl7NNjun6RpHT/Cn7JDH6ql86pgMO0dw6PDzPf0KY9DCrR
  47. ldQyzQ8WjN3FU55+En+8zmSnxUu7EbdqZwhVEF+UwfJ7IqJUnHll0aDTUA/qq0dk
  48. DqtMKIXvRnDVZJqKxHyRvARf8Zp8USsq3cVdlA9PhtcKrs4CbTDL0lJ3eWj1bDS1
  49. kIHXYo19lBqcS1oX+6TqvEs69oW/aG8UZIONN0Xh5TbxuJMedXD1dexV9oOA9lGR
  50. cS6Ye0wC7fCdnA6jfAmHFJ5t2qk7FOzcFZwap7m+EWn11z+72GVqz3BDSe5qH2m2
  51. XOHl59rVtJsZFtjyQEV34IFYyb2qBHHqUUdKwIwT1JOZIq+IdTJxaieIb1mnlmDw
  52. DDf4Kwr0C9tti1R1IsPaAmjF7eH0PGbDGAB3fJSCXbHf7EXTz1AUdknd2MHXQ7wO
  53. UBABkD2ETB+EotdHTly5FQt0jwbHfF2najBmezxtEjIygCnDb02Rtuei4HTansBu
  54. shqoyFXJvizZzje7HaTQv/eJTuA6rUOzu/sAv/eBx2YAPkA8oa3qUw==
  55. -----END RSA PRIVATE KEY-----';
  56. /**
  57. * @return void
  58. */
  59. public function testExceptionUnknownSigningMethod()
  60. {
  61. $this->expectException(\Cake\Core\Exception\Exception::class);
  62. $auth = new Oauth();
  63. $creds = [
  64. 'consumerSecret' => 'it is secret',
  65. 'consumerKey' => 'a key',
  66. 'token' => 'a token value',
  67. 'tokenSecret' => 'also secret',
  68. 'method' => 'silly goose',
  69. ];
  70. $request = new Request();
  71. $auth->authentication($request, $creds);
  72. }
  73. /**
  74. * Test plain-text signing.
  75. *
  76. * @return void
  77. */
  78. public function testPlainTextSigning()
  79. {
  80. $auth = new Oauth();
  81. $creds = [
  82. 'consumerSecret' => 'it is secret',
  83. 'consumerKey' => 'a key',
  84. 'token' => 'a token value',
  85. 'tokenSecret' => 'also secret',
  86. 'method' => 'plaintext',
  87. ];
  88. $request = new Request();
  89. $request = $auth->authentication($request, $creds);
  90. $result = $request->getHeaderLine('Authorization');
  91. $this->assertContains('OAuth', $result);
  92. $this->assertContains('oauth_version="1.0"', $result);
  93. $this->assertContains('oauth_token="a%20token%20value"', $result);
  94. $this->assertContains('oauth_consumer_key="a%20key"', $result);
  95. $this->assertContains('oauth_signature_method="PLAINTEXT"', $result);
  96. $this->assertContains('oauth_signature="it%20is%20secret%26also%20secret"', $result);
  97. $this->assertContains('oauth_timestamp=', $result);
  98. $this->assertContains('oauth_nonce=', $result);
  99. }
  100. /**
  101. * Test that baseString() normalizes the URL.
  102. *
  103. * @return void
  104. */
  105. public function testBaseStringNormalizeUrl()
  106. {
  107. $request = new Request('HTTP://exAmple.com:80/parts/foo');
  108. $auth = new Oauth();
  109. $creds = [];
  110. $result = $auth->baseString($request, $creds);
  111. $this->assertContains('GET&', $result, 'method was missing.');
  112. $this->assertContains('http%3A%2F%2Fexample.com%2Fparts%2Ffoo', $result);
  113. }
  114. /**
  115. * Test that the query string is stripped from the normalized host.
  116. *
  117. * @return void
  118. */
  119. public function testBaseStringWithQueryString()
  120. {
  121. $request = new Request('http://example.com/search?q=pogo&cat=2');
  122. $auth = new Oauth();
  123. $values = [
  124. 'oauth_version' => '1.0',
  125. 'oauth_nonce' => uniqid(),
  126. 'oauth_timestamp' => time(),
  127. 'oauth_signature_method' => 'HMAC-SHA1',
  128. 'oauth_token' => 'token',
  129. 'oauth_consumer_key' => 'consumer-key',
  130. ];
  131. $result = $auth->baseString($request, $values);
  132. $this->assertContains('GET&', $result, 'method was missing.');
  133. $this->assertContains(
  134. 'http%3A%2F%2Fexample.com%2Fsearch&',
  135. $result
  136. );
  137. $this->assertContains(
  138. 'cat%3D2%26oauth_consumer_key%3Dconsumer-key' .
  139. '%26oauth_nonce%3D' . $values['oauth_nonce'] .
  140. '%26oauth_signature_method%3DHMAC-SHA1' .
  141. '%26oauth_timestamp%3D' . $values['oauth_timestamp'] .
  142. '%26oauth_token%3Dtoken' .
  143. '%26oauth_version%3D1.0' .
  144. '%26q%3Dpogo',
  145. $result
  146. );
  147. }
  148. /**
  149. * Ensure that post data is sorted and encoded.
  150. *
  151. * Keys with array values have to be serialized using
  152. * a more standard HTTP approach. PHP flavoured HTTP
  153. * is not part of the Oauth spec.
  154. *
  155. * See Normalize Request Parameters (section 9.1.1)
  156. *
  157. * @return void
  158. */
  159. public function testBaseStringWithPostDataNestedArrays()
  160. {
  161. $request = new Request(
  162. 'http://example.com/search?q=pogo',
  163. Request::METHOD_POST,
  164. [],
  165. [
  166. 'search' => [
  167. 'filters' => [
  168. 'field' => 'date',
  169. 'value' => 'one two',
  170. ],
  171. ],
  172. ]
  173. );
  174. $auth = new Oauth();
  175. $values = [
  176. 'oauth_version' => '1.0',
  177. 'oauth_nonce' => uniqid(),
  178. 'oauth_timestamp' => time(),
  179. 'oauth_signature_method' => 'HMAC-SHA1',
  180. 'oauth_token' => 'token',
  181. 'oauth_consumer_key' => 'consumer-key',
  182. ];
  183. $result = $auth->baseString($request, $values);
  184. $this->assertContains('POST&', $result, 'method was missing.');
  185. $this->assertContains(
  186. 'http%3A%2F%2Fexample.com%2Fsearch&',
  187. $result
  188. );
  189. $this->assertContains(
  190. '&oauth_consumer_key%3Dconsumer-key' .
  191. '%26oauth_nonce%3D' . $values['oauth_nonce'] .
  192. '%26oauth_signature_method%3DHMAC-SHA1' .
  193. '%26oauth_timestamp%3D' . $values['oauth_timestamp'] .
  194. '%26oauth_token%3Dtoken' .
  195. '%26oauth_version%3D1.0' .
  196. '%26q%3Dpogo' .
  197. '%26search%5Bfilters%5D%5Bfield%5D%3Ddate' .
  198. '%26search%5Bfilters%5D%5Bvalue%5D%3Done%20two',
  199. $result
  200. );
  201. }
  202. /**
  203. * Ensure that post data is sorted and encoded.
  204. *
  205. * Keys with array values have to be serialized using
  206. * a more standard HTTP approach. PHP flavoured HTTP
  207. * is not part of the Oauth spec.
  208. *
  209. * See Normalize Request Parameters (section 9.1.1)
  210. * http://wiki.oauth.net/w/page/12238556/TestCases
  211. *
  212. * @return void
  213. */
  214. public function testBaseStringWithPostData()
  215. {
  216. $request = new Request(
  217. 'http://example.com/search?q=pogo',
  218. Request::METHOD_POST,
  219. [],
  220. [
  221. 'address' => 'post',
  222. 'zed' => 'last',
  223. 'tags' => ['oauth', 'cake'],
  224. ]
  225. );
  226. $auth = new Oauth();
  227. $values = [
  228. 'oauth_version' => '1.0',
  229. 'oauth_nonce' => uniqid(),
  230. 'oauth_timestamp' => time(),
  231. 'oauth_signature_method' => 'HMAC-SHA1',
  232. 'oauth_token' => 'token',
  233. 'oauth_consumer_key' => 'consumer-key',
  234. ];
  235. $result = $auth->baseString($request, $values);
  236. $this->assertContains('POST&', $result, 'method was missing.');
  237. $this->assertContains(
  238. 'http%3A%2F%2Fexample.com%2Fsearch&',
  239. $result
  240. );
  241. $this->assertContains(
  242. '&address%3Dpost' .
  243. '%26oauth_consumer_key%3Dconsumer-key' .
  244. '%26oauth_nonce%3D' . $values['oauth_nonce'] .
  245. '%26oauth_signature_method%3DHMAC-SHA1' .
  246. '%26oauth_timestamp%3D' . $values['oauth_timestamp'] .
  247. '%26oauth_token%3Dtoken' .
  248. '%26oauth_version%3D1.0' .
  249. '%26q%3Dpogo' .
  250. '%26tags%3Dcake' .
  251. '%26tags%3Doauth' .
  252. '%26zed%3Dlast',
  253. $result
  254. );
  255. }
  256. /**
  257. * Test HMAC-SHA1 signing
  258. *
  259. * Hash result + parameters taken from
  260. * http://wiki.oauth.net/w/page/12238556/TestCases
  261. *
  262. * @return void
  263. */
  264. public function testHmacSigning()
  265. {
  266. $request = new Request(
  267. 'http://photos.example.net/photos',
  268. 'GET',
  269. [],
  270. ['file' => 'vacation.jpg', 'size' => 'original']
  271. );
  272. $options = [
  273. 'consumerKey' => 'dpf43f3p2l4k3l03',
  274. 'consumerSecret' => 'kd94hf93k423kf44',
  275. 'tokenSecret' => 'pfkkdhi9sl3r4s00',
  276. 'token' => 'nnch734d00sl2jdk',
  277. 'nonce' => 'kllo9940pd9333jh',
  278. 'timestamp' => '1191242096',
  279. ];
  280. $auth = new Oauth();
  281. $request = $auth->authentication($request, $options);
  282. $result = $request->getHeaderLine('Authorization');
  283. $expected = 'tR3+Ty81lMeYAr/Fid0kMTYa/WM=';
  284. $this->assertContains(
  285. 'oauth_signature="' . $expected . '"',
  286. urldecode($result)
  287. );
  288. }
  289. /**
  290. * Test HMAC-SHA1 signing with a base64 consumer key
  291. *
  292. * @return void
  293. */
  294. public function testHmacBase64Signing()
  295. {
  296. $request = new Request(
  297. 'http://photos.example.net/photos',
  298. 'GET'
  299. );
  300. $options = [
  301. 'consumerKey' => 'ZHBmNDNmM3AybDRrM2wwMw==',
  302. 'consumerSecret' => 'kd94hf93k423kf44',
  303. 'tokenSecret' => 'pfkkdhi9sl3r4s00',
  304. 'token' => 'nnch734d00sl2jdk',
  305. 'nonce' => 'kllo9940pd9333jh',
  306. 'timestamp' => '1191242096',
  307. ];
  308. $auth = new Oauth();
  309. $request = $auth->authentication($request, $options);
  310. $result = $request->getHeaderLine('Authorization');
  311. $expected = '2hr/eoFyTSuWc6SfZIvkhpeRHdM=';
  312. $this->assertContains(
  313. 'oauth_signature="' . $expected . '"',
  314. urldecode($result)
  315. );
  316. }
  317. /**
  318. * Test RSA-SHA1 signing with a private key string
  319. *
  320. * Hash result + parameters taken from
  321. * http://wiki.oauth.net/w/page/12238556/TestCases
  322. *
  323. * @return void
  324. */
  325. public function testRsaSigningString()
  326. {
  327. $request = new Request(
  328. 'http://photos.example.net/photos',
  329. 'GET',
  330. [],
  331. ['file' => 'vacaction.jpg', 'size' => 'original']
  332. );
  333. $privateKey = $this->privateKeyString;
  334. $options = [
  335. 'method' => 'RSA-SHA1',
  336. 'consumerKey' => 'dpf43f3p2l4k3l03',
  337. 'nonce' => '13917289812797014437',
  338. 'timestamp' => '1196666512',
  339. 'privateKey' => $privateKey,
  340. ];
  341. $auth = new Oauth();
  342. $request = $auth->authentication($request, $options);
  343. $result = $request->getHeaderLine('Authorization');
  344. $expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
  345. $this->assertContains(
  346. 'oauth_signature="' . $expected . '"',
  347. urldecode($result)
  348. );
  349. }
  350. /**
  351. * Test RSA-SHA1 signing with a private key file
  352. *
  353. * Hash result + parameters taken from
  354. * http://wiki.oauth.net/w/page/12238556/TestCases
  355. *
  356. * @return void
  357. */
  358. public function testRsaSigningFile()
  359. {
  360. $request = new Request(
  361. 'http://photos.example.net/photos',
  362. 'GET',
  363. [],
  364. ['file' => 'vacaction.jpg', 'size' => 'original']
  365. );
  366. $privateKey = fopen(TEST_APP . DS . 'config' . DS . 'key.pem', 'r');
  367. $options = [
  368. 'method' => 'RSA-SHA1',
  369. 'consumerKey' => 'dpf43f3p2l4k3l03',
  370. 'nonce' => '13917289812797014437',
  371. 'timestamp' => '1196666512',
  372. 'privateKey' => $privateKey,
  373. ];
  374. $auth = new Oauth();
  375. $request = $auth->authentication($request, $options);
  376. $result = $request->getHeaderLine('Authorization');
  377. $expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
  378. $this->assertContains(
  379. 'oauth_signature="' . $expected . '"',
  380. urldecode($result)
  381. );
  382. }
  383. /**
  384. * Test RSA-SHA1 signing with a private key file passphrase string
  385. *
  386. * Hash result + parameters taken from
  387. * http://wiki.oauth.net/w/page/12238556/TestCases
  388. *
  389. * @return void
  390. */
  391. public function testRsaSigningWithPassphraseString()
  392. {
  393. $request = new Request(
  394. 'http://photos.example.net/photos',
  395. 'GET',
  396. [],
  397. ['file' => 'vacaction.jpg', 'size' => 'original']
  398. );
  399. $privateKey = fopen(TEST_APP . DS . 'config' . DS . 'key_with_passphrase.pem', 'r');
  400. $passphrase = 'fancy-cakephp-passphrase';
  401. $options = [
  402. 'method' => 'RSA-SHA1',
  403. 'consumerKey' => 'dpf43f3p2l4k3l03',
  404. 'nonce' => '13917289812797014437',
  405. 'timestamp' => '1196666512',
  406. 'privateKey' => $privateKey,
  407. 'privateKeyPassphrase' => $passphrase,
  408. ];
  409. $auth = new Oauth();
  410. $request = $auth->authentication($request, $options);
  411. $result = $request->getHeaderLine('Authorization');
  412. $expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
  413. $this->assertContains(
  414. 'oauth_signature="' . $expected . '"',
  415. urldecode($result)
  416. );
  417. }
  418. /**
  419. * Test RSA-SHA1 signing with a private key string and passphrase string
  420. *
  421. * Hash result + parameters taken from
  422. * http://wiki.oauth.net/w/page/12238556/TestCases
  423. *
  424. * @return void
  425. */
  426. public function testRsaSigningStringWithPassphraseString()
  427. {
  428. $request = new Request(
  429. 'http://photos.example.net/photos',
  430. 'GET',
  431. [],
  432. ['file' => 'vacaction.jpg', 'size' => 'original']
  433. );
  434. $privateKey = $this->privateKeyStringEnc;
  435. $passphrase = 'fancy-cakephp-passphrase';
  436. $options = [
  437. 'method' => 'RSA-SHA1',
  438. 'consumerKey' => 'dpf43f3p2l4k3l03',
  439. 'nonce' => '13917289812797014437',
  440. 'timestamp' => '1196666512',
  441. 'privateKey' => $privateKey,
  442. 'privateKeyPassphrase' => $passphrase,
  443. ];
  444. $auth = new Oauth();
  445. $request = $auth->authentication($request, $options);
  446. $result = $request->getHeaderLine('Authorization');
  447. $expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
  448. $this->assertContains(
  449. 'oauth_signature="' . $expected . '"',
  450. urldecode($result)
  451. );
  452. }
  453. /**
  454. * Test RSA-SHA1 signing with passphrase file
  455. *
  456. * Hash result + parameters taken from
  457. * http://wiki.oauth.net/w/page/12238556/TestCases
  458. *
  459. * @return void
  460. */
  461. public function testRsaSigningWithPassphraseFile()
  462. {
  463. $this->skipIf(PHP_EOL != "\n", 'Just the line ending "\n" is supported. You can run the test again e.g. on a linux system.');
  464. $request = new Request(
  465. 'http://photos.example.net/photos',
  466. 'GET',
  467. [],
  468. ['file' => 'vacaction.jpg', 'size' => 'original']
  469. );
  470. $privateKey = fopen(TEST_APP . DS . 'config' . DS . 'key_with_passphrase.pem', 'r');
  471. $passphrase = fopen(TEST_APP . DS . 'config' . DS . 'key_passphrase_lf', 'r');
  472. $options = [
  473. 'method' => 'RSA-SHA1',
  474. 'consumerKey' => 'dpf43f3p2l4k3l03',
  475. 'nonce' => '13917289812797014437',
  476. 'timestamp' => '1196666512',
  477. 'privateKey' => $privateKey,
  478. 'privateKeyPassphrase' => $passphrase,
  479. ];
  480. $auth = new Oauth();
  481. $request = $auth->authentication($request, $options);
  482. $result = $request->getHeaderLine('Authorization');
  483. $expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
  484. $this->assertContains(
  485. 'oauth_signature="' . $expected . '"',
  486. urldecode($result)
  487. );
  488. $expected = 0;
  489. $this->assertEquals($expected, ftell($passphrase));
  490. }
  491. /**
  492. * Test RSA-SHA1 signing with a private key string and passphrase file
  493. *
  494. * Hash result + parameters taken from
  495. * http://wiki.oauth.net/w/page/12238556/TestCases
  496. *
  497. * @return void
  498. */
  499. public function testRsaSigningStringWithPassphraseFile()
  500. {
  501. $this->skipIf(PHP_EOL != "\n", 'Just the line ending "\n" is supported. You can run the test again e.g. on a linux system.');
  502. $request = new Request(
  503. 'http://photos.example.net/photos',
  504. 'GET',
  505. [],
  506. ['file' => 'vacaction.jpg', 'size' => 'original']
  507. );
  508. $privateKey = $this->privateKeyStringEnc;
  509. $passphrase = fopen(TEST_APP . DS . 'config' . DS . 'key_passphrase_lf', 'r');
  510. $options = [
  511. 'method' => 'RSA-SHA1',
  512. 'consumerKey' => 'dpf43f3p2l4k3l03',
  513. 'nonce' => '13917289812797014437',
  514. 'timestamp' => '1196666512',
  515. 'privateKey' => $privateKey,
  516. 'privateKeyPassphrase' => $passphrase,
  517. ];
  518. $auth = new Oauth();
  519. $request = $auth->authentication($request, $options);
  520. $result = $request->getHeaderLine('Authorization');
  521. $expected = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
  522. $this->assertContains(
  523. 'oauth_signature="' . $expected . '"',
  524. urldecode($result)
  525. );
  526. $expected = 0;
  527. $this->assertEquals($expected, ftell($passphrase));
  528. }
  529. }