def testStates(self): self.server._state = protocol.FGDPServer_0_1.SERVER_STATE_DISCONNECTED c = protocol.Command(protocol.FGDP_0_1.AUTH_COMMAND, 'user', self.v) self.failUnlessRaises(protocol.UnexpectedCommand, self.server._checkState, c) self.server._state = protocol.FGDPServer_0_1.SERVER_STATE_AUTHENTICATE c = protocol.Command(protocol.FGDP_0_1.LOGIN_COMMAND, 'login', self.v) self.failUnlessRaises(protocol.UnexpectedCommand, self.server._checkState, c) self.server._state = protocol.FGDPServer_0_1.SERVER_STATE_CONNECTED c = protocol.Command(protocol.FGDP_0_1.LOGIN_COMMAND, 'login', self.v) self.failUnlessRaises(protocol.UnexpectedCommand, self.server._checkState, c)
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)
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)
def testCommand(self): c = protocol.Command('TEST', 'test', (1, 0)) self.assertEquals(c.command, 'TEST') self.assertEquals(c.content, 'test') self.assertEquals(c.version, (1, 0)) self.assertEquals(str(c), 'TEST test FGDP/1.0')
def testCommandInBadState(self): # We received an OK response, but we were waiting for a challenge c = protocol.Command(protocol.FGDP_0_1.AUTH_COMMAND, 'user', self.v) self.server.lineReceived(str(c)) self.assertEquals(self.server._state, protocol.FGDPClient_0_1.CLIENT_STATE_DISCONNECTED)