summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/wocky-porter-test.c80
-rw-r--r--wocky/wocky-c2s-porter.c14
2 files changed, 84 insertions, 10 deletions
diff --git a/tests/wocky-porter-test.c b/tests/wocky-porter-test.c
index ca64f0f..08e9d4d 100644
--- a/tests/wocky-porter-test.c
+++ b/tests/wocky-porter-test.c
@@ -3091,10 +3091,9 @@ handler_from_anyone (void)
send_query_from (test, "tybalt@capulet.lit", "anyone");
send_query_from (test, "tybalt@capulet.lit/FIXME", "anyone");
- /* Slightly counterintuitively, a stanza from our server's domain should not
- * be matched by got_stanza_from_server().
- */
- send_query_from (test, "capulet.lit", "anyone");
+ /* A stanza from our server's domain should be matched by
+ * got_stanza_from_server(). See fd.o#39057. */
+ send_query_from (test, "capulet.lit", "server");
/* On the other hand, a stanza with no sender should be picked up by
* got_stanza_from_server(). */
@@ -3290,12 +3289,83 @@ send_from_send_callback (void)
teardown_test (test);
}
+static gboolean
+test_reply_from_domain_handler_cb (WockyPorter *porter,
+ WockyStanza *stanza,
+ gpointer user_data)
+{
+ test_data_t *test = (test_data_t *) user_data;
+ WockyStanza *reply;
+ const gchar *id;
+
+ test_expected_stanza_received (test, stanza);
+
+ id = wocky_node_get_attribute (wocky_stanza_get_top_node (stanza),
+ "id");
+
+ /* Reply with from="domain" */
+ reply = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ,
+ WOCKY_STANZA_SUB_TYPE_RESULT, "example.com", "juliet@example.com",
+ '@', "id", id,
+ NULL);
+ wocky_porter_send_async (porter, reply,
+ NULL, test_send_iq_sent_cb, test);
+ g_queue_push_tail (test->expected_stanzas, reply);
+ test->outstanding++;
+
+ return TRUE;
+}
+
+static void
+test_reply_from_domain (void)
+{
+ test_data_t *test = setup_test ();
+ WockyStanza *iq;
+
+ g_test_bug ("39057");
+
+ /* Testing that when we send an iq to server, it can reply from the domain
+ instead of full/bare jid. This happens with xmpp.messenger.live.com.
+
+ <iq type="get" id="1062691559">...</iq>
+ <iq from="domain.com" id="1062691559"
+ to="user@domain.com/resource">...</iq>
+ */
+
+ test_open_both_connections (test);
+ wocky_porter_start (test->sched_out);
+ wocky_porter_start (test->sched_in);
+
+ /* register an IQ handler */
+ wocky_porter_register_handler_from_anyone (test->sched_out,
+ WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_NONE,
+ 0,
+ test_reply_from_domain_handler_cb, test, NULL);
+
+ /* Send an IQ query */
+ iq = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ,
+ WOCKY_STANZA_SUB_TYPE_GET, NULL, NULL,
+ '@', "id", "1",
+ NULL);
+
+ wocky_porter_send_iq_async (test->sched_in, iq,
+ NULL, test_send_iq_reply_cb, test);
+ g_queue_push_tail (test->expected_stanzas, iq);
+
+ test->outstanding += 2;
+ test_wait_pending (test);
+
+ test_close_both_porters (test);
+ teardown_test (test);
+}
+
int
main (int argc, char **argv)
{
int result;
test_init (argc, argv);
+ g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add_func ("/xmpp-porter/initiation", test_instantiation);
g_test_add_func ("/xmpp-porter/send", test_send);
@@ -3352,6 +3422,8 @@ main (int argc, char **argv)
close_from_send_callback);
g_test_add_func ("/xmpp-porter/send-from-send-callback",
send_from_send_callback);
+ g_test_add_func ("/xmpp-porter/reply-from-domain",
+ test_reply_from_domain);
result = g_test_run ();
test_deinit ();
diff --git a/wocky/wocky-c2s-porter.c b/wocky/wocky-c2s-porter.c
index 52ee2f9..713df5a 100644
--- a/wocky/wocky-c2s-porter.c
+++ b/wocky/wocky-c2s-porter.c
@@ -76,6 +76,7 @@ struct _WockyC2SPorterPrivate
gchar *full_jid;
gchar *bare_jid;
gchar *resource;
+ gchar *domain;
/* Queue of (sending_queue_elem *) */
GQueue *sending_queue;
@@ -361,7 +362,7 @@ wocky_c2s_porter_set_property (GObject *object,
switch (property_id)
{
- gchar *node, *domain;
+ gchar *node;
case PROP_CONNECTION:
g_assert (priv->connection == NULL);
@@ -376,10 +377,9 @@ wocky_c2s_porter_set_property (GObject *object,
priv->full_jid = g_value_dup_string (value);
g_assert (priv->full_jid != NULL);
- wocky_decode_jid (priv->full_jid, &node, &domain, &priv->resource);
- priv->bare_jid = wocky_compose_jid (node, domain, NULL);
+ wocky_decode_jid (priv->full_jid, &node, &priv->domain, &priv->resource);
+ priv->bare_jid = wocky_compose_jid (node, priv->domain, NULL);
g_free (node);
- g_free (domain);
break;
default:
@@ -580,6 +580,7 @@ wocky_c2s_porter_finalize (GObject *object)
g_free (priv->full_jid);
g_free (priv->bare_jid);
g_free (priv->resource);
+ g_free (priv->domain);
G_OBJECT_CLASS (wocky_c2s_porter_parent_class)->finalize (object);
}
@@ -816,7 +817,8 @@ stanza_is_from_server (
{
return (nfrom == NULL ||
!wocky_strdiff (nfrom, self->priv->full_jid) ||
- !wocky_strdiff (nfrom, self->priv->bare_jid));
+ !wocky_strdiff (nfrom, self->priv->bare_jid) ||
+ !wocky_strdiff (nfrom, self->priv->domain));
}
/* Return TRUE if not spoofed. */
@@ -844,7 +846,7 @@ check_spoofing (WockyC2SPorter *self,
goto finally;
/* if we sent an IQ without a 'to' attribute, it's to our server: allow it
- * to use our full or bare JID to reply */
+ * to use our full/bare JID or domain to reply */
if (should_be_from == NULL)
{
if (stanza_is_from_server (self, nfrom))