1 /* Copyright 2000-2004 The Apache Software Foundation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
20 #include "apr_errno.h"
21 #include "apr_strings.h"
22 #include "apr_file_io.h"
23 #include "apr_thread_proc.h"
36 passwords and hashes created with Apache's htpasswd utility like this:
38 htpasswd -c -b passwords pass1 pass1
39 htpasswd -b passwords pass2 pass2
40 htpasswd -b passwords pass3 pass3
41 htpasswd -b passwords pass4 pass4
42 htpasswd -b passwords pass5 pass5
43 htpasswd -b passwords pass6 pass6
44 htpasswd -b passwords pass7 pass7
45 htpasswd -b passwords pass8 pass8
46 (insert Perl one-liner to convert to initializer :) )
48 {"pass1", "1fWDc9QWYCWrQ"},
49 {"pass2", "1fiGx3u7QoXaM"},
50 {"pass3", "1fzijMylTiwCs"},
51 {"pass4", "nHUYc8U2UOP7s"},
52 {"pass5", "nHpETGLGPwAmA"},
53 {"pass6", "nHbsbWmJ3uyhc"},
54 {"pass7", "nHQ3BbF0Y9vpI"},
55 {"pass8", "nHZA1rViSldQk"}
57 static int num_passwords
= sizeof(passwords
) / sizeof(passwords
[0]);
59 static void test_crypt(abts_case
*tc
, void *data
)
63 for (i
= 0; i
< num_passwords
; i
++) {
64 apr_assert_success(tc
, "check for valid password",
65 apr_password_validate(passwords
[i
].password
,
72 static void * APR_THREAD_FUNC
testing_thread(apr_thread_t
*thd
,
78 for (i
= 0; i
< 100; i
++) {
85 /* test for threadsafe crypt() */
86 static void test_threadsafe(abts_case
*tc
, void *data
)
89 apr_thread_t
*my_threads
[NUM_THR
];
93 for (i
= 0; i
< NUM_THR
; i
++) {
94 apr_assert_success(tc
, "create test thread",
95 apr_thread_create(&my_threads
[i
], NULL
,
96 testing_thread
, tc
, p
));
99 for (i
= 0; i
< NUM_THR
; i
++) {
100 apr_thread_join(&rv
, my_threads
[i
]);
105 static void test_shapass(abts_case
*tc
, void *data
)
107 const char *pass
= "hellojed";
110 apr_sha1_base64(pass
, strlen(pass
), hash
);
112 apr_assert_success(tc
, "SHA1 password validated",
113 apr_password_validate(pass
, hash
));
116 static void test_md5pass(abts_case
*tc
, void *data
)
118 const char *pass
= "hellojed", *salt
= "sardine";
121 apr_md5_encode(pass
, salt
, hash
, sizeof hash
);
123 apr_assert_success(tc
, "MD5 password validated",
124 apr_password_validate(pass
, hash
));
127 abts_suite
*testpass(abts_suite
*suite
)
129 suite
= ADD_SUITE(suite
);
131 abts_run_test(suite
, test_crypt
, NULL
);
133 abts_run_test(suite
, test_threadsafe
, NULL
);
135 abts_run_test(suite
, test_shapass
, NULL
);
136 abts_run_test(suite
, test_md5pass
, NULL
);