~ubuntu-branches/ubuntu/natty/lighttpd/natty

« back to all changes in this revision

Viewing changes to tests/mod-fastcgi.t

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Marek
  • Date: 2005-11-26 11:48:51 UTC
  • Revision ID: james.westby@ubuntu.com-20051126114851-76t9q0rrwbzjnt2t
Tags: upstream-1.4.8
ImportĀ upstreamĀ versionĀ 1.4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
BEGIN {
 
3
    # add current source dir to the include-path
 
4
    # we need this for make distcheck
 
5
   (my $srcdir = $0) =~ s#/[^/]+$#/#;
 
6
   unshift @INC, $srcdir;
 
7
}
 
8
 
 
9
use strict;
 
10
use Test::More tests => 45;
 
11
use LightyTest;
 
12
 
 
13
my $tf = LightyTest->new();
 
14
 
 
15
my $t;
 
16
 
 
17
SKIP: {
 
18
        skip "no PHP running on port 1026", 28 unless $tf->listening_on(1026);
 
19
 
 
20
        ok($tf->start_proc == 0, "Starting lighttpd") or die();
 
21
 
 
22
        $t->{REQUEST} = ( <<EOF
 
23
GET /phpinfo.php HTTP/1.0
 
24
Host: www.example.org
 
25
EOF
 
26
 );
 
27
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
28
        ok($tf->handle_http($t) == 0, 'valid request');
 
29
 
 
30
        $t->{REQUEST}  = ( <<EOF
 
31
GET /phpinfofoobar.php HTTP/1.0
 
32
Host: www.example.org
 
33
EOF
 
34
 );
 
35
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
 
36
        ok($tf->handle_http($t) == 0, 'file not found');
 
37
 
 
38
        $t->{REQUEST}  = ( <<EOF
 
39
GET /go/ HTTP/1.0
 
40
Host: www.example.org
 
41
EOF
 
42
 );
 
43
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
44
        ok($tf->handle_http($t) == 0, 'index-file handling');
 
45
 
 
46
        $t->{REQUEST}  = ( <<EOF
 
47
GET /redirect.php HTTP/1.0
 
48
Host: www.example.org
 
49
EOF
 
50
 );
 
51
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ];
 
52
        ok($tf->handle_http($t) == 0, 'Status + Location via FastCGI');
 
53
 
 
54
        $t->{REQUEST}  = ( <<EOF
 
55
GET /get-server-env.php?env=PHP_SELF HTTP/1.0
 
56
Host: www.example.org
 
57
EOF
 
58
 );
 
59
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
60
        ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
 
61
 
 
62
        $t->{REQUEST}  = ( <<EOF
 
63
GET /get-server-env.php/foo?env=PHP_SELF HTTP/1.0
 
64
Host: www.example.org
 
65
EOF
 
66
 );
 
67
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/get-server-env.php' } ];
 
68
        ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
 
69
 
 
70
        $t->{REQUEST}  = ( <<EOF
 
71
GET /get-server-env.php/foo?env=PATH_INFO HTTP/1.0
 
72
Host: www.example.org
 
73
EOF
 
74
 );
 
75
        $t->{RESPONSE}  = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo' } ];
 
76
        ok($tf->handle_http($t) == 0, '$_SERVER["PATH_INFO"]');
 
77
 
 
78
        $t->{REQUEST}  = ( <<EOF
 
79
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
 
80
Host: www.example.org
 
81
EOF
 
82
 );
 
83
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
 
84
        ok($tf->handle_http($t) == 0, 'SERVER_NAME');
 
85
 
 
86
        $t->{REQUEST}  = ( <<EOF
 
87
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
 
88
Host: foo.example.org
 
89
EOF
 
90
 );
 
91
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
 
92
        ok($tf->handle_http($t) == 0, 'SERVER_NAME');
 
93
 
 
94
        $t->{REQUEST}  = ( <<EOF
 
95
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
 
96
Host: vvv.example.org
 
97
EOF
 
98
 );
 
99
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
 
100
        ok($tf->handle_http($t) == 0, 'SERVER_NAME');
 
101
 
 
102
        $t->{REQUEST}  = ( <<EOF
 
103
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
 
104
Host: zzz.example.org
 
105
EOF
 
106
 );
 
107
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
 
108
        ok($tf->handle_http($t) == 0, 'SERVER_NAME');
 
109
 
 
110
        $t->{REQUEST}  = ( <<EOF
 
111
GET /cgi.php/abc HTTP/1.0
 
112
EOF
 
113
 );
 
114
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
115
        ok($tf->handle_http($t) == 0, 'PATHINFO');
 
116
 
 
117
        $t->{REQUEST}  = ( <<EOF
 
118
GET /www/abc/def HTTP/1.0
 
119
EOF
 
120
 );
 
121
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
 
122
        ok($tf->handle_http($t) == 0, 'PATHINFO on a directory');
 
123
 
 
124
        $t->{REQUEST}  = ( <<EOF
 
125
GET /indexfile/ HTTP/1.0
 
126
EOF
 
127
 );
 
128
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ];
 
129
        ok($tf->handle_http($t) == 0, 'PHP_SELF + Indexfile, Bug #3');
 
130
 
 
131
        $t->{REQUEST}  = ( <<EOF
 
132
GET /prefix.fcgi?var=SCRIPT_NAME HTTP/1.0
 
133
EOF
 
134
 );
 
135
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
 
136
        ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
 
137
 
 
138
        $t->{REQUEST}  = ( <<EOF
 
139
GET /prefix.fcgi/foo/bar?var=SCRIPT_NAME HTTP/1.0
 
140
EOF
 
141
 );
 
142
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
 
143
        ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
 
144
 
 
145
        $t->{REQUEST}  = ( <<EOF
 
146
GET /prefix.fcgi/foo/bar?var=PATH_INFO HTTP/1.0
 
147
EOF
 
148
 );
 
149
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ];
 
150
        ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
 
151
 
 
152
        
 
153
        ok($tf->stop_proc == 0, "Stopping lighttpd");
 
154
 
 
155
 
 
156
        $tf->{CONFIGFILE} = 'fastcgi-10.conf';
 
157
        ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
 
158
        $t->{REQUEST}  = ( <<EOF
 
159
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
 
160
Host: zzz.example.org
 
161
EOF
 
162
 );
 
163
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'zzz.example.org' } ];
 
164
        ok($tf->handle_http($t) == 0, 'FastCGI + Host');
 
165
 
 
166
        ok($tf->stop_proc == 0, "Stopping lighttpd");
 
167
        
 
168
        $tf->{CONFIGFILE} = 'bug-06.conf';
 
169
        ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
 
170
        $t->{REQUEST}  = ( <<EOF
 
171
GET /indexfile/ HTTP/1.0
 
172
Host: www.example.org
 
173
EOF
 
174
 );
 
175
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ];
 
176
        ok($tf->handle_http($t) == 0, 'Bug #6');
 
177
 
 
178
        ok($tf->stop_proc == 0, "Stopping lighttpd");
 
179
 
 
180
        $tf->{CONFIGFILE} = 'bug-12.conf';
 
181
        ok($tf->start_proc == 0, "Starting lighttpd with bug-12.conf") or die();
 
182
        $t->{REQUEST}  = ( <<EOF
 
183
POST /indexfile/abc HTTP/1.0
 
184
Host: www.example.org
 
185
Content-Length: 0
 
186
EOF
 
187
 );
 
188
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/return-404.php' } ];
 
189
        ok($tf->handle_http($t) == 0, 'Bug #12');
 
190
 
 
191
        ok($tf->stop_proc == 0, "Stopping lighttpd");
 
192
}
 
193
 
 
194
SKIP: {
 
195
        skip "no fcgi-auth found", 4 unless -x $tf->{BASEDIR}."/tests/fcgi-auth" || -x $tf->{BASEDIR}."/tests/fcgi-auth.exe"; 
 
196
 
 
197
        $tf->{CONFIGFILE} = 'fastcgi-auth.conf';
 
198
        ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
 
199
        $t->{REQUEST}  = ( <<EOF
 
200
GET /index.html?ok HTTP/1.0
 
201
Host: www.example.org
 
202
EOF
 
203
 );
 
204
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
205
        ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
 
206
 
 
207
        $t->{REQUEST}  = ( <<EOF
 
208
GET /index.html?fail HTTP/1.0
 
209
Host: www.example.org
 
210
EOF
 
211
 );
 
212
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
 
213
        ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
 
214
 
 
215
        ok($tf->stop_proc == 0, "Stopping lighttpd");
 
216
}
 
217
 
 
218
SKIP: {
 
219
        skip "no php found", 4 unless -x "/home/jan/Documents/php-5.1.0b3/sapi/cgi/php"; 
 
220
        $tf->{CONFIGFILE} = 'fastcgi-13.conf';
 
221
        ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
 
222
        $t->{REQUEST}  = ( <<EOF
 
223
GET /indexfile/index.php HTTP/1.0
 
224
Host: www.example.org
 
225
EOF
 
226
 );
 
227
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
228
        ok($tf->handle_http($t) == 0, 'FastCGI + local spawning');
 
229
 
 
230
        $t->{REQUEST}  = ( <<EOF
 
231
GET /get-env.php?env=MAIL HTTP/1.0
 
232
Host: www.example.org
 
233
EOF
 
234
 );
 
235
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => '' } ];
 
236
        ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment');
 
237
 
 
238
 
 
239
 
 
240
        ok($tf->stop_proc == 0, "Stopping lighttpd");
 
241
}
 
242
 
 
243
 
 
244
SKIP: {
 
245
        skip "no fcgi-responder found", 9 unless -x $tf->{BASEDIR}."/tests/fcgi-responder" || -x $tf->{BASEDIR}."/tests/fcgi-responder.exe"; 
 
246
        
 
247
        $tf->{CONFIGFILE} = 'fastcgi-responder.conf';
 
248
        ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
 
249
        $t->{REQUEST}  = ( <<EOF
 
250
GET /index.fcgi?lf HTTP/1.0
 
251
Host: www.example.org
 
252
EOF
 
253
 );
 
254
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
 
255
        ok($tf->handle_http($t) == 0, 'line-ending \n\n');
 
256
 
 
257
        $t->{REQUEST}  = ( <<EOF
 
258
GET /index.fcgi?crlf HTTP/1.0
 
259
Host: www.example.org
 
260
EOF
 
261
 );
 
262
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
 
263
        ok($tf->handle_http($t) == 0, 'line-ending \r\n\r\n');
 
264
 
 
265
        $t->{REQUEST}  = ( <<EOF
 
266
GET /index.fcgi?slow-lf HTTP/1.0
 
267
Host: www.example.org
 
268
EOF
 
269
 );
 
270
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
 
271
        ok($tf->handle_http($t) == 0, 'line-ending \n + \n');
 
272
 
 
273
        $t->{REQUEST}  = ( <<EOF
 
274
GET /index.fcgi?slow-crlf HTTP/1.0
 
275
Host: www.example.org
 
276
EOF
 
277
 );
 
278
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
 
279
        ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
 
280
 
 
281
        $t->{REQUEST}  = ( <<EOF
 
282
GET /index.fcgi?die-at-end HTTP/1.0
 
283
Host: www.example.org
 
284
EOF
 
285
 );
 
286
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
 
287
        ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
 
288
 
 
289
        select(undef, undef, undef, 2);
 
290
        $t->{REQUEST}  = ( <<EOF
 
291
GET /index.fcgi?die-at-end HTTP/1.0
 
292
Host: www.example.org
 
293
EOF
 
294
 );
 
295
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
 
296
        ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
 
297
 
 
298
 
 
299
        select(undef, undef, undef, 2);
 
300
        $t->{REQUEST}  = ( <<EOF
 
301
GET /index.fcgi?crlf HTTP/1.0
 
302
Host: www.example.org
 
303
EOF
 
304
 );
 
305
        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
 
306
        ok($tf->handle_http($t) == 0, 'regular response of after restart');
 
307
 
 
308
 
 
309
        ok($tf->stop_proc == 0, "Stopping lighttpd");
 
310
}
 
311