1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
21
#include "apr_errno.h"
22
#include "apr_strings.h"
23
#include "apr_file_io.h"
24
#include "apr_thread_proc.h"
37
passwords and hashes created with Apache's htpasswd utility like this:
39
htpasswd -c -b passwords pass1 pass1
40
htpasswd -b passwords pass2 pass2
41
htpasswd -b passwords pass3 pass3
42
htpasswd -b passwords pass4 pass4
43
htpasswd -b passwords pass5 pass5
44
htpasswd -b passwords pass6 pass6
45
htpasswd -b passwords pass7 pass7
46
htpasswd -b passwords pass8 pass8
47
(insert Perl one-liner to convert to initializer :) )
49
{"pass1", "1fWDc9QWYCWrQ"},
50
{"pass2", "1fiGx3u7QoXaM"},
51
{"pass3", "1fzijMylTiwCs"},
52
{"pass4", "nHUYc8U2UOP7s"},
53
{"pass5", "nHpETGLGPwAmA"},
54
{"pass6", "nHbsbWmJ3uyhc"},
55
{"pass7", "nHQ3BbF0Y9vpI"},
56
{"pass8", "nHZA1rViSldQk"}
58
static int num_passwords = sizeof(passwords) / sizeof(passwords[0]);
60
static void test_crypt(abts_case *tc, void *data)
64
for (i = 0; i < num_passwords; i++) {
65
apr_assert_success(tc, "check for valid password",
66
apr_password_validate(passwords[i].password,
73
static void * APR_THREAD_FUNC testing_thread(apr_thread_t *thd,
79
for (i = 0; i < 100; i++) {
86
/* test for threadsafe crypt() */
87
static void test_threadsafe(abts_case *tc, void *data)
90
apr_thread_t *my_threads[NUM_THR];
94
for (i = 0; i < NUM_THR; i++) {
95
apr_assert_success(tc, "create test thread",
96
apr_thread_create(&my_threads[i], NULL,
97
testing_thread, tc, p));
100
for (i = 0; i < NUM_THR; i++) {
101
apr_thread_join(&rv, my_threads[i]);
106
static void test_shapass(abts_case *tc, void *data)
108
const char *pass = "hellojed";
111
apr_sha1_base64(pass, strlen(pass), hash);
113
apr_assert_success(tc, "SHA1 password validated",
114
apr_password_validate(pass, hash));
117
static void test_md5pass(abts_case *tc, void *data)
119
const char *pass = "hellojed", *salt = "sardine";
122
apr_md5_encode(pass, salt, hash, sizeof hash);
124
apr_assert_success(tc, "MD5 password validated",
125
apr_password_validate(pass, hash));
128
abts_suite *testpass(abts_suite *suite)
130
suite = ADD_SUITE(suite);
132
abts_run_test(suite, test_crypt, NULL);
134
abts_run_test(suite, test_threadsafe, NULL);
136
abts_run_test(suite, test_shapass, NULL);
137
abts_run_test(suite, test_md5pass, NULL);