Trigger basic HTTP authentication only when Basic authorization header is present (#16107).
git-svn-id: http://svn.redmine.org/redmine/trunk@12915 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
98e299857b
commit
58ff842d34
@ -119,7 +119,7 @@ class ApplicationController < ActionController::Base
|
|||||||
if (key = api_key_from_request)
|
if (key = api_key_from_request)
|
||||||
# Use API key
|
# Use API key
|
||||||
user = User.find_by_api_key(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
|
# HTTP Basic, either username/password or API key/random
|
||||||
authenticate_with_http_basic do |username, password|
|
authenticate_with_http_basic do |username, password|
|
||||||
user = User.try_to_login(username, password) || User.find_by_api_key(username)
|
user = User.try_to_login(username, password) || User.find_by_api_key(username)
|
||||||
|
@ -28,6 +28,16 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
|||||||
Setting.rest_api_enabled = '0'
|
Setting.rest_api_enabled = '0'
|
||||||
end
|
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('admin')
|
||||||
|
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'
|
||||||
|
end
|
||||||
|
|
||||||
def test_api_request_should_not_use_user_session
|
def test_api_request_should_not_use_user_session
|
||||||
log_user('jsmith', 'jsmith')
|
log_user('jsmith', 'jsmith')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user