diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 2 | ||||
-rw-r--r-- | tests/check.c | 4 | ||||
-rw-r--r-- | tests/check_arc.c | 35 | ||||
-rw-r--r-- | tests/check_irc.c | 4 | ||||
-rw-r--r-- | tests/check_jabber_sasl.c | 1 | ||||
-rw-r--r-- | tests/check_jabber_util.c | 91 |
6 files changed, 120 insertions, 17 deletions
diff --git a/tests/Makefile b/tests/Makefile index ae76fef5..db145503 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -12,7 +12,7 @@ distclean: clean main_objs = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_xml.o storage_text.o user.o -test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o check_jabber_sasl.o +test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o check_jabber_sasl.o check_jabber_util.o check: $(test_objs) $(addprefix ../, $(main_objs)) ../protocols/protocols.o ../lib/lib.o @echo '*' Linking $@ diff --git a/tests/check.c b/tests/check.c index b3ffb957..874acdd2 100644 --- a/tests/check.c +++ b/tests/check.c @@ -68,6 +68,9 @@ Suite *set_suite(void); /* From check_jabber_sasl.c */ Suite *jabber_sasl_suite(void); +/* From check_jabber_sasl.c */ +Suite *jabber_util_suite(void); + int main (int argc, char **argv) { int nf; @@ -114,6 +117,7 @@ int main (int argc, char **argv) srunner_add_suite(sr, crypting_suite()); srunner_add_suite(sr, set_suite()); srunner_add_suite(sr, jabber_sasl_suite()); + srunner_add_suite(sr, jabber_util_suite()); if (no_fork) srunner_set_fork_status(sr, CK_NOFORK); srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL); diff --git a/tests/check_arc.c b/tests/check_arc.c index a430f899..9d913dcd 100644 --- a/tests/check_arc.c +++ b/tests/check_arc.c @@ -6,13 +6,14 @@ #include <stdio.h> #include "arc.h" -char *password = "TotT"; +char *password = "ArcVier"; char *clear_tests[] = { "Wie dit leest is gek :-)", "ItllBeBitlBee", "One more boring password", + "Hoi hoi", NULL }; @@ -27,7 +28,7 @@ static void check_codec(int l) char *decrypted; int len; - len = arc_encode( clear_tests[i], 0, &crypted, password ); + len = arc_encode( clear_tests[i], 0, &crypted, password, 12 ); len = arc_decode( crypted, len, &decrypted, password ); fail_if( strcmp( clear_tests[i], decrypted ) != 0, @@ -40,27 +41,35 @@ static void check_codec(int l) struct { - unsigned char crypted[24]; + unsigned char crypted[30]; int len; char *decrypted; } decrypt_tests[] = { + /* One block with padding. */ { { - 0xc3, 0x0d, 0x43, 0xc3, 0xee, 0x80, 0xe2, 0x8c, 0x0b, 0x29, 0x32, 0x7e, - 0x38, 0x05, 0x82, 0x10, 0x21, 0x1c, 0x4a, 0x00, 0x2c - }, 21, "Debugging sucks" + 0x3f, 0x79, 0xb0, 0xf5, 0x91, 0x56, 0xd2, 0x1b, 0xd1, 0x4b, 0x67, 0xac, + 0xb1, 0x31, 0xc9, 0xdb, 0xf9, 0xaa + }, 18, "short pass" }, + + /* Two blocks with padding. */ { { - 0xb0, 0x00, 0x57, 0x0d, 0x0d, 0x0d, 0x70, 0xe1, 0xc0, 0x00, 0xa4, 0x25, - 0x7d, 0xbe, 0x03, 0xcc, 0x24, 0xd1, 0x0c - }, 19, "Testing rocks" + 0xf9, 0xa6, 0xec, 0x5d, 0xc7, 0x06, 0xb8, 0x6b, 0x63, 0x9f, 0x2d, 0xb5, + 0x7d, 0xaa, 0x32, 0xbb, 0xd8, 0x08, 0xfd, 0x81, 0x2e, 0xca, 0xb4, 0xd7, + 0x2f, 0x36, 0x9c, 0xac, 0xa0, 0xbc + }, 30, "longer password" }, + + /* This string is exactly two "blocks" long, to make sure unpadded strings also decrypt + properly. */ { { - 0xb6, 0x92, 0x59, 0xe4, 0xf9, 0xc1, 0x7a, 0xf6, 0xf3, 0x18, 0xea, 0x28, - 0x73, 0x6d, 0xb3, 0x0a, 0x6f, 0x0a, 0x2b, 0x43, 0x57, 0xe9, 0x3e, 0x63 - }, 24, "OSCAR is creepy..." + 0x95, 0x4d, 0xcf, 0x4d, 0x5e, 0x6c, 0xcf, 0xef, 0xb9, 0x80, 0x00, 0xef, + 0x25, 0xe9, 0x17, 0xf6, 0x29, 0x6a, 0x82, 0x79, 0x1c, 0xca, 0x68, 0xb5, + 0x4e, 0xd0, 0xc1, 0x41, 0x8e, 0xe6 + }, 30, "OSCAR is really creepy.." }, { "", 0, NULL } }; @@ -79,7 +88,7 @@ static void check_decod(int l) &decrypted, password ); fail_if( strcmp( decrypt_tests[i].decrypted, decrypted ) != 0, - "%s didn't decrypt properly", clear_tests[i] ); + "`%s' didn't decrypt properly", decrypt_tests[i].decrypted ); g_free( decrypted ); } diff --git a/tests/check_irc.c b/tests/check_irc.c index c1cf05a5..66fe0021 100644 --- a/tests/check_irc.c +++ b/tests/check_irc.c @@ -36,8 +36,8 @@ START_TEST(test_login) irc = irc_new(g_io_channel_unix_get_fd(ch1)); - fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\n" - "USER a a a a\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL); + fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\r\n" + "USER a a a a\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL); fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL); g_main_iteration(FALSE); diff --git a/tests/check_jabber_sasl.c b/tests/check_jabber_sasl.c index 6bceeb88..63118d39 100644 --- a/tests/check_jabber_sasl.c +++ b/tests/check_jabber_sasl.c @@ -4,7 +4,6 @@ #include <check.h> #include <string.h> #include <stdio.h> -#include "arc.h" char *sasl_get_part( char *data, char *field ); diff --git a/tests/check_jabber_util.c b/tests/check_jabber_util.c new file mode 100644 index 00000000..4728c5ee --- /dev/null +++ b/tests/check_jabber_util.c @@ -0,0 +1,91 @@ +#include <stdlib.h> +#include <glib.h> +#include <gmodule.h> +#include <check.h> +#include <string.h> +#include <stdio.h> +#include "jabber/jabber.h" + +static struct im_connection *ic; + +static void check_buddy_add(int l) +{ + struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud; + + budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee" ); + budw1->last_act = time( NULL ) - 100; + budw2 = jabber_buddy_add( ic, "WILMER@gaast.net/Telepathy" ); + budw2->priority = 2; + budw2->last_act = time( NULL ); + budw3 = jabber_buddy_add( ic, "wilmer@GAAST.NET/bitlbee" ); + budw3->last_act = time( NULL ) - 200; + budw3->priority = 4; + /* TODO(wilmer): Shouldn't this just return budw3? */ + fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" ) != NULL ); + + budn = jabber_buddy_add( ic, "nekkid@lamejab.net" ); + /* Shouldn't be allowed if there's already a bare JID. */ + fail_if( jabber_buddy_add( ic, "nekkid@lamejab.net/Illegal" ) ); + + /* Case sensitivity: Case only matters after the / */ + fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == + jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", 0 ) ); + fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/telepathy", 0 ) ); + + fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == budw1 ); + fail_unless( jabber_buddy_by_jid( ic, "WILMER@GAAST.NET/BitlBee", GET_BUDDY_EXACT ) == budw1 ); + fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/BitlBee", GET_BUDDY_CREAT ) == budw1 ); + + fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_EXACT ) ); + fail_unless( jabber_buddy_by_jid( ic, "WILMER@gaast.net", 0 ) == budw3 ); + + /* Check O_FIRST and see if it's indeed the first item from the list. */ + fail_unless( ( bud = jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) ) == budw1 ); + fail_unless( bud->next == budw2 && bud->next->next == budw3 && bud->next->next->next == NULL ); + + /* Change the resource_select setting, now we should get a different resource. */ + set_setstr( &ic->acc->set, "resource_select", "activity" ); + fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET", 0 ) == budw2 ); + + /* Some testing of bare JID handling (which is horrible). */ + fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", 0 ) ); + fail_if( jabber_buddy_by_jid( ic, "NEKKID@LAMEJAB.NET/Illegal", GET_BUDDY_CREAT ) ); + fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) == budn ); + fail_unless( jabber_buddy_by_jid( ic, "NEKKID@lamejab.net", GET_BUDDY_EXACT ) == budn ); + fail_unless( jabber_buddy_by_jid( ic, "nekkid@LAMEJAB.NET", GET_BUDDY_CREAT ) == budn ); + + /* More case sensitivity testing, and see if remove works properly. */ + fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) ); + fail_if( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/telepathy", GET_BUDDY_CREAT ) == budw2 ); + fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/Telepathy" ) ); + fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) ); + fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); + + fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ) ); + fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); + + /* Check if remove_bare() indeed gets rid of all. */ + fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) ); + fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) ); + + fail_if( jabber_buddy_remove( ic, "nekkid@lamejab.net/Illegal" ) ); + fail_unless( jabber_buddy_remove( ic, "nekkid@lamejab.net" ) ); + fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) ); +} + +Suite *jabber_util_suite (void) +{ + Suite *s = suite_create("jabber/util"); + TCase *tc_core = tcase_create("Buddy"); + struct jabber_data *jd; + + ic = g_new0( struct im_connection, 1 ); + ic->acc = g_new0( account_t, 1 ); + ic->proto_data = jd = g_new0( struct jabber_data, 1 ); + jd->buddies = g_hash_table_new( g_str_hash, g_str_equal ); + set_add( &ic->acc->set, "resource_select", "priority", NULL, ic->acc ); + + suite_add_tcase (s, tc_core); + tcase_add_test (tc_core, check_buddy_add); + return s; +} |