aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Schwenzien <jan@schwenzien.info>2009-08-09 01:24:26 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-08-09 01:28:43 +0100
commit1f6afe4a74bb815a33f41b2d75acd530de6e2eba (patch)
tree6d107e839215f3875b376d78b3720aa83182b4aa
parent618771beb57e623e05f70fd31f3bdb0c04318017 (diff)
downloadrails-1f6afe4a74bb815a33f41b2d75acd530de6e2eba.tar.gz
rails-1f6afe4a74bb815a33f41b2d75acd530de6e2eba.tar.bz2
rails-1f6afe4a74bb815a33f41b2d75acd530de6e2eba.zip
Fix HTTP basic authentication for long credentials [#2572 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rw-r--r--actionpack/lib/action_controller/metal/http_authentication.rb2
-rw-r--r--actionpack/test/controller/http_basic_authentication_test.rb25
2 files changed, 26 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb
index 525787bf92..5ebe1ee048 100644
--- a/actionpack/lib/action_controller/metal/http_authentication.rb
+++ b/actionpack/lib/action_controller/metal/http_authentication.rb
@@ -141,7 +141,7 @@ module ActionController
end
def decode_credentials(request)
- ActiveSupport::Base64.decode64(authorization(request).split.last || '')
+ ActiveSupport::Base64.decode64(authorization(request).split(' ', 2).last || '')
end
def encode_credentials(user_name, password)
diff --git a/actionpack/test/controller/http_basic_authentication_test.rb b/actionpack/test/controller/http_basic_authentication_test.rb
index fbc94a0df7..23688ca584 100644
--- a/actionpack/test/controller/http_basic_authentication_test.rb
+++ b/actionpack/test/controller/http_basic_authentication_test.rb
@@ -4,6 +4,7 @@ class HttpBasicAuthenticationTest < ActionController::TestCase
class DummyController < ActionController::Base
before_filter :authenticate, :only => :index
before_filter :authenticate_with_request, :only => :display
+ before_filter :authenticate_long_credentials, :only => :show
def index
render :text => "Hello Secret"
@@ -12,6 +13,10 @@ class HttpBasicAuthenticationTest < ActionController::TestCase
def display
render :text => 'Definitely Maybe'
end
+
+ def show
+ render :text => 'Only for loooooong credentials'
+ end
private
@@ -28,6 +33,12 @@ class HttpBasicAuthenticationTest < ActionController::TestCase
request_http_basic_authentication("SuperSecret")
end
end
+
+ def authenticate_long_credentials
+ authenticate_or_request_with_http_basic do |username, password|
+ username == '1234567890123456789012345678901234567890' && password == '1234567890123456789012345678901234567890'
+ end
+ end
end
AUTH_HEADERS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION', 'REDIRECT_X_HTTP_AUTHORIZATION']
@@ -42,6 +53,13 @@ class HttpBasicAuthenticationTest < ActionController::TestCase
assert_response :success
assert_equal 'Hello Secret', @response.body, "Authentication failed for request header #{header}"
end
+ test "successful authentication with #{header.downcase} and long credentials" do
+ @request.env[header] = encode_credentials('1234567890123456789012345678901234567890', '1234567890123456789012345678901234567890')
+ get :show
+
+ assert_response :success
+ assert_equal 'Only for loooooong credentials', @response.body, "Authentication failed for request header #{header} and long credentials"
+ end
end
AUTH_HEADERS.each do |header|
@@ -52,6 +70,13 @@ class HttpBasicAuthenticationTest < ActionController::TestCase
assert_response :unauthorized
assert_equal "HTTP Basic: Access denied.\n", @response.body, "Authentication didn't fail for request header #{header}"
end
+ test "unsuccessful authentication with #{header.downcase} and long credentials" do
+ @request.env[header] = encode_credentials('h4x0rh4x0rh4x0rh4x0rh4x0rh4x0rh4x0rh4x0r', 'worldworldworldworldworldworldworldworld')
+ get :show
+
+ assert_response :unauthorized
+ assert_equal "HTTP Basic: Access denied.\n", @response.body, "Authentication didn't fail for request header #{header} and long credentials"
+ end
end
test "authentication request without credential" do