From 2799ff94059f496b59420d04ec4f41f67aab2b9d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 16 Feb 2008 12:20:03 +0000 Subject: Fixed broken check in check_arc.c --- tests/check_arc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/check_arc.c b/tests/check_arc.c index 989a0a66..a430f899 100644 --- a/tests/check_arc.c +++ b/tests/check_arc.c @@ -61,14 +61,15 @@ struct 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..." - } + }, + { "", 0, NULL } }; static void check_decod(int l) { int i; - for( i = 0; clear_tests[i]; i++ ) + for( i = 0; decrypt_tests[i].len; i++ ) { tcase_fn_start (decrypt_tests[i].decrypted, __FILE__, __LINE__); char *decrypted; -- cgit v1.2.3 From af97b234ad86fb9d69aa744af426591e4b1eaf97 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 16 Feb 2008 13:17:52 +0000 Subject: Improved sasl_get_part() to deal with whitespace in challenge strings, as described in RFC 2831 secion 7.1 (the #rule description). Closes bug #362. --- tests/Makefile | 4 +- tests/check.c | 4 ++ tests/check_jabber_sasl.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 tests/check_jabber_sasl.c (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 5bc3fbde..ae76fef5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -10,9 +10,9 @@ clean: 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 +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 +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: $(test_objs) $(addprefix ../, $(main_objs)) ../protocols/protocols.o ../lib/lib.o @echo '*' Linking $@ diff --git a/tests/check.c b/tests/check.c index 043889d6..b3ffb957 100644 --- a/tests/check.c +++ b/tests/check.c @@ -65,6 +65,9 @@ Suite *crypting_suite(void); /* From check_set.c */ Suite *set_suite(void); +/* From check_jabber_sasl.c */ +Suite *jabber_sasl_suite(void); + int main (int argc, char **argv) { int nf; @@ -110,6 +113,7 @@ int main (int argc, char **argv) srunner_add_suite(sr, user_suite()); srunner_add_suite(sr, crypting_suite()); srunner_add_suite(sr, set_suite()); + srunner_add_suite(sr, jabber_sasl_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_jabber_sasl.c b/tests/check_jabber_sasl.c new file mode 100644 index 00000000..96c05837 --- /dev/null +++ b/tests/check_jabber_sasl.c @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include +#include +#include "arc.h" + +char *sasl_get_part( char *data, char *field ); + +#define challenge1 "nonce=\"1669585310\",qop=\"auth\",charset=utf-8,algorithm=md5-sess," \ + "something=\"Not \\\"standardized\\\"\"" +#define challenge2 "realm=\"quadpoint.org\", nonce=\"NPotlQpQf9RNYodOwierkQ==\", " \ + "qop=\"auth, auth-int\", charset=utf-8, algorithm=md5-sess" +#define challenge3 ", realm=\"localhost\", nonce=\"LlBV2txnO8RbB5hgs3KgiQ==\", " \ + "qop=\"auth, auth-int, \", ,\n, charset=utf-8, algorithm=md5-sess," + +struct +{ + const char *challenge; + char *key; + char *value; +} get_part_tests[] = { + { + challenge1, + "nonce", + "1669585310" + }, + { + challenge1, + "charset", + "utf-8" + }, + { + challenge1, + "harset", + NULL + }, + { + challenge1, + "something", + "Not \"standardized\"" + }, + { + challenge1, + "something_else", + NULL + }, + { + challenge2, + "realm", + "quadpoint.org", + }, + { + challenge2, + "real", + NULL + }, + { + challenge2, + "qop", + "auth, auth-int" + }, + { + challenge3, + "realm", + "localhost" + }, + { + challenge3, + "qop", + "auth, auth-int, " + }, + { + challenge3, + "charset", + "utf-8" + }, + { NULL, NULL, NULL } +}; + +static void check_get_part(int l) +{ + int i; + + for( i = 0; get_part_tests[i].key; i++ ) + { + tcase_fn_start( get_part_tests[i].key, __FILE__, i ); + char *res; + int len; + + res = sasl_get_part( get_part_tests[i].challenge, + get_part_tests[i].key ); + + if( get_part_tests[i].value == NULL ) + fail_if( res != NULL, "Found key %s in %s while it shouldn't be there!", + get_part_tests[i].key, get_part_tests[i].challenge ); + else if( res ) + fail_unless( strcmp( res, get_part_tests[i].value ) == 0, + "Incorrect value for key %s in %s: %s", + get_part_tests[i].key, get_part_tests[i].challenge, res ); + else + fail( "Could not find key %s in %s", + get_part_tests[i].key, get_part_tests[i].challenge ); + + g_free( res ); + } +} + +Suite *jabber_sasl_suite (void) +{ + Suite *s = suite_create("jabber/sasl"); + TCase *tc_core = tcase_create("Core"); + suite_add_tcase (s, tc_core); + tcase_add_test (tc_core, check_get_part); + return s; +} -- cgit v1.2.3 From 2d88d25aeb62d90e4288f8b83979baaff96cb7f2 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 16 Feb 2008 19:38:17 +0000 Subject: Added help_free() test, and fixed compiler warning in SASL test. --- tests/check_help.c | 7 +++++-- tests/check_jabber_sasl.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/check_help.c b/tests/check_help.c index 7e5283e3..5a2f28d9 100644 --- a/tests/check_help.c +++ b/tests/check_help.c @@ -6,11 +6,14 @@ #include #include "help.h" -START_TEST(test_help_none) +START_TEST(test_help_initfree) help_t *h, *r; r = help_init(&h, "/dev/null"); fail_if(r == NULL); fail_if(r != h); + + help_free(&h); + fail_if(h != NULL); END_TEST START_TEST(test_help_nonexistent) @@ -24,7 +27,7 @@ Suite *help_suite (void) Suite *s = suite_create("Help"); TCase *tc_core = tcase_create("Core"); suite_add_tcase (s, tc_core); - tcase_add_test (tc_core, test_help_none); + tcase_add_test (tc_core, test_help_initfree); tcase_add_test (tc_core, test_help_nonexistent); return s; } diff --git a/tests/check_jabber_sasl.c b/tests/check_jabber_sasl.c index 96c05837..6bceeb88 100644 --- a/tests/check_jabber_sasl.c +++ b/tests/check_jabber_sasl.c @@ -17,7 +17,7 @@ char *sasl_get_part( char *data, char *field ); struct { - const char *challenge; + char *challenge; char *key; char *value; } get_part_tests[] = { -- cgit v1.2.3 From ddcf491fa460fea612c240589c50da864dad6668 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 16 Mar 2008 14:18:22 +0000 Subject: Adding padding to encrypted IM-passwords so the exact password length can't be guessed from the encrypted data anymore. --- tests/check_arc.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'tests') 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 #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 ); } -- cgit v1.2.3 From 18ff38fad0d6d47853fb43ec5a99b29ba031a8ca Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 29 Mar 2008 23:15:04 +0000 Subject: Be more liberal with accepted line endings. ERC on Windows likes to use "\r\r\n", for example, and until now BitlBee only chopped off the \r\n, leaving the first \r as part of the command, which means it couldn't log in to BitlBee at all. (Bad character in nickname.) --- tests/check_irc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') 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); -- cgit v1.2.3