/pidgin/main: 8e7c187310d5: Move the scram tests to gtester

Gary Kramlich grim at reaperworld.com
Wed Mar 30 19:25:28 EDT 2016


Changeset: 8e7c187310d5322852d23721897c5c44dac1a30e
Author:	 Gary Kramlich <grim at reaperworld.com>
Date:	 2016-03-20 23:28 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/8e7c187310d5

Description:

Move the scram tests to gtester

diffstat:

 libpurple/protocols/jabber/tests/Makefile.am         |   2 +-
 libpurple/protocols/jabber/tests/test_jabber_jutil.c |   4 +-
 libpurple/protocols/jabber/tests/test_jabber_scram.c |  66 ++++++++-----------
 3 files changed, 32 insertions(+), 40 deletions(-)

diffs (163 lines):

diff --git a/libpurple/protocols/jabber/tests/Makefile.am b/libpurple/protocols/jabber/tests/Makefile.am
--- a/libpurple/protocols/jabber/tests/Makefile.am
+++ b/libpurple/protocols/jabber/tests/Makefile.am
@@ -10,7 +10,7 @@ COMMON_LIBS=\
 test_programs=\
 	test_jabber_caps \
 	test_jabber_digest_md5 \
-	test_jabber_jutil
+	test_jabber_jutil \
 	test_jabber_scram
 
 test_jabber_caps_SOURCES=test_jabber_caps.c
diff --git a/libpurple/protocols/jabber/tests/test_jabber_jutil.c b/libpurple/protocols/jabber/tests/test_jabber_jutil.c
--- a/libpurple/protocols/jabber/tests/test_jabber_jutil.c
+++ b/libpurple/protocols/jabber/tests/test_jabber_jutil.c
@@ -2,11 +2,11 @@
 
 #include "account.h"
 #include "conversation.h"
+#include "glibcompat.h"
+#include "tests.h"
 #include "xmlnode.h"
 #include "protocols/jabber/jutil.h"
 
-#include "tests.h"
-
 static void
 test_jabber_util_get_resource_exists(void) {
 	PurpleTestStringData data[] = {
diff --git a/libpurple/protocols/jabber/tests/test_jabber_scram.c b/libpurple/protocols/jabber/tests/test_jabber_scram.c
--- a/libpurple/protocols/jabber/tests/test_jabber_scram.c
+++ b/libpurple/protocols/jabber/tests/test_jabber_scram.c
@@ -1,10 +1,10 @@
 #include <string.h>
 
 #include "tests.h"
-#include "../util.h"
-#include "../protocols/jabber/auth_scram.h"
-#include "../protocols/jabber/jutil.h"
-#include "../ciphers/sha1hash.h"
+#include "util.h"
+#include "protocols/jabber/auth_scram.h"
+#include "protocols/jabber/jutil.h"
+#include "ciphers/sha1hash.h"
 
 static JabberScramHash sha1_mech = { "-SHA-1", purple_sha1_hash_new, 20 };
 
@@ -12,14 +12,14 @@ static JabberScramHash sha1_mech = { "-S
 	GString *p = g_string_new(password); \
 	GString *s = g_string_new(salt); \
 	guchar *result = jabber_scram_hi(&sha1_mech, p, s, count); \
-	fail_if(result == NULL, "Hi() returned NULL"); \
-	fail_if(0 != memcmp(result, expected, 20), "Hi() returned invalid result"); \
+	g_assert_nonnull(result); \
+	g_assert_cmpmem(result, 20, expected, 20); \
 	g_string_free(s, TRUE); \
 	g_string_free(p, TRUE); \
 }
 
-START_TEST(test_pbkdf2)
-{
+static void
+test_jabber_scram_pbkdf2(void) {
 	assert_pbkdf2_equal("password", "salt", 1, "\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6");
 	assert_pbkdf2_equal("password", "salt", 2, "\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a\xce\x1d\x41\xf0\xd8\xde\x89\x57");
 	assert_pbkdf2_equal("password", "salt", 4096, "\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26\xf7\x21\xd0\x65\xa4\x29\xc1");
@@ -29,10 +29,9 @@ START_TEST(test_pbkdf2)
 	assert_pbkdf2_equal("password", "salt", 16777216, "\xee\xfe\x3d\x61\xcd\x4d\xa4\xe4\xe9\x94\x5b\x3d\x6b\xa2\x15\x8c\x26\x34\xe9\x84");
 #endif
 }
-END_TEST
 
-START_TEST(test_proofs)
-{
+static void
+test_jabber_scram_proofs(void) {
 	JabberScramData *data = g_new0(JabberScramData, 1);
 	gboolean ret;
 	GString *salt;
@@ -48,14 +47,13 @@ START_TEST(test_proofs)
 
 	salt = g_string_new("salt");
 	ret = jabber_scram_calc_proofs(data, salt, 1);
-	fail_if(ret == FALSE, "Failed to calculate SCRAM proofs!");
+	g_assert_true(ret);
 
-	fail_unless(0 == memcmp(client_proof, data->client_proof->str, 20));
+	g_assert_cmpmem(client_proof, 20, data->client_proof->str, 20);
 	g_string_free(salt, TRUE);
 
 	jabber_scram_data_destroy(data);
 }
-END_TEST
 
 #define assert_successful_exchange(pw, nonce, start_data, challenge1, response1, success) { \
 	JabberScramData *data = g_new0(JabberScramData, 1); \
@@ -65,25 +63,25 @@ END_TEST
 	data->step = 1; \
 	data->hash = &sha1_mech; \
 	data->password = jabber_saslprep(pw); \
-	fail_if(data->password == NULL); \
+	g_assert_nonnull(data->password); \
 	data->cnonce = g_strdup(nonce); \
 	data->auth_message = g_string_new(start_data); \
 	\
 	ret = jabber_scram_feed_parser(data, challenge1, &out); \
-	fail_unless(ret == TRUE); \
-	fail_unless(g_str_equal(out, response1), "Got unexpected response to challenge. Expected %s, got %s", response1, out); \
+	g_assert_true(ret); \
+	g_assert_cmpstr(response1, ==, out); \
 	g_free(out); \
 	\
 	data->step = 2; \
 	ret = jabber_scram_feed_parser(data, success, &out); \
-	fail_unless(ret == TRUE); \
-	fail_unless(out == NULL); \
+	g_assert_true(ret); \
+	g_assert_null(out); \
 	\
 	jabber_scram_data_destroy(data); \
 }
 
-START_TEST(test_mech)
-{
+static void
+test_jabber_scram_exchange(void) {
 	assert_successful_exchange("password", "H7yDYKAWBCrM2Fa5SxGa4iez",
 			"n=paul,r=H7yDYKAWBCrM2Fa5SxGa4iez",
 			"r=H7yDYKAWBCrM2Fa5SxGa4iezFPVDPpDUcGxPkH3RzP,s=3rXeErP/os7jUNqU,i=4096",
@@ -98,23 +96,17 @@ START_TEST(test_mech)
 			"v=4TkZwKWy6JHNmrUbU2+IdAaXtos=");
 #endif
 }
-END_TEST
 
-Suite *
-jabber_scram_suite(void)
-{
-	Suite *s = suite_create("Jabber SASL SCRAM functions");
+gint
+main(gint argc, gchar **argv) {
+	g_test_init(&argc, &argv, NULL);
 
-	TCase *tc = tcase_create("PBKDF2 Functionality");
-	tcase_add_test(tc, test_pbkdf2);
-	suite_add_tcase(s, tc);
+	g_test_add_func("/jabber/scram/pbkdf2",
+	                test_jabber_scram_pbkdf2);
+	g_test_add_func("/jabber/scram/proofs",
+	                test_jabber_scram_proofs);
+	g_test_add_func("/jabber/scram/exchange",
+	                test_jabber_scram_exchange);
 
-	tc = tcase_create("SCRAM Proofs");
-	tcase_add_test(tc, test_proofs);
-	suite_add_tcase(s, tc);
-
-	tc = tcase_create("SCRAM exchange");
-	tcase_add_test(tc, test_mech);
-	suite_add_tcase(s, tc);
-	return s;
+	return g_test_run();
 }



More information about the Commits mailing list