Skip to content

Commit

Permalink
Eliminate newlines in basic auth. fixes #2882
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Sep 7, 2011
1 parent de03d4f commit 9959233
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -145,7 +145,7 @@ def decode_credentials(request)
end

def encode_credentials(user_name, password)
"Basic #{ActiveSupport::Base64.encode64("#{user_name}:#{password}")}"
"Basic #{ActiveSupport::Base64.encode64s("#{user_name}:#{password}")}"
end

def authentication_request(controller, realm)
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/controller/http_basic_authentication_test.rb
Expand Up @@ -85,6 +85,14 @@ def authenticate_long_credentials
end
end

def test_encode_credentials_has_no_newline
username = 'laskjdfhalksdjfhalkjdsfhalksdjfhklsdjhalksdjfhalksdjfhlakdsjfh'
password = 'kjfhueyt9485osdfasdkljfh4lkjhakldjfhalkdsjf'
result = ActionController::HttpAuthentication::Basic.encode_credentials(
username, password)
assert_no_match(/\n/, result)
end

test "authentication request without credential" do
get :display

Expand Down

0 comments on commit 9959233

Please sign in to comment.