Defect #44165 ยป Do-not-send-Basic-authentication-challenge-when-API-key-authentication-fails.patch
| app/controllers/application_controller.rb | ||
|---|---|---|
|
end
|
||
|
format.api do
|
||
|
if Setting.rest_api_enabled? && accept_api_auth?
|
||
|
head(:unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"')
|
||
|
if api_key_from_request
|
||
|
head(:unauthorized)
|
||
|
else
|
||
|
head(:unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"')
|
||
|
end
|
||
|
else
|
||
|
head(:forbidden)
|
||
|
end
|
||
| test/integration/api_test/authentication_test.rb | ||
|---|---|---|
|
end
|
||
|
get '/users/current.xml', :headers => credentials(user.login, 'wrong_password')
|
||
|
assert_response :unauthorized
|
||
|
assert response.headers.has_key?('WWW-Authenticate')
|
||
|
end
|
||
|
def test_api_should_deny_http_basic_auth_if_twofa_is_active
|
||
| ... | ... | |
|
token = Token.create!(:user => user, :action => 'feeds') # not the API key
|
||
|
get '/users/current.xml', :headers => credentials(token.value, 'X')
|
||
|
assert_response :unauthorized
|
||
|
assert response.headers.has_key?('WWW-Authenticate')
|
||
|
end
|
||
|
def test_api_should_accept_auth_using_api_key_as_parameter
|
||
| ... | ... | |
|
token = Token.create!(:user => user, :action => 'feeds') # not the API key
|
||
|
get "/users/current.xml?key=#{token.value}"
|
||
|
assert_response :unauthorized
|
||
|
assert_not response.headers.has_key?('WWW-Authenticate')
|
||
|
end
|
||
|
def test_api_should_accept_auth_using_api_key_as_request_header
|
||
| ... | ... | |
|
token = Token.create!(:user => user, :action => 'feeds') # not the API key
|
||
|
get "/users/current.xml", :headers => {'X-Redmine-API-Key' => token.value.to_s}
|
||
|
assert_response :unauthorized
|
||
|
assert_not response.headers.has_key?('WWW-Authenticate')
|
||
|
end
|
||
|
def test_api_should_trigger_basic_http_auth_with_basic_authorization_header
|
||