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, |
5dbf12d1 |
12 | SCRIPT_NAME => '/comics/dispatch.cgi', |
13 | REQUEST_URI => '/comics/', |
14 | ); |
eb3abf96 |
15 | is ''.$r->uri, 'http://www.foo.com/comics/'; |
16 | is ''.$r->base, 'http://www.foo.com/comics/'; |
17 | } |
18 | |
19 | # mod_rewrite to sub path under app root for non / based app |
20 | { |
661de072 |
21 | my $r = get_req (0, |
eb3abf96 |
22 | PATH_INFO => '/foo/bar.gif', |
eb3abf96 |
23 | SCRIPT_NAME => '/comics/dispatch.cgi', |
24 | REQUEST_URI => '/comics/foo/bar.gif', |
25 | ); |
26 | is ''.$r->uri, 'http://www.foo.com/comics/foo/bar.gif'; |
27 | is ''.$r->base, 'http://www.foo.com/comics/'; |
28 | } |
29 | |
30 | # Standard CGI hit for non / based app |
31 | { |
661de072 |
32 | my $r = get_req (0, |
eb3abf96 |
33 | PATH_INFO => '/static/css/blueprint/screen.css', |
34 | SCRIPT_NAME => '/~bobtfish/Gitalist/script/gitalist.cgi', |
35 | REQUEST_URI => '/~bobtfish/Gitalist/script/gitalist.cgi/static/css/blueprint/screen.css', |
36 | ); |
37 | is ''.$r->uri, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/static/css/blueprint/screen.css'; |
38 | is ''.$r->base, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/'; |
39 | } |
53f4422a |
40 | # / %2F %252F escaping case. |
41 | { |
661de072 |
42 | my $r = get_req (1, |
53f4422a |
43 | PATH_INFO => '/%2F/%2F', |
44 | SCRIPT_NAME => '/~bobtfish/Gitalist/script/gitalist.cgi', |
45 | REQUEST_URI => '/~bobtfish/Gitalist/script/gitalist.cgi/%252F/%252F', |
46 | ); |
47 | is ''.$r->uri, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/%252F/%252F'; |
48 | is ''.$r->base, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/'; |
49 | } |
eb3abf96 |
50 | |
b760ac3d |
51 | # Using rewrite rules to ask for a sub-path in your app. |
52 | # E.g. RewriteRule ^(.*)$ /path/to/fastcgi/domainprofi.fcgi/iframeredirect$1 [L,NS] |
53 | { |
661de072 |
54 | my $r = get_req (0, |
b760ac3d |
55 | PATH_INFO => '/iframeredirect/info', |
56 | SCRIPT_NAME => '', |
57 | REQUEST_URI => '/info', |
58 | ); |
59 | is ''.$r->uri, 'http://www.foo.com/iframeredirect/info'; |
60 | is ''.$r->base, 'http://www.foo.com/'; |
61 | } |
62 | |
661de072 |
63 | # nginx example from espent with path /"foo" |
64 | { |
65 | my $r = get_req (0, |
66 | PATH_INFO => '"foo"', |
67 | SCRIPT_NAME => '/', |
68 | REQUEST_URI => '/%22foo%22', |
69 | ); |
70 | is ''.$r->path, '%22foo%22'; |
71 | is ''.$r->uri, 'http://www.foo.com/%22foo%22'; |
72 | is ''.$r->base, 'http://www.foo.com/'; |
73 | } |
74 | |
75 | # nginx example from espent with path /"foo" and the app based at /oslobilder |
76 | { |
77 | my $r = get_req (1, |
78 | PATH_INFO => 'oslobilder/"foo"', |
79 | SCRIPT_NAME => '/oslobilder/', |
80 | REQUEST_URI => '/oslobilder/%22foo%22', |
81 | ); |
82 | is ''.$r->path, '%22foo%22', 'path correct'; |
83 | is ''.$r->uri, 'http://www.foo.com/oslobilder/%22foo%22', 'uri correct'; |
84 | is ''.$r->base, 'http://www.foo.com/oslobilder/', 'base correct'; |
85 | } |
86 | { |
87 | local $TODO = 'Another mod_rewrite case'; |
88 | my $r = get_req (0, |
89 | PATH_INFO => '/auth/login', |
90 | SCRIPT_NAME => '/tx', |
91 | REQUEST_URI => '/login', |
92 | ); |
93 | is ''.$r->path, 'auth/login', 'path correct'; |
94 | is ''.$r->uri, 'http://www.foo.com/tx/auth/login', 'uri correct'; |
95 | is ''.$r->base, 'http://www.foo.com/tx/', 'base correct'; |
96 | } |
97 | |
98 | # test req->base and c->uri_for work correctly after an internally redirected request |
99 | # (i.e. REDIRECT_URL set) when the PATH_INFO contains a regex |
100 | { |
101 | my $path = '/engine/request/uri/Rx(here)'; |
102 | my $r = get_req (0, |
103 | SCRIPT_NAME => '/', |
104 | PATH_INFO => $path, |
105 | REQUEST_URI => $path, |
106 | REDIRECT_URL => $path, |
107 | ); |
108 | |
109 | is $r->path, 'engine/request/uri/Rx(here)', 'URI contains correct path'; |
110 | is $r->base, 'http://www.foo.com/', 'Base is correct'; |
111 | } |
b760ac3d |
112 | |
113 | |
eb3abf96 |
114 | # FIXME - Test proxy logic |
eb3abf96 |
115 | # - Test query string |
116 | # - Test non standard port numbers |
117 | # - Test // in PATH_INFO |
118 | # - Test scheme (secure request on port 80) |
119 | |
120 | sub get_req { |
661de072 |
121 | my $use_request_uri_for_path = shift; |
122 | |
ee1ea13f |
123 | my %template = ( |
124 | HTTP_HOST => 'www.foo.com', |
125 | PATH_INFO => '/', |
126 | ); |
127 | |
d9d5d62d |
128 | my $engine = Catalyst::Engine->new( |
129 | env => { %template, @_ }, |
130 | ); |
5dbf12d1 |
131 | my $i = TestApp->new; |
661de072 |
132 | $i->setup_finished(0); |
133 | $i->config(use_request_uri_for_path => $use_request_uri_for_path); |
134 | $i->setup_finished(1); |
d9d5d62d |
135 | $engine->prepare_path($i); |
eb3abf96 |
136 | return $i->req; |
5dbf12d1 |
137 | } |
138 | |
139 | done_testing; |
140 | |