aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/http_digest_authentication_test.rb73
-rw-r--r--actionpack/test/controller/integration_test.rb88
-rw-r--r--actionpack/test/controller/request/multipart_params_parsing_test.rb14
3 files changed, 7 insertions, 168 deletions
diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb
deleted file mode 100644
index d5c8636a9e..0000000000
--- a/actionpack/test/controller/http_digest_authentication_test.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-require 'abstract_unit'
-
-class HttpDigestAuthenticationTest < Test::Unit::TestCase
- include ActionController::HttpAuthentication::Digest
-
- class DummyController
- attr_accessor :headers, :renders, :request, :response
-
- def initialize
- @headers, @renders = {}, []
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- request.session.session_id = "test_session"
- end
-
- def render(options)
- self.renderers << options
- end
- end
-
- def setup
- @controller = DummyController.new
- @credentials = {
- :username => "dhh",
- :realm => "testrealm@host.com",
- :nonce => ActionController::HttpAuthentication::Digest.nonce(@controller.request),
- :qop => "auth",
- :nc => "00000001",
- :cnonce => "0a4f113b",
- :opaque => ActionController::HttpAuthentication::Digest.opaque(@controller.request),
- :uri => "http://test.host/"
- }
- @encoded_credentials = ActionController::HttpAuthentication::Digest.encode_credentials("GET", @credentials, "secret")
- end
-
- def test_decode_credentials
- set_headers
- assert_equal @credentials, decode_credentials(@controller.request)
- end
-
- def test_nonce_format
- assert_nothing_thrown do
- validate_nonce(@controller.request, nonce(@controller.request))
- end
- end
-
- def test_authenticate_should_raise_for_nil_password
- set_headers ActionController::HttpAuthentication::Digest.encode_credentials(:get, @credentials, nil)
- assert_raise ActionController::HttpAuthentication::Error do
- authenticate(@controller, @credentials[:realm]) { |user| user == "dhh" && "secret" }
- end
- end
-
- def test_authenticate_should_raise_for_incorrect_password
- set_headers
- assert_raise ActionController::HttpAuthentication::Error do
- authenticate(@controller, @credentials[:realm]) { |user| user == "dhh" && "bad password" }
- end
- end
-
- def test_authenticate_should_not_raise_for_correct_password
- set_headers
- assert_nothing_thrown do
- authenticate(@controller, @credentials[:realm]) { |user| user == "dhh" && "secret" }
- end
- end
-
- private
- def set_headers(value = @encoded_credentials, name = 'HTTP_AUTHORIZATION', method = "GET")
- @controller.request.env[name] = value
- @controller.request.env["REQUEST_METHOD"] = method
- end
-end
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 7ac9d97096..4f07cbee47 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -8,25 +8,7 @@ class SessionTest < Test::Unit::TestCase
}
def setup
- @credentials = {
- :username => "username",
- :realm => "MyApp",
- :nonce => ActionController::HttpAuthentication::Digest.nonce("session_id"),
- :qop => "auth",
- :nc => "00000001",
- :cnonce => "0a4f113b",
- :opaque => ActionController::HttpAuthentication::Digest.opaque("session_id"),
- :uri => "/index"
- }
-
@session = ActionController::Integration::Session.new(StubApp)
- @session.nonce = @credentials[:nonce]
- @session.opaque = @credentials[:opaque]
- @session.realm = @credentials[:realm]
- end
-
- def encoded_credentials(method)
- ActionController::HttpAuthentication::Digest.encode_credentials(method, @credentials, "password")
end
def test_https_bang_works_and_sets_truth_by_default
@@ -150,76 +132,6 @@ class SessionTest < Test::Unit::TestCase
@session.head(path,params,headers)
end
- def test_get_with_basic
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n")
- @session.expects(:process).with(:get,path,params,expected_headers)
- @session.get_with_basic(path,params,headers,'username','password')
- end
-
- def test_post_with_basic
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n")
- @session.expects(:process).with(:post,path,params,expected_headers)
- @session.post_with_basic(path,params,headers,'username','password')
- end
-
- def test_put_with_basic
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n")
- @session.expects(:process).with(:put,path,params,expected_headers)
- @session.put_with_basic(path,params,headers,'username','password')
- end
-
- def test_delete_with_basic
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n")
- @session.expects(:process).with(:delete,path,params,expected_headers)
- @session.delete_with_basic(path,params,headers,'username','password')
- end
-
- def test_head_with_basic
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n")
- @session.expects(:process).with(:head,path,params,expected_headers)
- @session.head_with_basic(path,params,headers,'username','password')
- end
-
- def test_get_with_digest
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => encoded_credentials(:get))
- @session.expects(:process).with(:get,path,params,expected_headers)
- @session.get_with_digest(path,params,headers,'username','password')
- end
-
- def test_post_with_digest
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => encoded_credentials(:post))
- @session.expects(:process).with(:post,path,params,expected_headers)
- @session.post_with_digest(path,params,headers,'username','password')
- end
-
- def test_put_with_digest
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => encoded_credentials(:put))
- @session.expects(:process).with(:put,path,params,expected_headers)
- @session.put_with_digest(path,params,headers,'username','password')
- end
-
- def test_delete_with_digest
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => encoded_credentials(:delete))
- @session.expects(:process).with(:delete,path,params,expected_headers)
- @session.delete_with_digest(path,params,headers,'username','password')
- end
-
- def test_head_with_digest
- path = "/index"; params = "blah"; headers = {:location => 'blah'}
- expected_headers = headers.merge(:authorization => encoded_credentials(:head))
- @session.expects(:process).with(:head,path,params,expected_headers)
- @session.head_with_digest(path,params,headers,'username','password')
- end
-
def test_xml_http_request_get
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
diff --git a/actionpack/test/controller/request/multipart_params_parsing_test.rb b/actionpack/test/controller/request/multipart_params_parsing_test.rb
index 03ab164972..ce28ff46fe 100644
--- a/actionpack/test/controller/request/multipart_params_parsing_test.rb
+++ b/actionpack/test/controller/request/multipart_params_parsing_test.rb
@@ -3,11 +3,10 @@ require 'abstract_unit'
class MultipartParamsParsingTest < ActionController::IntegrationTest
class TestController < ActionController::Base
class << self
- attr_accessor :last_request_parameters, :last_request_type
+ attr_accessor :last_request_parameters
end
def parse
- self.class.last_request_type = ActionController::Base.param_parsers[request.content_type]
self.class.last_request_parameters = request.request_parameters
head :ok
end
@@ -21,7 +20,6 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
def teardown
TestController.last_request_parameters = nil
- TestController.last_request_type = nil
end
test "parses single parameter" do
@@ -103,11 +101,13 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
assert_equal 19756, files.size
end
- test "uploads and parses parameters" do
+ test "uploads and reads binary file" do
with_test_routing do
- params = { :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/mona_lisa.jpg", "image/jpg") }
- post '/parse', params, :location => 'blah'
- assert_equal(:multipart_form, TestController.last_request_type)
+ fixture = FIXTURE_PATH + "/mona_lisa.jpg"
+ params = { :uploaded_data => fixture_file_upload(fixture, "image/jpg") }
+ post '/read', params
+ expected_length = 'File: '.length + File.size(fixture)
+ assert_equal expected_length, response.content_length
end
end