[telepathy-gabble/master] Don't try to submit incomplete registration forms
Will Thompson
will.thompson at collabora.co.uk
Fri Apr 17 03:01:50 PDT 2009
Previously Gabble violated a MUST in XEP 0077 by not caring if it was
supposed to provide <email/> or other information.
---
src/register.c | 46 +++++++++++++++++++++++----------------
tests/twisted/test-register.py | 26 +++++++++++-----------
2 files changed, 40 insertions(+), 32 deletions(-)
diff --git a/src/register.c b/src/register.c
index 54eb790..b746dd8 100644
--- a/src/register.c
+++ b/src/register.c
@@ -248,8 +248,9 @@ get_reply_cb (GabbleConnection *conn,
gint err_code = -1;
const gchar *err_msg = NULL;
LmMessage *msg = NULL;
- LmMessageNode *query_node;
+ LmMessageNode *query_node, *child;
gchar *username, *password;
+ gboolean username_required = FALSE, password_required = FALSE;
if (lm_message_get_sub_type (reply_msg) != LM_MESSAGE_SUB_TYPE_RESULT)
{
@@ -259,25 +260,38 @@ get_reply_cb (GabbleConnection *conn,
goto OUT;
}
- /* sanity check the reply to some degree ... */
query_node = lm_message_node_get_child_with_namespace (reply_msg->node,
"query", NS_REGISTER);
if (query_node == NULL)
- goto ERROR_MALFORMED_REPLY;
+ {
+ err_code = TP_ERROR_NOT_AVAILABLE;
+ err_msg = "malformed reply from server";
+ goto OUT;
+ }
- if (!lm_message_node_get_child (query_node, "username"))
- goto ERROR_MALFORMED_REPLY;
+ for (child = query_node->children; child != NULL; child = child->next)
+ {
+ const gchar *n = lm_message_node_get_name (child);
- if (!lm_message_node_get_child (query_node, "password"))
- goto ERROR_MALFORMED_REPLY;
+ if (!tp_strdiff (n, "username"))
+ {
+ username_required = TRUE;
+ }
+ else if (!tp_strdiff (n, "password"))
+ {
+ password_required = TRUE;
+ }
+ else if (tp_strdiff (n, "instructions"))
+ {
+ DEBUG ("field %s is not username, password or instructions", n);
+ DEBUG ("we can't support registering with this server :'(");
- /* FIXME: "The requesting entity MUST provide information for all of the
- * elements (other than <instructions/>) contained in the IQ result."
- * What should we do if the IQ contains <email/> or something else
- * that we can't provide? Currently we just submit the form anyway and
- * hope for the best.
- */
+ err_code = TP_ERROR_NOT_AVAILABLE;
+ err_msg = "server requires information that Gabble can't supply";
+ goto OUT;
+ }
+ }
/* craft a reply */
msg = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
@@ -304,12 +318,6 @@ get_reply_cb (GabbleConnection *conn,
err_msg = error->message;
}
- goto OUT;
-
-ERROR_MALFORMED_REPLY:
- err_code = TP_ERROR_NOT_AVAILABLE;
- err_msg = "Malformed reply";
-
OUT:
if (err_code != -1)
{
diff --git a/tests/twisted/test-register.py b/tests/twisted/test-register.py
index b9f22f6..1e59f43 100644
--- a/tests/twisted/test-register.py
+++ b/tests/twisted/test-register.py
@@ -12,7 +12,7 @@ from twisted.words.xish import domish, xpath
import ns
import constants as cs
-def connect_and_send_form(q, conn, stream, require_email=False):
+def connect_and_send_form(q, conn, stream):
conn.Connect()
q.expect('dbus-signal', signal='StatusChanged',
args=[cs.CONN_STATUS_CONNECTING, cs.CSR_REQUESTED])
@@ -23,9 +23,6 @@ def connect_and_send_form(q, conn, stream, require_email=False):
query.addElement('username')
query.addElement('password')
- if require_email:
- query.addElement('email')
-
stream.send(result)
event = q.expect('stream-iq')
@@ -58,16 +55,19 @@ def test_conflict(q, bus, conn, stream):
args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_NAME_IN_USE])
def test_with_email(q, bus, conn, stream):
- # So, the form requires <email/> but Gabble doesn't notice and sends a
- # request with just <username/> and <password/>. Arguably it should notice
- # that other fields are needed and fail earlier.
- iq = connect_and_send_form(q, conn, stream, require_email=True)
+ # The form requires <email/>; so, Gabble should give up.
+ conn.Connect()
+ q.expect('dbus-signal', signal='StatusChanged',
+ args=[cs.CONN_STATUS_CONNECTING, cs.CSR_REQUESTED])
- error = domish.Element((None, 'error'))
- error['code'] = '406'
- error['type'] = 'modify'
- error.addElement((ns.STANZA, 'not-acceptable'))
- send_error_reply(stream, iq, error)
+ event = q.expect('stream-iq', query_ns=ns.REGISTER)
+ result = make_result_iq(stream, event.stanza)
+ query = result.firstChildElement()
+ query.addElement('username')
+ query.addElement('password')
+ query.addElement('email')
+
+ stream.send(result)
# AuthenticationFailed is the closest ConnectionStatusReason to "I tried
# but couldn't register you an account."
--
1.5.6.5
More information about the telepathy-commits
mailing list