1 import unittest
2 from openid.consumer.discover import \
3 OpenIDServiceEndpoint, OPENID_1_1_TYPE, OPENID_1_0_TYPE
4
5 from openid.yadis.services import applyFilter
6
7
8 XRDS_BOILERPLATE = '''\
9 <?xml version="1.0" encoding="UTF-8"?>
10 <xrds:XRDS xmlns:xrds="xri://$xrds"
11 xmlns="xri://$xrd*($v*2.0)"
12 xmlns:openid="http://openid.net/xmlns/1.0">
13 <XRD>
14 %s\
15 </XRD>
16 </xrds:XRDS>
17 '''
18
21
22 -def mkService(uris=None, type_uris=None, local_id=None, dent=' '):
23 chunks = [dent, '<Service>\n']
24 dent2 = dent + ' '
25 if type_uris:
26 for type_uri in type_uris:
27 chunks.extend([dent2 + '<Type>', type_uri, '</Type>\n'])
28
29 if uris:
30 for uri in uris:
31 if type(uri) is tuple:
32 uri, prio = uri
33 else:
34 prio = None
35
36 chunks.extend([dent2, '<URI'])
37 if prio is not None:
38 chunks.extend([' priority="', str(prio), '"'])
39 chunks.extend(['>', uri, '</URI>\n'])
40
41 if local_id:
42 chunks.extend(
43 [dent2, '<openid:Delegate>', local_id, '</openid:Delegate>\n'])
44
45 chunks.extend([dent, '</Service>\n'])
46
47 return ''.join(chunks)
48
49
50 server_url_options = [
51 [],
52 ['http://server.url/'],
53 ['https://server.url/'],
54 ['https://server.url/', 'http://server.url/'],
55 ['https://server.url/',
56 'http://server.url/',
57 'http://example.server.url/'],
58 ]
59
60
62 """Generate all non-empty sublists of a list"""
63 subsets_list = [[]]
64 for x in l:
65 subsets_list += [[x] + t for t in subsets_list]
66 return subsets_list
67
68
69
70 ext_types = [
71 'http://janrain.com/extension/blah',
72 'http://openid.net/sreg/1.0',
73 ]
74
75
76 type_uri_options = [
77 exts + ts
78
79
80 for ts in subsets([OPENID_1_0_TYPE, OPENID_1_1_TYPE])
81 if ts
82
83
84 for exts in subsets(ext_types)
85 ]
86
87
88 local_id_options = [
89 None,
90 'http://vanity.domain/',
91 'https://somewhere/yadis/',
92 ]
93
94
95 data = [
96 (uris, type_uris, local_id)
97 for uris in server_url_options
98 for type_uris in type_uri_options
99 for local_id in local_id_options
100 ]
101
103 - def __init__(self, uris, type_uris, local_id):
108
110
111 return 'Successful OpenID Yadis parsing case'
112
121
123
124 endpoints = applyFilter(
125 self.yadis_url, self.xrds, OpenIDServiceEndpoint)
126
127
128
129
130 self.failUnlessEqual(len(self.uris), len(endpoints))
131
132
133 type_uris = list(self.type_uris)
134 type_uris.sort()
135
136 seen_uris = []
137 for endpoint in endpoints:
138 seen_uris.append(endpoint.server_url)
139
140
141 self.failUnlessEqual(self.yadis_url, endpoint.claimed_id)
142
143
144 self.failUnlessEqual(self.local_id, endpoint.local_id)
145
146
147 actual_types = list(endpoint.type_uris)
148 actual_types.sort()
149 self.failUnlessEqual(actual_types, type_uris)
150
151
152
153 seen_uris.sort()
154 uris = list(self.uris)
155 uris.sort()
156
157
158 self.failUnlessEqual(uris, seen_uris)
159
165