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; |
d9d5d62d |
7 | use Catalyst::Engine; |
5dbf12d1 |
8 | |
eb3abf96 |
9 | # mod_rewrite to app root for non / based app |
5dbf12d1 |
10 | { |
661de072 |
11 | my $r = get_req (0, |
4904ee27 |
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 | { |
661de072 |
22 | my $r = get_req (0, |
eb3abf96 |
23 | PATH_INFO => '/foo/bar.gif', |
4904ee27 |
24 | REDIRECT_URL => '/comics/foo/bar.gif', |
eb3abf96 |
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 | { |
661de072 |
34 | my $r = get_req (0, |
eb3abf96 |
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 | { |
661de072 |
44 | my $r = get_req (1, |
53f4422a |
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 | { |
661de072 |
56 | my $r = get_req (0, |
b760ac3d |
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 | |
661de072 |
65 | # nginx example from espent with path /"foo" |
66 | { |
67 | my $r = get_req (0, |
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 | } |
76 | |
77 | # nginx example from espent with path /"foo" and the app based at /oslobilder |
78 | { |
79 | my $r = get_req (1, |
80 | PATH_INFO => 'oslobilder/"foo"', |
81 | SCRIPT_NAME => '/oslobilder/', |
82 | REQUEST_URI => '/oslobilder/%22foo%22', |
83 | ); |
84 | is ''.$r->path, '%22foo%22', 'path correct'; |
85 | is ''.$r->uri, 'http://www.foo.com/oslobilder/%22foo%22', 'uri correct'; |
86 | is ''.$r->base, 'http://www.foo.com/oslobilder/', 'base correct'; |
87 | } |
88 | { |
89 | local $TODO = 'Another mod_rewrite case'; |
90 | my $r = get_req (0, |
91 | PATH_INFO => '/auth/login', |
92 | SCRIPT_NAME => '/tx', |
93 | REQUEST_URI => '/login', |
94 | ); |
95 | is ''.$r->path, 'auth/login', 'path correct'; |
96 | is ''.$r->uri, 'http://www.foo.com/tx/auth/login', 'uri correct'; |
97 | is ''.$r->base, 'http://www.foo.com/tx/', 'base correct'; |
98 | } |
99 | |
100 | # test req->base and c->uri_for work correctly after an internally redirected request |
101 | # (i.e. REDIRECT_URL set) when the PATH_INFO contains a regex |
102 | { |
103 | my $path = '/engine/request/uri/Rx(here)'; |
104 | my $r = get_req (0, |
105 | SCRIPT_NAME => '/', |
106 | PATH_INFO => $path, |
107 | REQUEST_URI => $path, |
108 | REDIRECT_URL => $path, |
109 | ); |
110 | |
111 | is $r->path, 'engine/request/uri/Rx(here)', 'URI contains correct path'; |
112 | is $r->base, 'http://www.foo.com/', 'Base is correct'; |
113 | } |
b760ac3d |
114 | |
115 | |
eb3abf96 |
116 | # FIXME - Test proxy logic |
eb3abf96 |
117 | # - Test query string |
118 | # - Test non standard port numbers |
119 | # - Test // in PATH_INFO |
120 | # - Test scheme (secure request on port 80) |
121 | |
122 | sub get_req { |
661de072 |
123 | my $use_request_uri_for_path = shift; |
124 | |
ee1ea13f |
125 | my %template = ( |
126 | HTTP_HOST => 'www.foo.com', |
127 | PATH_INFO => '/', |
128 | ); |
129 | |
d9d5d62d |
130 | my $engine = Catalyst::Engine->new( |
131 | env => { %template, @_ }, |
132 | ); |
5dbf12d1 |
133 | my $i = TestApp->new; |
661de072 |
134 | $i->setup_finished(0); |
135 | $i->config(use_request_uri_for_path => $use_request_uri_for_path); |
136 | $i->setup_finished(1); |
d9d5d62d |
137 | $engine->prepare_path($i); |
eb3abf96 |
138 | return $i->req; |
5dbf12d1 |
139 | } |
140 | |
141 | done_testing; |
142 | |