jorton 2004/06/23 02:53:43
Modified: test Makefile.in abts_tests.h testutil.h testpass.c
Log:
* test/testpass.c: Adapted to abts framework; add tests for MD5 and
SHA1 passwords.
* test/abts_tests.h, test/Makefile.in, test/testutil.h: Integrate
testpass.
Revision Changes Path
1.45 +1 -6 apr-util/test/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr-util/test/Makefile.in,v
retrieving revision 1.44
retrieving revision 1.45
diff -d -w -u -r1.44 -r1.45
--- Makefile.in 22 Jun 2004 16:26:45 -0000 1.44
+++ Makefile.in 23 Jun 2004 09:53:43 -0000 1.45
@@ -66,13 +66,8 @@
testqueue: $(testqueue_OBJECTS) $(testqueue_LDADD)
$(LINK) $(APRUTIL_LDFLAGS) $(testqueue_OBJECTS) $(testqueue_LDADD)
$(PROGRAM_DEPENDENCIES)
-testpass_OBJECTS = testpass.lo
-testpass_LDADD = $(TARGET_LIB_PATH)
-testpass: $(testpass_OBJECTS) $(testpass_LDADD)
- $(LINK) $(APRUTIL_LDFLAGS) $(testpass_OBJECTS) $(testpass_LDADD)
$(PROGRAM_DEPENDENCIES)
-
testall_OBJECTS = teststrmatch.lo testuri.lo testuuid.lo abts.lo testutil.lo
\
- testbuckets.lo
+ testbuckets.lo testpass.lo
testall_LDADD = $(TARGET_LIB_PATH)
testall: $(testall_OBJECTS) $(testall_LDADD)
$(LINK) $(APRUTIL_LDFLAGS) $(testall_OBJECTS) $(testall_LDADD)
$(PROGRAM_DEPENDENCIES)
1.5 +2 -1 apr-util/test/abts_tests.h
Index: abts_tests.h
===================================================================
RCS file: /home/cvs/apr-util/test/abts_tests.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -d -w -u -r1.4 -r1.5
--- abts_tests.h 22 Jun 2004 16:26:45 -0000 1.4
+++ abts_tests.h 23 Jun 2004 09:53:43 -0000 1.5
@@ -25,7 +25,8 @@
{teststrmatch},
{testuri},
{testuuid},
- {testbuckets}
+ {testbuckets},
+ {testpass}
};
#endif /* APR_TEST_INCLUDES */
1.5 +1 -0 apr-util/test/testutil.h
Index: testutil.h
===================================================================
RCS file: /home/cvs/apr-util/test/testutil.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -d -w -u -r1.4 -r1.5
--- testutil.h 22 Jun 2004 16:28:29 -0000 1.4
+++ testutil.h 23 Jun 2004 09:53:43 -0000 1.5
@@ -46,5 +46,6 @@
abts_suite *testuri(abts_suite *suite);
abts_suite *testuuid(abts_suite *suite);
abts_suite *testbuckets(abts_suite *suite);
+abts_suite *testpass(abts_suite *suite);
#endif /* APR_TEST_INCLUDES */
1.3 +44 -33 apr-util/test/testpass.c
Index: testpass.c
===================================================================
RCS file: /home/cvs/apr-util/test/testpass.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -d -w -u -r1.2 -r1.3
--- testpass.c 13 Feb 2004 09:55:26 -0000 1.2
+++ testpass.c 23 Jun 2004 09:53:43 -0000 1.3
@@ -22,6 +22,10 @@
#include "apr_file_io.h"
#include "apr_thread_proc.h"
#include "apr_md5.h"
+#include "apr_sha1.h"
+
+#include "abts.h"
+#include "testutil.h"
static struct {
const char *password;
@@ -52,22 +56,14 @@
};
static int num_passwords = sizeof(passwords) / sizeof(passwords[0]);
-static void check_rv(apr_status_t rv)
-{
- if (rv != APR_SUCCESS) {
- fprintf(stderr, "bailing\n");
- exit(1);
- }
-}
-
-static void test(void)
+static void test_crypt(abts_case *tc, void *data)
{
int i;
for (i = 0; i < num_passwords; i++) {
- apr_status_t rv = apr_password_validate(passwords[i].password,
- passwords[i].hash);
- assert(rv == APR_SUCCESS);
+ apr_assert_success(tc, "check for valid password",
+ apr_password_validate(passwords[i].password,
+ passwords[i].hash));
}
}
@@ -76,15 +72,18 @@
static void * APR_THREAD_FUNC testing_thread(apr_thread_t *thd,
void *data)
{
+ abts_case *tc = data;
int i;
for (i = 0; i < 100; i++) {
- test();
+ test_crypt(tc, NULL);
}
+
return APR_SUCCESS;
}
-static void thread_safe_test(apr_pool_t *p)
+/* test for threadsafe crypt() */
+static void test_threadsafe(abts_case *tc, void *data)
{
#define NUM_THR 20
apr_thread_t *my_threads[NUM_THR];
@@ -92,8 +91,9 @@
apr_status_t rv;
for (i = 0; i < NUM_THR; i++) {
- rv = apr_thread_create(&my_threads[i], NULL, testing_thread, NULL,
p);
- check_rv(rv);
+ apr_assert_success(tc, "create test thread",
+ apr_thread_create(&my_threads[i], NULL,
+ testing_thread, tc, p));
}
for (i = 0; i < NUM_THR; i++) {
@@ -102,27 +102,38 @@
}
#endif
-int main(void)
+static void test_shapass(abts_case *tc, void *data)
{
- apr_status_t rv;
- apr_pool_t *p;
+ const char *pass = "hellojed";
+ char hash[100];
- rv = apr_initialize();
- check_rv(rv);
- rv = apr_pool_create(&p, NULL);
- check_rv(rv);
- atexit(apr_terminate);
+ apr_sha1_base64(pass, strlen(pass), hash);
- /* before creating any threads, test it first just to check
- * for problems with the test driver
- */
- printf("dry run\n");
- test();
+ apr_assert_success(tc, "SHA1 password validated",
+ apr_password_validate(pass, hash));
+}
+
+static void test_md5pass(abts_case *tc, void *data)
+{
+ const char *pass = "hellojed", *salt = "sardine";
+ char hash[100];
+ apr_md5_encode(pass, salt, hash, sizeof hash);
+
+ apr_assert_success(tc, "MD5 password validated",
+ apr_password_validate(pass, hash));
+}
+
+abts_suite *testpass(abts_suite *suite)
+{
+ suite = ADD_SUITE(suite);
+
+ abts_run_test(suite, test_crypt, NULL);
#if APR_HAS_THREADS
- printf("thread-safe test\n");
- thread_safe_test(p);
+ abts_run_test(suite, test_threadsafe, NULL);
#endif
+ abts_run_test(suite, test_shapass, NULL);
+ abts_run_test(suite, test_md5pass, NULL);
- return 0;
+ return suite;
}