aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--protocols/jabber/sasl.c27
-rw-r--r--tests/Makefile4
-rw-r--r--tests/check.c4
-rw-r--r--tests/check_jabber_sasl.c117
4 files changed, 143 insertions, 9 deletions
diff --git a/protocols/jabber/sasl.c b/protocols/jabber/sasl.c
index 87059051..53248ef3 100644
--- a/protocols/jabber/sasl.c
+++ b/protocols/jabber/sasl.c
@@ -21,6 +21,8 @@
* *
\***************************************************************************/
+#include <ctype.h>
+
#include "jabber.h"
#include "base64.h"
@@ -106,12 +108,17 @@ xt_status sasl_pkt_mechanisms( struct xt_node *node, gpointer data )
return XT_HANDLED;
}
-static char *sasl_get_part( char *data, char *field )
+/* Non-static function, but not mentioned in jabber.h because it's for internal
+ use, just that the unittest should be able to reach it... */
+char *sasl_get_part( char *data, char *field )
{
int i, len;
len = strlen( field );
+ while( isspace( *data ) || *data == ',' )
+ data ++;
+
if( g_strncasecmp( data, field, len ) == 0 && data[len] == '=' )
{
i = strlen( field ) + 1;
@@ -128,13 +135,19 @@ static char *sasl_get_part( char *data, char *field )
i ++;
}
- /* If we got a comma, we got a new field. Check it. */
- if( data[i] == ',' &&
- g_strncasecmp( data + i + 1, field, len ) == 0 &&
- data[i+len+1] == '=' )
+ /* If we got a comma, we got a new field. Check it,
+ find the next key after it. */
+ if( data[i] == ',' )
{
- i += len + 2;
- break;
+ while( isspace( data[i] ) || data[i] == ',' )
+ i ++;
+
+ if( g_strncasecmp( data + i, field, len ) == 0 &&
+ data[i+len] == '=' )
+ {
+ i += len + 1;
+ break;
+ }
}
}
}
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 <stdlib.h>
+#include <glib.h>
+#include <gmodule.h>
+#include <check.h>
+#include <string.h>
+#include <stdio.h>
+#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;
+}