PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/boomhammer/vendor/gems/ruby-openid-2.1.4/test/test_discover.rb

http://strd6.googlecode.com/
Ruby | 838 lines | 724 code | 92 blank | 22 comment | 8 complexity | 27ffc2e8eb068865067e31a7aaff645a MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, GPL-3.0
  1. require 'testutil'
  2. require 'util'
  3. require 'test/unit'
  4. require 'openid/fetchers'
  5. require 'openid/yadis/discovery'
  6. require 'openid/consumer/discovery'
  7. require 'openid/yadis/xrires'
  8. require 'openid/yadis/xri'
  9. require 'openid/message'
  10. require 'openid/util'
  11. ### Tests for conditions that trigger DiscoveryFailure
  12. module OpenID
  13. class SimpleMockFetcher
  14. def initialize(test, responses)
  15. @test = test
  16. @responses = responses.dup
  17. end
  18. def fetch(url, body=nil, headers=nil, limit=nil)
  19. response = @responses.shift
  20. @test.assert(body.nil?)
  21. @test.assert_equal(response.final_url, url)
  22. return response
  23. end
  24. end
  25. class TestDiscoveryFailure < Test::Unit::TestCase
  26. def initialize(*args)
  27. super(*args)
  28. @responses = [
  29. [HTTPResponse._from_raw_data(nil, nil, {}, 'http://network.error/')],
  30. [HTTPResponse._from_raw_data(404, nil, {}, 'http://not.found/')],
  31. [HTTPResponse._from_raw_data(400, nil, {}, 'http://bad.request/')],
  32. [HTTPResponse._from_raw_data(500, nil, {}, 'http://server.error/')],
  33. [HTTPResponse._from_raw_data(200, nil, {'x-xrds-location' => 'http://xrds.missing/'},
  34. 'http://header.found/'),
  35. HTTPResponse._from_raw_data(404, nil, {}, 'http://xrds.missing/')],
  36. ]
  37. end
  38. def test_discovery_failure
  39. @responses.each { |response_set|
  40. @url = response_set[0].final_url
  41. OpenID.fetcher = SimpleMockFetcher.new(self, response_set)
  42. expected_status = response_set[-1].code
  43. begin
  44. OpenID.discover(@url)
  45. rescue DiscoveryFailure => why
  46. assert_equal(why.http_response.code, expected_status)
  47. else
  48. flunk('Did not raise DiscoveryFailure')
  49. end
  50. OpenID.fetcher = nil
  51. }
  52. end
  53. end
  54. ### Tests for raising/catching exceptions from the fetcher through
  55. ### the discover function
  56. class ErrorRaisingFetcher
  57. # Just raise an exception when fetch is called
  58. def initialize(thing_to_raise)
  59. @thing_to_raise = thing_to_raise
  60. end
  61. def fetch(url, body=nil, headers=nil, limit=nil)
  62. raise @thing_to_raise
  63. end
  64. end
  65. class DidFetch < Exception
  66. # Custom exception just to make sure it's not handled differently
  67. end
  68. class TestFetchException < Test::Unit::TestCase
  69. # Discovery should only raise DiscoveryFailure
  70. def initialize(*args)
  71. super(*args)
  72. @cases = [
  73. DidFetch.new(),
  74. Exception.new(),
  75. ArgumentError.new(),
  76. RuntimeError.new(),
  77. ]
  78. end
  79. def test_fetch_exception
  80. @cases.each { |exc|
  81. OpenID.fetcher = ErrorRaisingFetcher.new(exc)
  82. assert_raises(DiscoveryFailure) {
  83. OpenID.discover('http://doesnt.matter/')
  84. }
  85. OpenID.fetcher = nil
  86. }
  87. end
  88. end
  89. ### Tests for openid.consumer.discover.discover
  90. class TestNormalization < Test::Unit::TestCase
  91. def test_addingProtocol
  92. f = ErrorRaisingFetcher.new(RuntimeError.new())
  93. OpenID.fetcher = f
  94. begin
  95. OpenID.discover('users.stompy.janrain.com:8000/x')
  96. rescue DiscoveryFailure => why
  97. assert why.to_s.match("Failed to fetch")
  98. rescue RuntimeError
  99. end
  100. OpenID.fetcher = nil
  101. end
  102. end
  103. class DiscoveryMockFetcher
  104. def initialize(documents)
  105. @redirect = nil
  106. @documents = documents
  107. @fetchlog = []
  108. end
  109. def fetch(url, body=nil, headers=nil, limit=nil)
  110. @fetchlog << [url, body, headers]
  111. if @redirect
  112. final_url = @redirect
  113. else
  114. final_url = url
  115. end
  116. begin
  117. ctype, body = @documents.fetch(url)
  118. rescue IndexError
  119. status = 404
  120. ctype = 'text/plain'
  121. body = ''
  122. else
  123. status = 200
  124. end
  125. return HTTPResponse._from_raw_data(status, body, {'content-type' => ctype}, final_url)
  126. end
  127. end
  128. class BaseTestDiscovery < Test::Unit::TestCase
  129. attr_accessor :id_url, :fetcher_class
  130. def initialize(*args)
  131. super(*args)
  132. @id_url = "http://someuser.unittest/"
  133. @documents = {}
  134. @fetcher_class = DiscoveryMockFetcher
  135. end
  136. def _checkService(s, server_url, claimed_id=nil,
  137. local_id=nil, canonical_id=nil,
  138. types=nil, used_yadis=false,
  139. display_identifier=nil)
  140. assert_equal(server_url, s.server_url)
  141. if types == ['2.0 OP']
  142. assert(!claimed_id)
  143. assert(!local_id)
  144. assert(!s.claimed_id)
  145. assert(!s.local_id)
  146. assert(!s.get_local_id())
  147. assert(!s.compatibility_mode())
  148. assert(s.is_op_identifier())
  149. assert_equal(s.preferred_namespace(),
  150. OPENID_2_0_MESSAGE_NS)
  151. else
  152. assert_equal(claimed_id, s.claimed_id)
  153. assert_equal(local_id, s.get_local_id())
  154. end
  155. if used_yadis
  156. assert(s.used_yadis, "Expected to use Yadis")
  157. else
  158. assert(!s.used_yadis,
  159. "Expected to use old-style discovery")
  160. end
  161. openid_types = {
  162. '1.1' => OPENID_1_1_TYPE,
  163. '1.0' => OPENID_1_0_TYPE,
  164. '2.0' => OPENID_2_0_TYPE,
  165. '2.0 OP' => OPENID_IDP_2_0_TYPE,
  166. }
  167. type_uris = types.collect { |t| openid_types[t] }
  168. assert_equal(type_uris, s.type_uris)
  169. assert_equal(canonical_id, s.canonical_id)
  170. if canonical_id.nil?
  171. assert_equal(claimed_id, s.display_identifier)
  172. else
  173. assert_equal(display_identifier, s.display_identifier)
  174. end
  175. end
  176. def setup
  177. # @documents = @documents.dup
  178. @fetcher = @fetcher_class.new(@documents)
  179. OpenID.fetcher = @fetcher
  180. end
  181. def teardown
  182. OpenID.fetcher = nil
  183. end
  184. def test_blank
  185. # XXX to avoid > 0 test requirement
  186. end
  187. end
  188. # def readDataFile(filename):
  189. # module_directory = os.path.dirname(os.path.abspath(__file__))
  190. # filename = os.path.join(
  191. # module_directory, 'data', 'test_discover', filename)
  192. # return file(filename).read()
  193. class TestDiscovery < BaseTestDiscovery
  194. include TestDataMixin
  195. def _discover(content_type, data,
  196. expected_services, expected_id=nil)
  197. if expected_id.nil?
  198. expected_id = @id_url
  199. end
  200. @documents[@id_url] = [content_type, data]
  201. id_url, services = OpenID.discover(@id_url)
  202. assert_equal(expected_services, services.length)
  203. assert_equal(expected_id, id_url)
  204. return services
  205. end
  206. def test_404
  207. assert_raise(DiscoveryFailure) {
  208. OpenID.discover(@id_url + '/404')
  209. }
  210. end
  211. def test_noOpenID
  212. services = _discover('text/plain',
  213. "junk", 0)
  214. services = _discover(
  215. 'text/html',
  216. read_data_file('test_discover/openid_no_delegate.html', false),
  217. 1)
  218. _checkService(
  219. services[0],
  220. "http://www.myopenid.com/server",
  221. @id_url,
  222. @id_url,
  223. nil,
  224. ['1.1'],
  225. false)
  226. end
  227. def test_malformed_meta_tag
  228. @id_url = "http://user.myopenid.com/"
  229. services = _discover(
  230. 'text/html',
  231. read_data_file('test_discover/malformed_meta_tag.html', false),
  232. 2)
  233. _checkService(
  234. services[0],
  235. "http://www.myopenid.com/server",
  236. @id_url,
  237. @id_url,
  238. nil,
  239. ['2.0'],
  240. false)
  241. _checkService(
  242. services[1],
  243. "http://www.myopenid.com/server",
  244. @id_url,
  245. @id_url,
  246. nil,
  247. ['1.1'],
  248. false)
  249. end
  250. def test_html1
  251. services = _discover('text/html',
  252. read_data_file('test_discover/openid.html', false),
  253. 1)
  254. _checkService(services[0],
  255. "http://www.myopenid.com/server",
  256. @id_url,
  257. 'http://smoker.myopenid.com/',
  258. nil,
  259. ['1.1'],
  260. false)
  261. end
  262. def test_html1Fragment
  263. # Ensure that the Claimed Identifier does not have a fragment if
  264. # one is supplied in the User Input.
  265. content_type = 'text/html'
  266. data = read_data_file('test_discover/openid.html', false)
  267. expected_services = 1
  268. @documents[@id_url] = [content_type, data]
  269. expected_id = @id_url
  270. @id_url = @id_url + '#fragment'
  271. id_url, services = OpenID.discover(@id_url)
  272. assert_equal(expected_services, services.length)
  273. assert_equal(expected_id, id_url)
  274. _checkService(services[0],
  275. "http://www.myopenid.com/server",
  276. expected_id,
  277. 'http://smoker.myopenid.com/',
  278. nil,
  279. ['1.1'],
  280. false)
  281. end
  282. def test_html2
  283. services = _discover('text/html',
  284. read_data_file('test_discover/openid2.html', false),
  285. 1)
  286. _checkService(services[0],
  287. "http://www.myopenid.com/server",
  288. @id_url,
  289. 'http://smoker.myopenid.com/',
  290. nil,
  291. ['2.0'],
  292. false)
  293. end
  294. def test_html1And2
  295. services = _discover(
  296. 'text/html',
  297. read_data_file('test_discover/openid_1_and_2.html', false),
  298. 2)
  299. services.zip(['2.0', '1.1']).each { |s, t|
  300. _checkService(s,
  301. "http://www.myopenid.com/server",
  302. @id_url,
  303. 'http://smoker.myopenid.com/',
  304. nil,
  305. [t],
  306. false)
  307. }
  308. end
  309. def test_yadisEmpty
  310. services = _discover('application/xrds+xml',
  311. read_data_file('test_discover/yadis_0entries.xml', false),
  312. 0)
  313. end
  314. def test_htmlEmptyYadis
  315. # HTML document has discovery information, but points to an
  316. # empty Yadis document. The XRDS document pointed to by
  317. # "openid_and_yadis.html"
  318. @documents[@id_url + 'xrds'] = ['application/xrds+xml',
  319. read_data_file('test_discover/yadis_0entries.xml', false)]
  320. services = _discover('text/html',
  321. read_data_file('test_discover/openid_and_yadis.html', false),
  322. 1)
  323. _checkService(services[0],
  324. "http://www.myopenid.com/server",
  325. @id_url,
  326. 'http://smoker.myopenid.com/',
  327. nil,
  328. ['1.1'],
  329. false)
  330. end
  331. def test_yadis1NoDelegate
  332. services = _discover('application/xrds+xml',
  333. read_data_file('test_discover/yadis_no_delegate.xml', false),
  334. 1)
  335. _checkService(services[0],
  336. "http://www.myopenid.com/server",
  337. @id_url,
  338. @id_url,
  339. nil,
  340. ['1.0'],
  341. true)
  342. end
  343. def test_yadis2NoLocalID
  344. services = _discover('application/xrds+xml',
  345. read_data_file('test_discover/openid2_xrds_no_local_id.xml', false),
  346. 1)
  347. _checkService(services[0],
  348. "http://www.myopenid.com/server",
  349. @id_url,
  350. @id_url,
  351. nil,
  352. ['2.0'],
  353. true)
  354. end
  355. def test_yadis2
  356. services = _discover('application/xrds+xml',
  357. read_data_file('test_discover/openid2_xrds.xml', false),
  358. 1)
  359. _checkService(services[0],
  360. "http://www.myopenid.com/server",
  361. @id_url,
  362. 'http://smoker.myopenid.com/',
  363. nil,
  364. ['2.0'],
  365. true)
  366. end
  367. def test_yadis2OP
  368. services = _discover('application/xrds+xml',
  369. read_data_file('test_discover/yadis_idp.xml', false),
  370. 1)
  371. _checkService(services[0],
  372. "http://www.myopenid.com/server",
  373. nil, nil, nil,
  374. ['2.0 OP'],
  375. true)
  376. end
  377. def test_yadis2OPDelegate
  378. # The delegate tag isn't meaningful for OP entries.
  379. services = _discover('application/xrds+xml',
  380. read_data_file('test_discover/yadis_idp_delegate.xml', false),
  381. 1)
  382. _checkService(services[0],
  383. "http://www.myopenid.com/server",
  384. nil, nil, nil,
  385. ['2.0 OP'],
  386. true)
  387. end
  388. def test_yadis2BadLocalID
  389. assert_raise(DiscoveryFailure) {
  390. _discover('application/xrds+xml',
  391. read_data_file('test_discover/yadis_2_bad_local_id.xml', false),
  392. 1)
  393. }
  394. end
  395. def test_yadis1And2
  396. services = _discover('application/xrds+xml',
  397. read_data_file('test_discover/openid_1_and_2_xrds.xml', false),
  398. 1)
  399. _checkService(services[0],
  400. "http://www.myopenid.com/server",
  401. @id_url,
  402. 'http://smoker.myopenid.com/',
  403. nil,
  404. ['2.0', '1.1'],
  405. true)
  406. end
  407. def test_yadis1And2BadLocalID
  408. assert_raise(DiscoveryFailure) {
  409. _discover('application/xrds+xml',
  410. read_data_file('test_discover/openid_1_and_2_xrds_bad_delegate.xml', false),
  411. 1)
  412. }
  413. end
  414. end
  415. class MockFetcherForXRIProxy
  416. def initialize(documents, proxy_url=Yadis::XRI::ProxyResolver::DEFAULT_PROXY)
  417. @documents = documents
  418. @fetchlog = []
  419. @proxy_url = nil
  420. end
  421. def fetch(url, body=nil, headers=nil, limit=nil)
  422. @fetchlog << [url, body, headers]
  423. u = URI::parse(url)
  424. proxy_host = u.host
  425. xri = u.path
  426. query = u.query
  427. if !headers and !query
  428. raise ArgumentError.new("No headers or query; you probably didn't " +
  429. "mean to do that.")
  430. end
  431. if xri.starts_with?('/')
  432. xri = xri[1..-1]
  433. end
  434. begin
  435. ctype, body = @documents.fetch(xri)
  436. rescue IndexError
  437. status = 404
  438. ctype = 'text/plain'
  439. body = ''
  440. else
  441. status = 200
  442. end
  443. return HTTPResponse._from_raw_data(status, body,
  444. {'content-type' => ctype}, url)
  445. end
  446. end
  447. class TestXRIDiscovery < BaseTestDiscovery
  448. include TestDataMixin
  449. include TestUtil
  450. def initialize(*args)
  451. super(*args)
  452. @fetcher_class = MockFetcherForXRIProxy
  453. @documents = {'=smoker' => ['application/xrds+xml',
  454. read_data_file('test_discover/yadis_2entries_delegate.xml', false)],
  455. '=smoker*bad' => ['application/xrds+xml',
  456. read_data_file('test_discover/yadis_another_delegate.xml', false)]}
  457. end
  458. def test_xri
  459. user_xri, services = OpenID.discover_xri('=smoker')
  460. _checkService(services[0],
  461. "http://www.myopenid.com/server",
  462. Yadis::XRI.make_xri("=!1000"),
  463. 'http://smoker.myopenid.com/',
  464. Yadis::XRI.make_xri("=!1000"),
  465. ['1.0'],
  466. true,
  467. '=smoker')
  468. _checkService(services[1],
  469. "http://www.livejournal.com/openid/server.bml",
  470. Yadis::XRI.make_xri("=!1000"),
  471. 'http://frank.livejournal.com/',
  472. Yadis::XRI.make_xri("=!1000"),
  473. ['1.0'],
  474. true,
  475. '=smoker')
  476. end
  477. def test_xri_normalize
  478. user_xri, services = OpenID.discover_xri('xri://=smoker')
  479. _checkService(services[0],
  480. "http://www.myopenid.com/server",
  481. Yadis::XRI.make_xri("=!1000"),
  482. 'http://smoker.myopenid.com/',
  483. Yadis::XRI.make_xri("=!1000"),
  484. ['1.0'],
  485. true,
  486. '=smoker')
  487. _checkService(services[1],
  488. "http://www.livejournal.com/openid/server.bml",
  489. Yadis::XRI.make_xri("=!1000"),
  490. 'http://frank.livejournal.com/',
  491. Yadis::XRI.make_xri("=!1000"),
  492. ['1.0'],
  493. true,
  494. '=smoker')
  495. end
  496. def test_xriNoCanonicalID
  497. silence_logging {
  498. user_xri, services = OpenID.discover_xri('=smoker*bad')
  499. assert(services.empty?)
  500. }
  501. end
  502. def test_useCanonicalID
  503. # When there is no delegate, the CanonicalID should be used with
  504. # XRI.
  505. endpoint = OpenIDServiceEndpoint.new()
  506. endpoint.claimed_id = Yadis::XRI.make_xri("=!1000")
  507. endpoint.canonical_id = Yadis::XRI.make_xri("=!1000")
  508. assert_equal(endpoint.get_local_id, Yadis::XRI.make_xri("=!1000"))
  509. end
  510. end
  511. class TestXRIDiscoveryIDP < BaseTestDiscovery
  512. include TestDataMixin
  513. def initialize(*args)
  514. super(*args)
  515. @fetcher_class = MockFetcherForXRIProxy
  516. @documents = {'=smoker' => ['application/xrds+xml',
  517. read_data_file('test_discover/yadis_2entries_idp.xml', false)] }
  518. end
  519. def test_xri
  520. user_xri, services = OpenID.discover_xri('=smoker')
  521. assert(!services.empty?, "Expected services, got zero")
  522. assert_equal(services[0].server_url,
  523. "http://www.livejournal.com/openid/server.bml")
  524. end
  525. end
  526. class TestPreferredNamespace < Test::Unit::TestCase
  527. def initialize(*args)
  528. super(*args)
  529. @cases = [
  530. [OPENID1_NS, []],
  531. [OPENID1_NS, ['http://jyte.com/']],
  532. [OPENID1_NS, [OPENID_1_0_TYPE]],
  533. [OPENID1_NS, [OPENID_1_1_TYPE]],
  534. [OPENID2_NS, [OPENID_2_0_TYPE]],
  535. [OPENID2_NS, [OPENID_IDP_2_0_TYPE]],
  536. [OPENID2_NS, [OPENID_2_0_TYPE,
  537. OPENID_1_0_TYPE]],
  538. [OPENID2_NS, [OPENID_1_0_TYPE,
  539. OPENID_2_0_TYPE]],
  540. ]
  541. end
  542. def test_preferred_namespace
  543. @cases.each { |expected_ns, type_uris|
  544. endpoint = OpenIDServiceEndpoint.new()
  545. endpoint.type_uris = type_uris
  546. actual_ns = endpoint.preferred_namespace()
  547. assert_equal(actual_ns, expected_ns)
  548. }
  549. end
  550. end
  551. class TestIsOPIdentifier < Test::Unit::TestCase
  552. def setup
  553. @endpoint = OpenIDServiceEndpoint.new()
  554. end
  555. def test_none
  556. assert(!@endpoint.is_op_identifier())
  557. end
  558. def test_openid1_0
  559. @endpoint.type_uris = [OPENID_1_0_TYPE]
  560. assert(!@endpoint.is_op_identifier())
  561. end
  562. def test_openid1_1
  563. @endpoint.type_uris = [OPENID_1_1_TYPE]
  564. assert(!@endpoint.is_op_identifier())
  565. end
  566. def test_openid2
  567. @endpoint.type_uris = [OPENID_2_0_TYPE]
  568. assert(!@endpoint.is_op_identifier())
  569. end
  570. def test_openid2OP
  571. @endpoint.type_uris = [OPENID_IDP_2_0_TYPE]
  572. assert(@endpoint.is_op_identifier())
  573. end
  574. def test_multipleMissing
  575. @endpoint.type_uris = [OPENID_2_0_TYPE,
  576. OPENID_1_0_TYPE]
  577. assert(!@endpoint.is_op_identifier())
  578. end
  579. def test_multiplePresent
  580. @endpoint.type_uris = [OPENID_2_0_TYPE,
  581. OPENID_1_0_TYPE,
  582. OPENID_IDP_2_0_TYPE]
  583. assert(@endpoint.is_op_identifier())
  584. end
  585. end
  586. class TestFromOPEndpointURL < Test::Unit::TestCase
  587. def setup
  588. @op_endpoint_url = 'http://example.com/op/endpoint'
  589. @endpoint = OpenIDServiceEndpoint.from_op_endpoint_url(@op_endpoint_url)
  590. end
  591. def test_isOPEndpoint
  592. assert(@endpoint.is_op_identifier())
  593. end
  594. def test_noIdentifiers
  595. assert_equal(@endpoint.get_local_id, nil)
  596. assert_equal(@endpoint.claimed_id, nil)
  597. end
  598. def test_compatibility
  599. assert(!@endpoint.compatibility_mode())
  600. end
  601. def test_canonical_id
  602. assert_equal(@endpoint.canonical_id, nil)
  603. end
  604. def test_serverURL
  605. assert_equal(@endpoint.server_url, @op_endpoint_url)
  606. end
  607. end
  608. class TestDiscoverFunction < Test::Unit::TestCase
  609. def test_discover_function
  610. # XXX these were all different tests in python, but they're
  611. # combined here so I only have to use with_method_overridden
  612. # once.
  613. discoverXRI = Proc.new { |identifier|
  614. return 'XRI'
  615. }
  616. discoverURI = Proc.new { |identifier|
  617. return 'URI'
  618. }
  619. OpenID.extend(OverrideMethodMixin)
  620. OpenID.with_method_overridden(:discover_uri, discoverURI) do
  621. OpenID.with_method_overridden(:discover_xri, discoverXRI) do
  622. assert_equal('URI', OpenID.discover('http://woo!'))
  623. assert_equal('URI', OpenID.discover('not a URL or XRI'))
  624. assert_equal('XRI', OpenID.discover('xri://=something'))
  625. assert_equal('XRI', OpenID.discover('=something'))
  626. end
  627. end
  628. end
  629. end
  630. class TestEndpointSupportsType < Test::Unit::TestCase
  631. def setup
  632. @endpoint = OpenIDServiceEndpoint.new()
  633. end
  634. def failUnlessSupportsOnly(*types)
  635. ['foo',
  636. OPENID_1_1_TYPE,
  637. OPENID_1_0_TYPE,
  638. OPENID_2_0_TYPE,
  639. OPENID_IDP_2_0_TYPE].each { |t|
  640. if types.member?(t)
  641. assert(@endpoint.supports_type(t),
  642. sprintf("Must support %s", t))
  643. else
  644. assert(!@endpoint.supports_type(t),
  645. sprintf("Shouldn't support %s", t))
  646. end
  647. }
  648. end
  649. def test_supportsNothing
  650. failUnlessSupportsOnly()
  651. end
  652. def test_openid2
  653. @endpoint.type_uris = [OPENID_2_0_TYPE]
  654. failUnlessSupportsOnly(OPENID_2_0_TYPE)
  655. end
  656. def test_openid2provider
  657. @endpoint.type_uris = [OPENID_IDP_2_0_TYPE]
  658. failUnlessSupportsOnly(OPENID_IDP_2_0_TYPE,
  659. OPENID_2_0_TYPE)
  660. end
  661. def test_openid1_0
  662. @endpoint.type_uris = [OPENID_1_0_TYPE]
  663. failUnlessSupportsOnly(OPENID_1_0_TYPE)
  664. end
  665. def test_openid1_1
  666. @endpoint.type_uris = [OPENID_1_1_TYPE]
  667. failUnlessSupportsOnly(OPENID_1_1_TYPE)
  668. end
  669. def test_multiple
  670. @endpoint.type_uris = [OPENID_1_1_TYPE,
  671. OPENID_2_0_TYPE]
  672. failUnlessSupportsOnly(OPENID_1_1_TYPE,
  673. OPENID_2_0_TYPE)
  674. end
  675. def test_multipleWithProvider
  676. @endpoint.type_uris = [OPENID_1_1_TYPE,
  677. OPENID_2_0_TYPE,
  678. OPENID_IDP_2_0_TYPE]
  679. failUnlessSupportsOnly(OPENID_1_1_TYPE,
  680. OPENID_2_0_TYPE,
  681. OPENID_IDP_2_0_TYPE)
  682. end
  683. end
  684. class TestEndpointDisplayIdentifier < Test::Unit::TestCase
  685. def test_strip_fragment
  686. @endpoint = OpenIDServiceEndpoint.new()
  687. @endpoint.claimed_id = 'http://recycled.invalid/#123'
  688. assert_equal 'http://recycled.invalid/', @endpoint.display_identifier
  689. end
  690. end
  691. class TestNormalizeURL < Test::Unit::TestCase
  692. def test_no_host
  693. assert_raise(DiscoveryFailure) {
  694. OpenID::normalize_url('http:///too-many.invalid/slashes')
  695. }
  696. end
  697. end
  698. end