diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2013-02-20 08:19:37 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2013-02-20 08:38:48 +0000 |
commit | b2e1a6d147a3931190e2d328feb1f5c62e6ac7d8 (patch) | |
tree | 36d8b5988d0be125bec61e4667001ca8e9734f11 | |
parent | a904ca719ee560fc0b81b58a8a14efa0c181b9d4 (diff) |
Correctly extract type='' from unrecognised errors
-rw-r--r-- | tests/wocky-stanza-test.c | 48 | ||||
-rw-r--r-- | wocky/wocky-xmpp-error.c | 12 |
2 files changed, 58 insertions, 2 deletions
diff --git a/tests/wocky-stanza-test.c b/tests/wocky-stanza-test.c index 2b8e685..77290df 100644 --- a/tests/wocky-stanza-test.c +++ b/tests/wocky-stanza-test.c @@ -586,6 +586,52 @@ test_extract_errors_legacy_code (void) g_object_unref (stanza); } + +static void +test_extract_errors_unrecognised_condition (void) +{ + WockyNodeTree *error_tree; + WockyXmppErrorType type; + GError *core = NULL, *specialized = NULL; + WockyNode *specialized_node = NULL; + const gchar *text = "The room is currently overactive, please try again later"; + + /* I got a <policy-violation> error back from prosody with type='wait', but + * Wocky didn't know about policy-violation (which was introduced in + * RFC6120). Not only did it ignore <policy-violation>, it also ignored + * type='wait' and returned the default, WOCKY_XMPP_ERROR_TYPE_CANCEL. + */ + g_test_bug ("43166#c9"); + + error_tree = wocky_node_tree_new ("error", WOCKY_XMPP_NS_JABBER_CLIENT, + '@', "type", "wait", + '(', "typo-violation", ':', WOCKY_XMPP_NS_STANZAS, ')', + '(', "text", ':', WOCKY_XMPP_NS_STANZAS, + '$', text, + ')', NULL); + + wocky_xmpp_error_extract (wocky_node_tree_get_top_node (error_tree), + &type, &core, &specialized, &specialized_node); + + g_assert_cmpuint (type, ==, WOCKY_XMPP_ERROR_TYPE_WAIT); + + /* Wocky should default to undefined-condition when the server returns an + * unknown core error element. + */ + g_assert_error (core, WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_UNDEFINED_CONDITION); + g_assert_cmpstr (core->message, ==, text); + g_clear_error (&core); + + /* The unrecognised error element was in the :xmpp-stanzas namespace, so it + * shouldn't be returned as a specialized error. + */ + g_assert_no_error (specialized); + g_assert (specialized_node == NULL); + + g_object_unref (error_tree); +} + + static void test_extract_errors_no_sense (void) { @@ -805,6 +851,8 @@ main (int argc, char **argv) test_extract_errors_extra_application_specific); g_test_add_func ("/xmpp-stanza/errors/legacy-code", test_extract_errors_legacy_code); + g_test_add_func ("/xmpp-stanza/errors/unrecognised-condition", + test_extract_errors_unrecognised_condition); g_test_add_func ("/xmpp-stanza/errors/no-sense", test_extract_errors_no_sense); g_test_add_func ("/xmpp-stanza/errors/not-really", diff --git a/wocky/wocky-xmpp-error.c b/wocky/wocky-xmpp-error.c index 42a2c8f..75cd7a7 100644 --- a/wocky/wocky-xmpp-error.c +++ b/wocky/wocky-xmpp-error.c @@ -451,9 +451,17 @@ wocky_xmpp_error_extract (WockyNode *error, if (type_attr != NULL && wocky_enum_from_nick (WOCKY_TYPE_XMPP_ERROR_TYPE, type_attr, &type_i)) - *type = type_i; + { + *type = type_i; + /* Don't let the xmpp_error_from_code() path below clobber the valid + * type we found. + */ + type = NULL; + } else - *type = WOCKY_XMPP_ERROR_TYPE_CANCEL; + { + *type = WOCKY_XMPP_ERROR_TYPE_CANCEL; + } } for (l = error->children; l != NULL; l = g_slist_next (l)) |