'ssh_USERAUTH_FAILURE should sort the methods by their position
in SSHUserAuthClient.preferredOrder.  Methods that are not in
preferredOrder should be sorted at the end of that list.'

def test_USERAUTH_FAILURE_sorting(self):

    def auth_firstmethod():
        self.authClient.transport.sendPacket(255, 'here    is    data')
    def auth_anothermethod():
        self.authClient.transport.sendPacket(254, 'other    data')
        return True
    self.authClient.auth_firstmethod = auth_firstmethod
    self.authClient.auth_anothermethod = auth_anothermethod
    self.authClient.ssh_USERAUTH_FAILURE((NS('anothermethod,password') + '\x00'))
    self.assertEqual(self.authClient.transport.packets[(-1)], (userauth.MSG_USERAUTH_REQUEST, ((((NS('foo') + NS('nancy')) + NS('password')) + '\x00') + NS('foo'))))
    self.authClient.ssh_USERAUTH_FAILURE((NS('firstmethod,anothermethod,password') + '\xff'))
    self.assertEqual(self.authClient.transport.packets[(-2):], [(255, 'here    is    data'), (254, 'other    data')])
