forked from openid/python-openid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_discover.py
783 lines (639 loc) · 25.9 KB
/
test_discover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
import sys
import unittest
import datadriven
import os.path
from openid import fetchers
from openid.fetchers import HTTPResponse
from openid.yadis.discover import DiscoveryFailure
from openid.consumer import discover
from openid.yadis import xrires
from openid.yadis.xri import XRI
from urlparse import urlsplit
from openid import message
### Tests for conditions that trigger DiscoveryFailure
class SimpleMockFetcher(object):
def __init__(self, responses):
self.responses = list(responses)
def fetch(self, url, body=None, headers=None):
response = self.responses.pop(0)
assert body is None
assert response.final_url == url
return response
class TestDiscoveryFailure(datadriven.DataDrivenTestCase):
cases = [
[HTTPResponse('http://network.error/', None)],
[HTTPResponse('http://not.found/', 404)],
[HTTPResponse('http://bad.request/', 400)],
[HTTPResponse('http://server.error/', 500)],
[HTTPResponse('http://header.found/', 200,
headers={'x-xrds-location':'http://xrds.missing/'}),
HTTPResponse('http://xrds.missing/', 404)],
]
def __init__(self, responses):
self.url = responses[0].final_url
datadriven.DataDrivenTestCase.__init__(self, self.url)
self.responses = responses
def setUp(self):
fetcher = SimpleMockFetcher(self.responses)
fetchers.setDefaultFetcher(fetcher)
def tearDown(self):
fetchers.setDefaultFetcher(None)
def runOneTest(self):
expected_status = self.responses[-1].status
try:
discover.discover(self.url)
except DiscoveryFailure, why:
self.failUnlessEqual(why.http_response.status, expected_status)
else:
self.fail('Did not raise DiscoveryFailure')
### Tests for raising/catching exceptions from the fetcher through the
### discover function
# Python 2.5 displays a message when running this test, which is
# testing the behaviour in the presence of string exceptions,
# deprecated or not, so tell it no to complain when this particular
# string exception is raised.
import warnings
warnings.filterwarnings('ignore', 'raising a string.*', DeprecationWarning,
r'^openid\.test\.test_discover$', 77)
class ErrorRaisingFetcher(object):
"""Just raise an exception when fetch is called"""
def __init__(self, thing_to_raise):
self.thing_to_raise = thing_to_raise
def fetch(self, url, body=None, headers=None):
raise self.thing_to_raise
class DidFetch(Exception):
"""Custom exception just to make sure it's not handled differently"""
class TestFetchException(datadriven.DataDrivenTestCase):
"""Make sure exceptions get passed through discover function from
fetcher."""
cases = [
Exception(),
DidFetch(),
ValueError(),
RuntimeError(),
]
# String exceptions are finally gone from Python 2.6.
if sys.version_info[:2] < (2, 6):
cases.append('oi!')
def __init__(self, exc):
datadriven.DataDrivenTestCase.__init__(self, repr(exc))
self.exc = exc
def setUp(self):
fetcher = ErrorRaisingFetcher(self.exc)
fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False)
def tearDown(self):
fetchers.setDefaultFetcher(None)
def runOneTest(self):
try:
discover.discover('http://doesnt.matter/')
except:
exc = sys.exc_info()[1]
if exc is None:
# str exception
self.failUnless(self.exc is sys.exc_info()[0])
else:
self.failUnless(self.exc is exc, exc)
else:
self.fail('Expected %r', self.exc)
### Tests for openid.consumer.discover.discover
class TestNormalization(unittest.TestCase):
def testAddingProtocol(self):
f = ErrorRaisingFetcher(RuntimeError())
fetchers.setDefaultFetcher(f, wrap_exceptions=False)
try:
discover.discover('users.stompy.janrain.com:8000/x')
except DiscoveryFailure, why:
self.fail('failed to parse url with port correctly')
except RuntimeError:
pass #expected
fetchers.setDefaultFetcher(None)
class DiscoveryMockFetcher(object):
redirect = None
def __init__(self, documents):
self.documents = documents
self.fetchlog = []
def fetch(self, url, body=None, headers=None):
self.fetchlog.append((url, body, headers))
if self.redirect:
final_url = self.redirect
else:
final_url = url
try:
ctype, body = self.documents[url]
except KeyError:
status = 404
ctype = 'text/plain'
body = ''
else:
status = 200
return HTTPResponse(final_url, status, {'content-type': ctype}, body)
# from twisted.trial import unittest as trialtest
class BaseTestDiscovery(unittest.TestCase):
id_url = "http://someuser.unittest/"
documents = {}
fetcherClass = DiscoveryMockFetcher
def _checkService(self, s,
server_url,
claimed_id=None,
local_id=None,
canonical_id=None,
types=None,
used_yadis=False,
display_identifier=None
):
self.failUnlessEqual(server_url, s.server_url)
if types == ['2.0 OP']:
self.failIf(claimed_id)
self.failIf(local_id)
self.failIf(s.claimed_id)
self.failIf(s.local_id)
self.failIf(s.getLocalID())
self.failIf(s.compatibilityMode())
self.failUnless(s.isOPIdentifier())
self.failUnlessEqual(s.preferredNamespace(),
discover.OPENID_2_0_MESSAGE_NS)
else:
self.failUnlessEqual(claimed_id, s.claimed_id)
self.failUnlessEqual(local_id, s.getLocalID())
if used_yadis:
self.failUnless(s.used_yadis, "Expected to use Yadis")
else:
self.failIf(s.used_yadis,
"Expected to use old-style discovery")
openid_types = {
'1.1': discover.OPENID_1_1_TYPE,
'1.0': discover.OPENID_1_0_TYPE,
'2.0': discover.OPENID_2_0_TYPE,
'2.0 OP': discover.OPENID_IDP_2_0_TYPE,
}
type_uris = [openid_types[t] for t in types]
self.failUnlessEqual(type_uris, s.type_uris)
self.failUnlessEqual(canonical_id, s.canonicalID)
if s.canonicalID:
self.failUnless(s.getDisplayIdentifier() != claimed_id)
self.failUnless(s.getDisplayIdentifier() is not None)
self.failUnlessEqual(display_identifier, s.getDisplayIdentifier())
self.failUnlessEqual(s.claimed_id, s.canonicalID)
self.failUnlessEqual(s.display_identifier or s.claimed_id, s.getDisplayIdentifier())
def setUp(self):
self.documents = self.documents.copy()
self.fetcher = self.fetcherClass(self.documents)
fetchers.setDefaultFetcher(self.fetcher)
def tearDown(self):
fetchers.setDefaultFetcher(None)
def readDataFile(filename):
module_directory = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(
module_directory, 'data', 'test_discover', filename)
return file(filename).read()
class TestDiscovery(BaseTestDiscovery):
def _discover(self, content_type, data,
expected_services, expected_id=None):
if expected_id is None:
expected_id = self.id_url
self.documents[self.id_url] = (content_type, data)
id_url, services = discover.discover(self.id_url)
self.failUnlessEqual(expected_services, len(services))
self.failUnlessEqual(expected_id, id_url)
return services
def test_404(self):
self.failUnlessRaises(DiscoveryFailure,
discover.discover, self.id_url + '/404')
def test_noOpenID(self):
services = self._discover(content_type='text/plain',
data="junk",
expected_services=0)
services = self._discover(
content_type='text/html',
data=readDataFile('openid_no_delegate.html'),
expected_services=1,
)
self._checkService(
services[0],
used_yadis=False,
types=['1.1'],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id=self.id_url,
)
def test_html1(self):
services = self._discover(
content_type='text/html',
data=readDataFile('openid.html'),
expected_services=1)
self._checkService(
services[0],
used_yadis=False,
types=['1.1'],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id='http://smoker.myopenid.com/',
display_identifier=self.id_url,
)
def test_html1Fragment(self):
"""Ensure that the Claimed Identifier does not have a fragment
if one is supplied in the User Input."""
content_type = 'text/html'
data = readDataFile('openid.html')
expected_services = 1
self.documents[self.id_url] = (content_type, data)
expected_id = self.id_url
self.id_url = self.id_url + '#fragment'
id_url, services = discover.discover(self.id_url)
self.failUnlessEqual(expected_services, len(services))
self.failUnlessEqual(expected_id, id_url)
self._checkService(
services[0],
used_yadis=False,
types=['1.1'],
server_url="http://www.myopenid.com/server",
claimed_id=expected_id,
local_id='http://smoker.myopenid.com/',
display_identifier=expected_id,
)
def test_html2(self):
services = self._discover(
content_type='text/html',
data=readDataFile('openid2.html'),
expected_services=1,
)
self._checkService(
services[0],
used_yadis=False,
types=['2.0'],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id='http://smoker.myopenid.com/',
display_identifier=self.id_url,
)
def test_html1And2(self):
services = self._discover(
content_type='text/html',
data=readDataFile('openid_1_and_2.html'),
expected_services=2,
)
for t, s in zip(['2.0', '1.1'], services):
self._checkService(
s,
used_yadis=False,
types=[t],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id='http://smoker.myopenid.com/',
display_identifier=self.id_url,
)
def test_yadisEmpty(self):
services = self._discover(content_type='application/xrds+xml',
data=readDataFile('yadis_0entries.xml'),
expected_services=0)
def test_htmlEmptyYadis(self):
"""HTML document has discovery information, but points to an
empty Yadis document."""
# The XRDS document pointed to by "openid_and_yadis.html"
self.documents[self.id_url + 'xrds'] = (
'application/xrds+xml', readDataFile('yadis_0entries.xml'))
services = self._discover(content_type='text/html',
data=readDataFile('openid_and_yadis.html'),
expected_services=1)
self._checkService(
services[0],
used_yadis=False,
types=['1.1'],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id='http://smoker.myopenid.com/',
display_identifier=self.id_url,
)
def test_yadis1NoDelegate(self):
services = self._discover(content_type='application/xrds+xml',
data=readDataFile('yadis_no_delegate.xml'),
expected_services=1)
self._checkService(
services[0],
used_yadis=True,
types=['1.0'],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id=self.id_url,
display_identifier=self.id_url,
)
def test_yadis2NoLocalID(self):
services = self._discover(
content_type='application/xrds+xml',
data=readDataFile('openid2_xrds_no_local_id.xml'),
expected_services=1,
)
self._checkService(
services[0],
used_yadis=True,
types=['2.0'],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id=self.id_url,
display_identifier=self.id_url,
)
def test_yadis2(self):
services = self._discover(
content_type='application/xrds+xml',
data=readDataFile('openid2_xrds.xml'),
expected_services=1,
)
self._checkService(
services[0],
used_yadis=True,
types=['2.0'],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id='http://smoker.myopenid.com/',
display_identifier=self.id_url,
)
def test_yadis2OP(self):
services = self._discover(
content_type='application/xrds+xml',
data=readDataFile('yadis_idp.xml'),
expected_services=1,
)
self._checkService(
services[0],
used_yadis=True,
types=['2.0 OP'],
server_url="http://www.myopenid.com/server",
display_identifier=self.id_url,
)
def test_yadis2OPDelegate(self):
"""The delegate tag isn't meaningful for OP entries."""
services = self._discover(
content_type='application/xrds+xml',
data=readDataFile('yadis_idp_delegate.xml'),
expected_services=1,
)
self._checkService(
services[0],
used_yadis=True,
types=['2.0 OP'],
server_url="http://www.myopenid.com/server",
display_identifier=self.id_url,
)
def test_yadis2BadLocalID(self):
self.failUnlessRaises(DiscoveryFailure, self._discover,
content_type='application/xrds+xml',
data=readDataFile('yadis_2_bad_local_id.xml'),
expected_services=1,
)
def test_yadis1And2(self):
services = self._discover(
content_type='application/xrds+xml',
data=readDataFile('openid_1_and_2_xrds.xml'),
expected_services=1,
)
self._checkService(
services[0],
used_yadis=True,
types=['2.0', '1.1'],
server_url="http://www.myopenid.com/server",
claimed_id=self.id_url,
local_id='http://smoker.myopenid.com/',
display_identifier=self.id_url,
)
def test_yadis1And2BadLocalID(self):
self.failUnlessRaises(DiscoveryFailure, self._discover,
content_type='application/xrds+xml',
data=readDataFile('openid_1_and_2_xrds_bad_delegate.xml'),
expected_services=1,
)
class MockFetcherForXRIProxy(object):
def __init__(self, documents, proxy_url=xrires.DEFAULT_PROXY):
self.documents = documents
self.fetchlog = []
self.proxy_url = None
def fetch(self, url, body=None, headers=None):
self.fetchlog.append((url, body, headers))
u = urlsplit(url)
proxy_host = u[1]
xri = u[2]
query = u[3]
if not headers and not query:
raise ValueError("No headers or query; you probably didn't "
"mean to do that.")
if xri.startswith('/'):
xri = xri[1:]
try:
ctype, body = self.documents[xri]
except KeyError:
status = 404
ctype = 'text/plain'
body = ''
else:
status = 200
return HTTPResponse(url, status, {'content-type': ctype}, body)
class TestXRIDiscovery(BaseTestDiscovery):
fetcherClass = MockFetcherForXRIProxy
documents = {'=smoker': ('application/xrds+xml',
readDataFile('yadis_2entries_delegate.xml')),
'=smoker*bad': ('application/xrds+xml',
readDataFile('yadis_another_delegate.xml')) }
def test_xri(self):
user_xri, services = discover.discoverXRI('=smoker')
self._checkService(
services[0],
used_yadis=True,
types=['1.0'],
server_url="http://www.myopenid.com/server",
claimed_id=XRI("=!1000"),
canonical_id=XRI("=!1000"),
local_id='http://smoker.myopenid.com/',
display_identifier='=smoker'
)
self._checkService(
services[1],
used_yadis=True,
types=['1.0'],
server_url="http://www.livejournal.com/openid/server.bml",
claimed_id=XRI("=!1000"),
canonical_id=XRI("=!1000"),
local_id='http://frank.livejournal.com/',
display_identifier='=smoker'
)
def test_xri_normalize(self):
user_xri, services = discover.discoverXRI('xri://=smoker')
self._checkService(
services[0],
used_yadis=True,
types=['1.0'],
server_url="http://www.myopenid.com/server",
claimed_id=XRI("=!1000"),
canonical_id=XRI("=!1000"),
local_id='http://smoker.myopenid.com/',
display_identifier='=smoker'
)
self._checkService(
services[1],
used_yadis=True,
types=['1.0'],
server_url="http://www.livejournal.com/openid/server.bml",
claimed_id=XRI("=!1000"),
canonical_id=XRI("=!1000"),
local_id='http://frank.livejournal.com/',
display_identifier='=smoker'
)
def test_xriNoCanonicalID(self):
user_xri, services = discover.discoverXRI('=smoker*bad')
self.failIf(services)
def test_useCanonicalID(self):
"""When there is no delegate, the CanonicalID should be used with XRI.
"""
endpoint = discover.OpenIDServiceEndpoint()
endpoint.claimed_id = XRI("=!1000")
endpoint.canonicalID = XRI("=!1000")
self.failUnlessEqual(endpoint.getLocalID(), XRI("=!1000"))
class TestXRIDiscoveryIDP(BaseTestDiscovery):
fetcherClass = MockFetcherForXRIProxy
documents = {'=smoker': ('application/xrds+xml',
readDataFile('yadis_2entries_idp.xml')) }
def test_xri(self):
user_xri, services = discover.discoverXRI('=smoker')
self.failUnless(services, "Expected services, got zero")
self.failUnlessEqual(services[0].server_url,
"http://www.livejournal.com/openid/server.bml")
class TestPreferredNamespace(datadriven.DataDrivenTestCase):
def __init__(self, expected_ns, type_uris):
datadriven.DataDrivenTestCase.__init__(
self, 'Expecting %s from %s' % (expected_ns, type_uris))
self.expected_ns = expected_ns
self.type_uris = type_uris
def runOneTest(self):
endpoint = discover.OpenIDServiceEndpoint()
endpoint.type_uris = self.type_uris
actual_ns = endpoint.preferredNamespace()
self.failUnlessEqual(actual_ns, self.expected_ns)
cases = [
(message.OPENID1_NS, []),
(message.OPENID1_NS, ['http://jyte.com/']),
(message.OPENID1_NS, [discover.OPENID_1_0_TYPE]),
(message.OPENID1_NS, [discover.OPENID_1_1_TYPE]),
(message.OPENID2_NS, [discover.OPENID_2_0_TYPE]),
(message.OPENID2_NS, [discover.OPENID_IDP_2_0_TYPE]),
(message.OPENID2_NS, [discover.OPENID_2_0_TYPE,
discover.OPENID_1_0_TYPE]),
(message.OPENID2_NS, [discover.OPENID_1_0_TYPE,
discover.OPENID_2_0_TYPE]),
]
class TestIsOPIdentifier(unittest.TestCase):
def setUp(self):
self.endpoint = discover.OpenIDServiceEndpoint()
def test_none(self):
self.failIf(self.endpoint.isOPIdentifier())
def test_openid1_0(self):
self.endpoint.type_uris = [discover.OPENID_1_0_TYPE]
self.failIf(self.endpoint.isOPIdentifier())
def test_openid1_1(self):
self.endpoint.type_uris = [discover.OPENID_1_1_TYPE]
self.failIf(self.endpoint.isOPIdentifier())
def test_openid2(self):
self.endpoint.type_uris = [discover.OPENID_2_0_TYPE]
self.failIf(self.endpoint.isOPIdentifier())
def test_openid2OP(self):
self.endpoint.type_uris = [discover.OPENID_IDP_2_0_TYPE]
self.failUnless(self.endpoint.isOPIdentifier())
def test_multipleMissing(self):
self.endpoint.type_uris = [discover.OPENID_2_0_TYPE,
discover.OPENID_1_0_TYPE]
self.failIf(self.endpoint.isOPIdentifier())
def test_multiplePresent(self):
self.endpoint.type_uris = [discover.OPENID_2_0_TYPE,
discover.OPENID_1_0_TYPE,
discover.OPENID_IDP_2_0_TYPE]
self.failUnless(self.endpoint.isOPIdentifier())
class TestFromOPEndpointURL(unittest.TestCase):
def setUp(self):
self.op_endpoint_url = 'http://example.com/op/endpoint'
self.endpoint = discover.OpenIDServiceEndpoint.fromOPEndpointURL(
self.op_endpoint_url)
def test_isOPEndpoint(self):
self.failUnless(self.endpoint.isOPIdentifier())
def test_noIdentifiers(self):
self.failUnlessEqual(self.endpoint.getLocalID(), None)
self.failUnlessEqual(self.endpoint.claimed_id, None)
def test_compatibility(self):
self.failIf(self.endpoint.compatibilityMode())
def test_canonicalID(self):
self.failUnlessEqual(self.endpoint.canonicalID, None)
def test_serverURL(self):
self.failUnlessEqual(self.endpoint.server_url, self.op_endpoint_url)
class TestDiscoverFunction(unittest.TestCase):
def setUp(self):
self._old_discoverURI = discover.discoverURI
self._old_discoverXRI = discover.discoverXRI
discover.discoverXRI = self.discoverXRI
discover.discoverURI = self.discoverURI
def tearDown(self):
discover.discoverURI = self._old_discoverURI
discover.discoverXRI = self._old_discoverXRI
def discoverXRI(self, identifier):
return 'XRI'
def discoverURI(self, identifier):
return 'URI'
def test_uri(self):
self.failUnlessEqual('URI', discover.discover('http://woo!'))
def test_uriForBogus(self):
self.failUnlessEqual('URI', discover.discover('not a URL or XRI'))
def test_xri(self):
self.failUnlessEqual('XRI', discover.discover('xri://=something'))
def test_xriChar(self):
self.failUnlessEqual('XRI', discover.discover('=something'))
class TestEndpointSupportsType(unittest.TestCase):
def setUp(self):
self.endpoint = discover.OpenIDServiceEndpoint()
def failUnlessSupportsOnly(self, *types):
for t in [
'foo',
discover.OPENID_1_1_TYPE,
discover.OPENID_1_0_TYPE,
discover.OPENID_2_0_TYPE,
discover.OPENID_IDP_2_0_TYPE,
]:
if t in types:
self.failUnless(self.endpoint.supportsType(t),
"Must support %r" % (t,))
else:
self.failIf(self.endpoint.supportsType(t),
"Shouldn't support %r" % (t,))
def test_supportsNothing(self):
self.failUnlessSupportsOnly()
def test_openid2(self):
self.endpoint.type_uris = [discover.OPENID_2_0_TYPE]
self.failUnlessSupportsOnly(discover.OPENID_2_0_TYPE)
def test_openid2provider(self):
self.endpoint.type_uris = [discover.OPENID_IDP_2_0_TYPE]
self.failUnlessSupportsOnly(discover.OPENID_IDP_2_0_TYPE,
discover.OPENID_2_0_TYPE)
def test_openid1_0(self):
self.endpoint.type_uris = [discover.OPENID_1_0_TYPE]
self.failUnlessSupportsOnly(discover.OPENID_1_0_TYPE)
def test_openid1_1(self):
self.endpoint.type_uris = [discover.OPENID_1_1_TYPE]
self.failUnlessSupportsOnly(discover.OPENID_1_1_TYPE)
def test_multiple(self):
self.endpoint.type_uris = [discover.OPENID_1_1_TYPE,
discover.OPENID_2_0_TYPE]
self.failUnlessSupportsOnly(discover.OPENID_1_1_TYPE,
discover.OPENID_2_0_TYPE)
def test_multipleWithProvider(self):
self.endpoint.type_uris = [discover.OPENID_1_1_TYPE,
discover.OPENID_2_0_TYPE,
discover.OPENID_IDP_2_0_TYPE]
self.failUnlessSupportsOnly(discover.OPENID_1_1_TYPE,
discover.OPENID_2_0_TYPE,
discover.OPENID_IDP_2_0_TYPE,
)
class TestEndpointDisplayIdentifier(unittest.TestCase):
def test_strip_fragment(self):
endpoint = discover.OpenIDServiceEndpoint()
endpoint.claimed_id = 'http://recycled.invalid/#123'
self.failUnlessEqual('http://recycled.invalid/', endpoint.getDisplayIdentifier())
def pyUnitTests():
return datadriven.loadTests(__name__)
if __name__ == '__main__':
suite = pyUnitTests()
runner = unittest.TextTestRunner()
runner.run(suite)