actionpack 2.3.2 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +5 -0
- data/Rakefile +10 -9
- data/lib/action_controller.rb +2 -7
- data/lib/action_controller/assertions/response_assertions.rb +11 -3
- data/lib/action_controller/base.rb +7 -2
- data/lib/action_controller/caching.rb +1 -1
- data/lib/action_controller/caching/actions.rb +9 -1
- data/lib/action_controller/caching/sweeper.rb +45 -0
- data/lib/action_controller/caching/sweeping.rb +0 -42
- data/lib/action_controller/failsafe.rb +40 -6
- data/lib/action_controller/flash.rb +11 -3
- data/lib/action_controller/http_authentication.rb +5 -2
- data/lib/action_controller/integration.rb +5 -12
- data/lib/action_controller/middlewares.rb +0 -1
- data/lib/action_controller/reloader.rb +34 -3
- data/lib/action_controller/request.rb +6 -2
- data/lib/action_controller/response.rb +2 -2
- data/lib/action_controller/routing/route_set.rb +2 -1
- data/lib/action_controller/streaming.rb +1 -1
- data/lib/action_controller/test_process.rb +9 -1
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view/helpers.rb +1 -1
- data/lib/action_view/helpers/asset_tag_helper.rb +21 -9
- data/lib/action_view/helpers/date_helper.rb +2 -2
- data/lib/action_view/helpers/form_helper.rb +25 -12
- data/lib/action_view/helpers/form_options_helper.rb +2 -0
- data/lib/action_view/helpers/form_tag_helper.rb +10 -4
- data/lib/action_view/helpers/number_helper.rb +1 -1
- data/lib/action_view/helpers/prototype_helper.rb +7 -7
- data/lib/action_view/helpers/scriptaculous_helper.rb +5 -5
- data/lib/action_view/helpers/text_helper.rb +3 -3
- data/lib/action_view/helpers/url_helper.rb +1 -1
- data/lib/action_view/paths.rb +1 -1
- data/lib/action_view/template.rb +22 -33
- data/test/abstract_unit.rb +1 -1
- data/test/activerecord/active_record_store_test.rb +3 -3
- data/test/controller/action_pack_assertions_test.rb +27 -0
- data/test/controller/caching_test.rb +39 -0
- data/test/controller/cookie_test.rb +10 -0
- data/test/controller/dispatcher_test.rb +9 -7
- data/test/controller/failsafe_test.rb +60 -0
- data/test/controller/filter_params_test.rb +2 -1
- data/test/controller/flash_test.rb +6 -1
- data/test/controller/http_digest_authentication_test.rb +34 -3
- data/test/controller/integration_test.rb +31 -3
- data/test/controller/redirect_test.rb +4 -1
- data/test/controller/reloader_test.rb +97 -0
- data/test/controller/render_test.rb +19 -9
- data/test/controller/request/multipart_params_parsing_test.rb +1 -62
- data/test/controller/request/test_request_test.rb +35 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +0 -38
- data/test/controller/request_test.rb +218 -230
- data/test/controller/resources_test.rb +8 -0
- data/test/controller/routing_test.rb +21 -0
- data/test/controller/send_file_test.rb +1 -1
- data/test/controller/session/cookie_store_test.rb +9 -32
- data/test/controller/test_test.rb +8 -0
- data/test/fixtures/failsafe/500.html +1 -0
- data/test/template/active_record_helper_test.rb +1 -1
- data/test/template/asset_tag_helper_test.rb +46 -0
- data/test/template/form_helper_test.rb +117 -6
- data/test/template/form_options_helper_test.rb +22 -0
- data/test/template/form_tag_helper_test.rb +23 -6
- data/test/template/prototype_helper_test.rb +11 -11
- data/test/template/template_test.rb +32 -0
- metadata +20 -63
- data/lib/action_controller/rewindable_input.rb +0 -28
- data/lib/action_controller/vendor/rack-1.0/rack.rb +0 -89
- data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +0 -22
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +0 -37
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +0 -37
- data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +0 -58
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +0 -124
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +0 -51
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +0 -55
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +0 -40
- data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +0 -480
- data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +0 -63
- data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +0 -36
- data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +0 -49
- data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +0 -61
- data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +0 -45
- data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +0 -29
- data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +0 -23
- data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +0 -85
- data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +0 -153
- data/lib/action_controller/vendor/rack-1.0/rack/file.rb +0 -88
- data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +0 -48
- data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +0 -61
- data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +0 -8
- data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +0 -89
- data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +0 -55
- data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +0 -84
- data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +0 -59
- data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +0 -8
- data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +0 -18
- data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +0 -67
- data/lib/action_controller/vendor/rack-1.0/rack/head.rb +0 -19
- data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +0 -462
- data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +0 -65
- data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +0 -16
- data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +0 -27
- data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +0 -204
- data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +0 -160
- data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +0 -57
- data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +0 -64
- data/lib/action_controller/vendor/rack-1.0/rack/request.rb +0 -241
- data/lib/action_controller/vendor/rack-1.0/rack/response.rb +0 -179
- data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +0 -142
- data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +0 -91
- data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +0 -109
- data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +0 -100
- data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +0 -349
- data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +0 -106
- data/lib/action_controller/vendor/rack-1.0/rack/static.rb +0 -38
- data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +0 -55
- data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +0 -392
@@ -3,7 +3,6 @@ require 'abstract_unit'
|
|
3
3
|
class RequestTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
5
5
|
ActionController::Base.relative_url_root = nil
|
6
|
-
@request = ActionController::TestRequest.new
|
7
6
|
end
|
8
7
|
|
9
8
|
def teardown
|
@@ -11,60 +10,52 @@ class RequestTest < ActiveSupport::TestCase
|
|
11
10
|
end
|
12
11
|
|
13
12
|
def test_remote_ip
|
14
|
-
|
13
|
+
request = stub_request 'REMOTE_ADDR' => '1.2.3.4'
|
14
|
+
assert_equal '1.2.3.4', request.remote_ip
|
15
15
|
|
16
|
-
|
17
|
-
assert_equal '1.2.3.4',
|
16
|
+
request = stub_request 'REMOTE_ADDR' => '1.2.3.4,3.4.5.6'
|
17
|
+
assert_equal '1.2.3.4', request.remote_ip
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
request = stub_request 'REMOTE_ADDR' => '1.2.3.4',
|
20
|
+
'HTTP_X_FORWARDED_FOR' => '3.4.5.6'
|
21
|
+
assert_equal '1.2.3.4', request.remote_ip
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
request = stub_request 'REMOTE_ADDR' => '127.0.0.1',
|
24
|
+
'HTTP_X_FORWARDED_FOR' => '3.4.5.6'
|
25
|
+
assert_equal '3.4.5.6', request.remote_ip
|
24
26
|
|
25
|
-
|
26
|
-
assert_equal '
|
27
|
-
@request.env.delete 'HTTP_CLIENT_IP'
|
27
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,3.4.5.6'
|
28
|
+
assert_equal '3.4.5.6', request.remote_ip
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
assert_equal '1.2.3.4', @request.remote_ip
|
30
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '172.16.0.1,3.4.5.6'
|
31
|
+
assert_equal '3.4.5.6', request.remote_ip
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
assert_equal '3.4.5.6', @request.remote_ip
|
33
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '192.168.0.1,3.4.5.6'
|
34
|
+
assert_equal '3.4.5.6', request.remote_ip
|
36
35
|
|
37
|
-
|
38
|
-
assert_equal '3.4.5.6',
|
36
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '10.0.0.1,3.4.5.6'
|
37
|
+
assert_equal '3.4.5.6', request.remote_ip
|
39
38
|
|
40
|
-
|
41
|
-
assert_equal '3.4.5.6',
|
39
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '10.0.0.1, 10.0.0.1, 3.4.5.6'
|
40
|
+
assert_equal '3.4.5.6', request.remote_ip
|
42
41
|
|
43
|
-
|
44
|
-
assert_equal '3.4.5.6',
|
42
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '127.0.0.1,3.4.5.6'
|
43
|
+
assert_equal '3.4.5.6', request.remote_ip
|
45
44
|
|
46
|
-
|
47
|
-
assert_equal '
|
45
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,192.168.0.1'
|
46
|
+
assert_equal 'unknown', request.remote_ip
|
48
47
|
|
49
|
-
|
50
|
-
assert_equal '3.4.5.6',
|
48
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4'
|
49
|
+
assert_equal '3.4.5.6', request.remote_ip
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
@request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,192.168.0.1'
|
56
|
-
assert_equal 'unknown', @request.remote_ip
|
57
|
-
|
58
|
-
@request.env['HTTP_X_FORWARDED_FOR'] = '9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4'
|
59
|
-
assert_equal '3.4.5.6', @request.remote_ip
|
60
|
-
|
61
|
-
@request.env['HTTP_CLIENT_IP'] = '8.8.8.8'
|
51
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '1.1.1.1',
|
52
|
+
'HTTP_CLIENT_IP' => '2.2.2.2'
|
62
53
|
e = assert_raise(ActionController::ActionControllerError) {
|
63
|
-
|
54
|
+
request.remote_ip
|
64
55
|
}
|
65
56
|
assert_match /IP spoofing attack/, e.message
|
66
|
-
assert_match /HTTP_X_FORWARDED_FOR="
|
67
|
-
assert_match /HTTP_CLIENT_IP="
|
57
|
+
assert_match /HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message
|
58
|
+
assert_match /HTTP_CLIENT_IP="2.2.2.2"/, e.message
|
68
59
|
|
69
60
|
# turn IP Spoofing detection off.
|
70
61
|
# This is useful for sites that are aimed at non-IP clients. The typical
|
@@ -72,336 +63,333 @@ class RequestTest < ActiveSupport::TestCase
|
|
72
63
|
# leap of faith to assume that their proxies are ever going to set the
|
73
64
|
# HTTP_CLIENT_IP/HTTP_X_FORWARDED_FOR headers properly.
|
74
65
|
ActionController::Base.ip_spoofing_check = false
|
75
|
-
|
66
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '1.1.1.1',
|
67
|
+
'HTTP_CLIENT_IP' => '2.2.2.2'
|
68
|
+
assert_equal '2.2.2.2', request.remote_ip
|
76
69
|
ActionController::Base.ip_spoofing_check = true
|
77
70
|
|
78
|
-
|
79
|
-
assert_equal '
|
80
|
-
|
81
|
-
@request.env.delete 'HTTP_CLIENT_IP'
|
82
|
-
@request.env.delete 'HTTP_X_FORWARDED_FOR'
|
71
|
+
request = stub_request 'HTTP_X_FORWARDED_FOR' => '8.8.8.8, 9.9.9.9'
|
72
|
+
assert_equal '9.9.9.9', request.remote_ip
|
83
73
|
end
|
84
74
|
|
85
75
|
def test_domains
|
86
|
-
|
87
|
-
assert_equal "rubyonrails.org",
|
88
|
-
|
89
|
-
@request.host = "www.rubyonrails.co.uk"
|
90
|
-
assert_equal "rubyonrails.co.uk", @request.domain(2)
|
76
|
+
request = stub_request 'HTTP_HOST' => 'www.rubyonrails.org'
|
77
|
+
assert_equal "rubyonrails.org", request.domain
|
91
78
|
|
92
|
-
|
93
|
-
|
79
|
+
request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk"
|
80
|
+
assert_equal "rubyonrails.co.uk", request.domain(2)
|
94
81
|
|
95
|
-
|
96
|
-
assert_nil
|
82
|
+
request = stub_request 'HTTP_HOST' => "192.168.1.200"
|
83
|
+
assert_nil request.domain
|
97
84
|
|
98
|
-
|
99
|
-
|
85
|
+
request = stub_request 'HTTP_HOST' => "foo.192.168.1.200"
|
86
|
+
assert_nil request.domain
|
100
87
|
|
101
|
-
|
102
|
-
|
88
|
+
request = stub_request 'HTTP_HOST' => "192.168.1.200.com"
|
89
|
+
assert_equal "200.com", request.domain
|
103
90
|
end
|
104
91
|
|
105
92
|
def test_subdomains
|
106
|
-
|
107
|
-
assert_equal %w( www ),
|
93
|
+
request = stub_request 'HTTP_HOST' => "www.rubyonrails.org"
|
94
|
+
assert_equal %w( www ), request.subdomains
|
108
95
|
|
109
|
-
|
110
|
-
assert_equal %w( www ),
|
96
|
+
request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk"
|
97
|
+
assert_equal %w( www ), request.subdomains(2)
|
111
98
|
|
112
|
-
|
113
|
-
assert_equal %w( dev www ),
|
99
|
+
request = stub_request 'HTTP_HOST' => "dev.www.rubyonrails.co.uk"
|
100
|
+
assert_equal %w( dev www ), request.subdomains(2)
|
114
101
|
|
115
|
-
|
116
|
-
assert_equal %w( foobar ),
|
102
|
+
request = stub_request 'HTTP_HOST' => "foobar.foobar.com"
|
103
|
+
assert_equal %w( foobar ), request.subdomains
|
117
104
|
|
118
|
-
|
119
|
-
assert_equal [],
|
105
|
+
request = stub_request 'HTTP_HOST' => "192.168.1.200"
|
106
|
+
assert_equal [], request.subdomains
|
120
107
|
|
121
|
-
|
122
|
-
assert_equal [],
|
108
|
+
request = stub_request 'HTTP_HOST' => "foo.192.168.1.200"
|
109
|
+
assert_equal [], request.subdomains
|
123
110
|
|
124
|
-
|
125
|
-
assert_equal %w( 192 168 1 ),
|
111
|
+
request = stub_request 'HTTP_HOST' => "192.168.1.200.com"
|
112
|
+
assert_equal %w( 192 168 1 ), request.subdomains
|
126
113
|
|
127
|
-
|
128
|
-
assert_equal [],
|
114
|
+
request = stub_request 'HTTP_HOST' => nil
|
115
|
+
assert_equal [], request.subdomains
|
129
116
|
end
|
130
117
|
|
131
118
|
def test_port_string
|
132
|
-
|
133
|
-
assert_equal "",
|
119
|
+
request = stub_request 'HTTP_HOST' => 'www.example.org:80'
|
120
|
+
assert_equal "", request.port_string
|
134
121
|
|
135
|
-
|
136
|
-
assert_equal ":8080",
|
122
|
+
request = stub_request 'HTTP_HOST' => 'www.example.org:8080'
|
123
|
+
assert_equal ":8080", request.port_string
|
137
124
|
end
|
138
125
|
|
139
126
|
def test_request_uri
|
140
|
-
|
127
|
+
request = stub_request 'REQUEST_URI' => "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
|
128
|
+
assert_equal "/path/of/some/uri?mapped=1", request.request_uri
|
129
|
+
assert_equal "/path/of/some/uri", request.path
|
141
130
|
|
142
|
-
|
143
|
-
assert_equal "/path/of/some/uri
|
144
|
-
assert_equal "/path/of/some/uri",
|
131
|
+
request = stub_request 'REQUEST_URI' => "http://www.rubyonrails.org/path/of/some/uri"
|
132
|
+
assert_equal "/path/of/some/uri", request.request_uri
|
133
|
+
assert_equal "/path/of/some/uri", request.path
|
145
134
|
|
146
|
-
|
147
|
-
assert_equal "/path/of/some/uri",
|
148
|
-
assert_equal "/path/of/some/uri",
|
135
|
+
request = stub_request 'REQUEST_URI' => "/path/of/some/uri"
|
136
|
+
assert_equal "/path/of/some/uri", request.request_uri
|
137
|
+
assert_equal "/path/of/some/uri", request.path
|
149
138
|
|
150
|
-
|
151
|
-
assert_equal "/
|
152
|
-
assert_equal "/
|
139
|
+
request = stub_request 'REQUEST_URI' => "/"
|
140
|
+
assert_equal "/", request.request_uri
|
141
|
+
assert_equal "/", request.path
|
153
142
|
|
154
|
-
|
155
|
-
assert_equal "
|
156
|
-
assert_equal "/",
|
143
|
+
request = stub_request 'REQUEST_URI' => "/?m=b"
|
144
|
+
assert_equal "/?m=b", request.request_uri
|
145
|
+
assert_equal "/", request.path
|
157
146
|
|
158
|
-
|
159
|
-
assert_equal "
|
160
|
-
assert_equal "/",
|
161
|
-
|
162
|
-
@request.set_REQUEST_URI "/"
|
163
|
-
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
|
164
|
-
assert_equal "/", @request.request_uri
|
165
|
-
assert_equal "/", @request.path
|
147
|
+
request = stub_request 'REQUEST_URI' => "/", 'SCRIPT_NAME' => '/dispatch.cgi'
|
148
|
+
assert_equal "/", request.request_uri
|
149
|
+
assert_equal "/", request.path
|
166
150
|
|
167
151
|
ActionController::Base.relative_url_root = "/hieraki"
|
168
|
-
|
169
|
-
|
170
|
-
assert_equal "/
|
171
|
-
assert_equal "/", @request.path
|
152
|
+
request = stub_request 'REQUEST_URI' => "/hieraki/", 'SCRIPT_NAME' => "/hieraki/dispatch.cgi"
|
153
|
+
assert_equal "/hieraki/", request.request_uri
|
154
|
+
assert_equal "/", request.path
|
172
155
|
ActionController::Base.relative_url_root = nil
|
173
156
|
|
174
157
|
ActionController::Base.relative_url_root = "/collaboration/hieraki"
|
175
|
-
|
176
|
-
|
177
|
-
assert_equal "/collaboration/hieraki/books/edit/2",
|
178
|
-
assert_equal "/books/edit/2",
|
158
|
+
request = stub_request 'REQUEST_URI' => "/collaboration/hieraki/books/edit/2",
|
159
|
+
'SCRIPT_NAME' => "/collaboration/hieraki/dispatch.cgi"
|
160
|
+
assert_equal "/collaboration/hieraki/books/edit/2", request.request_uri
|
161
|
+
assert_equal "/books/edit/2", request.path
|
179
162
|
ActionController::Base.relative_url_root = nil
|
180
163
|
|
181
164
|
# The following tests are for when REQUEST_URI is not supplied (as in IIS)
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
assert_equal "/path/of/some/uri?mapped=1",
|
186
|
-
assert_equal "/path/of/some/uri",
|
165
|
+
request = stub_request 'PATH_INFO' => "/path/of/some/uri?mapped=1",
|
166
|
+
'SCRIPT_NAME' => nil,
|
167
|
+
'REQUEST_URI' => nil
|
168
|
+
assert_equal "/path/of/some/uri?mapped=1", request.request_uri
|
169
|
+
assert_equal "/path/of/some/uri", request.path
|
187
170
|
|
188
171
|
ActionController::Base.relative_url_root = '/path'
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
assert_equal "/path/of/some/uri?mapped=1",
|
193
|
-
assert_equal "/of/some/uri",
|
172
|
+
request = stub_request 'PATH_INFO' => "/path/of/some/uri?mapped=1",
|
173
|
+
'SCRIPT_NAME' => "/path/dispatch.rb",
|
174
|
+
'REQUEST_URI' => nil
|
175
|
+
assert_equal "/path/of/some/uri?mapped=1", request.request_uri
|
176
|
+
assert_equal "/of/some/uri", request.path
|
194
177
|
ActionController::Base.relative_url_root = nil
|
195
178
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
assert_equal "/path/of/some/uri",
|
200
|
-
assert_equal "/path/of/some/uri",
|
179
|
+
request = stub_request 'PATH_INFO' => "/path/of/some/uri",
|
180
|
+
'SCRIPT_NAME' => nil,
|
181
|
+
'REQUEST_URI' => nil
|
182
|
+
assert_equal "/path/of/some/uri", request.request_uri
|
183
|
+
assert_equal "/path/of/some/uri", request.path
|
201
184
|
|
202
|
-
|
203
|
-
|
204
|
-
assert_equal "/",
|
205
|
-
assert_equal "/", @request.path
|
185
|
+
request = stub_request 'PATH_INFO' => '/', 'REQUEST_URI' => nil
|
186
|
+
assert_equal "/", request.request_uri
|
187
|
+
assert_equal "/", request.path
|
206
188
|
|
207
|
-
|
208
|
-
|
209
|
-
assert_equal "
|
210
|
-
assert_equal "/", @request.path
|
189
|
+
request = stub_request 'PATH_INFO' => '/?m=b', 'REQUEST_URI' => nil
|
190
|
+
assert_equal "/?m=b", request.request_uri
|
191
|
+
assert_equal "/", request.path
|
211
192
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
assert_equal "/",
|
216
|
-
assert_equal "/",
|
193
|
+
request = stub_request 'PATH_INFO' => "/",
|
194
|
+
'SCRIPT_NAME' => "/dispatch.cgi",
|
195
|
+
'REQUEST_URI' => nil
|
196
|
+
assert_equal "/", request.request_uri
|
197
|
+
assert_equal "/", request.path
|
217
198
|
|
218
199
|
ActionController::Base.relative_url_root = '/hieraki'
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
assert_equal "/hieraki/",
|
223
|
-
assert_equal "/",
|
200
|
+
request = stub_request 'PATH_INFO' => "/hieraki/",
|
201
|
+
'SCRIPT_NAME' => "/hieraki/dispatch.cgi",
|
202
|
+
'REQUEST_URI' => nil
|
203
|
+
assert_equal "/hieraki/", request.request_uri
|
204
|
+
assert_equal "/", request.path
|
224
205
|
ActionController::Base.relative_url_root = nil
|
225
206
|
|
226
|
-
|
207
|
+
request = stub_request 'REQUEST_URI' => '/hieraki/dispatch.cgi'
|
227
208
|
ActionController::Base.relative_url_root = '/hieraki'
|
228
|
-
assert_equal "/dispatch.cgi",
|
209
|
+
assert_equal "/dispatch.cgi", request.path
|
229
210
|
ActionController::Base.relative_url_root = nil
|
230
211
|
|
231
|
-
|
212
|
+
request = stub_request 'REQUEST_URI' => '/hieraki/dispatch.cgi'
|
232
213
|
ActionController::Base.relative_url_root = '/foo'
|
233
|
-
assert_equal "/hieraki/dispatch.cgi",
|
214
|
+
assert_equal "/hieraki/dispatch.cgi", request.path
|
234
215
|
ActionController::Base.relative_url_root = nil
|
235
216
|
|
236
217
|
# This test ensures that Rails uses REQUEST_URI over PATH_INFO
|
237
218
|
ActionController::Base.relative_url_root = nil
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
assert_equal "/some/path",
|
242
|
-
assert_equal "/some/path",
|
219
|
+
request = stub_request 'REQUEST_URI' => "/some/path",
|
220
|
+
'PATH_INFO' => "/another/path",
|
221
|
+
'SCRIPT_NAME' => "/dispatch.cgi"
|
222
|
+
assert_equal "/some/path", request.request_uri
|
223
|
+
assert_equal "/some/path", request.path
|
243
224
|
end
|
244
225
|
|
245
226
|
def test_host_with_default_port
|
246
|
-
|
247
|
-
|
248
|
-
assert_equal "rubyonrails.org", @request.host_with_port
|
227
|
+
request = stub_request 'HTTP_HOST' => 'rubyonrails.org:80'
|
228
|
+
assert_equal "rubyonrails.org", request.host_with_port
|
249
229
|
end
|
250
230
|
|
251
231
|
def test_host_with_non_default_port
|
252
|
-
|
253
|
-
|
254
|
-
assert_equal "rubyonrails.org:81", @request.host_with_port
|
232
|
+
request = stub_request 'HTTP_HOST' => 'rubyonrails.org:81'
|
233
|
+
assert_equal "rubyonrails.org:81", request.host_with_port
|
255
234
|
end
|
256
235
|
|
257
236
|
def test_server_software
|
258
|
-
|
237
|
+
request = stub_request
|
238
|
+
assert_equal nil, request.server_software
|
259
239
|
|
260
|
-
|
261
|
-
assert_equal 'apache',
|
240
|
+
request = stub_request 'SERVER_SOFTWARE' => 'Apache3.422'
|
241
|
+
assert_equal 'apache', request.server_software
|
262
242
|
|
263
|
-
|
264
|
-
assert_equal 'lighttpd',
|
243
|
+
request = stub_request 'SERVER_SOFTWARE' => 'lighttpd(1.1.4)'
|
244
|
+
assert_equal 'lighttpd', request.server_software
|
265
245
|
end
|
266
246
|
|
267
247
|
def test_xml_http_request
|
268
|
-
|
269
|
-
|
248
|
+
request = stub_request
|
249
|
+
|
250
|
+
assert !request.xml_http_request?
|
251
|
+
assert !request.xhr?
|
270
252
|
|
271
|
-
|
272
|
-
assert
|
273
|
-
assert
|
253
|
+
request = stub_request 'HTTP_X_REQUESTED_WITH' => 'DefinitelyNotAjax1.0'
|
254
|
+
assert !request.xml_http_request?
|
255
|
+
assert !request.xhr?
|
274
256
|
|
275
|
-
|
276
|
-
assert
|
277
|
-
assert
|
257
|
+
request = stub_request 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
|
258
|
+
assert request.xml_http_request?
|
259
|
+
assert request.xhr?
|
278
260
|
end
|
279
261
|
|
280
262
|
def test_reports_ssl
|
281
|
-
|
282
|
-
|
283
|
-
|
263
|
+
request = stub_request
|
264
|
+
assert !request.ssl?
|
265
|
+
|
266
|
+
request = stub_request 'HTTPS' => 'on'
|
267
|
+
assert request.ssl?
|
284
268
|
end
|
285
269
|
|
286
270
|
def test_reports_ssl_when_proxied_via_lighttpd
|
287
|
-
|
288
|
-
|
289
|
-
|
271
|
+
request = stub_request
|
272
|
+
assert !request.ssl?
|
273
|
+
|
274
|
+
request = stub_request 'HTTP_X_FORWARDED_PROTO' => 'https'
|
275
|
+
assert request.ssl?
|
290
276
|
end
|
291
277
|
|
292
278
|
def test_symbolized_request_methods
|
293
279
|
[:get, :post, :put, :delete].each do |method|
|
294
|
-
|
295
|
-
assert_equal method,
|
280
|
+
request = stub_request 'REQUEST_METHOD' => method.to_s.upcase
|
281
|
+
assert_equal method, request.method
|
296
282
|
end
|
297
283
|
end
|
298
284
|
|
299
285
|
def test_invalid_http_method_raises_exception
|
300
286
|
assert_raise(ActionController::UnknownHttpMethod) do
|
301
|
-
|
302
|
-
|
287
|
+
request = stub_request 'REQUEST_METHOD' => 'RANDOM_METHOD'
|
288
|
+
request.request_method
|
303
289
|
end
|
304
290
|
end
|
305
291
|
|
306
292
|
def test_allow_method_hacking_on_post
|
307
293
|
[:get, :head, :options, :put, :post, :delete].each do |method|
|
308
|
-
|
309
|
-
assert_equal(method == :head ? :get : method,
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
def test_invalid_method_hacking_on_post_raises_exception
|
314
|
-
assert_raise(ActionController::UnknownHttpMethod) do
|
315
|
-
self.request_method = :_random_method
|
316
|
-
@request.request_method
|
294
|
+
request = stub_request 'REQUEST_METHOD' => method.to_s.upcase
|
295
|
+
assert_equal(method == :head ? :get : method, request.method)
|
317
296
|
end
|
318
297
|
end
|
319
298
|
|
320
299
|
def test_restrict_method_hacking
|
321
|
-
@request.instance_eval { @parameters = { :_method => 'put' } }
|
322
300
|
[:get, :put, :delete].each do |method|
|
323
|
-
|
324
|
-
|
301
|
+
request = stub_request 'REQUEST_METHOD' => method.to_s.upcase,
|
302
|
+
'action_controller.request.request_parameters' => { :_method => 'put' }
|
303
|
+
assert_equal method, request.method
|
325
304
|
end
|
326
305
|
end
|
327
306
|
|
328
307
|
def test_head_masquerading_as_get
|
329
|
-
|
330
|
-
assert_equal :get,
|
331
|
-
assert
|
332
|
-
assert
|
308
|
+
request = stub_request 'REQUEST_METHOD' => 'HEAD'
|
309
|
+
assert_equal :get, request.method
|
310
|
+
assert request.get?
|
311
|
+
assert request.head?
|
333
312
|
end
|
334
313
|
|
335
314
|
def test_xml_format
|
336
|
-
|
337
|
-
|
315
|
+
request = stub_request
|
316
|
+
request.expects(:parameters).at_least_once.returns({ :format => 'xml' })
|
317
|
+
assert_equal Mime::XML, request.format
|
338
318
|
end
|
339
319
|
|
340
320
|
def test_xhtml_format
|
341
|
-
|
342
|
-
|
321
|
+
request = stub_request
|
322
|
+
request.expects(:parameters).at_least_once.returns({ :format => 'xhtml' })
|
323
|
+
assert_equal Mime::HTML, request.format
|
343
324
|
end
|
344
325
|
|
345
326
|
def test_txt_format
|
346
|
-
|
347
|
-
|
327
|
+
request = stub_request
|
328
|
+
request.expects(:parameters).at_least_once.returns({ :format => 'txt' })
|
329
|
+
assert_equal Mime::TEXT, request.format
|
348
330
|
end
|
349
331
|
|
350
|
-
def
|
332
|
+
def test_xml_http_request
|
351
333
|
ActionController::Base.use_accept_header, old =
|
352
334
|
false, ActionController::Base.use_accept_header
|
353
335
|
|
354
|
-
|
355
|
-
|
356
|
-
assert
|
357
|
-
assert_equal Mime::JS,
|
358
|
-
|
336
|
+
request = stub_request 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
|
337
|
+
request.expects(:parameters).at_least_once.returns({})
|
338
|
+
assert request.xhr?
|
339
|
+
assert_equal Mime::JS, request.format
|
359
340
|
ensure
|
360
341
|
ActionController::Base.use_accept_header = old
|
361
342
|
end
|
362
343
|
|
363
344
|
def test_content_type
|
364
|
-
|
365
|
-
assert_equal Mime::HTML,
|
345
|
+
request = stub_request 'CONTENT_TYPE' => 'text/html'
|
346
|
+
assert_equal Mime::HTML, request.content_type
|
366
347
|
end
|
367
348
|
|
368
|
-
def
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
349
|
+
def test_can_override_format_with_parameter
|
350
|
+
request = stub_request
|
351
|
+
request.expects(:parameters).at_least_once.returns({ :format => :txt })
|
352
|
+
assert !request.format.xml?
|
353
|
+
|
354
|
+
request = stub_request
|
355
|
+
request.expects(:parameters).at_least_once.returns({ :format => :xml })
|
356
|
+
assert request.format.xml?
|
373
357
|
end
|
374
358
|
|
375
359
|
def test_content_no_type
|
376
|
-
|
360
|
+
request = stub_request
|
361
|
+
assert_equal nil, request.content_type
|
377
362
|
end
|
378
363
|
|
379
364
|
def test_content_type_xml
|
380
|
-
|
381
|
-
assert_equal Mime::XML,
|
365
|
+
request = stub_request 'CONTENT_TYPE' => 'application/xml'
|
366
|
+
assert_equal Mime::XML, request.content_type
|
382
367
|
end
|
383
368
|
|
384
369
|
def test_content_type_with_charset
|
385
|
-
|
386
|
-
assert_equal Mime::XML,
|
370
|
+
request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
|
371
|
+
assert_equal Mime::XML, request.content_type
|
387
372
|
end
|
388
373
|
|
389
374
|
def test_user_agent
|
390
|
-
|
375
|
+
request = stub_request 'HTTP_USER_AGENT' => 'TestAgent'
|
376
|
+
assert_equal 'TestAgent', request.user_agent
|
391
377
|
end
|
392
378
|
|
393
379
|
def test_parameters
|
394
|
-
|
395
|
-
|
380
|
+
request = stub_request
|
381
|
+
request.stubs(:request_parameters).returns({ "foo" => 1 })
|
382
|
+
request.stubs(:query_parameters).returns({ "bar" => 2 })
|
396
383
|
|
397
|
-
assert_equal({"foo" => 1, "bar" => 2},
|
398
|
-
assert_equal({"foo" => 1},
|
399
|
-
assert_equal({"bar" => 2},
|
384
|
+
assert_equal({"foo" => 1, "bar" => 2}, request.parameters)
|
385
|
+
assert_equal({"foo" => 1}, request.request_parameters)
|
386
|
+
assert_equal({"bar" => 2}, request.query_parameters)
|
387
|
+
end
|
388
|
+
|
389
|
+
protected
|
390
|
+
|
391
|
+
def stub_request(env={})
|
392
|
+
ActionController::Request.new(env)
|
400
393
|
end
|
401
394
|
|
402
|
-
protected
|
403
|
-
def request_method=(method)
|
404
|
-
@request.env['REQUEST_METHOD'] = method.to_s.upcase
|
405
|
-
@request.request_method = nil # Reset the ivar cache
|
406
|
-
end
|
407
395
|
end
|