~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr-util/test/testpass.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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.
 
15
 */
 
16
 
 
17
#include <assert.h>
 
18
#include <stdio.h>
 
19
#include <stdlib.h>
 
20
 
 
21
#include "apr_errno.h"
 
22
#include "apr_strings.h"
 
23
#include "apr_file_io.h"
 
24
#include "apr_thread_proc.h"
 
25
#include "apr_md5.h"
 
26
#include "apr_sha1.h"
 
27
 
 
28
#include "abts.h"
 
29
#include "testutil.h"
 
30
 
 
31
static struct {
 
32
    const char *password;
 
33
    const char *hash;
 
34
} passwords[] =
 
35
{
 
36
/*
 
37
  passwords and hashes created with Apache's htpasswd utility like this:
 
38
  
 
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 :) )
 
48
 */
 
49
    {"pass1", "1fWDc9QWYCWrQ"},
 
50
    {"pass2", "1fiGx3u7QoXaM"},
 
51
    {"pass3", "1fzijMylTiwCs"},
 
52
    {"pass4", "nHUYc8U2UOP7s"},
 
53
    {"pass5", "nHpETGLGPwAmA"},
 
54
    {"pass6", "nHbsbWmJ3uyhc"},
 
55
    {"pass7", "nHQ3BbF0Y9vpI"},
 
56
    {"pass8", "nHZA1rViSldQk"}
 
57
};
 
58
static int num_passwords = sizeof(passwords) / sizeof(passwords[0]);
 
59
 
 
60
static void test_crypt(abts_case *tc, void *data)
 
61
{
 
62
    int i;
 
63
 
 
64
    for (i = 0; i < num_passwords; i++) {
 
65
        apr_assert_success(tc, "check for valid password",
 
66
                           apr_password_validate(passwords[i].password,
 
67
                                                 passwords[i].hash));
 
68
    }
 
69
}
 
70
 
 
71
#if APR_HAS_THREADS
 
72
 
 
73
static void * APR_THREAD_FUNC testing_thread(apr_thread_t *thd,
 
74
                                             void *data)
 
75
{
 
76
    abts_case *tc = data;
 
77
    int i;
 
78
 
 
79
    for (i = 0; i < 100; i++) {
 
80
        test_crypt(tc, NULL);
 
81
    }
 
82
 
 
83
    return APR_SUCCESS;
 
84
}
 
85
 
 
86
/* test for threadsafe crypt() */
 
87
static void test_threadsafe(abts_case *tc, void *data)
 
88
{
 
89
#define NUM_THR 20
 
90
    apr_thread_t *my_threads[NUM_THR];
 
91
    int i;
 
92
    apr_status_t rv;
 
93
    
 
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));
 
98
    }
 
99
 
 
100
    for (i = 0; i < NUM_THR; i++) {
 
101
        apr_thread_join(&rv, my_threads[i]);
 
102
    }
 
103
}
 
104
#endif
 
105
 
 
106
static void test_shapass(abts_case *tc, void *data)
 
107
{
 
108
    const char *pass = "hellojed";
 
109
    char hash[100];
 
110
 
 
111
    apr_sha1_base64(pass, strlen(pass), hash);
 
112
 
 
113
    apr_assert_success(tc, "SHA1 password validated",
 
114
                       apr_password_validate(pass, hash));
 
115
}
 
116
 
 
117
static void test_md5pass(abts_case *tc, void *data)
 
118
{
 
119
    const char *pass = "hellojed", *salt = "sardine";
 
120
    char hash[100];
 
121
 
 
122
    apr_md5_encode(pass, salt, hash, sizeof hash);
 
123
 
 
124
    apr_assert_success(tc, "MD5 password validated",
 
125
                       apr_password_validate(pass, hash));
 
126
}
 
127
 
 
128
abts_suite *testpass(abts_suite *suite)
 
129
{
 
130
    suite = ADD_SUITE(suite);
 
131
 
 
132
    abts_run_test(suite, test_crypt, NULL);
 
133
#if APR_HAS_THREADS
 
134
    abts_run_test(suite, test_threadsafe, NULL);
 
135
#endif
 
136
    abts_run_test(suite, test_shapass, NULL);
 
137
    abts_run_test(suite, test_md5pass, NULL);
 
138
    
 
139
    return suite;
 
140
}