Commit | Line | Data |
21a20b7e |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin '$Bin'; |
7 | use lib "$Bin/lib"; |
8 | |
d5ba2ab2 |
9 | use Test::More; |
21a20b7e |
10 | use HTTP::Request::Common; |
11 | |
f316e295 |
12 | my %orig_sig; |
8cf93f58 |
13 | BEGIN { |
14 | %orig_sig = %SIG; |
15 | # perl < 5.8.9 won't set a %SIG entry to undef, it sets it to '' |
16 | %orig_sig = map { defined $_ ? $_ : '' } %orig_sig |
17 | if $] < 5.008009; |
18 | } |
f316e295 |
19 | |
20 | use Catalyst::Test 'TestCGIBin'; |
21 | |
46a4350c |
22 | # this should be ignored |
23 | $ENV{MOD_PERL} = "mod_perl/2.0"; |
24 | |
f316e295 |
25 | is_deeply \%SIG, \%orig_sig, '%SIG is preserved on compile'; |
f316e295 |
26 | |
9cc2dd4c |
27 | my $response = request POST '/my-bin/path/test.pl', [ |
21a20b7e |
28 | foo => 'bar', |
29 | bar => 'baz' |
30 | ]; |
31 | |
32 | is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File'); |
33 | |
06d193b4 |
34 | $response = request '/my-bin/path/test.pl?foo=bar&bar=baz'; |
35 | |
36 | is($response->content, 'foo:bar bar:baz', |
37 | 'Perl CGI File invoked with query params'); |
38 | |
bdb35995 |
39 | $response = request POST '/my-bin/exit.pl', [ |
40 | name => 'world', |
41 | ]; |
42 | |
43 | is($response->content, 'hello world', 'POST to Perl CGI with exit()'); |
44 | |
45 | $response = request POST '/my-bin/exit.pl', [ |
46 | name => 'world', |
47 | exit => 17, |
48 | ]; |
49 | |
50 | is($response->code, 500, 'POST to Perl CGI with nonzero exit()'); |
9e040aeb |
51 | |
52 | $response = request '/my-bin/ignored.cgi'; |
53 | |
54 | is($response->code, 500, "file not matching 'cgi_file_pattern' is ignored"); |
bdb35995 |
55 | |
21a20b7e |
56 | $response = request POST '/cgihandler/mtfnpy', [ |
57 | foo => 'bar', |
58 | bar => 'baz' |
59 | ]; |
60 | |
61 | is($response->content, 'foo:bar bar:baz', |
62 | 'POST to Perl CGI File through a forward via cgi_action'); |
63 | |
63096ad1 |
64 | $response = request '/my-bin/path/testdata.pl'; |
fbaba9dd |
65 | is($response->content, "testing\n", |
66 | 'scripts with __DATA__ sections work'); |
67 | |
f410f043 |
68 | $response = request '/my-bin/pathinfo.pl/path/info'; |
69 | is($response->content, '/path/info', |
70 | 'PATH_INFO works'); |
71 | |
d5ba2ab2 |
72 | ok request '/my-bin/sigs.pl'; |
73 | |
74 | is_deeply \%SIG, \%orig_sig, '%SIG is preserved'; |
75 | |
21a20b7e |
76 | SKIP: { |
77 | skip "Can't run shell scripts on non-*nix", 1 |
78 | if $^O eq 'MSWin32' || $^O eq 'VMS'; |
79 | |
5709e6bd |
80 | # for some reason the +x is not preserved in the dist |
81 | system "chmod +x $Bin/lib/TestCGIBin/root/cgi-bin/test.sh"; |
d9280b8f |
82 | system "chmod +x $Bin/lib/TestCGIBin/root/cgi-bin/exit_nonzero.sh"; |
5709e6bd |
83 | |
9cc2dd4c |
84 | is(get('/my-bin/test.sh'), "Hello!\n", 'Non-Perl CGI File'); |
d9280b8f |
85 | |
86 | $response = request GET '/my-bin/exit_nonzero.sh'; |
87 | is $response->code, 500, 'Non-Perl CGI with non-zero exit dies'; |
21a20b7e |
88 | } |
d5ba2ab2 |
89 | |
604b5dbb |
90 | { $response = get('/my-bin/time.pl'); |
91 | sleep 1; |
92 | my $response_2 = get('/my-bin/time.pl'); |
93 | isnt( $response, $response_2, 'cgis are getting invoked each time' ); |
94 | } |
95 | |
d5ba2ab2 |
96 | done_testing; |