Esempio n. 1
0
 def testStates(self):
     self.client._state = protocol.FGDPClient_0_1.CLIENT_STATE_LOGIN
     r = protocol.Response(protocol.FGDP_0_1.OK_RESPONSE, 'OK', self.v)
     self.failUnlessRaises(protocol.UnexpectedResponse,
                           self.client._checkState, r)
     self.client._state = \
             protocol.FGDPClient_0_1.CLIENT_STATE_AUTHENTICATING
     r = protocol.Response(protocol.FGDP_0_1.CHALLENGE_RESPONSE, '', self.v)
     self.failUnlessRaises(protocol.UnexpectedResponse,
                           self.client._checkState, r)
     self.client._state = protocol.FGDPClient_0_1.CLIENT_STATE_CONNECTED
     r = protocol.Response(protocol.FGDP_0_1.CHALLENGE_RESPONSE, '', self.v)
     self.failUnlessRaises(protocol.UnexpectedResponse,
                           self.client._checkState, r)
Esempio n. 2
0
 def testResponseInBadState(self):
     # The client starts the protocol
     self.client._state = protocol.FGDPClient_0_1.CLIENT_STATE_LOGIN
     # We received an OK response, but we were waiting for a challenge
     r = protocol.Response(protocol.FGDP_0_1.OK_RESPONSE, 'OK', self.v)
     self.client.lineReceived(str(r))
     self.assertEquals(self.client._state,
                       protocol.FGDPClient_0_1.CLIENT_STATE_DISCONNECTED)
Esempio n. 3
0
 def testFullProtocol(self):
     # The client starts the protocol
     self.client._state = protocol.FGDPClient_0_1.CLIENT_STATE_LOGIN
     # The server answer with a CHALLENGE response
     r = protocol.Response(protocol.FGDP_0_1.CHALLENGE_RESPONSE, '1',
                           self.v)
     self.client.lineReceived(str(r))
     # The client replies with an AUTH command
     h = self.client._makeHash(
         [self.client._user, self.client._password, '1'])
     c = protocol.Command(protocol.FGDP_0_1.AUTH_COMMAND, h, self.v)
     self.assertTrue(self.transport.lastWrite, str(c))
     # The server answer with an OK response
     r = protocol.Response(protocol.FGDP_0_1.OK_RESPONSE, 'OK', self.v)
     self.client.lineReceived(str(r))
     self.assertEquals(self.client._state,
                       protocol.FGDPClient_0_1.CLIENT_STATE_CONNECTED)
Esempio n. 4
0
 def testErrorResponse(self):
     # The client starts the protocol
     self.client._state = protocol.FGDPClient_0_1.CLIENT_STATE_LOGIN
     # The server answer with an Error response
     r = protocol.Response(protocol.FGDP_0_1.ERROR_RESPONSE,
                           'already connected', self.v)
     self.client.lineReceived(str(r))
     self.assertEquals(self.client._state,
                       protocol.FGDPClient_0_1.CLIENT_STATE_DISCONNECTED)
Esempio n. 5
0
 def testFullProtocol_0_1(self):
     # The client start the protocol with a LOGIN command
     c = protocol.Command(protocol.FGDP_0_1.LOGIN_COMMAND, 'user', self.v)
     self.server.lineReceived(str(c))
     # The server is now in the AUTHENTICATE state
     self.server._state = protocol.FGDPServer_0_1.SERVER_STATE_AUTHENTICATE
     # The server replies with a CHALLENGE response
     r = protocol.Response(protocol.FGDP_0_1.CHALLENGE_RESPONSE,
                           self.server._challenge, self.v)
     self.assertTrue(self.transport.lastWrite, str(r))
     # The client replies with an AUTH command
     h = self.server._makeHash(
         [self.server._user, self.server._password, self.server._challenge])
     c = protocol.Command(protocol.FGDP_0_1.AUTH_COMMAND, h, self.v)
     self.server.lineReceived(str(c))
     # The server replies with an OK response
     r = protocol.Response(protocol.FGDP_0_1.OK_RESPONSE, 'OK', self.v)
     self.assertTrue(self.transport.lastWrite, str(r))
     self.assertEquals(self.server._state,
                       protocol.FGDPServer_0_1.SERVER_STATE_CONNECTED)
Esempio n. 6
0
 def testResonse(self):
     r = protocol.Response('TEST', 'test response', (1, 0))
     self.assertEquals(r.response, 'TEST')
     self.assertEquals(r.content, 'test response')
     self.assertEquals(r.version, (1, 0))
     self.assertEquals(str(r), 'FGDP/1.0 TEST test response')