From 9d5d16dabbb84a44d230996cd1d1480f5b767ec0 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 19 Jun 2012 13:08:11 +0200 Subject: Add unit test for see-other-host stream error --- tests/wocky-test-connector-server.c | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'tests/wocky-test-connector-server.c') diff --git a/tests/wocky-test-connector-server.c b/tests/wocky-test-connector-server.c index 9919f9e..5f0bfc2 100644 --- a/tests/wocky-test-connector-server.c +++ b/tests/wocky-test-connector-server.c @@ -109,6 +109,9 @@ struct _TestConnectorServerPrivate GSimpleAsyncResult *teardown_result; struct { ServerProblem sasl; ConnectorProblem *connector; } problem; + + gchar *other_host; + guint other_port; }; static void @@ -1387,6 +1390,24 @@ force_closed_cb (GObject *source, server_dec_outstanding (self); } +static void +see_other_host_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + TestConnectorServer *self = user_data; + + g_assert (wocky_xmpp_connection_send_stanza_finish (self->priv->conn, + result, NULL)); + + if (server_dec_outstanding (self)) + return; + + server_enc_outstanding (self); + wocky_xmpp_connection_force_close_async (self->priv->conn, + self->priv->cancellable, force_closed_cb, self); +} + static void xmpp_init (GObject *source, GAsyncResult *result, @@ -1470,6 +1491,28 @@ xmpp_init (GObject *source, priv->cancellable, xmpp_handler, self); } + else if (priv->problem.connector->xmpp & XMPP_PROBLEM_SEE_OTHER_HOST) + { + WockyStanza *stanza; + WockyNode *node; + gchar *host_and_port; + + host_and_port = g_strdup_printf ("%s:%u", self->priv->other_host, + self->priv->other_port); + + DEBUG ("Redirect to another host: %s", host_and_port); + + stanza = wocky_stanza_new ("error", WOCKY_XMPP_NS_STREAM); + node = wocky_stanza_get_top_node (stanza); + wocky_node_add_child_with_content_ns (node, "see-other-host", + host_and_port, WOCKY_XMPP_NS_STREAMS); + + server_enc_outstanding (self); + wocky_xmpp_connection_send_stanza_async (self->priv->conn, stanza, + self->priv->cancellable, see_other_host_cb, self); + + g_object_unref (stanza); + } else { xml = feature_stanza (self); @@ -1645,3 +1688,17 @@ test_connector_server_get_used_mech (TestConnectorServer *self) return priv->used_mech; } + +void +test_connector_server_set_other_host (TestConnectorServer *self, + const gchar *host, + guint port) +{ + g_return_if_fail (TEST_IS_CONNECTOR_SERVER (self)); + g_return_if_fail (self->priv->other_host == NULL); + g_return_if_fail (self->priv->other_port == 0); + + self->priv->other_host = g_strdup (host); + self->priv->other_port = port; + +} -- cgit v1.2.3