diff options
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | libpurple/protocols/jabber/Makefile.am | 2 | ||||
-rw-r--r-- | libpurple/protocols/jabber/tests/.hgignore | 10 | ||||
-rw-r--r-- | libpurple/protocols/jabber/tests/Makefile.am | 37 | ||||
-rw-r--r-- | libpurple/protocols/jabber/tests/test_jabber_caps.c | 59 | ||||
-rw-r--r-- | libpurple/protocols/jabber/tests/test_jabber_digest_md5.c | 50 | ||||
-rw-r--r-- | libpurple/protocols/jabber/tests/test_jabber_jutil.c | 295 | ||||
-rw-r--r-- | libpurple/protocols/jabber/tests/test_jabber_scram.c (renamed from libpurple/tests/test_jabber_scram.c) | 0 | ||||
-rw-r--r-- | libpurple/tests/test_jabber_caps.c | 64 | ||||
-rw-r--r-- | libpurple/tests/test_jabber_digest_md5.c | 59 | ||||
-rw-r--r-- | libpurple/tests/test_jabber_jutil.c | 207 |
12 files changed, 455 insertions, 330 deletions
@@ -150,6 +150,7 @@ stamp-h1 test-driver win32-install-dir(\.release)? +subinclude:libpurple/protocols/jabber/tests/.hgignore subinclude:libpurple/protocols/oscar/tests/.hgignore subinclude:libpurple/protocols/yahoo/tests/.hgignore subinclude:libpurple/tests/.hgignore diff --git a/configure.ac b/configure.ac index 659c441430..577a9cf421 100644 --- a/configure.ac +++ b/configure.ac @@ -2255,6 +2255,7 @@ AC_CONFIG_FILES([Makefile libpurple/protocols/gg/Makefile libpurple/protocols/irc/Makefile libpurple/protocols/jabber/Makefile + libpurple/protocols/jabber/tests/Makefile libpurple/protocols/msn/Makefile libpurple/protocols/mxit/Makefile libpurple/protocols/novell/Makefile diff --git a/libpurple/protocols/jabber/Makefile.am b/libpurple/protocols/jabber/Makefile.am index dda5b7fe8f..8b0bae09c4 100644 --- a/libpurple/protocols/jabber/Makefile.am +++ b/libpurple/protocols/jabber/Makefile.am @@ -137,3 +137,5 @@ AM_CPPFLAGS = \ $(LIBXML_CFLAGS) \ $(FARSTREAM_CFLAGS) \ $(GSTREAMER_CFLAGS) + +SUBDIRS = tests diff --git a/libpurple/protocols/jabber/tests/.hgignore b/libpurple/protocols/jabber/tests/.hgignore new file mode 100644 index 0000000000..157127e9f7 --- /dev/null +++ b/libpurple/protocols/jabber/tests/.hgignore @@ -0,0 +1,10 @@ +syntax: regexp +^test_jabber_caps$ +^test_jabber_digest_md5$ +^test_jabber_jutil$ +^test_jabber_scram$ + +syntax: glob +*.log +*.trs + diff --git a/libpurple/protocols/jabber/tests/Makefile.am b/libpurple/protocols/jabber/tests/Makefile.am new file mode 100644 index 0000000000..15767c51d3 --- /dev/null +++ b/libpurple/protocols/jabber/tests/Makefile.am @@ -0,0 +1,37 @@ +include $(top_srcdir)/glib-tap.mk + +COMMON_LIBS=\ + $(top_builddir)/libpurple/libpurple.la \ + $(top_builddir)/libpurple/protocols/jabber/libjabber.la \ + $(GLIB_LIBS) \ + $(GPLUGIN_LIBS) \ + $(LIBXML_LIBS) + +test_programs=\ + test_jabber_caps \ + test_jabber_digest_md5 \ + test_jabber_jutil + test_jabber_scram + +test_jabber_caps_SOURCES=test_jabber_caps.c +test_jabber_caps_LDADD=$(COMMON_LIBS) + +test_jabber_digest_md5_SOURCES=test_jabber_digest_md5.c +test_jabber_digest_md5_LDADD=$(COMMON_LIBS) + +test_jabber_jutil_SOURCES=test_jabber_jutil.c +test_jabber_jutil_LDADD=$(COMMON_LIBS) + +test_jabber_scram_SOURCES=test_jabber_scram.c +test_jabber_scram_LDADD=$(COMMON_LIBS) + +AM_CPPFLAGS = \ + -I$(top_srcdir)/libpurple \ + -I$(top_builddir)/libpurple \ + $(DEBUG_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GPLUGIN_CFLAGS) \ + $(PLUGIN_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(LIBXML_CFLAGS) \ + $(NSS_CFLAGS) diff --git a/libpurple/protocols/jabber/tests/test_jabber_caps.c b/libpurple/protocols/jabber/tests/test_jabber_caps.c new file mode 100644 index 0000000000..d3c7f502c6 --- /dev/null +++ b/libpurple/protocols/jabber/tests/test_jabber_caps.c @@ -0,0 +1,59 @@ +#include <glib.h> + +#include "xmlnode.h" +#include "ciphers/sha1hash.h" +#include "protocols/jabber/caps.h" + +static void +test_jabber_caps_parse_invalid_nodes(void) { + PurpleXmlNode *query; + + g_assert_null(jabber_caps_parse_client_info(NULL)); + + /* Something other than a disco#info query */ + query = purple_xmlnode_new("foo"); + g_assert_null(jabber_caps_parse_client_info(query)); + purple_xmlnode_free(query); + + query = purple_xmlnode_new("query"); + g_assert_null(jabber_caps_parse_client_info(query)); + + purple_xmlnode_set_namespace(query, "jabber:iq:last"); + g_assert_null(jabber_caps_parse_client_info(query)); + purple_xmlnode_free(query); +} + +static void +_test_jabber_caps_match(PurpleHash *hash, const gchar *in, const gchar *expected) { + PurpleXmlNode *query = purple_xmlnode_from_str(in, -1); + JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); + gchar *got = NULL; + + got = jabber_caps_calculate_hash(info, hash); + g_object_unref(G_OBJECT(hash)); + + g_assert_cmpstr(expected, ==, got); + g_free(got); +} + +static void +test_jabber_caps_calculate_from_xmlnode(void) { + _test_jabber_caps_match( + purple_sha1_hash_new(), + "<query xmlns='http://jabber.org/protocol/disco#info' node='http://tkabber.jabber.ru/#GNjxthSckUNvAIoCCJFttjl6VL8='><identity category='client' type='pc' name='Tkabber'/><x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='software'><value>Tkabber</value></field><field var='software_version'><value> ( 8.5.5 )</value></field><field var='os'><value>ATmega640-16AU</value></field><field var='os_version'><value/></field></x><feature var='games:board'/><feature var='google:mail:notify'/><feature var='http://jabber.org/protocol/activity'/><feature var='http://jabber.org/protocol/bytestreams'/><feature var='http://jabber.org/protocol/chatstates'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/disco#info'/><feature var='http://jabber.org/protocol/disco#items'/><feature var='http://jabber.org/protocol/feature-neg'/><feature var='http://jabber.org/protocol/geoloc'/><feature var='http://jabber.org/protocol/ibb'/><feature var='http://jabber.org/protocol/iqibb'/><feature var='http://jabber.org/protocol/mood'/><feature var='http://jabber.org/protocol/muc'/><feature var='http://jabber.org/protocol/mute#ancestor'/><feature var='http://jabber.org/protocol/mute#editor'/><feature var='http://jabber.org/protocol/rosterx'/><feature var='http://jabber.org/protocol/si'/><feature var='http://jabber.org/protocol/si/profile/file-transfer'/><feature var='http://jabber.org/protocol/tune'/><feature var='jabber:iq:avatar'/><feature var='jabber:iq:browse'/><feature var='jabber:iq:dtcp'/><feature var='jabber:iq:filexfer'/><feature var='jabber:iq:ibb'/><feature var='jabber:iq:inband'/><feature var='jabber:iq:jidlink'/><feature var='jabber:iq:last'/><feature var='jabber:iq:oob'/><feature var='jabber:iq:privacy'/><feature var='jabber:iq:time'/><feature var='jabber:iq:version'/><feature var='jabber:x:data'/><feature var='jabber:x:event'/><feature var='jabber:x:oob'/><feature var='urn:xmpp:ping'/><feature var='urn:xmpp:receipts'/><feature var='urn:xmpp:time'/></query>", + "GNjxthSckUNvAIoCCJFttjl6VL8=" + ); +} + +gint +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/jabber/caps/parse invalid nodes", + test_jabber_caps_parse_invalid_nodes); + + g_test_add_func("/jabber/caps/calulate from xmlnode", + test_jabber_caps_calculate_from_xmlnode); + + return g_test_run(); +} diff --git a/libpurple/protocols/jabber/tests/test_jabber_digest_md5.c b/libpurple/protocols/jabber/tests/test_jabber_digest_md5.c new file mode 100644 index 0000000000..bb2e05a10f --- /dev/null +++ b/libpurple/protocols/jabber/tests/test_jabber_digest_md5.c @@ -0,0 +1,50 @@ +#include <glib.h> + +#include "util.h" +#include "protocols/jabber/auth_digest_md5.h" +#include "protocols/jabber/jutil.h" + +static void +test_jabber_digest_md5_parsing(void) { + GHashTable *table; + const gchar *value = NULL; + + #define check_value(name, expected) G_STMT_START {\ + value = g_hash_table_lookup(table, (name)); \ + g_assert_nonnull(value); \ + g_assert_cmpstr((expected), ==, value); \ + } G_STMT_END + + table = jabber_auth_digest_md5_parse("r=\"realm\",token= \" asdf\""); + check_value("r", "realm"); + check_value("token", "asdf"); + g_hash_table_destroy(table); + + table = jabber_auth_digest_md5_parse("r=\"a\", token= \" asdf\""); + check_value("r", "a"); + check_value("token", "asdf"); + g_hash_table_destroy(table); + + table = jabber_auth_digest_md5_parse("r=\"\", token= \" asdf\""); + check_value("r", ""); + check_value("token", "asdf"); + g_hash_table_destroy(table); + + table = jabber_auth_digest_md5_parse("realm=\"somerealm\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",charset=utf-8,algorithm=md5-sess"); + check_value("realm", "somerealm"); + check_value("nonce", "OA6MG9tEQGm2hh"); + check_value("qop", "auth"); + check_value("charset", "utf-8"); + check_value("algorithm", "md5-sess"); + g_hash_table_destroy(table); +} + +gint +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/jabber/digest/md5/parsing", + test_jabber_digest_md5_parsing); + + return g_test_run(); +} diff --git a/libpurple/protocols/jabber/tests/test_jabber_jutil.c b/libpurple/protocols/jabber/tests/test_jabber_jutil.c new file mode 100644 index 0000000000..ea4faf9c2d --- /dev/null +++ b/libpurple/protocols/jabber/tests/test_jabber_jutil.c @@ -0,0 +1,295 @@ +#include <glib.h> + +#include "account.h" +#include "conversation.h" +#include "xmlnode.h" +#include "protocols/jabber/jutil.h" + +typedef struct { + const gchar *input; + const gchar *output; +} TestStringData; + +typedef const gchar *(*test_string_func)(const gchar *); +typedef gchar *(*test_string_free_func)(const gchar *); + +static void +_test_string_compare_func(TestStringData data[], test_string_func func) { + gint i; + + for(i = 0; data[i].input; i++) + g_assert_cmpstr(data[i].output, ==, func(data[i].input)); +} + +static void +_test_string_compare_func_free(TestStringData data[], test_string_free_func func) { + gint i; + + for(i = 0; data[i].input; i++) { + gchar *got = func(data[i].input); + + g_assert_cmpstr(data[i].output, ==, got); + + g_free(got); + } +} + +static void +test_jabber_util_get_resource_exists(void) { + TestStringData data[] = { + { "foo@bar/baz", "baz" }, + { "bar/baz", "baz" }, + { "foo@bar/baz/bat", "baz/bat" }, + { "bar/baz/bat", "baz/bat" }, + { NULL, NULL }, + }; + + _test_string_compare_func_free(data, jabber_get_resource); +} + +static void +test_jabber_util_get_resource_none(void) { + TestStringData data[] = { + { "foo@bar", NULL }, + { "bar", NULL }, + { NULL, NULL }, + }; + + _test_string_compare_func_free(data, jabber_get_resource); +} + +static void +test_jabber_util_get_bare_jid(void) { + TestStringData data[] = { + { "foo@bar", "foo@bar" }, + { "foo@bar/baz", "foo@bar" }, + { "bar", "bar" }, + { "bar/baz", "bar" }, + { NULL, NULL }, + }; + + _test_string_compare_func_free(data, jabber_get_bare_jid); +} + +static void +test_jabber_util_nodeprep_validate(void) { + const gchar *data[] = { + "foo", + "%d", + "y\\z", + "a=", + "a,", + NULL, + }; + gchar *longnode; + gint i; + + for(i = 0; data[i]; i++) { + g_assert_true(jabber_nodeprep_validate(data[i])); + } + + longnode = g_strnfill(1023, 'a'); + g_assert_true(jabber_nodeprep_validate(longnode)); + g_free(longnode); + + longnode = g_strnfill(1024, 'a'); + g_assert_false(jabber_nodeprep_validate(longnode)); + g_free(longnode); +} + +static void +test_jabber_util_nodeprep_validate_illegal_chars(void) { + const gchar *data[] = { + "don't", + "m@ke", + "\"me\"", + "&ngry", + "c:", + "a/b", + "4>2", + "4<7", + NULL, + }; + gint i; + + for(i = 0; data[i]; i++) + g_assert_false(jabber_nodeprep_validate(data[i])); +} + +static void +test_jabber_util_nodeprep_validate_too_long(void) { + gchar *longnode = g_strnfill(1024, 'a'); + + g_assert_false(jabber_nodeprep_validate(longnode)); + + g_free(longnode); +} + +static void +test_jabber_util_jabber_id_new_valid(void) { + const gchar *jids[] = { + "gmail.com", + "gmail.com/Test", + "gmail.com/Test@", + "gmail.com/@", + "gmail.com/Test@alkjaweflkj", + "mark.doliner@gmail.com", + "mark.doliner@gmail.com/Test12345", + "mark.doliner@gmail.com/Test@12345", + "mark.doliner@gmail.com/Te/st@12@//345", + "わいど@conference.jabber.org", + "まりるーむ@conference.jabber.org", + "mark.doliner@gmail.com/まりるーむ", + "mark.doliner@gmail/stuff.org", + "stuart@nödåtXäYZ.se", + "stuart@nödåtXäYZ.se/まりるーむ", + "mark.doliner@わいど.org", + "nick@まつ.おおかみ.net", + "paul@10.0.42.230/s", + "paul@[::1]", /* IPv6 */ + "paul@[2001:470:1f05:d58::2]", + "paul@[2001:470:1f05:d58::2]/foo", + "pa=ul@10.0.42.230", + "pa,ul@10.0.42.230", + NULL + }; + gint i; + + for(i = 0; jids[i]; i++) { + JabberID *jid = jabber_id_new(jids[i]); + + g_assert_nonnull(jid); + + jabber_id_free(jid); + } +} + +static void +test_jabber_util_jabber_id_new_invalid(void) { + const gchar *jids[] = { + "@gmail.com", + "@@gmail.com", + "mark.doliner@@gmail.com/Test12345", + "mark@doliner@gmail.com/Test12345", + "@gmail.com/Test@12345", + "/Test@12345", + "mark.doliner@", + "mark.doliner/", + "mark.doliner@gmail_stuff.org", + "mark.doliner@gmail[stuff.org", + "mark.doliner@gmail\\stuff.org", + "paul@[::1]124", + "paul@2[::1]124/as", + "paul@まつ.おおかみ/\x01", + /* + * RFC 3454 Section 6 reads, in part, + * "If a string contains any RandALCat character, the + * string MUST NOT contain any LCat character." + * The character is U+066D (ARABIC FIVE POINTED STAR). + */ + "foo@example.com/٭simplexe٭", + NULL, + }; + gint i; + + for(i = 0; jids[i]; i++) + g_assert_null(jabber_id_new(jids[i])); +} + +#define assert_jid_parts(expect_node, expect_domain, str) G_STMT_START { \ + JabberID *jid = jabber_id_new(str); \ + g_assert_nonnull(jid); \ + g_assert_nonnull(jid->node); \ + g_assert_nonnull(jid->domain); \ + g_assert_null(jid->resource); \ + g_assert_cmpstr(expect_node, ==, jid->node); \ + g_assert_cmpstr(expect_domain, ==, jid->domain); \ + jabber_id_free(jid); \ +} G_STMT_END + + +static void +test_jabber_util_jid_parts(void) { + /* Ensure that jabber_id_new is properly lowercasing node and domains */ + assert_jid_parts("paul", "darkrain42.org", "PaUL@darkrain42.org"); + assert_jid_parts("paul", "darkrain42.org", "paul@DaRkRaIn42.org"); + + /* These case-mapping tests culled from examining RFC3454 B.2 */ + + /* Cyrillic capital EF (U+0424) maps to lowercase EF (U+0444) */ + assert_jid_parts("ф", "darkrain42.org", "Ф@darkrain42.org"); + +#ifdef USE_IDN + /* + * These character (U+A664 and U+A665) are not mapped to anything in + * RFC3454 B.2. This first test *fails* when not using IDN because glib's + * case-folding/utf8_strdown improperly (for XMPP) lowercases the character. + * + * This is known, but not (very?) likely to actually cause a problem, so + * this test is commented out when using glib's functions. + */ + assert_jid_parts("Ꙥ", "darkrain42.org", "Ꙥ@darkrain42.org"); + assert_jid_parts("ꙥ", "darkrain42.org", "ꙥ@darkrain42.org"); +#endif + + /* U+04E9 to U+04E9 */ + assert_jid_parts("paul", "өarkrain42.org", "paul@Өarkrain42.org"); +} + +static const gchar * +partial_jabber_normalize(const gchar *str) { + return jabber_normalize(NULL, str); +} + +static void +test_jabber_util_jabber_normalize(void) { + TestStringData data[] = { + { + "PaUL@DaRkRain42.org", + "paul@darkrain42.org", + }, { + "PaUL@DaRkRain42.org/", + "paul@darkrain42.org", + }, { + "PaUL@DaRkRain42.org/resource", + "paul@darkrain42.org", + }, { + NULL, + NULL, + } + }; + + _test_string_compare_func(data, partial_jabber_normalize); +} + +gint +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/jabber/util/get_resource/exists", + test_jabber_util_get_resource_exists); + g_test_add_func("/jabber/util/get_resource/none", + test_jabber_util_get_resource_none); + + g_test_add_func("/jabber/util/get_bare_jid", + test_jabber_util_get_bare_jid); + + g_test_add_func("/jabber/util/nodeprep/validate/valid", + test_jabber_util_nodeprep_validate); + g_test_add_func("/jabber/util/nodeprep/validate/illegal_chars", + test_jabber_util_nodeprep_validate_illegal_chars); + g_test_add_func("/jabber/util/nodeprep/validate/too_long", + test_jabber_util_nodeprep_validate_too_long); + + g_test_add_func("/jabber/util/id_new/valid", + test_jabber_util_jabber_id_new_valid); + g_test_add_func("/jabber/util/id_new/invalid", + test_jabber_util_jabber_id_new_invalid); + g_test_add_func("/jabber/util/id_new/jid_parts", + test_jabber_util_jid_parts); + + g_test_add_func("/jabber/util/normalize", + test_jabber_util_jabber_normalize); + + return g_test_run(); +} diff --git a/libpurple/tests/test_jabber_scram.c b/libpurple/protocols/jabber/tests/test_jabber_scram.c index bb440100a5..bb440100a5 100644 --- a/libpurple/tests/test_jabber_scram.c +++ b/libpurple/protocols/jabber/tests/test_jabber_scram.c diff --git a/libpurple/tests/test_jabber_caps.c b/libpurple/tests/test_jabber_caps.c deleted file mode 100644 index 0f534787d6..0000000000 --- a/libpurple/tests/test_jabber_caps.c +++ /dev/null @@ -1,64 +0,0 @@ -#include <string.h> - -#include "tests.h" -#include "../xmlnode.h" -#include "../protocols/jabber/caps.h" -#include "../ciphers/md5hash.h" -#include "../ciphers/sha1hash.h" - -START_TEST(test_parse_invalid) -{ - PurpleXmlNode *query; - - fail_unless(NULL == jabber_caps_parse_client_info(NULL)); - - /* Something other than a disco#info query */ - query = purple_xmlnode_new("foo"); - fail_unless(NULL == jabber_caps_parse_client_info(query)); - purple_xmlnode_free(query); - - query = purple_xmlnode_new("query"); - fail_unless(NULL == jabber_caps_parse_client_info(query)); - purple_xmlnode_set_namespace(query, "jabber:iq:last"); - fail_unless(NULL == jabber_caps_parse_client_info(query)); - purple_xmlnode_free(query); -} -END_TEST - -#define assert_caps_calculate_match(hash_func, hash, str) { \ - PurpleXmlNode *query = purple_xmlnode_from_str((str), -1); \ - PurpleHash *hasher = NULL; \ - JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); \ - gchar *got_hash; \ - if (g_str_equal(hash_func, "sha-1")) { \ - hasher = purple_sha1_hash_new(); \ - } else if (g_str_equal(hash_func, "md5")) { \ - hasher = purple_md5_hash_new(); \ - } \ - got_hash = jabber_caps_calculate_hash(info, hasher); \ - g_object_unref(hasher); \ - assert_string_equal_free((hash), got_hash); \ -} - -START_TEST(test_calculate_caps) -{ - assert_caps_calculate_match("sha-1", "GNjxthSckUNvAIoCCJFttjl6VL8=", - "<query xmlns='http://jabber.org/protocol/disco#info' node='http://tkabber.jabber.ru/#GNjxthSckUNvAIoCCJFttjl6VL8='><identity category='client' type='pc' name='Tkabber'/><x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='software'><value>Tkabber</value></field><field var='software_version'><value> ( 8.5.5 )</value></field><field var='os'><value>ATmega640-16AU</value></field><field var='os_version'><value/></field></x><feature var='games:board'/><feature var='google:mail:notify'/><feature var='http://jabber.org/protocol/activity'/><feature var='http://jabber.org/protocol/bytestreams'/><feature var='http://jabber.org/protocol/chatstates'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/disco#info'/><feature var='http://jabber.org/protocol/disco#items'/><feature var='http://jabber.org/protocol/feature-neg'/><feature var='http://jabber.org/protocol/geoloc'/><feature var='http://jabber.org/protocol/ibb'/><feature var='http://jabber.org/protocol/iqibb'/><feature var='http://jabber.org/protocol/mood'/><feature var='http://jabber.org/protocol/muc'/><feature var='http://jabber.org/protocol/mute#ancestor'/><feature var='http://jabber.org/protocol/mute#editor'/><feature var='http://jabber.org/protocol/rosterx'/><feature var='http://jabber.org/protocol/si'/><feature var='http://jabber.org/protocol/si/profile/file-transfer'/><feature var='http://jabber.org/protocol/tune'/><feature var='jabber:iq:avatar'/><feature var='jabber:iq:browse'/><feature var='jabber:iq:dtcp'/><feature var='jabber:iq:filexfer'/><feature var='jabber:iq:ibb'/><feature var='jabber:iq:inband'/><feature var='jabber:iq:jidlink'/><feature var='jabber:iq:last'/><feature var='jabber:iq:oob'/><feature var='jabber:iq:privacy'/><feature var='jabber:iq:time'/><feature var='jabber:iq:version'/><feature var='jabber:x:data'/><feature var='jabber:x:event'/><feature var='jabber:x:oob'/><feature var='urn:xmpp:ping'/><feature var='urn:xmpp:receipts'/><feature var='urn:xmpp:time'/></query>"); -} -END_TEST - -Suite * -jabber_caps_suite(void) -{ - Suite *s = suite_create("Jabber Caps Functions"); - - TCase *tc = tcase_create("Parsing invalid ndoes"); - tcase_add_test(tc, test_parse_invalid); - suite_add_tcase(s, tc); - - tc = tcase_create("Calculating from XMLnode"); - tcase_add_test(tc, test_calculate_caps); - suite_add_tcase(s, tc); - - return s; -} diff --git a/libpurple/tests/test_jabber_digest_md5.c b/libpurple/tests/test_jabber_digest_md5.c deleted file mode 100644 index a426b9a2a5..0000000000 --- a/libpurple/tests/test_jabber_digest_md5.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <string.h> - -#include "tests.h" -#include "../util.h" -#include "../protocols/jabber/auth_digest_md5.h" -#include "../protocols/jabber/jutil.h" - -START_TEST(test_parsing) -{ - GHashTable *table; - - table = jabber_auth_digest_md5_parse("r=\"realm\",token= \" asdf\""); - fail_if(g_hash_table_lookup(table, "r") == NULL); - assert_string_equal("realm", g_hash_table_lookup(table, "r")); - fail_if(g_hash_table_lookup(table, "token") == NULL); - assert_string_equal("asdf", g_hash_table_lookup(table, "token")); - g_hash_table_destroy(table); - - table = jabber_auth_digest_md5_parse("r=\"a\", token= \" asdf\""); - fail_if(g_hash_table_lookup(table, "r") == NULL); - assert_string_equal("a", g_hash_table_lookup(table, "r")); - fail_if(g_hash_table_lookup(table, "token") == NULL); - assert_string_equal("asdf", g_hash_table_lookup(table, "token")); - g_hash_table_destroy(table); - - table = jabber_auth_digest_md5_parse("r=\"\", token= \" asdf\""); - fail_if(g_hash_table_lookup(table, "r") == NULL); - assert_string_equal("", g_hash_table_lookup(table, "r")); - fail_if(g_hash_table_lookup(table, "token") == NULL); - assert_string_equal("asdf", g_hash_table_lookup(table, "token")); - g_hash_table_destroy(table); - - table = jabber_auth_digest_md5_parse("realm=\"somerealm\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",charset=utf-8,algorithm=md5-sess"); - fail_if(g_hash_table_lookup(table, "realm") == NULL); - assert_string_equal("somerealm", g_hash_table_lookup(table, "realm")); - fail_if(g_hash_table_lookup(table, "nonce") == NULL); - assert_string_equal("OA6MG9tEQGm2hh", g_hash_table_lookup(table, "nonce")); - fail_if(g_hash_table_lookup(table, "qop") == NULL); - assert_string_equal("auth", g_hash_table_lookup(table, "qop")); - fail_if(g_hash_table_lookup(table, "charset") == NULL); - assert_string_equal("utf-8", g_hash_table_lookup(table, "charset")); - fail_if(g_hash_table_lookup(table, "algorithm") == NULL); - assert_string_equal("md5-sess", g_hash_table_lookup(table, "algorithm")); - - g_hash_table_destroy(table); - -} -END_TEST - -Suite * -jabber_digest_md5_suite(void) -{ - Suite *s = suite_create("Jabber SASL DIGEST-MD5 functions"); - - TCase *tc = tcase_create("Parsing Functionality"); - tcase_add_test(tc, test_parsing); - suite_add_tcase(s, tc); - return s; -} diff --git a/libpurple/tests/test_jabber_jutil.c b/libpurple/tests/test_jabber_jutil.c deleted file mode 100644 index 713115cab8..0000000000 --- a/libpurple/tests/test_jabber_jutil.c +++ /dev/null @@ -1,207 +0,0 @@ -#include <string.h> - -#include "tests.h" -#include "../account.h" -#include "../conversation.h" -#include "../xmlnode.h" -#include "../protocols/jabber/jutil.h" - -START_TEST(test_get_resource) -{ - assert_string_equal_free("baz", jabber_get_resource("foo@bar/baz")); - assert_string_equal_free("baz", jabber_get_resource("bar/baz")); - assert_string_equal_free("baz/bat", jabber_get_resource("foo@bar/baz/bat")); - assert_string_equal_free("baz/bat", jabber_get_resource("bar/baz/bat")); -} -END_TEST - -START_TEST(test_get_resource_no_resource) -{ - - fail_unless(NULL == jabber_get_resource("foo@bar")); - fail_unless(NULL == jabber_get_resource("bar")); -} -END_TEST - -START_TEST(test_get_bare_jid) -{ - assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar")); - assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar/baz")); - assert_string_equal_free("bar", jabber_get_bare_jid("bar")); - assert_string_equal_free("bar", jabber_get_bare_jid("bar/baz")); -} -END_TEST - -START_TEST(test_nodeprep_validate) -{ - char *longnode; - - fail_unless(jabber_nodeprep_validate(NULL)); - fail_unless(jabber_nodeprep_validate("foo")); - fail_unless(jabber_nodeprep_validate("%d")); - fail_unless(jabber_nodeprep_validate("y\\z")); - fail_unless(jabber_nodeprep_validate("a=")); - fail_unless(jabber_nodeprep_validate("a,")); - - longnode = g_strnfill(1023, 'a'); - fail_unless(jabber_nodeprep_validate(longnode)); - g_free(longnode); - - longnode = g_strnfill(1024, 'a'); - fail_if(jabber_nodeprep_validate(longnode)); - g_free(longnode); -} -END_TEST - -START_TEST(test_nodeprep_validate_illegal_chars) -{ - fail_if(jabber_nodeprep_validate("don't")); - fail_if(jabber_nodeprep_validate("m@ke")); - fail_if(jabber_nodeprep_validate("\"me\"")); - fail_if(jabber_nodeprep_validate("&ngry")); - fail_if(jabber_nodeprep_validate("c:")); - fail_if(jabber_nodeprep_validate("a/b")); - fail_if(jabber_nodeprep_validate("4>2")); - fail_if(jabber_nodeprep_validate("4<7")); -} -END_TEST - -START_TEST(test_nodeprep_validate_too_long) -{ - char *longnode = g_strnfill(1024, 'a'); - fail_if(jabber_nodeprep_validate(longnode)); - g_free(longnode); -} -END_TEST - -#define assert_valid_jid(str) { \ - JabberID *jid = jabber_id_new(str); \ - fail_if(jid == NULL, "JID '%s' is valid but jabber_id_new() rejected it", str); \ - jabber_id_free(jid); \ -} - -#define assert_invalid_jid(str) { \ - JabberID *jid = jabber_id_new(str); \ - fail_if(jid != NULL, "JID '%s' is invalid but jabber_id_new() allowed it", str); \ - jabber_id_free(jid); \ -} - -#define assert_jid_parts(expect_node, expect_domain, str) { \ - JabberID *jid = jabber_id_new(str); \ - fail_if(jid == NULL, "JID '%s' is valid but jabber_id_new() rejected it", str); \ - fail_if(jid->node == NULL, "JID '%s' is valid but jabber_id_new() didn't return a node", str); \ - fail_if(jid->domain == NULL, "JID '%s' is valid but jabber_id_new() didn't return a domain", str); \ - fail_if(jid->resource != NULL, "JID '%s' doesn't contain a resource", str); \ - assert_string_equal(expect_node, jid->node); \ - assert_string_equal(expect_domain, jid->domain); \ - jabber_id_free(jid); \ -} - -START_TEST(test_jabber_id_new) -{ - assert_valid_jid("gmail.com"); - assert_valid_jid("gmail.com/Test"); - assert_valid_jid("gmail.com/Test@"); - assert_valid_jid("gmail.com/@"); - assert_valid_jid("gmail.com/Test@alkjaweflkj"); - assert_valid_jid("mark.doliner@gmail.com"); - assert_valid_jid("mark.doliner@gmail.com/Test12345"); - assert_valid_jid("mark.doliner@gmail.com/Test@12345"); - assert_valid_jid("mark.doliner@gmail.com/Te/st@12@//345"); - assert_valid_jid("わいど@conference.jabber.org"); - assert_valid_jid("まりるーむ@conference.jabber.org"); - assert_valid_jid("mark.doliner@gmail.com/まりるーむ"); - assert_valid_jid("mark.doliner@gmail/stuff.org"); - assert_valid_jid("stuart@nödåtXäYZ.se"); - assert_valid_jid("stuart@nödåtXäYZ.se/まりるーむ"); - assert_valid_jid("mark.doliner@わいど.org"); - assert_valid_jid("nick@まつ.おおかみ.net"); - assert_valid_jid("paul@10.0.42.230/s"); - assert_valid_jid("paul@[::1]"); /* IPv6 */ - assert_valid_jid("paul@[2001:470:1f05:d58::2]"); - assert_valid_jid("paul@[2001:470:1f05:d58::2]/foo"); - assert_valid_jid("pa=ul@10.0.42.230"); - assert_valid_jid("pa,ul@10.0.42.230"); - - assert_invalid_jid("@gmail.com"); - assert_invalid_jid("@@gmail.com"); - assert_invalid_jid("mark.doliner@@gmail.com/Test12345"); - assert_invalid_jid("mark@doliner@gmail.com/Test12345"); - assert_invalid_jid("@gmail.com/Test@12345"); - assert_invalid_jid("/Test@12345"); - assert_invalid_jid("mark.doliner@"); - assert_invalid_jid("mark.doliner/"); - assert_invalid_jid("mark.doliner@gmail_stuff.org"); - assert_invalid_jid("mark.doliner@gmail[stuff.org"); - assert_invalid_jid("mark.doliner@gmail\\stuff.org"); - assert_invalid_jid("paul@[::1]124"); - assert_invalid_jid("paul@2[::1]124/as"); - assert_invalid_jid("paul@まつ.おおかみ/\x01"); - - /* - * RFC 3454 Section 6 reads, in part, - * "If a string contains any RandALCat character, the - * string MUST NOT contain any LCat character." - * The character is U+066D (ARABIC FIVE POINTED STAR). - */ - assert_invalid_jid("foo@example.com/٭simplexe٭"); - - /* Ensure that jabber_id_new is properly lowercasing node and domains */ - assert_jid_parts("paul", "darkrain42.org", "PaUL@darkrain42.org"); - assert_jid_parts("paul", "darkrain42.org", "paul@DaRkRaIn42.org"); - - /* These case-mapping tests culled from examining RFC3454 B.2 */ - - /* Cyrillic capital EF (U+0424) maps to lowercase EF (U+0444) */ - assert_jid_parts("ф", "darkrain42.org", "Ф@darkrain42.org"); - -#ifdef USE_IDN - /* - * These character (U+A664 and U+A665) are not mapped to anything in - * RFC3454 B.2. This first test *fails* when not using IDN because glib's - * case-folding/utf8_strdown improperly (for XMPP) lowercases the character. - * - * This is known, but not (very?) likely to actually cause a problem, so - * this test is commented out when using glib's functions. - */ - assert_jid_parts("Ꙥ", "darkrain42.org", "Ꙥ@darkrain42.org"); - assert_jid_parts("ꙥ", "darkrain42.org", "ꙥ@darkrain42.org"); -#endif - - /* U+04E9 to U+04E9 */ - assert_jid_parts("paul", "өarkrain42.org", "paul@Өarkrain42.org"); -} -END_TEST - -START_TEST(test_jabber_normalize) -{ - assert_string_equal("paul@darkrain42.org", jabber_normalize(NULL, "PaUL@DaRkRain42.org")); - assert_string_equal("paul@darkrain42.org", jabber_normalize(NULL, "PaUL@DaRkRain42.org/")); - assert_string_equal("paul@darkrain42.org", jabber_normalize(NULL, "PaUL@DaRkRain42.org/resource")); -} -END_TEST - -Suite * -jabber_jutil_suite(void) -{ - Suite *s = suite_create("Jabber Utility Functions"); - - TCase *tc = tcase_create("Get Resource"); - tcase_add_test(tc, test_get_resource); - tcase_add_test(tc, test_get_resource_no_resource); - suite_add_tcase(s, tc); - - tc = tcase_create("Get Bare JID"); - tcase_add_test(tc, test_get_bare_jid); - suite_add_tcase(s, tc); - - tc = tcase_create("JID validate"); - tcase_add_test(tc, test_nodeprep_validate); - tcase_add_test(tc, test_nodeprep_validate_illegal_chars); - tcase_add_test(tc, test_nodeprep_validate_too_long); - tcase_add_test(tc, test_jabber_id_new); - tcase_add_test(tc, test_jabber_normalize); - suite_add_tcase(s, tc); - - return s; -} |