pidgin: 1a66fe9f: jabber: Test harness for DIGEST-MD5 pars...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Wed Feb 2 00:55:47 EST 2011


----------------------------------------------------------------------
Revision: 1a66fe9f8b86d69adad25c8f61b8fcbad648a8bf
Parent:   36816746a73da13a5358b6c78bb82d1d40925555
Author:   darkrain42 at pidgin.im
Date:     02/02/11 00:47:50
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/1a66fe9f8b86d69adad25c8f61b8fcbad648a8bf

Changelog: 

jabber: Test harness for DIGEST-MD5 parsing function.

One of these tests fails, pending the next commit.

Changes against parent 36816746a73da13a5358b6c78bb82d1d40925555

  added    libpurple/protocols/jabber/auth_digest_md5.h
  added    libpurple/tests/test_jabber_digest_md5.c
  patched  libpurple/protocols/jabber/Makefile.am
  patched  libpurple/protocols/jabber/auth_digest_md5.c
  patched  libpurple/tests/Makefile.am
  patched  libpurple/tests/check_libpurple.c
  patched  libpurple/tests/tests.h

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/Makefile.am	9c9c664e7262b61ad796bba3066f6813dcf5c613
+++ libpurple/protocols/jabber/Makefile.am	40c300efe4daebed6eff7bac83b6e46eb8c0b77d
@@ -11,6 +11,7 @@ JABBERSOURCES = \
 			  auth.c \
 			  auth.h \
 			  auth_digest_md5.c \
+			  auth_digest_md5.h \
 			  auth_plain.c \
 			  auth_scram.c \
 			  auth_scram.h \
============================================================
--- libpurple/tests/Makefile.am	fa9fea1ab00102fa5cf81bc4e2f41cc350fcffb7
+++ libpurple/tests/Makefile.am	b86fb99070acfd4e786b0fe1ee5845132fa5a3f6
@@ -11,6 +11,7 @@ check_libpurple_SOURCES=\
 	    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 \
============================================================
--- libpurple/tests/check_libpurple.c	044a5ca539a834dab33d525b24471d738cafaf35
+++ libpurple/tests/check_libpurple.c	d345c0eeaccf9aec715c22cb9d71448f4cb18339
@@ -85,6 +85,7 @@ int main(void)
 
 	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());
============================================================
--- libpurple/tests/tests.h	22617c5e913e74696b8e448991b84242d0fd8f3c
+++ libpurple/tests/tests.h	f8644231baaadb435974d502bf96358113db3dcf
@@ -10,6 +10,7 @@ Suite * jabber_caps_suite(void);
 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);
============================================================
--- libpurple/protocols/jabber/auth_digest_md5.c	c32a82e931b9ae544229e5ec2d1d9d163ea4ef90
+++ libpurple/protocols/jabber/auth_digest_md5.c	b191c64248fdc92be9eb9994f3c93d9e1fef042a
@@ -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 @@ digest_md5_start(JabberStream *js, xmlno
 }
 
 /* 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 @@ digest_md5_handle_challenge(JabberStream
 			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	
+++ libpurple/protocols/jabber/auth_digest_md5.h	6b8619dd9a43aa963ba4d4e95a0b1c8d0ff0f4d0
@@ -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_ */
============================================================
--- /dev/null	
+++ libpurple/tests/test_jabber_digest_md5.c	3717d5cad05ca848545c40f0a358d27dc7430b13
@@ -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;
+}


More information about the Commits mailing list