Permalink
Browse files

Add HTTP Authentication to the new base

  • Loading branch information...
1 parent d2cac9d commit 1a52b246eb245d159a1c331417a4b14923e9bc4e @lifo lifo committed May 21, 2009
View
@@ -65,6 +65,7 @@ Rake::TestTask.new(:test_new_base_on_old_tests) do |t|
flash mime_responds record_identifier redirect
render render_json render_xml
send_file request_forgery_protection rescue url_rewriter verification webservice
+ http_basic_authentication http_digest_authentication
).map { |name| "test/controller/#{name}_test.rb" }
end
@@ -31,6 +31,8 @@ module ActionController
autoload :Flash, 'action_controller/base/chained/flash'
autoload :RequestForgeryProtection, 'action_controller/base/request_forgery_protection'
autoload :Streaming, 'action_controller/base/streaming'
+ autoload :HttpAuthentication, 'action_controller/base/http_authentication'
+
require 'action_controller/routing'
end
@@ -30,6 +30,8 @@ class Base < Http
include ActionController::Verification
include ActionController::RequestForgeryProtection
include ActionController::Streaming
+ include ActionController::HttpAuthentication::Basic::ControllerMethods
+ include ActionController::HttpAuthentication::Digest::ControllerMethods
# TODO: Extract into its own module
# This should be moved together with other normalizing behavior
@@ -89,6 +91,11 @@ def _normalize_options(action = nil, options = {})
if options.key?(:action) && options[:action].to_s.index("/")
options[:template] = options.delete(:action)
end
+
+ if options[:status]
+ options[:status] = interpret_status(options.delete(:status)).to_i
+ end
+
options
end
@@ -57,7 +57,7 @@ def head(*args)
raise ArgumentError, "too few arguments to head"
end
options = args.extract_options!
- status = interpret_status(args.shift || options.delete(:status) || :ok)
+ status = args.shift || options.delete(:status) || :ok
options.each do |key, value|
headers[key.to_s.dasherize.split(/-/).map { |v| v.capitalize }.join("-")] = value.to_s
@@ -80,7 +80,7 @@ def _render_partial(partial, options)
def _process_options(options)
status, content_type, location = options.values_at(:status, :content_type, :location)
- response.status = status.to_i if status
+ response.status = status if status
response.content_type = content_type if content_type
response.headers["Location"] = url_for(location) if location
end
@@ -38,6 +38,15 @@ def authenticate_with_request
tests DummyDigestController
+ setup do
+ # Used as secret in generating nonce to prevent tampering of timestamp
+ @old_secret, ActionController::Base.session_options[:secret] = ActionController::Base.session_options[:secret], "session_options_secret"
+ end
+
+ teardown do
+ ActionController::Base.session_options[:secret] = @old_secret
+ end
+
AUTH_HEADERS.each do |header|
test "successful authentication with #{header.downcase}" do
@request.env[header] = encode_credentials(:username => 'lifo', :password => 'world')
@@ -165,10 +174,6 @@ def encode_credentials(options)
options.reverse_merge!(:nc => "00000001", :cnonce => "0a4f113b", :password_is_ha1 => false)
password = options.delete(:password)
- # Set in /initializers/session_store.rb. Used as secret in generating nonce
- # to prevent tampering of timestamp
- ActionController::Base.session_options[:secret] = "session_options_secret"
-
# Perform unauthenticated request to retrieve digest parameters to use on subsequent request
method = options.delete(:method) || 'GET'
@@ -11,12 +11,17 @@ class SendFileController < ActionController::Base
layout "layouts/standard" # to make sure layouts don't interfere
attr_writer :options
- def options() @options ||= {} end
+ def options
+ @options ||= {}
+ end
- def file() send_file(file_path, options) end
- def data() send_data(file_data, options) end
+ def file
+ send_file(file_path, options)
+ end
- def rescue_action(e) raise end
+ def data
+ send_data(file_data, options)
+ end
end
class SendFileTest < ActionController::TestCase

0 comments on commit 1a52b24

Please sign in to comment.