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

« back to all changes in this revision

Viewing changes to srclib/apr-util/test/testuri.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 <stdio.h>
 
18
#include <stdlib.h>
 
19
 
 
20
#include "testutil.h"
 
21
#include "apr_general.h"
 
22
#include "apr_strings.h"
 
23
#include "apr_uri.h"
 
24
 
 
25
struct aup_test {
 
26
    const char *uri;
 
27
    apr_status_t rv;
 
28
    const char *scheme;
 
29
    const char *hostinfo;
 
30
    const char *user;
 
31
    const char *password;
 
32
    const char *hostname;
 
33
    const char *port_str;
 
34
    const char *path;
 
35
    const char *query;
 
36
    const char *fragment;
 
37
    apr_port_t  port;
 
38
};
 
39
 
 
40
struct aup_test aup_tests[] =
 
41
{
 
42
    { "http://[/::1]/index.html", APR_EGENERAL },
 
43
    { "http://[", APR_EGENERAL },
 
44
    { "http://[?::1]/index.html", APR_EGENERAL },
 
45
 
 
46
    {
 
47
        "http://127.0.0.1:9999/asdf.html",
 
48
        0, "http", "127.0.0.1:9999", NULL, NULL, "127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
 
49
    },
 
50
    {
 
51
        "http://127.0.0.1:9999a/asdf.html",
 
52
        APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
 
53
    },
 
54
    {
 
55
        "http://[::127.0.0.1]:9999/asdf.html",
 
56
        0, "http", "[::127.0.0.1]:9999", NULL, NULL, "::127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
 
57
    },
 
58
    {
 
59
        "http://[::127.0.0.1]:9999a/asdf.html",
 
60
        APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
 
61
    },
 
62
    {
 
63
        "/error/include/top.html",
 
64
        0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/top.html", NULL, NULL, 0
 
65
    },
 
66
    {
 
67
        "/error/include/../contact.html.var",
 
68
        0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/../contact.html.var", NULL, NULL, 0
 
69
    },
 
70
    {
 
71
        "/",
 
72
        0, NULL, NULL, NULL, NULL, NULL, NULL, "/", NULL, NULL, 0
 
73
    },
 
74
    {
 
75
        "/manual/",
 
76
        0, NULL, NULL, NULL, NULL, NULL, NULL, "/manual/", NULL, NULL, 0
 
77
    },
 
78
    {
 
79
        "/cocoon/developing/graphics/Using%20Databases-label_over.jpg",
 
80
        0, NULL, NULL, NULL, NULL, NULL, NULL, "/cocoon/developing/graphics/Using%20Databases-label_over.jpg", NULL, NULL, 0
 
81
    },
 
82
    {
 
83
        "http://sonyamt:garbage@127.0.0.1/filespace/",
 
84
        0, "http", "sonyamt:garbage@127.0.0.1", "sonyamt", "garbage", "127.0.0.1", NULL, "/filespace/", NULL, NULL, 0
 
85
    },
 
86
    {
 
87
        "http://sonyamt:garbage@[fe80::1]/filespace/",
 
88
        0, "http", "sonyamt:garbage@[fe80::1]", "sonyamt", "garbage", "fe80::1", NULL, "/filespace/", NULL, NULL, 0
 
89
    },
 
90
    {
 
91
        "http://sonyamt@[fe80::1]/filespace/?arg1=store",
 
92
        0, "http", "sonyamt@[fe80::1]", "sonyamt", NULL, "fe80::1", NULL, "/filespace/", "arg1=store", NULL, 0
 
93
    },
 
94
    {
 
95
        "//www.apache.org/",
 
96
        0, NULL, "www.apache.org", NULL, NULL, "www.apache.org", NULL, "/", NULL, NULL, 0
 
97
    },
 
98
};
 
99
 
 
100
struct uph_test {
 
101
    const char *hostinfo;
 
102
    apr_status_t rv;
 
103
    const char *hostname;
 
104
    const char *port_str;
 
105
    apr_port_t port;
 
106
};
 
107
 
 
108
struct uph_test uph_tests[] =
 
109
{
 
110
    {
 
111
        "www.ibm.com:443",
 
112
        0, "www.ibm.com", "443", 443
 
113
    },
 
114
    {
 
115
        "[fe80::1]:443",
 
116
        0, "fe80::1", "443", 443
 
117
    },
 
118
    {
 
119
        "127.0.0.1:443",
 
120
        0, "127.0.0.1", "443", 443
 
121
    },
 
122
    {
 
123
        "127.0.0.1",
 
124
        APR_EGENERAL, NULL, NULL, 0
 
125
    },
 
126
    {
 
127
        "[fe80:80",
 
128
        APR_EGENERAL, NULL, NULL, 0
 
129
    },
 
130
    {
 
131
        "fe80::80]:443",
 
132
        APR_EGENERAL, NULL, NULL, 0
 
133
    }
 
134
};
 
135
 
 
136
#if 0
 
137
static void show_info(apr_status_t rv, apr_status_t expected, const apr_uri_t *info)
 
138
{
 
139
    if (rv != expected) {
 
140
        fprintf(stderr, "  actual rv: %d    expected rv:  %d\n", rv, expected);
 
141
    }
 
142
    else {
 
143
        fprintf(stderr, 
 
144
                "  scheme:           %s\n"
 
145
                "  hostinfo:         %s\n"
 
146
                "  user:             %s\n"
 
147
                "  password:         %s\n"
 
148
                "  hostname:         %s\n"
 
149
                "  port_str:         %s\n"
 
150
                "  path:             %s\n"
 
151
                "  query:            %s\n"
 
152
                "  fragment:         %s\n"
 
153
                "  hostent:          %p\n"
 
154
                "  port:             %u\n"
 
155
                "  is_initialized:   %u\n"
 
156
                "  dns_looked_up:    %u\n"
 
157
                "  dns_resolved:     %u\n",
 
158
                info->scheme, info->hostinfo, info->user, info->password,
 
159
                info->hostname, info->port_str, info->path, info->query,
 
160
                info->fragment, info->hostent, info->port, info->is_initialized,
 
161
                info->dns_looked_up, info->dns_resolved);
 
162
    }
 
163
}
 
164
#endif
 
165
 
 
166
static void test_aup(abts_case *tc, void *data)
 
167
{
 
168
    int i;
 
169
    apr_status_t rv;
 
170
    apr_uri_t info;
 
171
    struct aup_test *t;
 
172
    const char *s = NULL;
 
173
 
 
174
    for (i = 0; i < sizeof(aup_tests) / sizeof(aup_tests[0]); i++) {
 
175
        char msg[256];
 
176
 
 
177
        memset(&info, 0, sizeof(info));
 
178
        t = &aup_tests[i];
 
179
        rv = apr_uri_parse(p, t->uri, &info);
 
180
        apr_snprintf(msg, sizeof msg, "uri '%s': rv=%d not %d", t->uri,
 
181
                     rv, t->rv);
 
182
        ABTS_ASSERT(tc, msg, rv == t->rv);
 
183
        if (t->rv == APR_SUCCESS) {
 
184
            ABTS_STR_EQUAL(tc, info.scheme, t->scheme);
 
185
            ABTS_STR_EQUAL(tc, info.hostinfo, t->hostinfo);
 
186
            ABTS_STR_EQUAL(tc, info.user, t->user);
 
187
            ABTS_STR_EQUAL(tc, info.password, t->password);
 
188
            ABTS_STR_EQUAL(tc, info.hostname, t->hostname);
 
189
            ABTS_STR_EQUAL(tc, info.port_str, t->port_str);
 
190
            ABTS_STR_EQUAL(tc, info.path, t->path);
 
191
            ABTS_STR_EQUAL(tc, info.query, t->query);
 
192
            ABTS_STR_EQUAL(tc, info.user, t->user);
 
193
            ABTS_INT_EQUAL(tc, info.port, t->port);
 
194
 
 
195
            s = apr_uri_unparse(p, &info, APR_URI_UNP_REVEALPASSWORD);
 
196
            ABTS_STR_EQUAL(tc, s, t->uri);
 
197
        }
 
198
    }
 
199
}
 
200
 
 
201
static void test_uph(abts_case *tc, void *data)
 
202
{
 
203
    int i;
 
204
    apr_status_t rv;
 
205
    apr_uri_t info;
 
206
    struct uph_test *t;
 
207
 
 
208
    for (i = 0; i < sizeof(uph_tests) / sizeof(uph_tests[0]); i++) {
 
209
        memset(&info, 0, sizeof(info));
 
210
        t = &uph_tests[i];
 
211
        rv = apr_uri_parse_hostinfo(p, t->hostinfo, &info);
 
212
        ABTS_INT_EQUAL(tc, rv, t->rv);
 
213
        if (t->rv == APR_SUCCESS) {
 
214
            ABTS_STR_EQUAL(tc, info.hostname, t->hostname);
 
215
            ABTS_STR_EQUAL(tc, info.port_str, t->port_str);
 
216
            ABTS_INT_EQUAL(tc, info.port, t->port);
 
217
        }
 
218
    }
 
219
}
 
220
 
 
221
abts_suite *testuri(abts_suite *suite)
 
222
{
 
223
    suite = ADD_SUITE(suite);
 
224
 
 
225
    abts_run_test(suite, test_aup, NULL);
 
226
    abts_run_test(suite, test_uph, NULL);
 
227
 
 
228
    return suite;
 
229
}
 
230