[telepathy-gabble/master] Expose <host-unknown> during login as Auth_Failed
Will Thompson
will.thompson at collabora.co.uk
Thu Apr 16 06:12:30 PDT 2009
---
src/connection.c | 38 +++++++++++++++++++++++++----------
tests/twisted/connect/test-fail.py | 29 +++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/src/connection.c b/src/connection.c
index b384f28..866c8e3 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1704,23 +1704,39 @@ connection_stream_error_cb (LmMessageHandler *handler,
gpointer user_data)
{
GabbleConnection *conn = GABBLE_CONNECTION (user_data);
- LmMessageNode *conflict_node;
+ TpConnectionStatusReason r = TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED;
g_assert (connection == conn->lmconn);
NODE_DEBUG (message->node, "got stream error");
- conflict_node = lm_message_node_get_child (message->node, "conflict");
- if (conflict_node)
+ if (lm_message_node_get_child (message->node, "conflict") != NULL)
{
- DEBUG ("found conflict node, emiting status change");
+ /* Another client with the same resource just appeared, we're going down.
+ */
+ DEBUG ("found <conflict> node");
+ r = TP_CONNECTION_STATUS_REASON_NAME_IN_USE;
+ }
+ else if (lm_message_node_get_child (message->node, "host-unknown") != NULL)
+ {
+ /* If we get this while we're logging in, it's because we're trying to
+ * connect to foo at bar.com but the server doesn't know about bar.com,
+ * probably because the user entered a non-GTalk JID into a GTalk profile
+ * that forces the server.
+ */
+ if (conn->parent.status == TP_CONNECTION_STATUS_CONNECTING)
+ {
+ DEBUG ("found <host-unknown> and we're connecting");
+ r = TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED;
+ }
+ }
- /* Another client with the same resource just
- * appeared, we're going down. */
- tp_base_connection_change_status ((TpBaseConnection *) conn,
- TP_CONNECTION_STATUS_DISCONNECTED,
- TP_CONNECTION_STATUS_REASON_NAME_IN_USE);
- return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+ if (r != TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED)
+ {
+ DEBUG ("changing status to Disconnected for reason %u", r);
+
+ tp_base_connection_change_status ((TpBaseConnection *) conn,
+ TP_CONNECTION_STATUS_DISCONNECTED, r);
}
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
diff --git a/tests/twisted/connect/test-fail.py b/tests/twisted/connect/test-fail.py
index c27b3fa..bb73831 100644
--- a/tests/twisted/connect/test-fail.py
+++ b/tests/twisted/connect/test-fail.py
@@ -7,6 +7,7 @@ from twisted.words.protocols.jabber import xmlstream
import dbus
+from servicetest import assertEquals
from gabbletest import exec_test
import constants as cs
import ns
@@ -31,6 +32,34 @@ def test_conflict_after_connect(q, bus, conn, stream):
q.expect('dbus-signal', signal='StatusChanged',
args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_NAME_IN_USE])
+class HostUnknownAuthenticator(xmlstream.Authenticator):
+ def __init__(self):
+ xmlstream.Authenticator.__init__(self)
+
+ def streamStarted(self, root=None):
+ if root:
+ self.xmlstream.sid = root.getAttribute('id')
+
+ self.xmlstream.sendHeader()
+
+ no = domish.Element((xmlstream.NS_STREAMS, 'error'))
+ no.addElement((ns.STREAMS, 'host-unknown'))
+ self.xmlstream.send(no)
+
+def test_host_unknown(q, bus, conn, stream):
+ conn.Connect()
+
+ q.expect('dbus-signal', signal='StatusChanged',
+ args=[cs.CONN_STATUS_CONNECTING, cs.CSR_REQUESTED])
+
+ e = q.expect('dbus-signal', signal='StatusChanged')
+ status, reason = e.args
+ assertEquals(cs.CONN_STATUS_DISCONNECTED, status)
+ assertEquals(cs.CSR_AUTHENTICATION_FAILED, reason)
+
if __name__ == '__main__':
exec_test(test_network_error, {'port': dbus.UInt32(4243)})
exec_test(test_conflict_after_connect)
+ exec_test(test_host_unknown, {'server': 'localhost',
+ 'account': 'test at example.org',
+ }, authenticator=HostUnknownAuthenticator())
--
1.5.6.5
More information about the telepathy-commits
mailing list