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 | |
46b58c90 |
89 | { |
90 | my $r = get_req ( |
91 | PATH_INFO => '/auth/login', |
92 | SCRIPT_NAME => '/tx', |
93 | REQUEST_URI => '/login', |
94 | ); |
95 | is ''.$r->path, 'auth/login'; |
96 | is ''.$r->uri, 'http://www.foo.com/tx/auth/login'; |
97 | is ''.$r->base, 'http://www.foo.com/tx/'; |
98 | } |
a9a405db |
99 | |
4dfe7bde |
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 ( |
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 | } |
114 | |
a9a405db |
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 { |
ee1ea13f |
123 | my %template = ( |
124 | HTTP_HOST => 'www.foo.com', |
125 | PATH_INFO => '/', |
126 | ); |
127 | |
eb3abf96 |
128 | local %ENV = (%template, @_); |
ee1ea13f |
129 | |
5dbf12d1 |
130 | my $i = TestApp->new; |
131 | $i->engine(Catalyst::Engine::CGI->new); |
132 | $i->engine->prepare_path($i); |
eb3abf96 |
133 | return $i->req; |
5dbf12d1 |
134 | } |
135 | |
136 | done_testing; |
137 | |