Test cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8478 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-01-02 20:09:53 +00:00
parent 131f258f5f
commit 6b5f75bb1d
1 changed files with 28 additions and 81 deletions

View File

@ -20,94 +20,41 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest
Setting.login_required = '0' Setting.login_required = '0'
end end
# Using the NewsController because it's a simple API. def test_with_a_valid_api_token
context "get /news with the API disabled" do @user = User.generate_with_protected!
@token = Token.generate!(:user => @user, :action => 'api')
context "in :xml format" do get "/news.xml?key=#{@token.value}"
context "with a valid api token" do assert_response :unauthorized
setup do assert_equal User.anonymous, User.current
@user = User.generate_with_protected!
@token = Token.generate!(:user => @user, :action => 'api')
get "/news.xml?key=#{@token.value}"
end
should_respond_with :unauthorized get "/news.json?key=#{@token.value}"
should_respond_with_content_type :xml assert_response :unauthorized
should "not login as the user" do assert_equal User.anonymous, User.current
assert_equal User.anonymous, User.current end
end
end
context "with a valid HTTP authentication" do def test_with_valid_username_password_http_authentication
setup do @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
@user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
get "/news.xml", nil, credentials(@user.login, 'my_password')
end
should_respond_with :unauthorized get "/news.xml", nil, credentials(@user.login, 'my_password')
should_respond_with_content_type :xml assert_response :unauthorized
should "not login as the user" do assert_equal User.anonymous, User.current
assert_equal User.anonymous, User.current
end
end
context "with a valid HTTP authentication using the API token" do get "/news.json", nil, credentials(@user.login, 'my_password')
setup do assert_response :unauthorized
@user = User.generate_with_protected! assert_equal User.anonymous, User.current
@token = Token.generate!(:user => @user, :action => 'api') end
get "/news.xml", nil, credentials(@token.value, 'X')
end
should_respond_with :unauthorized def test_with_valid_token_http_authentication
should_respond_with_content_type :xml @user = User.generate_with_protected!
should "not login as the user" do @token = Token.generate!(:user => @user, :action => 'api')
assert_equal User.anonymous, User.current
end
end
end
context "in :json format" do get "/news.xml", nil, credentials(@token.value, 'X')
context "with a valid api token" do assert_response :unauthorized
setup do assert_equal User.anonymous, User.current
@user = User.generate_with_protected!
@token = Token.generate!(:user => @user, :action => 'api')
get "/news.json?key=#{@token.value}"
end
should_respond_with :unauthorized get "/news.json", nil, credentials(@token.value, 'X')
should_respond_with_content_type :json assert_response :unauthorized
should "not login as the user" do assert_equal User.anonymous, User.current
assert_equal User.anonymous, User.current
end
end
context "with a valid HTTP authentication" do
setup do
@user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
get "/news.json", nil, credentials(@user.login, 'my_password')
end
should_respond_with :unauthorized
should_respond_with_content_type :json
should "not login as the user" do
assert_equal User.anonymous, User.current
end
end
context "with a valid HTTP authentication using the API token" do
setup do
@user = User.generate_with_protected!
@token = Token.generate!(:user => @user, :action => 'api')
get "/news.json", nil, credentials(@token.value, 'DoesNotMatter')
end
should_respond_with :unauthorized
should_respond_with_content_type :json
should "not login as the user" do
assert_equal User.anonymous, User.current
end
end
end
end end
end end