1
2 from openid.extensions.draft import pape2 as pape
3 from openid.message import *
4 from openid.server import server
5
6 import unittest
7
11
13 self.failUnlessEqual([], self.req.preferred_auth_policies)
14 self.failUnlessEqual(None, self.req.max_auth_age)
15 self.failUnlessEqual('pape', self.req.ns_alias)
16
17 req2 = pape.Request([pape.AUTH_MULTI_FACTOR], 1000)
18 self.failUnlessEqual([pape.AUTH_MULTI_FACTOR], req2.preferred_auth_policies)
19 self.failUnlessEqual(1000, req2.max_auth_age)
20
33
35 self.failUnlessEqual({'preferred_auth_policies': ''}, self.req.getExtensionArgs())
36 self.req.addPolicyURI('http://uri')
37 self.failUnlessEqual({'preferred_auth_policies': 'http://uri'}, self.req.getExtensionArgs())
38 self.req.addPolicyURI('http://zig')
39 self.failUnlessEqual({'preferred_auth_policies': 'http://uri http://zig'}, self.req.getExtensionArgs())
40 self.req.max_auth_age = 789
41 self.failUnlessEqual({'preferred_auth_policies': 'http://uri http://zig', 'max_auth_age': '789'}, self.req.getExtensionArgs())
42
44 args = {'preferred_auth_policies': 'http://foo http://bar',
45 'max_auth_age': '9'}
46 self.req.parseExtensionArgs(args)
47 self.failUnlessEqual(9, self.req.max_auth_age)
48 self.failUnlessEqual(['http://foo','http://bar'], self.req.preferred_auth_policies)
49
51 self.req.parseExtensionArgs({})
52 self.failUnlessEqual(None, self.req.max_auth_age)
53 self.failUnlessEqual([], self.req.preferred_auth_policies)
54
68
75
82
84 - def __init__(self, message, signed_stuff):
87
89 return self.signed_stuff
90
94
96 self.failUnlessEqual([], self.req.auth_policies)
97 self.failUnlessEqual(None, self.req.auth_time)
98 self.failUnlessEqual('pape', self.req.ns_alias)
99 self.failUnlessEqual(None, self.req.nist_auth_level)
100
101 req2 = pape.Response([pape.AUTH_MULTI_FACTOR], "2004-12-11T10:30:44Z", 3)
102 self.failUnlessEqual([pape.AUTH_MULTI_FACTOR], req2.auth_policies)
103 self.failUnlessEqual("2004-12-11T10:30:44Z", req2.auth_time)
104 self.failUnlessEqual(3, req2.nist_auth_level)
105
116
118 self.failUnlessEqual({'auth_policies': 'none'}, self.req.getExtensionArgs())
119 self.req.addPolicyURI('http://uri')
120 self.failUnlessEqual({'auth_policies': 'http://uri'}, self.req.getExtensionArgs())
121 self.req.addPolicyURI('http://zig')
122 self.failUnlessEqual({'auth_policies': 'http://uri http://zig'}, self.req.getExtensionArgs())
123 self.req.auth_time = "1776-07-04T14:43:12Z"
124 self.failUnlessEqual({'auth_policies': 'http://uri http://zig', 'auth_time': "1776-07-04T14:43:12Z"}, self.req.getExtensionArgs())
125 self.req.nist_auth_level = 3
126 self.failUnlessEqual({'auth_policies': 'http://uri http://zig', 'auth_time': "1776-07-04T14:43:12Z", 'nist_auth_level': '3'}, self.req.getExtensionArgs())
127
129 self.req.auth_time = "long ago"
130 self.failUnlessRaises(ValueError, self.req.getExtensionArgs)
131
133 self.req.nist_auth_level = "high as a kite"
134 self.failUnlessRaises(ValueError, self.req.getExtensionArgs)
135 self.req.nist_auth_level = 5
136 self.failUnlessRaises(ValueError, self.req.getExtensionArgs)
137 self.req.nist_auth_level = -1
138 self.failUnlessRaises(ValueError, self.req.getExtensionArgs)
139
141 args = {'auth_policies': 'http://foo http://bar',
142 'auth_time': '1970-01-01T00:00:00Z'}
143 self.req.parseExtensionArgs(args)
144 self.failUnlessEqual('1970-01-01T00:00:00Z', self.req.auth_time)
145 self.failUnlessEqual(['http://foo','http://bar'], self.req.auth_policies)
146
148 self.req.parseExtensionArgs({})
149 self.failUnlessEqual(None, self.req.auth_time)
150 self.failUnlessEqual([], self.req.auth_policies)
151
153 args = {'auth_policies': 'http://foo http://bar',
154 'auth_time': 'yesterday'}
155 self.failUnlessRaises(ValueError, self.req.parseExtensionArgs,
156 args, True)
157
159 args = {'auth_policies': 'http://foo http://bar',
160 'auth_time': '1970-01-01T00:00:00Z',
161 'nist_auth_level': 'some'}
162 self.failUnlessRaises(ValueError, self.req.parseExtensionArgs,
163 args, True)
164
166 args = {'auth_policies': 'http://foo http://bar',
167 'auth_time': '1970-01-01T00:00:00Z',
168 'nist_auth_level': '0'}
169 self.req.parseExtensionArgs(args, True)
170 self.failUnlessEqual(['http://foo','http://bar'], self.req.auth_policies)
171 self.failUnlessEqual('1970-01-01T00:00:00Z', self.req.auth_time)
172 self.failUnlessEqual(0, self.req.nist_auth_level)
173
175 args = {'auth_policies': 'http://foo http://bar',
176 'auth_time': 'when the cows come home',
177 'nist_auth_level': 'some'}
178 self.req.parseExtensionArgs(args)
179 self.failUnlessEqual(['http://foo','http://bar'], self.req.auth_policies)
180 self.failUnlessEqual(None, self.req.auth_time)
181 self.failUnlessEqual(None, self.req.nist_auth_level)
182
184 openid_req_msg = Message.fromOpenIDArgs({
185 'mode': 'id_res',
186 'ns': OPENID2_NS,
187 'ns.pape': pape.ns_uri,
188 'pape.auth_policies': ' '.join([pape.AUTH_MULTI_FACTOR, pape.AUTH_PHISHING_RESISTANT]),
189 'pape.auth_time': '1970-01-01T00:00:00Z'
190 })
191 signed_stuff = {
192 'auth_policies': ' '.join([pape.AUTH_MULTI_FACTOR, pape.AUTH_PHISHING_RESISTANT]),
193 'auth_time': '1970-01-01T00:00:00Z'
194 }
195 oid_req = DummySuccessResponse(openid_req_msg, signed_stuff)
196 req = pape.Response.fromSuccessResponse(oid_req)
197 self.failUnlessEqual([pape.AUTH_MULTI_FACTOR, pape.AUTH_PHISHING_RESISTANT], req.auth_policies)
198 self.failUnlessEqual('1970-01-01T00:00:00Z', req.auth_time)
199
201 openid_req_msg = Message.fromOpenIDArgs({
202 'mode': 'id_res',
203 'ns': OPENID2_NS,
204 'ns.pape': pape.ns_uri,
205 'pape.auth_policies': ' '.join([pape.AUTH_MULTI_FACTOR, pape.AUTH_PHISHING_RESISTANT]),
206 'pape.auth_time': '1970-01-01T00:00:00Z'
207 })
208
209 signed_stuff = {}
210
211 class NoSigningDummyResponse(DummySuccessResponse):
212 def getSignedNS(self, ns_uri):
213 return None
214
215 oid_req = NoSigningDummyResponse(openid_req_msg, signed_stuff)
216 resp = pape.Response.fromSuccessResponse(oid_req)
217 self.failUnless(resp is None)
218