Skip to content

Commit 61206d4

Browse files
author
Josh Hoyt
committed
[project @ Add service type checking to the discovery tests]
1 parent 1ca5def commit 61206d4

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

‎openid/test/test_discover.py‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,26 @@ def _usedYadis(self, service):
198198
def _notUsedYadis(self, service):
199199
self.failIf(service.used_yadis, "Expected to use old-style discovery")
200200

201+
def _hasTypes(self, service, *types):
202+
"""Check to see if the specified type URIs are present in the
203+
service element in order"""
204+
openid_types = {
205+
'1.1': discover.OPENID_1_1_TYPE,
206+
'1.0': discover.OPENID_1_0_TYPE,
207+
'2.0': discover.OPENID_2_0_TYPE,
208+
'2.0 OP': discover.OPENID_IDP_2_0_TYPE,
209+
}
210+
211+
it = iter(service.type_uris)
212+
for type_code in types:
213+
type_uri = openid_types[type_code]
214+
for t in it:
215+
if t == type_uri:
216+
break
217+
else:
218+
self.fail('Did not find types %r in %r'
219+
% (types, service.type_uris))
220+
201221
def test_404(self):
202222
self.failUnlessRaises(DiscoveryFailure,
203223
discover.discover, self.id_url + '/404')
@@ -216,9 +236,11 @@ def test_yadis(self):
216236
self.failUnlessEqual(services[0].server_url,
217237
"http://www.myopenid.com/server")
218238
self._usedYadis(services[0])
239+
self._hasTypes(services[0], '1.0')
219240
self.failUnlessEqual(services[1].server_url,
220241
"http://www.livejournal.com/openid/server.bml")
221242
self._usedYadis(services[1])
243+
self._hasTypes(services[0], '1.0')
222244

223245
def test_yadis_another(self):
224246
services = self._discover(
@@ -231,6 +253,7 @@ def test_yadis_another(self):
231253
self.failUnlessEqual(services[0].server_url,
232254
"http://vroom.unittest/server")
233255
self._usedYadis(services[0])
256+
self._hasTypes(services[0], '1.0')
234257

235258
def test_redirect(self):
236259
expected_final_url = "http://elsewhere.unittest/"
@@ -246,6 +269,7 @@ def test_redirect(self):
246269
"http://smoker.myopenid.com/")
247270
self.failUnlessEqual(services[0].claimed_id, expected_final_url)
248271
self._notUsedYadis(services[0])
272+
self._hasTypes(services[0], '1.1')
249273

250274
def test_emptyList(self):
251275
services = self._discover(content_type='application/xrds+xml',
@@ -265,6 +289,7 @@ def test_emptyListWithLegacy(self):
265289
"http://www.myopenid.com/server")
266290
self.failUnlessEqual(services[0].claimed_id, self.id_url)
267291
self._notUsedYadis(services[0])
292+
self._hasTypes(services[0], '1.1')
268293

269294
def test_yadisNoDelegate(self):
270295
services = self._discover(content_type='application/xrds+xml',
@@ -277,6 +302,7 @@ def test_yadisNoDelegate(self):
277302
'Delegate should be None. Got %r' %
278303
(services[0].local_id,))
279304
self._usedYadis(services[0])
305+
self._hasTypes(services[0], '1.0')
280306

281307
def test_yadisIDP(self):
282308
services = self._discover(content_type='application/xrds+xml',
@@ -290,6 +316,7 @@ def test_yadisIDP(self):
290316
'Delegate should be None. Got %r' %
291317
(services[0].local_id,))
292318
self._usedYadis(services[0])
319+
self._hasTypes(services[0], '2.0 OP')
293320

294321
def test_yadisIDPdelegate(self):
295322
"""The delegate tag isn't meaningful for IdP entries."""
@@ -306,7 +333,7 @@ def test_yadisIDPdelegate(self):
306333
'Delegate should be None. Got %r' %
307334
(services[0].local_id,))
308335
self._usedYadis(services[0])
309-
336+
self._hasTypes(services[0], '2.0 OP')
310337

311338
def test_openidNoDelegate(self):
312339
services = self._discover(
@@ -322,6 +349,7 @@ def test_openidNoDelegate(self):
322349
(services[0].local_id,))
323350

324351
self._notUsedYadis(services[0])
352+
self._hasTypes(services[0], '1.1')
325353

326354
def test_openid2(self):
327355
services = self._discover(
@@ -336,7 +364,7 @@ def test_openid2(self):
336364
services[0].local_id)
337365
self.failUnlessEqual([discover.OPENID_2_0_TYPE], services[0].type_uris)
338366
self._notUsedYadis(services[0])
339-
self.failUnlessEqual(1, len(services))
367+
self._hasTypes(services[0], '2.0')
340368

341369
def test_openid1(self):
342370
services = self._discover(
@@ -351,6 +379,7 @@ def test_openid1(self):
351379
services[0].local_id)
352380
self.failUnlessEqual([discover.OPENID_1_1_TYPE], services[0].type_uris)
353381
self._notUsedYadis(services[0])
382+
self._hasTypes(services[0], '1.1')
354383

355384
def test_openid_1_and_2(self):
356385
services = self._discover(
@@ -363,8 +392,8 @@ def test_openid_1_and_2(self):
363392
self.failUnlessEqual(services[1].claimed_id, self.id_url)
364393
self.failUnlessEqual('http://smoker.myopenid.com/',
365394
services[1].local_id)
366-
self.failUnlessEqual([discover.OPENID_2_0_TYPE], services[1].type_uris)
367395
self._notUsedYadis(services[1])
396+
self._hasTypes(services[1], '2.0')
368397

369398

370399
self.failUnlessEqual(services[0].server_url,
@@ -374,6 +403,7 @@ def test_openid_1_and_2(self):
374403
services[0].local_id)
375404
self.failUnlessEqual([discover.OPENID_1_1_TYPE], services[0].type_uris)
376405
self._notUsedYadis(services[0])
406+
self._hasTypes(services[0], '1.1')
377407

378408

379409
class MockFetcherForXRIProxy(object):

0 commit comments

Comments
 (0)