Commit | Line | Data |
5dbf12d1 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | use FindBin qw/$Bin/; |
5 | use lib "$Bin/../lib"; |
6 | use TestApp; |
7 | use Catalyst::Engine::CGI; |
8 | |
eb3abf96 |
9 | # mod_rewrite to app root for non / based app |
5dbf12d1 |
10 | { |
eb3abf96 |
11 | my $r = get_req ( |
5dbf12d1 |
12 | REDIRECT_URL => '/comics/', |
5dbf12d1 |
13 | SCRIPT_NAME => '/comics/dispatch.cgi', |
14 | REQUEST_URI => '/comics/', |
15 | ); |
eb3abf96 |
16 | is ''.$r->uri, 'http://www.foo.com/comics/'; |
17 | is ''.$r->base, 'http://www.foo.com/comics/'; |
18 | } |
19 | |
20 | # mod_rewrite to sub path under app root for non / based app |
21 | { |
22 | my $r = get_req ( |
23 | PATH_INFO => '/foo/bar.gif', |
24 | REDIRECT_URL => '/comics/foo/bar.gif', |
25 | SCRIPT_NAME => '/comics/dispatch.cgi', |
26 | REQUEST_URI => '/comics/foo/bar.gif', |
27 | ); |
28 | is ''.$r->uri, 'http://www.foo.com/comics/foo/bar.gif'; |
29 | is ''.$r->base, 'http://www.foo.com/comics/'; |
30 | } |
31 | |
32 | # Standard CGI hit for non / based app |
33 | { |
34 | my $r = get_req ( |
35 | PATH_INFO => '/static/css/blueprint/screen.css', |
36 | SCRIPT_NAME => '/~bobtfish/Gitalist/script/gitalist.cgi', |
37 | REQUEST_URI => '/~bobtfish/Gitalist/script/gitalist.cgi/static/css/blueprint/screen.css', |
38 | ); |
39 | is ''.$r->uri, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/static/css/blueprint/screen.css'; |
40 | is ''.$r->base, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/'; |
41 | } |
53f4422a |
42 | # / %2F %252F escaping case. |
43 | { |
44 | my $r = get_req ( |
45 | PATH_INFO => '/%2F/%2F', |
46 | SCRIPT_NAME => '/~bobtfish/Gitalist/script/gitalist.cgi', |
47 | REQUEST_URI => '/~bobtfish/Gitalist/script/gitalist.cgi/%252F/%252F', |
48 | ); |
49 | is ''.$r->uri, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/%252F/%252F'; |
50 | is ''.$r->base, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/'; |
51 | } |
eb3abf96 |
52 | |
b760ac3d |
53 | # Using rewrite rules to ask for a sub-path in your app. |
54 | # E.g. RewriteRule ^(.*)$ /path/to/fastcgi/domainprofi.fcgi/iframeredirect$1 [L,NS] |
55 | { |
56 | my $r = get_req ( |
57 | PATH_INFO => '/iframeredirect/info', |
58 | SCRIPT_NAME => '', |
59 | REQUEST_URI => '/info', |
60 | ); |
61 | is ''.$r->uri, 'http://www.foo.com/iframeredirect/info'; |
62 | is ''.$r->base, 'http://www.foo.com/'; |
63 | } |
64 | |
f54950f5 |
65 | # nginx example from espent with path /"foo" |
66 | { |
67 | my $r = get_req ( |
68 | PATH_INFO => '"foo"', |
69 | SCRIPT_NAME => '/', |
70 | REQUEST_URI => '/%22foo%22', |
71 | ); |
72 | is ''.$r->path, '%22foo%22'; |
73 | is ''.$r->uri, 'http://www.foo.com/%22foo%22'; |
74 | is ''.$r->base, 'http://www.foo.com/'; |
75 | } |
b760ac3d |
76 | |
a9a405db |
77 | # nginx example from espent with path /"foo" and the app based at /oslobilder |
78 | { |
79 | my $r = get_req ( |
80 | PATH_INFO => 'oslobilder/"foo"', |
81 | SCRIPT_NAME => '/oslobilder/', |
82 | REQUEST_URI => '/oslobilder/%22foo%22', |
83 | ); |
84 | is ''.$r->path, '%22foo%22'; |
85 | is ''.$r->uri, 'http://www.foo.com/oslobilder/%22foo%22'; |
86 | is ''.$r->base, 'http://www.foo.com/oslobilder/'; |
87 | } |
88 | |
89 | |
90 | |
91 | |
eb3abf96 |
92 | # FIXME - Test proxy logic |
eb3abf96 |
93 | # - Test query string |
94 | # - Test non standard port numbers |
95 | # - Test // in PATH_INFO |
96 | # - Test scheme (secure request on port 80) |
97 | |
98 | sub get_req { |
ee1ea13f |
99 | my %template = ( |
100 | HTTP_HOST => 'www.foo.com', |
101 | PATH_INFO => '/', |
102 | ); |
103 | |
eb3abf96 |
104 | local %ENV = (%template, @_); |
ee1ea13f |
105 | |
5dbf12d1 |
106 | my $i = TestApp->new; |
107 | $i->engine(Catalyst::Engine::CGI->new); |
108 | $i->engine->prepare_path($i); |
eb3abf96 |
109 | return $i->req; |
5dbf12d1 |
110 | } |
111 | |
112 | done_testing; |
113 | |