def negotiate(self, user, passwd): """Normally this negotiation would take place over a network. The `sdata' and `cdata' variables are the data that could be sent from the server and from the client. The `sk' and `ck' variables represent the "continuation" of the server and client. A continuation is a procedure if the exchange should continue, False if authentication failed, or True if authentication succeeded, or None if the decision is left up to the other end of the exchange.""" ## Server issues a challenge. sk = self.mech.challenge() ## Client responds. with fluid.let((USER, user), (PASS, passwd)): ck = self.mech.respond(sk.data) while not (sk.finished() and ck.finished()): if not sk.finished(): sk = sk(ck.data) if not ck.finished(): ck = ck(sk.data) return (sk, ck)
def test_response(self): """Test basic expectations about a response.""" state = self.mech.challenge() with fluid.let((USER, '*****@*****.**'), (PASS, 'secret')): rstate = self.mech.respond(state.data) resp = dict(rfc.data(self.mech.RESPOND, rstate.data)) self.assertNotEqual(resp['nonce'], resp['cnonce']) ## These are random, so pop them off before equality ## comparison. self.assert_(resp.pop('nonce')) self.assert_(resp.pop('cnonce')) self.assert_(resp.pop('response')) self.assertEqual(sorted(resp.items()), [(u'charset', u'utf-8'), (u'digest-uri', u'test-service/example.net'), (u'nc', 1), (u'realm', u'*****@*****.**'), (u'username', u'*****@*****.**')])
def test_response(self): """Test basic expectations about a response.""" state = self.mech.challenge() with fluid.let((USER, '*****@*****.**'), (PASS, 'secret')): rstate = self.mech.respond(state.data) resp = dict(rfc.data(self.mech.RESPOND, rstate.data)) self.assertNotEqual(resp['nonce'], resp['cnonce']) ## These are random, so pop them off before equality ## comparison. self.assert_(resp.pop('nonce')) self.assert_(resp.pop('cnonce')) self.assert_(resp.pop('response')) self.assertEqual(sorted(resp.items()), [ (u'charset', u'utf-8'), (u'digest-uri', u'test-service/example.net'), (u'nc', 1), (u'realm', u'*****@*****.**'), (u'username', u'*****@*****.**') ])
def focused(expr, items): for (index, focus) in enumerate(items): with fluid.let((INDEX, index), (FOCUS, focus)): for item in expr(): yield item