Project

General

Profile

Feature #30086 » 30086-http-status-code-403.patch

Yuichi HARADA, 2018-12-10 03:18

View differences:

app/controllers/application_controller.rb
format.any(:atom, :pdf, :csv) {
redirect_to signin_path(:back_url => url)
}
format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
format.api {
if Setting.rest_api_enabled? && accept_api_auth?
head(:unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"')
else
head(:forbidden)
end
}
format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
format.any { head :unauthorized }
end
return false
test/integration/api_test/disabled_rest_api_test.rb
@token = Token.create!(:user => @user, :action => 'api')
get "/news.xml?key=#{@token.value}"
assert_response :unauthorized
assert_response :forbidden
assert_equal User.anonymous, User.current
get "/news.json?key=#{@token.value}"
assert_response :unauthorized
assert_response :forbidden
assert_equal User.anonymous, User.current
end
......
end
get "/news.xml", :headers => credentials(@user.login, 'my_password')
assert_response :unauthorized
assert_response :forbidden
assert_equal User.anonymous, User.current
get "/news.json", :headers => credentials(@user.login, 'my_password')
assert_response :unauthorized
assert_response :forbidden
assert_equal User.anonymous, User.current
end
def test_with_valid_username_and_wrong_password_http_authentication
@user = User.generate! do |user|
user.password = 'my_password'
end
get '/news.xml', :headers => credentials(@user.login, 'wrong_password')
assert_response :forbidden
assert_equal User.anonymous, User.current
get "/news.json", :headers => credentials(@user.login, 'wrong_password')
assert_response :forbidden
assert_equal User.anonymous, User.current
end
......
@token = Token.create!(:user => @user, :action => 'api')
get "/news.xml", :headers => credentials(@token.value, 'X')
assert_response :unauthorized
assert_response :forbidden
assert_equal User.anonymous, User.current
get "/news.json", :headers => credentials(@token.value, 'X')
assert_response :unauthorized
assert_response :forbidden
assert_equal User.anonymous, User.current
end
end
(1-1/2)