Mercurial > hg > nginx-tests
annotate fastcgi_variables.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
688
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Test for fastcgi variables. |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 use Socket qw/ CRLF /; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 eval { require FCGI; }; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 plan(skip_all => 'FCGI not installed') if $@; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 my $t = Test::Nginx->new()->has(qw/http fastcgi rewrite/)->plan(3) |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 ->write_file_expand('nginx.conf', <<'EOF'); |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 %%TEST_GLOBALS%% |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 daemon off; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 events { |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 } |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 http { |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 %%TEST_GLOBALS_HTTP%% |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 listen 127.0.0.1:8080; |
688
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 server_name localhost; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 add_header X-Script-Name $fastcgi_script_name; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 add_header X-Path-Info $fastcgi_path_info; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
52 fastcgi_pass 127.0.0.1:8081; |
688
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 fastcgi_index index.php; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 } |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 location /info { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 fastcgi_pass 127.0.0.1:8081; |
688
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 fastcgi_split_path_info ^(.+\.php)(.*)$; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 } |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 } |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 } |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 EOF |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 $t->run_daemon(\&fastcgi_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
66 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
688
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 ############################################################################### |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 like(http_get('/'), qr/X-Script-Name: \/index\.php/ms, 'script name'); |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 like(http_get('/info.php/path/info'), qr/X-Script-Name: \/info\.php/ms, |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 'info script name'); |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 like(http_get('/info.php/path/info'), qr/X-Path-Info: \/path\/info/ms, |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 'info path'); |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 ############################################################################### |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 sub fastcgi_daemon { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
79 my $socket = FCGI::OpenSocket('127.0.0.1:' . port(8081), 5); |
688
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 $socket); |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 while( $request->Accept() >= 0 ) { |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 print CRLF . CRLF; |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 } |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 FCGI::CloseSocket($socket); |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 } |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
d40623cda299
Tests: added fastcgi variables tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |