Discover_OpenID.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. <?php
  2. require_once 'TestUtil.php';
  3. require_once 'Auth/OpenID.php';
  4. require_once 'Auth/OpenID/Discover.php';
  5. require_once 'Auth/Yadis/Manager.php';
  6. require_once 'Auth/Yadis/Misc.php';
  7. require_once 'Auth/Yadis/XRI.php';
  8. /**
  9. * Tests for the core of the PHP Yadis library discovery logic.
  10. */
  11. class _SimpleMockFetcher {
  12. function _SimpleMockFetcher($responses)
  13. {
  14. $this->responses = $responses;
  15. }
  16. function get($url)
  17. {
  18. $response = array_pop($this->responses);
  19. assert($response[1] == $url);
  20. return $response;
  21. }
  22. }
  23. class Tests_Auth_OpenID_ServiceEndpoint extends PHPUnit_Framework_TestCase {
  24. function setUp() {
  25. $this->endpoint = new Auth_OpenID_ServiceEndpoint();
  26. }
  27. function test_getDisplayIdentifier_noFragment() {
  28. $urls = array("http://foo.bar.com/something",
  29. "http://foo.bar.com/something?else=what&nothing=0",
  30. "https://smoker.myopenid.com/"
  31. );
  32. foreach ($urls as $url) {
  33. $this->endpoint->claimed_id = $url;
  34. $this->assertEquals($url, $this->endpoint->getDisplayIdentifier());
  35. }
  36. }
  37. function test_getDisplayIdentifier_withFragment() {
  38. $urls = array("http://foo.bar.com/something#fragged",
  39. "http://foo.bar.com/something?else=what&nothing=0#ow",
  40. "https://smoker.myopenid.com/#myentirelife"
  41. );
  42. foreach ($urls as $url) {
  43. $this->endpoint->claimed_id = $url;
  44. $split = explode('#', $url);
  45. $this->assertEquals($split[0],
  46. $this->endpoint->getDisplayIdentifier());
  47. }
  48. }
  49. }
  50. class Tests_Auth_OpenID_DiscoveryFailure extends PHPUnit_Framework_TestCase {
  51. function Tests_Auth_OpenID_DiscoveryFailure($responses)
  52. {
  53. // Response is ($code, $url, $body).
  54. $this->cases = array(
  55. array(null, 'http://network.error/', ''),
  56. array(404, 'http://not.found/', ''),
  57. array(400, 'http://bad.request/', ''),
  58. array(500, 'http://server.error/', ''),
  59. array(200, 'http://header.found/', 200,
  60. array('x-xrds-location' => 'http://xrds.missing/')),
  61. array(404, 'http://xrds.missing/', ''));
  62. $this->url = $responses[0]->final_url;
  63. $this->responses = $responses;
  64. $this->fetcher = new _SimpleMockFetcher($this->responses);
  65. }
  66. function runTest()
  67. {
  68. foreach ($this->cases as $case) {
  69. list($status, $url, $body) = $case;
  70. $expected_status = $status;
  71. $result = Auth_OpenID_discover($this->url, $this->fetcher);
  72. list($id_url, $svclist) = $result;
  73. $this->assertEquals($svclist, array());
  74. }
  75. }
  76. }
  77. ### Tests for raising/catching exceptions from the fetcher through the
  78. ### discover function
  79. class _ErrorRaisingFetcher {
  80. // Just raise an exception when fetch is called
  81. function _ErrorRaisingFetcher($thing_to_raise)
  82. {
  83. $this->thing_to_raise = $thing_to_raise;
  84. }
  85. function post($body = null)
  86. {
  87. __raiseError($this->thing_to_raise);
  88. }
  89. function get($url)
  90. {
  91. __raiseError($this->thing_to_raise);
  92. }
  93. }
  94. define('E_AUTH_OPENID_EXCEPTION', 'e_exception');
  95. define('E_AUTH_OPENID_DIDFETCH', 'e_didfetch');
  96. define('E_AUTH_OPENID_VALUE_ERROR', 'e_valueerror');
  97. define('E_AUTH_OPENID_RUNTIME_ERROR', 'e_runtimeerror');
  98. define('E_AUTH_OPENID_OI', 'e_oi');
  99. class Tests_Auth_OpenID_Discover_FetchException extends PHPUnit_Framework_TestCase {
  100. // Make sure exceptions get passed through discover function from
  101. // fetcher.
  102. function Tests_Auth_OpenID_Discover_FetchException($exc)
  103. {
  104. $this->cases = array(E_AUTH_OPENID_EXCEPTION,
  105. E_AUTH_OPENID_DIDFETCH,
  106. E_AUTH_OPENID_VALUE_ERROR,
  107. E_AUTH_OPENID_RUNTIME_ERROR,
  108. E_AUTH_OPENID_OI);
  109. }
  110. function runTest()
  111. {
  112. foreach ($this->cases as $thing_to_raise) {
  113. $fetcher = ErrorRaisingFetcher($thing_to_raise);
  114. Auth_OpenID_discover('http://doesnt.matter/', $fetcher);
  115. $exc = __getError();
  116. if ($exc !== $thing_to_raise) {
  117. $this->fail('FetchException expected %s to be raised',
  118. $thing_to_raise);
  119. }
  120. }
  121. }
  122. }
  123. // Tests for openid.consumer.discover.discover
  124. class _DiscoveryMockFetcher extends Auth_Yadis_HTTPFetcher {
  125. function _DiscoveryMockFetcher($documents)
  126. {
  127. $this->redirect = null;
  128. $this->documents = $documents;
  129. $this->fetchlog = array();
  130. }
  131. function supportsSSL()
  132. {
  133. return true;
  134. }
  135. function post($url, $body = null, $headers = null)
  136. {
  137. return $this->get($url, $headers, $body);
  138. }
  139. function get($url, $headers = null, $body = null)
  140. {
  141. $this->fetchlog[] = array($url, $body, $headers);
  142. if ($this->redirect) {
  143. $final_url = $this->redirect;
  144. } else {
  145. $final_url = $url;
  146. }
  147. if (array_key_exists($url, $this->documents)) {
  148. list($ctype, $body) = $this->documents[$url];
  149. $status = 200;
  150. } else {
  151. $status = 404;
  152. $ctype = 'text/plain';
  153. $body = '';
  154. }
  155. return new Auth_Yadis_HTTPResponse($final_url, $status,
  156. array('content-type' => $ctype), $body);
  157. }
  158. }
  159. class _DiscoveryBase extends PHPUnit_Framework_TestCase {
  160. var $id_url = "http://someuser.unittest/";
  161. var $fetcherClass = '_DiscoveryMockFetcher';
  162. function _checkService($s,
  163. $server_url,
  164. $claimed_id=null,
  165. $local_id=null,
  166. $canonical_id=null,
  167. $types=null,
  168. $used_yadis=false,
  169. $display_identifier=null)
  170. {
  171. $this->assertEquals($server_url, $s->server_url);
  172. if ($types == array('2.0 OP')) {
  173. $this->assertFalse($claimed_id);
  174. $this->assertFalse($local_id);
  175. $this->assertFalse($s->claimed_id);
  176. $this->assertFalse($s->local_id);
  177. $this->assertFalse($s->getLocalID());
  178. $this->assertFalse($s->compatibilityMode());
  179. $this->assertTrue($s->isOPIdentifier());
  180. $this->assertEquals($s->preferredNamespace(),
  181. Auth_OpenID_OPENID2_NS);
  182. } else {
  183. $this->assertEquals($claimed_id, $s->claimed_id);
  184. $this->assertEquals($local_id, $s->getLocalID());
  185. }
  186. if ($used_yadis) {
  187. $this->assertTrue($s->used_yadis, "Expected to use Yadis");
  188. } else {
  189. $this->assertFalse($s->used_yadis,
  190. "Expected to use old-style discovery");
  191. }
  192. $openid_types = array(
  193. '1.1' => Auth_OpenID_TYPE_1_1,
  194. '1.0' => Auth_OpenID_TYPE_1_0,
  195. '2.0' => Auth_OpenID_TYPE_2_0,
  196. '2.0 OP' => Auth_OpenID_TYPE_2_0_IDP);
  197. $type_uris = array();
  198. foreach ($types as $t) {
  199. $type_uris[] = $openid_types[$t];
  200. }
  201. $this->assertEquals($type_uris, $s->type_uris);
  202. $this->assertEquals($canonical_id, $s->canonicalID);
  203. if ($s->canonicalID) {
  204. $this->assertTrue($s->getDisplayIdentifier() != $claimed_id);
  205. $this->assertTrue($s->getDisplayIdentifier() !== null);
  206. $this->assertEquals($display_identifier, $s->getDisplayIdentifier());
  207. $this->assertEquals($s->claimed_id, $s->canonicalID);
  208. }
  209. $this->assertEquals($s->display_identifier ? $s->display_identifier : $s->claimed_id,
  210. $s->getDisplayIdentifier());
  211. }
  212. function setUp()
  213. {
  214. $cls = $this->fetcherClass;
  215. // D is for Dumb.
  216. $d = array();
  217. $this->fetcher = new $cls($d);
  218. }
  219. }
  220. class Tests_Auth_OpenID_Discover_OpenID extends _DiscoveryBase {
  221. function _discover($content_type, $data,
  222. $expected_services, $expected_id=null)
  223. {
  224. if ($expected_id === null) {
  225. $expected_id = $this->id_url;
  226. }
  227. $this->fetcher->documents[$this->id_url] = array($content_type, $data);
  228. list($id_url, $services) = Auth_OpenID_discover($this->id_url,
  229. $this->fetcher);
  230. $this->assertEquals($expected_services, count($services));
  231. $this->assertEquals($expected_id, $id_url);
  232. return $services;
  233. }
  234. function test_404()
  235. {
  236. list($url, $services) = Auth_OpenID_discover($this->id_url . '/404',
  237. $this->fetcher);
  238. $this->assertTrue($services == array());
  239. }
  240. function test_noOpenID()
  241. {
  242. $services = $this->_discover('text/plain',
  243. "junk",
  244. 0);
  245. $services = $this->_discover(
  246. 'text/html',
  247. Tests_Auth_OpenID_readdata('test_discover_openid_no_delegate.html'),
  248. 1);
  249. $this->_checkService($services[0],
  250. "http://www.myopenid.com/server",
  251. $this->id_url,
  252. $this->id_url,
  253. null,
  254. array('1.1'),
  255. false);
  256. }
  257. function test_html1()
  258. {
  259. $services = $this->_discover('text/html',
  260. Tests_Auth_OpenID_readdata('test_discover_openid.html'),
  261. 1);
  262. $this->_checkService($services[0],
  263. "http://www.myopenid.com/server",
  264. $this->id_url,
  265. 'http://smoker.myopenid.com/',
  266. null,
  267. array('1.1'),
  268. false,
  269. $this->id_url);
  270. }
  271. /*
  272. * Ensure that the Claimed Identifier does not have a fragment if
  273. * one is supplied in the User Input.
  274. */
  275. function test_html1Fragment()
  276. {
  277. $data = Tests_Auth_OpenID_readdata('openid.html');
  278. $content_type = 'text/html';
  279. $expected_services = 1;
  280. $this->fetcher->documents[$this->id_url] = array($content_type, $data);
  281. $expected_id = $this->id_url;
  282. $this->id_url = $this->id_url . '#fragment';
  283. list($id_url, $services) = Auth_OpenID_discover($this->id_url, $this->fetcher);
  284. $this->assertEquals($expected_services, count($services));
  285. $this->assertEquals($expected_id, $id_url);
  286. $this->_checkService(
  287. $services[0],
  288. "http://www.myopenid.com/server",
  289. $expected_id,
  290. 'http://smoker.myopenid.com/',
  291. null,
  292. array('1.1'),
  293. false,
  294. $this->id_url);
  295. }
  296. function test_html2()
  297. {
  298. $services = $this->_discover('text/html',
  299. Tests_Auth_OpenID_readdata('test_discover_openid2.html'),
  300. 1);
  301. $this->_checkService($services[0],
  302. "http://www.myopenid.com/server",
  303. $this->id_url,
  304. 'http://smoker.myopenid.com/',
  305. null,
  306. array('2.0'),
  307. false,
  308. $this->id_url);
  309. }
  310. function test_html1And2()
  311. {
  312. $services = $this->_discover('text/html',
  313. Tests_Auth_OpenID_readdata('test_discover_openid_1_and_2.html'),
  314. 2);
  315. $types = array('2.0', '1.1');
  316. for ($i = 0; $i < count($types); $i++) {
  317. $t = $types[$i];
  318. $s = $services[$i];
  319. $this->_checkService(
  320. $s,
  321. "http://www.myopenid.com/server",
  322. $this->id_url,
  323. 'http://smoker.myopenid.com/',
  324. null,
  325. array($t),
  326. false,
  327. $this->id_url);
  328. }
  329. }
  330. function test_yadisEmpty()
  331. {
  332. $services = $this->_discover('application/xrds+xml',
  333. Tests_Auth_OpenID_readdata('test_discover_yadis_0entries.xml'),
  334. 0);
  335. }
  336. function test_htmlEmptyYadis()
  337. {
  338. // HTML document has discovery information, but points to an
  339. // empty Yadis document.
  340. // The XRDS document pointed to by "openid_and_yadis.html"
  341. $this->fetcher->documents[$this->id_url . 'xrds'] =
  342. array('application/xrds+xml',
  343. Tests_Auth_OpenID_readdata('test_discover_yadis_0entries.xml'));
  344. $services = $this->_discover('text/html',
  345. Tests_Auth_OpenID_readdata('test_discover_openid_and_yadis.html'),
  346. 1);
  347. $this->_checkService($services[0],
  348. "http://www.myopenid.com/server",
  349. $this->id_url,
  350. 'http://smoker.myopenid.com/',
  351. null,
  352. array('1.1'),
  353. false,
  354. $this->id_url);
  355. }
  356. function test_yadis1NoDelegate()
  357. {
  358. $services = $this->_discover('application/xrds+xml',
  359. Tests_Auth_OpenID_readdata('test_discover_yadis_no_delegate.xml'),
  360. 1);
  361. $this->_checkService(
  362. $services[0],
  363. "http://www.myopenid.com/server",
  364. $this->id_url,
  365. $this->id_url,
  366. null,
  367. array('1.0'),
  368. true,
  369. $this->id_url);
  370. }
  371. function test_yadis2NoLocalID()
  372. {
  373. $services = $this->_discover('application/xrds+xml',
  374. Tests_Auth_OpenID_readdata('test_discover_openid2_xrds_no_local_id.xml'),
  375. 1);
  376. $this->_checkService(
  377. $services[0],
  378. "http://www.myopenid.com/server",
  379. $this->id_url,
  380. $this->id_url,
  381. null,
  382. array('2.0'),
  383. true,
  384. $this->id_url);
  385. }
  386. function test_yadis2()
  387. {
  388. $services = $this->_discover('application/xrds+xml',
  389. Tests_Auth_OpenID_readdata('test_discover_openid2_xrds.xml'),
  390. 1);
  391. $this->_checkService($services[0],
  392. "http://www.myopenid.com/server",
  393. $this->id_url,
  394. 'http://smoker.myopenid.com/',
  395. null,
  396. array('2.0'),
  397. true,
  398. $this->id_url);
  399. }
  400. function test_yadis2OP()
  401. {
  402. $services = $this->_discover('application/xrds+xml',
  403. Tests_Auth_OpenID_readdata('test_discover_yadis_idp.xml'),
  404. 1);
  405. $this->_checkService($services[0],
  406. "http://www.myopenid.com/server",
  407. null,
  408. null,
  409. null,
  410. array('2.0 OP'),
  411. true,
  412. $this->id_url);
  413. }
  414. function test_yadis2OPDelegate()
  415. {
  416. // The delegate tag isn't meaningful for OP entries.
  417. $services = $this->_discover('application/xrds+xml',
  418. Tests_Auth_OpenID_readdata('test_discover_yadis_idp_delegate.xml'),
  419. 1);
  420. $this->_checkService(
  421. $services[0],
  422. "http://www.myopenid.com/server",
  423. null, null, null,
  424. array('2.0 OP'),
  425. true,
  426. $this->id_url);
  427. }
  428. function test_yadis2BadLocalID()
  429. {
  430. $services = $this->_discover('application/xrds+xml',
  431. Tests_Auth_OpenID_readdata('test_discover_yadis_2_bad_local_id.xml'),
  432. 0);
  433. }
  434. function test_yadis1And2()
  435. {
  436. $services = $this->_discover('application/xrds+xml',
  437. Tests_Auth_OpenID_readdata('test_discover_openid_1_and_2_xrds.xml'),
  438. 1);
  439. $this->_checkService(
  440. $services[0],
  441. "http://www.myopenid.com/server",
  442. $this->id_url,
  443. 'http://smoker.myopenid.com/',
  444. null,
  445. array('2.0', '1.1'),
  446. true);
  447. }
  448. function test_yadis1And2BadLocalID()
  449. {
  450. $services = $this->_discover('application/xrds+xml',
  451. Tests_Auth_OpenID_readdata('test_discover_openid_1_and_2_xrds_bad_delegate.xml'),
  452. 0);
  453. }
  454. }
  455. class _MockFetcherForXRIProxy extends Auth_Yadis_HTTPFetcher {
  456. function _MockFetcherForXRIProxy($documents)
  457. {
  458. $this->documents = $documents;
  459. $this->fetchlog = array();
  460. }
  461. function get($url, $headers=null)
  462. {
  463. return $this->fetch($url, $headers);
  464. }
  465. function post($url, $body)
  466. {
  467. return $this->fetch($url, $body);
  468. }
  469. function fetch($url, $body=null, $headers=null)
  470. {
  471. $this->fetchlog[] = array($url, $body, $headers);
  472. $u = parse_url($url);
  473. $proxy_host = $u['host'];
  474. $xri = $u['path'];
  475. $query = Auth_OpenID::arrayGet($u, 'query');
  476. if ((!$headers) && (!$query)) {
  477. trigger_error('Error in mock XRI fetcher: no headers or query');
  478. }
  479. if (Auth_Yadis_startswith($xri, '/')) {
  480. $xri = substr($xri, 1);
  481. }
  482. if (array_key_exists($xri, $this->documents)) {
  483. list($ctype, $body) = $this->documents[$xri];
  484. $status = 200;
  485. } else {
  486. $status = 404;
  487. $ctype = 'text/plain';
  488. $body = '';
  489. }
  490. return new Auth_Yadis_HTTPResponse($url, $status,
  491. array('content-type' => $ctype),
  492. $body);
  493. }
  494. }
  495. class TestXRIDiscovery extends _DiscoveryBase {
  496. var $fetcherClass = '_MockFetcherForXRIProxy';
  497. function setUp() {
  498. parent::setUp();
  499. $this->fetcher->documents = array('=smoker' => array('application/xrds+xml',
  500. Tests_Auth_OpenID_readdata('yadis_2entries_delegate.xml')),
  501. '=smoker*bad' => array('application/xrds+xml',
  502. Tests_Auth_OpenID_readdata('yadis_another_delegate.xml')));
  503. }
  504. function test_xri() {
  505. list($user_xri, $services) = Auth_OpenID_discoverXRI('=smoker');
  506. $this->_checkService(
  507. $services[0],
  508. "http://www.myopenid.com/server",
  509. Auth_Yadis_XRI("=!1000"),
  510. 'http://smoker.myopenid.com/',
  511. Auth_Yadis_XRI("=!1000"),
  512. array('1.0'),
  513. true,
  514. '=smoker');
  515. $this->_checkService(
  516. $services[1],
  517. "http://www.livejournal.com/openid/server.bml",
  518. Auth_Yadis_XRI("=!1000"),
  519. 'http://frank.livejournal.com/',
  520. Auth_Yadis_XRI("=!1000"),
  521. array('1.0'),
  522. true,
  523. '=smoker');
  524. }
  525. function test_xriNoCanonicalID() {
  526. list($user_xri, $services) = Auth_OpenID_discoverXRI('=smoker*bad');
  527. $this->assertFalse($services);
  528. }
  529. function test_useCanonicalID() {
  530. $endpoint = new Auth_OpenID_ServiceEndpoint();
  531. $endpoint->claimed_id = Auth_Yadis_XRI("=!1000");
  532. $endpoint->canonicalID = Auth_Yadis_XRI("=!1000");
  533. $htis->assertEquals($endpoint->getLocalID(), Auth_Yadis_XRI("=!1000"));
  534. }
  535. }
  536. class Tests_Auth_OpenID_DiscoverSession {
  537. function Tests_Auth_OpenID_DiscoverSession()
  538. {
  539. $this->data = array();
  540. }
  541. function set($name, $value)
  542. {
  543. $this->data[$name] = $value;
  544. }
  545. function get($name, $default=null)
  546. {
  547. if (array_key_exists($name, $this->data)) {
  548. return $this->data[$name];
  549. } else {
  550. return $default;
  551. }
  552. }
  553. function del($name)
  554. {
  555. unset($this->data[$name]);
  556. }
  557. }
  558. global $__Tests_BOGUS_SERVICE;
  559. $__Tests_BOGUS_SERVICE = new Auth_OpenID_ServiceEndpoint();
  560. $__Tests_BOGUS_SERVICE->claimed_id = "=really.bogus.endpoint";
  561. function __serviceCheck_discover_cb($url, $fetcher)
  562. {
  563. global $__Tests_BOGUS_SERVICE;
  564. return array($url, array($__Tests_BOGUS_SERVICE));
  565. }
  566. class _FetcherWithSSL extends _DiscoveryMockFetcher {
  567. function supportsSSL()
  568. {
  569. return true;
  570. }
  571. }
  572. class _FetcherWithoutSSL extends _DiscoveryMockFetcher {
  573. function supportsSSL()
  574. {
  575. return false;
  576. }
  577. }
  578. class _NonFetcher extends _DiscoveryMockFetcher {
  579. var $used = false;
  580. function _NonFetcher()
  581. {
  582. $a = array();
  583. parent::_DiscoveryMockFetcher($a);
  584. }
  585. function supportsSSL()
  586. {
  587. return false;
  588. }
  589. function get($url, $headers)
  590. {
  591. $this->used = true;
  592. }
  593. }
  594. class Tests_Auth_OpenID_SSLSupport extends PHPUnit_Framework_TestCase {
  595. function test_discoverDropSSL()
  596. {
  597. // In the absence of SSL support, the discovery process should
  598. // drop endpoints whose server URLs are HTTPS.
  599. $id_url = 'http://bogus/';
  600. $d = array(
  601. $id_url => array('application/xrds+xml',
  602. Tests_Auth_OpenID_readdata('test_discover_openid_ssl.xml'))
  603. );
  604. $f = new _FetcherWithoutSSL($d);
  605. $result = Auth_OpenID_discover($id_url, $f);
  606. list($url, $services) = $result;
  607. $this->assertTrue($url == $id_url);
  608. $this->assertTrue(count($services) == 1);
  609. $e = $services[0];
  610. $this->assertTrue($e->server_url == 'http://nossl.vroom.unittest/server');
  611. }
  612. function test_discoverRetainSSL()
  613. {
  614. // In the presence of SSL support, the discovery process
  615. // should NOT drop endpoints whose server URLs are HTTPS.
  616. // In the absence of SSL support, the discovery process should
  617. // drop endpoints whose server URLs are HTTPS.
  618. $id_url = 'http://bogus/';
  619. $d = array(
  620. $id_url => array('application/xrds+xml',
  621. Tests_Auth_OpenID_readdata('test_discover_openid_ssl.xml'))
  622. );
  623. $f = new _FetcherWithSSL($d);
  624. $result = Auth_OpenID_discover($id_url, $f);
  625. list($url, $services) = $result;
  626. $this->assertTrue($url == $id_url);
  627. $this->assertTrue(count($services) == 2);
  628. $e = $services[0];
  629. $this->assertTrue($e->server_url == 'http://nossl.vroom.unittest/server');
  630. $e = $services[1];
  631. $this->assertTrue($e->server_url == 'https://ssl.vroom.unittest/server');
  632. }
  633. function test_discoverSSL()
  634. {
  635. // The consumer code should not attempt to perform discovery
  636. // on an HTTPS identity URL in the absence of SSL support.
  637. $id_url = 'https://unsupported/';
  638. $f = new _NonFetcher();
  639. $result = Auth_OpenID_discover($id_url, $f);
  640. $this->assertTrue($result == array($id_url, array()));
  641. $this->assertFalse($f->used);
  642. }
  643. }
  644. global $Tests_Auth_OpenID_Discover_OpenID_other;
  645. $Tests_Auth_OpenID_Discover_OpenID_other = array(
  646. new Tests_Auth_OpenID_SSLSupport()
  647. );