]> source.dussan.org Git - redmine.git/commitdiff
Merged r12915 to 12918 (#16107).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 23 Feb 2014 08:20:42 +0000 (08:20 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 23 Feb 2014 08:20:42 +0000 (08:20 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/2.5-stable@12923 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/application_controller.rb
app/models/user.rb
test/integration/api_test/authentication_test.rb

index b297aa738f1866a7bfc8e870a0925ef0ff72e23f..43257b2bfaa73321c4f38ce0cb461e6cf0f16788 100644 (file)
@@ -119,7 +119,7 @@ class ApplicationController < ActionController::Base
       if (key = api_key_from_request)
         # Use API key
         user = User.find_by_api_key(key)
-      else
+      elsif request.authorization.to_s =~ /\ABasic /i
         # HTTP Basic, either username/password or API key/random
         authenticate_with_http_basic do |username, password|
           user = User.try_to_login(username, password) || User.find_by_api_key(username)
index a31cb46e9e61fd87045fff1f71e2f004ec5ab8ee..4a33590f7048b6bbb1c4cac843e80184d9f88cf5 100644 (file)
@@ -384,8 +384,8 @@ class User < Principal
   # Find a user account by matching the exact login and then a case-insensitive
   # version.  Exact matches will be given priority.
   def self.find_by_login(login)
+    login = Redmine::CodesetUtil.replace_invalid_utf8(login.to_s)
     if login.present?
-      login = login.to_s
       # First look for an exact match
       user = where(:login => login).detect {|u| u.login == login}
       unless user
index 3a6a4d696deed33b0bd7020c4fe7881c6c571920..16c589d3effdfa1dd71bd1fe222c10a01f8a7ecd 100644 (file)
@@ -28,6 +28,29 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
     Setting.rest_api_enabled = '0'
   end
 
+  def test_api_should_trigger_basic_http_auth_with_basic_authorization_header
+    ApplicationController.any_instance.expects(:authenticate_with_http_basic).once
+    get '/users/current.xml', {}, credentials('jsmith')
+    assert_response 401
+  end
+
+  def test_api_should_not_trigger_basic_http_auth_with_non_basic_authorization_header
+    ApplicationController.any_instance.expects(:authenticate_with_http_basic).never
+    get '/users/current.xml', {}, 'HTTP_AUTHORIZATION' => 'Digest foo bar'
+    assert_response 401
+  end
+
+  def test_invalid_utf8_credentials_should_not_trigger_an_error
+    invalid_utf8 = "\x82"
+    if invalid_utf8.respond_to?(:force_encoding)
+      invalid_utf8.force_encoding('UTF-8') 
+      assert !invalid_utf8.valid_encoding?
+    end
+    assert_nothing_raised do
+      get '/users/current.xml', {}, credentials(invalid_utf8, "foo")
+    end
+  end
+
   def test_api_request_should_not_use_user_session
     log_user('jsmith', 'jsmith')