Home | Trees | Indices | Help |
|
---|
|
1 import cgi 2 import unittest 3 4 from openid.consumer import consumer 5 from openid import message 6 from openid.test import support 79 preferred_namespace = None 10 local_id = None 11 server_url = None 12 is_op_identifier = False 132215 return self.preferred_namespace1618 return self.local_id1921 return self.is_op_identifier24 handle = "assoc-handle"2527 """Mixin for AuthRequest tests for OpenID 1 and 2; DON'T add 28 unittest.TestCase as a base class here.""" 29 30 preferred_namespace = None 31 immediate = False 32 expected_mode = 'checkid_setup' 3310335 self.endpoint = DummyEndpoint() 36 self.endpoint.local_id = 'http://server.unittest/joe' 37 self.endpoint.claimed_id = 'http://joe.vanity.example/' 38 self.endpoint.server_url = 'http://server.unittest/' 39 self.endpoint.preferred_namespace = self.preferred_namespace 40 self.realm = 'http://example/' 41 self.return_to = 'http://example/return/' 42 self.assoc = DummyAssoc() 43 self.authreq = consumer.AuthRequest(self.endpoint, self.assoc)44 4850 self.failUnlessEqual(self.preferred_namespace, 51 self.authreq.message.getOpenIDNamespace()) 52 53 self.failUnlessEqual(self.preferred_namespace, 54 msg.getOpenIDNamespace()) 55 56 self.failUnlessOpenIDValueEquals(msg, 'mode', 57 self.expected_mode) 58 59 # Implement these in subclasses because they depend on 60 # protocol differences! 61 self.failUnlessHasRealm(msg) 62 self.failUnlessIdentifiersPresent(msg)63 64 # TESTS 6567 self.authreq.assoc = None 68 msg = self.authreq.getMessage(self.realm, self.return_to, 69 self.immediate) 70 71 self.failIfOpenIDKeyExists(msg, 'assoc_handle')7274 msg = self.authreq.getMessage(self.realm, self.return_to, 75 self.immediate) 76 77 self.failUnlessOpenIDValueEquals(msg, 'assoc_handle', 78 self.assoc.handle)7981 self.authreq.addExtensionArg('bag:', 'color', 'brown') 82 self.authreq.addExtensionArg('bag:', 'material', 'paper') 83 self.failUnless('bag:' in self.authreq.message.namespaces) 84 self.failUnlessEqual(self.authreq.message.getArgs('bag:'), 85 {'color': 'brown', 86 'material': 'paper'}) 87 msg = self.authreq.getMessage(self.realm, self.return_to, 88 self.immediate) 89 90 # XXX: this depends on the way that Message assigns 91 # namespaces. Really it doesn't care that it has alias "0", 92 # but that is tested anyway 93 post_args = msg.toPostArgs() 94 self.failUnlessEqual('brown', post_args['openid.ext0.color']) 95 self.failUnlessEqual('paper', post_args['openid.ext0.material'])9698 msg = self.authreq.getMessage(self.realm, self.return_to, 99 self.immediate) 100 101 self.failUnlessHasIdentifiers( 102 msg, self.endpoint.local_id, self.endpoint.claimed_id)105 preferred_namespace = message.OPENID2_NS 106153108 # check presence of proper realm key and absence of the wrong 109 # one. 110 self.failUnlessOpenIDValueEquals(msg, 'realm', self.realm) 111 self.failIfOpenIDKeyExists(msg, 'trust_root')112114 identity_present = msg.hasKey(message.OPENID_NS, 'identity') 115 claimed_present = msg.hasKey(message.OPENID_NS, 'claimed_id') 116 117 self.failUnlessEqual(claimed_present, identity_present)118120 self.failUnlessOpenIDValueEquals(msg, 'identity', op_specific_id) 121 self.failUnlessOpenIDValueEquals(msg, 'claimed_id', claimed_id)122 123 # TESTS 124126 """OpenID AuthRequests should be able to set 'anonymous' to true.""" 127 self.failUnless(self.authreq.message.isOpenID2()) 128 self.authreq.setAnonymous(True) 129 self.authreq.setAnonymous(False)130132 self.authreq.setAnonymous(True) 133 msg = self.authreq.getMessage(self.realm, self.return_to, 134 self.immediate) 135 self.failUnlessHasRequiredFields(msg) 136 self.failUnlessAnonymous(msg)137139 self.endpoint.is_op_identifier = True 140 self.authreq.setAnonymous(True) 141 msg = self.authreq.getMessage(self.realm, self.return_to, 142 self.immediate) 143 self.failUnlessHasRequiredFields(msg) 144 self.failUnlessAnonymous(msg)145147 self.endpoint.is_op_identifier = True 148 msg = self.authreq.getMessage(self.realm, self.return_to, 149 self.immediate) 150 self.failUnlessHasRequiredFields(msg) 151 self.failUnlessHasIdentifiers( 152 msg, message.IDENTIFIER_SELECT, message.IDENTIFIER_SELECT)155 preferred_namespace = message.OPENID1_NS 156196 200 204 205 if __name__ == '__main__': 206 unittest.main() 207158 TestAuthRequestBase.setUpEndpoint(self) 159 self.endpoint.preferred_namespace = message.OPENID1_NS160162 """Make sure claimed_is is *absent* in request.""" 163 self.failUnlessOpenIDValueEquals(msg, 'identity', op_specific_id) 164 self.failIfOpenIDKeyExists(msg, 'claimed_id')165167 self.failIfOpenIDKeyExists(msg, 'claimed_id') 168 self.failUnless(msg.hasKey(message.OPENID_NS, 'identity'))169171 # check presence of proper realm key and absence of the wrong 172 # one. 173 self.failUnlessOpenIDValueEquals(msg, 'trust_root', self.realm) 174 self.failIfOpenIDKeyExists(msg, 'realm')175 176 # TESTS 177179 """OpenID 1 requests MUST NOT be able to set anonymous to True""" 180 self.failUnless(self.authreq.message.isOpenID1()) 181 self.failUnlessRaises(ValueError, self.authreq.setAnonymous, True) 182 self.authreq.setAnonymous(False)183185 """Identfier select SHOULD NOT be sent, but this pathway is in 186 here in case some special discovery stuff is done to trigger 187 it with OpenID 1. If it is triggered, it will send 188 identifier_select just like OpenID 2. 189 """ 190 self.endpoint.is_op_identifier = True 191 msg = self.authreq.getMessage(self.realm, self.return_to, 192 self.immediate) 193 self.failUnlessHasRequiredFields(msg) 194 self.failUnlessEqual(message.IDENTIFIER_SELECT, 195 msg.getArg(message.OPENID1_NS, 'identity'))
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Jul 29 15:11:35 2010 | http://epydoc.sourceforge.net |