changeset 31176:e743507b3767

jabber: Test harness for DIGEST-MD5 parsing function. One of these tests fails, pending the next commit.
author Paul Aurich <paul@darkrain42.org>
date Wed, 02 Feb 2011 05:47:50 +0000
parents 928335d6461b
children 53096ba34fe6
files libpurple/protocols/jabber/Makefile.am libpurple/protocols/jabber/auth_digest_md5.c libpurple/protocols/jabber/auth_digest_md5.h libpurple/tests/Makefile.am libpurple/tests/check_libpurple.c libpurple/tests/test_jabber_digest_md5.c libpurple/tests/tests.h
diffstat 7 files changed, 105 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/Makefile.am	Tue Feb 01 04:00:50 2011 +0000
+++ b/libpurple/protocols/jabber/Makefile.am	Wed Feb 02 05:47:50 2011 +0000
@@ -11,6 +11,7 @@
 			  auth.c \
 			  auth.h \
 			  auth_digest_md5.c \
+			  auth_digest_md5.h \
 			  auth_plain.c \
 			  auth_scram.c \
 			  auth_scram.h \
--- a/libpurple/protocols/jabber/auth_digest_md5.c	Tue Feb 01 04:00:50 2011 +0000
+++ b/libpurple/protocols/jabber/auth_digest_md5.c	Wed Feb 02 05:47:50 2011 +0000
@@ -27,6 +27,7 @@
 #include "util.h"
 #include "xmlnode.h"
 
+#include "auth_digest_md5.h"
 #include "auth.h"
 #include "jabber.h"
 
@@ -43,7 +44,7 @@
 }
 
 /* Parts of this algorithm are inspired by stuff in libgsasl */
-static GHashTable* parse_challenge(const char *challenge)
+GHashTable* jabber_auth_digest_md5_parse(const char *challenge)
 {
 	const char *token_start, *val_start, *val_end, *cur;
 	GHashTable *ret = g_hash_table_new_full(g_str_hash, g_str_equal,
@@ -186,7 +187,7 @@
 			dec_in != NULL ? strlen(dec_in) : 0,
 			dec_in != NULL  ? dec_in : "(null)");
 
-	parts = parse_challenge(dec_in);
+	parts = jabber_auth_digest_md5_parse(dec_in);
 
 	if (g_hash_table_lookup(parts, "rspauth")) {
 		char *rspauth = g_hash_table_lookup(parts, "rspauth");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/jabber/auth_digest_md5.h	Wed Feb 02 05:47:50 2011 +0000
@@ -0,0 +1,39 @@
+/**
+ * @file auth_digest_md5.h Implementation of SASL DIGEST-MD5 authentication
+ *
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#ifndef PURPLE_JABBER_AUTH_DIGEST_MD5_H_
+#define PURPLE_JABBER_AUTH_DIGEST_MD5_H_
+
+#include "internal.h"
+
+/*
+ * Every function in this file is ONLY exposed for tests.
+ * DO NOT USE ANYTHING HERE OR YOU WILL BE SENT TO THE PIT OF DESPAIR.
+ */
+
+/*
+ * Parse a DIGEST-MD5 challenge.
+ */
+GHashTable *jabber_auth_digest_md5_parse(const char *challenge);
+
+#endif /* PURPLE_JABBER_AUTH_DIGEST_MD5_H_ */
--- a/libpurple/tests/Makefile.am	Tue Feb 01 04:00:50 2011 +0000
+++ b/libpurple/tests/Makefile.am	Wed Feb 02 05:47:50 2011 +0000
@@ -11,6 +11,7 @@
 	    tests.h \
 		test_cipher.c \
 		test_jabber_caps.c \
+		test_jabber_digest_md5.c \
 		test_jabber_jutil.c \
 		test_jabber_scram.c \
 		test_qq.c \
--- a/libpurple/tests/check_libpurple.c	Tue Feb 01 04:00:50 2011 +0000
+++ b/libpurple/tests/check_libpurple.c	Wed Feb 02 05:47:50 2011 +0000
@@ -85,6 +85,7 @@
 
 	srunner_add_suite(sr, cipher_suite());
 	srunner_add_suite(sr, jabber_caps_suite());
+	srunner_add_suite(sr, jabber_digest_md5_suite());
 	srunner_add_suite(sr, jabber_jutil_suite());
 	srunner_add_suite(sr, jabber_scram_suite());
 	srunner_add_suite(sr, qq_suite());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_jabber_digest_md5.c	Wed Feb 02 05:47:50 2011 +0000
@@ -0,0 +1,59 @@
+#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;
+}
--- a/libpurple/tests/tests.h	Tue Feb 01 04:00:50 2011 +0000
+++ b/libpurple/tests/tests.h	Wed Feb 02 05:47:50 2011 +0000
@@ -10,6 +10,7 @@
 Suite * master_suite(void);
 Suite * cipher_suite(void);
 Suite * jabber_caps_suite(void);
+Suite * jabber_digest_md5_suite(void);
 Suite * jabber_jutil_suite(void);
 Suite * jabber_scram_suite(void);
 Suite * qq_suite(void);