actionpack 2.2.3 → 2.3.2
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 +433 -375
- data/MIT-LICENSE +1 -1
- data/README +21 -75
- data/Rakefile +1 -1
- data/lib/action_controller.rb +80 -43
- data/lib/action_controller/assertions/model_assertions.rb +1 -0
- data/lib/action_controller/assertions/response_assertions.rb +43 -16
- data/lib/action_controller/assertions/routing_assertions.rb +1 -1
- data/lib/action_controller/assertions/selector_assertions.rb +17 -12
- data/lib/action_controller/assertions/tag_assertions.rb +1 -4
- data/lib/action_controller/base.rb +153 -82
- data/lib/action_controller/benchmarking.rb +9 -9
- data/lib/action_controller/caching.rb +9 -11
- data/lib/action_controller/caching/actions.rb +11 -18
- data/lib/action_controller/caching/fragments.rb +28 -20
- data/lib/action_controller/caching/pages.rb +13 -15
- data/lib/action_controller/caching/sweeping.rb +2 -2
- data/lib/action_controller/cgi_ext.rb +0 -1
- data/lib/action_controller/cgi_ext/cookie.rb +2 -0
- data/lib/action_controller/cgi_process.rb +54 -162
- data/lib/action_controller/cookies.rb +13 -25
- data/lib/action_controller/dispatcher.rb +43 -122
- data/lib/action_controller/failsafe.rb +52 -0
- data/lib/action_controller/flash.rb +38 -47
- data/lib/action_controller/helpers.rb +13 -9
- data/lib/action_controller/http_authentication.rb +203 -23
- data/lib/action_controller/integration.rb +126 -70
- data/lib/action_controller/layout.rb +36 -39
- data/lib/action_controller/middleware_stack.rb +119 -0
- data/lib/action_controller/middlewares.rb +13 -0
- data/lib/action_controller/mime_responds.rb +19 -4
- data/lib/action_controller/mime_type.rb +8 -0
- data/lib/action_controller/params_parser.rb +71 -0
- data/lib/action_controller/performance_test.rb +0 -1
- data/lib/action_controller/polymorphic_routes.rb +36 -30
- data/lib/action_controller/reloader.rb +14 -0
- data/lib/action_controller/request.rb +107 -499
- data/lib/action_controller/request_forgery_protection.rb +7 -39
- data/lib/action_controller/rescue.rb +55 -35
- data/lib/action_controller/resources.rb +34 -31
- data/lib/action_controller/response.rb +99 -57
- data/lib/action_controller/rewindable_input.rb +28 -0
- data/lib/action_controller/routing.rb +7 -7
- data/lib/action_controller/routing/builder.rb +4 -1
- data/lib/action_controller/routing/optimisations.rb +1 -1
- data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
- data/lib/action_controller/routing/route.rb +15 -5
- data/lib/action_controller/routing/route_set.rb +82 -35
- data/lib/action_controller/routing/segments.rb +35 -0
- data/lib/action_controller/session/abstract_store.rb +181 -0
- data/lib/action_controller/session/cookie_store.rb +197 -175
- data/lib/action_controller/session/mem_cache_store.rb +36 -83
- data/lib/action_controller/session_management.rb +26 -134
- data/lib/action_controller/streaming.rb +24 -7
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +87 -30
- data/lib/action_controller/test_process.rb +145 -104
- data/lib/action_controller/uploaded_file.rb +44 -0
- data/lib/action_controller/url_rewriter.rb +3 -6
- data/lib/action_controller/vendor/html-scanner.rb +16 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
- data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
- data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
- data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
- data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
- data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
- data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
- data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
- data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
- data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
- data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
- data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
- data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
- data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
- data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
- data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
- data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
- data/lib/action_controller/verification.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +22 -17
- data/lib/action_view/base.rb +53 -79
- data/lib/action_view/erb/util.rb +38 -0
- data/lib/action_view/helpers.rb +24 -5
- data/lib/action_view/helpers/active_record_helper.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
- data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
- data/lib/action_view/helpers/benchmark_helper.rb +26 -5
- data/lib/action_view/helpers/date_helper.rb +82 -7
- data/lib/action_view/helpers/form_helper.rb +295 -64
- data/lib/action_view/helpers/form_options_helper.rb +160 -18
- data/lib/action_view/helpers/form_tag_helper.rb +2 -2
- data/lib/action_view/helpers/number_helper.rb +31 -18
- data/lib/action_view/helpers/prototype_helper.rb +2 -12
- data/lib/action_view/helpers/sanitize_helper.rb +0 -10
- data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
- data/lib/action_view/helpers/tag_helper.rb +3 -4
- data/lib/action_view/helpers/text_helper.rb +99 -122
- data/lib/action_view/helpers/translation_helper.rb +19 -1
- data/lib/action_view/helpers/url_helper.rb +25 -2
- data/lib/action_view/inline_template.rb +1 -1
- data/lib/action_view/locale/en.yml +19 -1
- data/lib/action_view/partials.rb +46 -9
- data/lib/action_view/paths.rb +28 -84
- data/lib/action_view/reloadable_template.rb +117 -0
- data/lib/action_view/renderable.rb +28 -35
- data/lib/action_view/renderable_partial.rb +3 -4
- data/lib/action_view/template.rb +172 -31
- data/lib/action_view/template_error.rb +8 -9
- data/lib/action_view/template_handler.rb +1 -1
- data/lib/action_view/template_handlers.rb +9 -6
- data/lib/action_view/template_handlers/erb.rb +2 -39
- data/lib/action_view/template_handlers/rjs.rb +1 -0
- data/lib/action_view/test_case.rb +27 -1
- data/test/abstract_unit.rb +23 -17
- data/test/active_record_unit.rb +5 -4
- data/test/activerecord/active_record_store_test.rb +139 -106
- data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
- data/test/controller/action_pack_assertions_test.rb +25 -23
- data/test/controller/addresses_render_test.rb +3 -6
- data/test/controller/assert_select_test.rb +83 -70
- data/test/controller/base_test.rb +11 -13
- data/test/controller/benchmark_test.rb +3 -3
- data/test/controller/caching_test.rb +34 -24
- data/test/controller/capture_test.rb +3 -6
- data/test/controller/content_type_test.rb +3 -6
- data/test/controller/cookie_test.rb +31 -66
- data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
- data/test/controller/dispatcher_test.rb +23 -28
- data/test/controller/fake_models.rb +8 -0
- data/test/controller/filters_test.rb +6 -2
- data/test/controller/flash_test.rb +2 -6
- data/test/controller/helper_test.rb +15 -1
- data/test/controller/html-scanner/document_test.rb +1 -1
- data/test/controller/html-scanner/sanitizer_test.rb +1 -1
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +56 -52
- data/test/controller/layout_test.rb +46 -44
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +7 -11
- data/test/controller/mime_type_test.rb +9 -0
- data/test/controller/polymorphic_routes_test.rb +235 -151
- data/test/controller/rack_test.rb +52 -81
- data/test/controller/redirect_test.rb +6 -14
- data/test/controller/render_test.rb +273 -60
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +17 -98
- data/test/controller/request_test.rb +45 -530
- data/test/controller/rescue_test.rb +45 -22
- data/test/controller/resources_test.rb +112 -37
- data/test/controller/routing_test.rb +1442 -1384
- data/test/controller/selector_test.rb +3 -3
- data/test/controller/send_file_test.rb +30 -3
- data/test/controller/session/cookie_store_test.rb +169 -240
- data/test/controller/session/mem_cache_store_test.rb +94 -148
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +32 -13
- data/test/controller/url_rewriter_test.rb +54 -4
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -15
- data/test/controller/webservice_test.rb +178 -147
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
- data/test/fixtures/layouts/default_html.html.erb +1 -0
- data/test/fixtures/layouts/xhr.html.erb +2 -0
- data/test/fixtures/multipart/empty +10 -0
- data/test/fixtures/multipart/hello.txt +1 -0
- data/test/fixtures/multipart/none +9 -0
- data/test/fixtures/public/500.da.html +1 -0
- data/test/fixtures/quiz/questions/_question.html.erb +1 -0
- data/test/fixtures/replies.yml +1 -1
- data/test/fixtures/test/_one.html.erb +1 -0
- data/test/fixtures/test/_two.html.erb +1 -0
- data/test/fixtures/test/dont_pick_me +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hello_world.da.html.erb +1 -0
- data/test/fixtures/test/hello_world.erb~ +1 -0
- data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
- data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
- data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
- data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
- data/test/fixtures/test/utf8.html.erb +2 -0
- data/test/template/active_record_helper_i18n_test.rb +31 -33
- data/test/template/active_record_helper_test.rb +34 -0
- data/test/template/asset_tag_helper_test.rb +52 -14
- data/test/template/atom_feed_helper_test.rb +3 -5
- data/test/template/benchmark_helper_test.rb +50 -24
- data/test/template/compiled_templates_test.rb +177 -33
- data/test/template/date_helper_i18n_test.rb +88 -81
- data/test/template/date_helper_test.rb +427 -43
- data/test/template/form_helper_test.rb +243 -44
- data/test/template/form_options_helper_test.rb +631 -565
- data/test/template/form_tag_helper_test.rb +9 -2
- data/test/template/javascript_helper_test.rb +0 -5
- data/test/template/number_helper_i18n_test.rb +60 -48
- data/test/template/number_helper_test.rb +1 -0
- data/test/template/render_test.rb +117 -35
- data/test/template/test_test.rb +4 -6
- data/test/template/text_helper_test.rb +129 -50
- data/test/template/translation_helper_test.rb +23 -19
- data/test/template/url_helper_test.rb +35 -2
- data/test/view/test_case_test.rb +8 -0
- metadata +197 -23
- data/lib/action_controller/assertions.rb +0 -69
- data/lib/action_controller/caching/sql_cache.rb +0 -18
- data/lib/action_controller/cgi_ext/session.rb +0 -53
- data/lib/action_controller/components.rb +0 -169
- data/lib/action_controller/rack_process.rb +0 -297
- data/lib/action_controller/request_profiler.rb +0 -169
- data/lib/action_controller/session/active_record_store.rb +0 -340
- data/lib/action_controller/session/drb_server.rb +0 -32
- data/lib/action_controller/session/drb_store.rb +0 -35
- data/test/controller/cgi_test.rb +0 -269
- data/test/controller/components_test.rb +0 -156
- data/test/controller/http_authentication_test.rb +0 -54
- data/test/controller/integration_upload_test.rb +0 -43
- data/test/controller/session_fixation_test.rb +0 -89
- data/test/controller/session_management_test.rb +0 -178
- data/test/fixtures/test/hello_world.js +0 -1
@@ -1,24 +1,22 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
|
3
|
-
uses_mocha 'dispatcher tests' do
|
4
|
-
|
5
|
-
require 'action_controller/dispatcher'
|
6
|
-
|
7
3
|
class DispatcherTest < Test::Unit::TestCase
|
8
4
|
Dispatcher = ActionController::Dispatcher
|
9
5
|
|
10
6
|
def setup
|
11
|
-
@output = StringIO.new
|
12
7
|
ENV['REQUEST_METHOD'] = 'GET'
|
13
8
|
|
9
|
+
Dispatcher.middleware = ActionController::MiddlewareStack.new do |middleware|
|
10
|
+
middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/middlewares.rb"))
|
11
|
+
middleware.instance_eval(File.read(middlewares))
|
12
|
+
end
|
13
|
+
|
14
14
|
# Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
|
15
15
|
Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
16
16
|
Dispatcher.instance_variable_set("@before_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
17
17
|
Dispatcher.instance_variable_set("@after_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
18
18
|
|
19
19
|
Dispatcher.stubs(:require_dependency)
|
20
|
-
|
21
|
-
@dispatcher = Dispatcher.new(@output)
|
22
20
|
end
|
23
21
|
|
24
22
|
def teardown
|
@@ -27,12 +25,12 @@ class DispatcherTest < Test::Unit::TestCase
|
|
27
25
|
|
28
26
|
def test_clears_dependencies_after_dispatch_if_in_loading_mode
|
29
27
|
ActiveSupport::Dependencies.expects(:clear).once
|
30
|
-
dispatch(
|
28
|
+
dispatch(false)
|
31
29
|
end
|
32
30
|
|
33
31
|
def test_reloads_routes_before_dispatch_if_in_loading_mode
|
34
32
|
ActionController::Routing::Routes.expects(:reload).once
|
35
|
-
dispatch(
|
33
|
+
dispatch(false)
|
36
34
|
end
|
37
35
|
|
38
36
|
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
|
@@ -48,12 +46,16 @@ class DispatcherTest < Test::Unit::TestCase
|
|
48
46
|
end
|
49
47
|
|
50
48
|
def test_failsafe_response
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
assert_nothing_raised
|
55
|
-
|
56
|
-
|
49
|
+
Dispatcher.any_instance.expects(:dispatch).raises('b00m')
|
50
|
+
ActionController::Failsafe.any_instance.expects(:log_failsafe_exception)
|
51
|
+
|
52
|
+
assert_nothing_raised do
|
53
|
+
assert_equal [
|
54
|
+
500,
|
55
|
+
{"Content-Type" => "text/html"},
|
56
|
+
"<html><body><h1>500 Internal Server Error</h1></body></html>"
|
57
|
+
], dispatch
|
58
|
+
end
|
57
59
|
end
|
58
60
|
|
59
61
|
def test_prepare_callbacks
|
@@ -66,7 +68,7 @@ class DispatcherTest < Test::Unit::TestCase
|
|
66
68
|
assert_nil a || b || c
|
67
69
|
|
68
70
|
# Run callbacks
|
69
|
-
|
71
|
+
Dispatcher.run_prepare_callbacks
|
70
72
|
|
71
73
|
assert_equal 1, a
|
72
74
|
assert_equal 2, b
|
@@ -74,7 +76,7 @@ class DispatcherTest < Test::Unit::TestCase
|
|
74
76
|
|
75
77
|
# Make sure they are only run once
|
76
78
|
a = b = c = nil
|
77
|
-
|
79
|
+
dispatch
|
78
80
|
assert_nil a || b || c
|
79
81
|
end
|
80
82
|
|
@@ -83,26 +85,19 @@ class DispatcherTest < Test::Unit::TestCase
|
|
83
85
|
Dispatcher.to_prepare(:unique_id) { |*args| a = b = 1 }
|
84
86
|
Dispatcher.to_prepare(:unique_id) { |*args| a = 2 }
|
85
87
|
|
86
|
-
|
88
|
+
Dispatcher.run_prepare_callbacks
|
87
89
|
assert_equal 2, a
|
88
90
|
assert_equal nil, b
|
89
91
|
end
|
90
92
|
|
91
93
|
private
|
92
|
-
def dispatch(
|
93
|
-
|
94
|
-
controller.stubs(:process).returns(controller)
|
95
|
-
controller.stubs(:out).with(output).returns('response')
|
96
|
-
|
97
|
-
ActionController::Routing::Routes.stubs(:recognize).returns(controller)
|
98
|
-
|
94
|
+
def dispatch(cache_classes = true)
|
95
|
+
ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response'])
|
99
96
|
Dispatcher.define_dispatcher_callbacks(cache_classes)
|
100
|
-
Dispatcher.
|
97
|
+
Dispatcher.new.call({})
|
101
98
|
end
|
102
99
|
|
103
100
|
def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
|
104
101
|
assert_equal howmany, klass.subclasses.size, message
|
105
102
|
end
|
106
103
|
end
|
107
|
-
|
108
|
-
end
|
@@ -634,9 +634,11 @@ class FilterTest < Test::Unit::TestCase
|
|
634
634
|
|
635
635
|
private
|
636
636
|
def test_process(controller, action = "show")
|
637
|
+
ActionController::Base.class_eval { include ActionController::ProcessWithTest } unless ActionController::Base < ActionController::ProcessWithTest
|
637
638
|
request = ActionController::TestRequest.new
|
638
639
|
request.action = action
|
639
|
-
controller.
|
640
|
+
controller = controller.new if controller.is_a?(Class)
|
641
|
+
controller.process_with_test(request, ActionController::TestResponse.new)
|
640
642
|
end
|
641
643
|
end
|
642
644
|
|
@@ -874,8 +876,10 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase
|
|
874
876
|
|
875
877
|
protected
|
876
878
|
def test_process(controller, action = "show")
|
879
|
+
ActionController::Base.class_eval { include ActionController::ProcessWithTest } unless ActionController::Base < ActionController::ProcessWithTest
|
877
880
|
request = ActionController::TestRequest.new
|
878
881
|
request.action = action
|
879
|
-
controller.
|
882
|
+
controller = controller.new if controller.is_a?(Class)
|
883
|
+
controller.process_with_test(request, ActionController::TestResponse.new)
|
880
884
|
end
|
881
885
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
|
3
|
-
class FlashTest <
|
3
|
+
class FlashTest < ActionController::TestCase
|
4
4
|
class TestController < ActionController::Base
|
5
5
|
def set_flash
|
6
6
|
flash["that"] = "hello"
|
@@ -73,11 +73,7 @@ class FlashTest < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
|
-
@request = ActionController::TestRequest.new
|
78
|
-
@response = ActionController::TestResponse.new
|
79
|
-
@controller = TestController.new
|
80
|
-
end
|
76
|
+
tests TestController
|
81
77
|
|
82
78
|
def test_flash
|
83
79
|
get :set_flash
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
|
3
|
-
ActionController::
|
3
|
+
ActionController::Base.helpers_dir = File.dirname(__FILE__) + '/../fixtures/helpers'
|
4
4
|
|
5
5
|
class TestController < ActionController::Base
|
6
6
|
attr_accessor :delegate_attr
|
@@ -130,6 +130,20 @@ class HelperTest < Test::Unit::TestCase
|
|
130
130
|
assert methods.include?('foobar')
|
131
131
|
end
|
132
132
|
|
133
|
+
def test_all_helpers_with_alternate_helper_dir
|
134
|
+
@controller_class.helpers_dir = File.dirname(__FILE__) + '/../fixtures/alternate_helpers'
|
135
|
+
|
136
|
+
# Reload helpers
|
137
|
+
@controller_class.master_helper_module = Module.new
|
138
|
+
@controller_class.helper :all
|
139
|
+
|
140
|
+
# helpers/abc_helper.rb should not be included
|
141
|
+
assert !master_helper_methods.include?('bare_a')
|
142
|
+
|
143
|
+
# alternate_helpers/foo_helper.rb
|
144
|
+
assert master_helper_methods.include?('baz')
|
145
|
+
end
|
146
|
+
|
133
147
|
def test_helper_proxy
|
134
148
|
methods = ApplicationController.helpers.methods.map(&:to_s)
|
135
149
|
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class HttpBasicAuthenticationTest < ActionController::TestCase
|
4
|
+
class DummyController < ActionController::Base
|
5
|
+
before_filter :authenticate, :only => :index
|
6
|
+
before_filter :authenticate_with_request, :only => :display
|
7
|
+
|
8
|
+
def index
|
9
|
+
render :text => "Hello Secret"
|
10
|
+
end
|
11
|
+
|
12
|
+
def display
|
13
|
+
render :text => 'Definitely Maybe'
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def authenticate
|
19
|
+
authenticate_or_request_with_http_basic do |username, password|
|
20
|
+
username == 'lifo' && password == 'world'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def authenticate_with_request
|
25
|
+
if authenticate_with_http_basic { |username, password| username == 'pretty' && password == 'please' }
|
26
|
+
@logged_in = true
|
27
|
+
else
|
28
|
+
request_http_basic_authentication("SuperSecret")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
AUTH_HEADERS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION', 'REDIRECT_X_HTTP_AUTHORIZATION']
|
34
|
+
|
35
|
+
tests DummyController
|
36
|
+
|
37
|
+
AUTH_HEADERS.each do |header|
|
38
|
+
test "successful authentication with #{header.downcase}" do
|
39
|
+
@request.env[header] = encode_credentials('lifo', 'world')
|
40
|
+
get :index
|
41
|
+
|
42
|
+
assert_response :success
|
43
|
+
assert_equal 'Hello Secret', @response.body, "Authentication failed for request header #{header}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
AUTH_HEADERS.each do |header|
|
48
|
+
test "unsuccessful authentication with #{header.downcase}" do
|
49
|
+
@request.env[header] = encode_credentials('h4x0r', 'world')
|
50
|
+
get :index
|
51
|
+
|
52
|
+
assert_response :unauthorized
|
53
|
+
assert_equal "HTTP Basic: Access denied.\n", @response.body, "Authentication didn't fail for request header #{header}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
test "authentication request without credential" do
|
58
|
+
get :display
|
59
|
+
|
60
|
+
assert_response :unauthorized
|
61
|
+
assert_equal "HTTP Basic: Access denied.\n", @response.body
|
62
|
+
assert_equal 'Basic realm="SuperSecret"', @response.headers['WWW-Authenticate']
|
63
|
+
end
|
64
|
+
|
65
|
+
test "authentication request with invalid credential" do
|
66
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials('pretty', 'foo')
|
67
|
+
get :display
|
68
|
+
|
69
|
+
assert_response :unauthorized
|
70
|
+
assert_equal "HTTP Basic: Access denied.\n", @response.body
|
71
|
+
assert_equal 'Basic realm="SuperSecret"', @response.headers['WWW-Authenticate']
|
72
|
+
end
|
73
|
+
|
74
|
+
test "authentication request with valid credential" do
|
75
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials('pretty', 'please')
|
76
|
+
get :display
|
77
|
+
|
78
|
+
assert_response :success
|
79
|
+
assert assigns(:logged_in)
|
80
|
+
assert_equal 'Definitely Maybe', @response.body
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def encode_credentials(username, password)
|
86
|
+
"Basic #{ActiveSupport::Base64.encode64("#{username}:#{password}")}"
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class HttpDigestAuthenticationTest < ActionController::TestCase
|
4
|
+
class DummyDigestController < ActionController::Base
|
5
|
+
before_filter :authenticate, :only => :index
|
6
|
+
before_filter :authenticate_with_request, :only => :display
|
7
|
+
|
8
|
+
USERS = { 'lifo' => 'world', 'pretty' => 'please',
|
9
|
+
'dhh' => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":"))}
|
10
|
+
|
11
|
+
def index
|
12
|
+
render :text => "Hello Secret"
|
13
|
+
end
|
14
|
+
|
15
|
+
def display
|
16
|
+
render :text => 'Definitely Maybe'
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def authenticate
|
22
|
+
authenticate_or_request_with_http_digest("SuperSecret") do |username|
|
23
|
+
# Return the password
|
24
|
+
USERS[username]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def authenticate_with_request
|
29
|
+
if authenticate_with_http_digest("SuperSecret") { |username| USERS[username] }
|
30
|
+
@logged_in = true
|
31
|
+
else
|
32
|
+
request_http_digest_authentication("SuperSecret", "Authentication Failed")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
AUTH_HEADERS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION', 'REDIRECT_X_HTTP_AUTHORIZATION']
|
38
|
+
|
39
|
+
tests DummyDigestController
|
40
|
+
|
41
|
+
AUTH_HEADERS.each do |header|
|
42
|
+
test "successful authentication with #{header.downcase}" do
|
43
|
+
@request.env[header] = encode_credentials(:username => 'lifo', :password => 'world')
|
44
|
+
get :index
|
45
|
+
|
46
|
+
assert_response :success
|
47
|
+
assert_equal 'Hello Secret', @response.body, "Authentication failed for request header #{header}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
AUTH_HEADERS.each do |header|
|
52
|
+
test "unsuccessful authentication with #{header.downcase}" do
|
53
|
+
@request.env[header] = encode_credentials(:username => 'h4x0r', :password => 'world')
|
54
|
+
get :index
|
55
|
+
|
56
|
+
assert_response :unauthorized
|
57
|
+
assert_equal "HTTP Digest: Access denied.\n", @response.body, "Authentication didn't fail for request header #{header}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
test "authentication request without credential" do
|
62
|
+
get :display
|
63
|
+
|
64
|
+
assert_response :unauthorized
|
65
|
+
assert_equal "Authentication Failed", @response.body
|
66
|
+
credentials = decode_credentials(@response.headers['WWW-Authenticate'])
|
67
|
+
assert_equal 'SuperSecret', credentials[:realm]
|
68
|
+
end
|
69
|
+
|
70
|
+
test "authentication request with invalid password" do
|
71
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo')
|
72
|
+
get :display
|
73
|
+
|
74
|
+
assert_response :unauthorized
|
75
|
+
assert_equal "Authentication Failed", @response.body
|
76
|
+
end
|
77
|
+
|
78
|
+
test "authentication request with invalid nonce" do
|
79
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', :nonce => "xxyyzz")
|
80
|
+
get :display
|
81
|
+
|
82
|
+
assert_response :unauthorized
|
83
|
+
assert_equal "Authentication Failed", @response.body
|
84
|
+
end
|
85
|
+
|
86
|
+
test "authentication request with invalid opaque" do
|
87
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo', :opaque => "xxyyzz")
|
88
|
+
get :display
|
89
|
+
|
90
|
+
assert_response :unauthorized
|
91
|
+
assert_equal "Authentication Failed", @response.body
|
92
|
+
end
|
93
|
+
|
94
|
+
test "authentication request with invalid realm" do
|
95
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo', :realm => "NotSecret")
|
96
|
+
get :display
|
97
|
+
|
98
|
+
assert_response :unauthorized
|
99
|
+
assert_equal "Authentication Failed", @response.body
|
100
|
+
end
|
101
|
+
|
102
|
+
test "authentication request with valid credential" do
|
103
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please')
|
104
|
+
get :display
|
105
|
+
|
106
|
+
assert_response :success
|
107
|
+
assert assigns(:logged_in)
|
108
|
+
assert_equal 'Definitely Maybe', @response.body
|
109
|
+
end
|
110
|
+
|
111
|
+
test "authentication request with valid credential and nil session" do
|
112
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please')
|
113
|
+
|
114
|
+
# session_id = "" in functional test, but is +nil+ in real life
|
115
|
+
@request.session.session_id = nil
|
116
|
+
get :display
|
117
|
+
|
118
|
+
assert_response :success
|
119
|
+
assert assigns(:logged_in)
|
120
|
+
assert_equal 'Definitely Maybe', @response.body
|
121
|
+
end
|
122
|
+
|
123
|
+
test "authentication request with request-uri that doesn't match credentials digest-uri" do
|
124
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please')
|
125
|
+
@request.env['REQUEST_URI'] = "/http_digest_authentication_test/dummy_digest/altered/uri"
|
126
|
+
get :display
|
127
|
+
|
128
|
+
assert_response :unauthorized
|
129
|
+
assert_equal "Authentication Failed", @response.body
|
130
|
+
end
|
131
|
+
|
132
|
+
test "authentication request with absolute uri" do
|
133
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:uri => "http://test.host/http_digest_authentication_test/dummy_digest/display",
|
134
|
+
:username => 'pretty', :password => 'please')
|
135
|
+
@request.env['REQUEST_URI'] = "http://test.host/http_digest_authentication_test/dummy_digest/display"
|
136
|
+
get :display
|
137
|
+
|
138
|
+
assert_response :success
|
139
|
+
assert assigns(:logged_in)
|
140
|
+
assert_equal 'Definitely Maybe', @response.body
|
141
|
+
end
|
142
|
+
|
143
|
+
test "authentication request with password stored as ha1 digest hash" do
|
144
|
+
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'dhh',
|
145
|
+
:password => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":")),
|
146
|
+
:password_is_ha1 => true)
|
147
|
+
get :display
|
148
|
+
|
149
|
+
assert_response :success
|
150
|
+
assert assigns(:logged_in)
|
151
|
+
assert_equal 'Definitely Maybe', @response.body
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def encode_credentials(options)
|
157
|
+
options.reverse_merge!(:nc => "00000001", :cnonce => "0a4f113b", :password_is_ha1 => false)
|
158
|
+
password = options.delete(:password)
|
159
|
+
|
160
|
+
# Set in /initializers/session_store.rb. Used as secret in generating nonce
|
161
|
+
# to prevent tampering of timestamp
|
162
|
+
ActionController::Base.session_options[:secret] = "session_options_secret"
|
163
|
+
|
164
|
+
# Perform unauthenticated GET to retrieve digest parameters to use on subsequent request
|
165
|
+
get :index
|
166
|
+
|
167
|
+
assert_response :unauthorized
|
168
|
+
|
169
|
+
credentials = decode_credentials(@response.headers['WWW-Authenticate'])
|
170
|
+
credentials.merge!(options)
|
171
|
+
credentials.reverse_merge!(:uri => "#{@request.env['REQUEST_URI']}")
|
172
|
+
ActionController::HttpAuthentication::Digest.encode_credentials("GET", credentials, password, options[:password_is_ha1])
|
173
|
+
end
|
174
|
+
|
175
|
+
def decode_credentials(header)
|
176
|
+
ActionController::HttpAuthentication::Digest.decode_credentials(@response.headers['WWW-Authenticate'])
|
177
|
+
end
|
178
|
+
end
|