summaryrefslogtreecommitdiff
path: root/tests/wocky-test-connector-server.c
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.co.uk>2012-06-19 13:08:11 +0200
committerXavier Claessens <xavier.claessens@collabora.co.uk>2012-06-19 18:03:40 +0200
commit9d5d16dabbb84a44d230996cd1d1480f5b767ec0 (patch)
treed83c8ece9bcafd6fdc1f1a8c4cb880df11ed726b /tests/wocky-test-connector-server.c
parentd065b5ccf63b3a02a132cee370407a8a115fc444 (diff)
Add unit test for see-other-host stream error
Diffstat (limited to 'tests/wocky-test-connector-server.c')
-rw-r--r--tests/wocky-test-connector-server.c57
1 files changed, 57 insertions, 0 deletions
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
@@ -1388,6 +1391,24 @@ force_closed_cb (GObject *source,
}
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,
gpointer data)
@@ -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;
+
+}