diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-01-02 20:09:53 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-01-02 20:09:53 +0000 |
commit | 6b5f75bb1d9c673aa263120d95ac6cd8750f54f1 (patch) | |
tree | adb43ca396bf47bee6c83a2f248d22d935699b14 /test/integration | |
parent | 131f258f5fba320a779bdd69e3681beab07fb8e3 (diff) | |
download | redmine-6b5f75bb1d9c673aa263120d95ac6cd8750f54f1.tar.gz redmine-6b5f75bb1d9c673aa263120d95ac6cd8750f54f1.zip |
Test cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8478 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/integration')
-rw-r--r-- | test/integration/api_test/disabled_rest_api_test.rb | 109 |
1 files changed, 28 insertions, 81 deletions
diff --git a/test/integration/api_test/disabled_rest_api_test.rb b/test/integration/api_test/disabled_rest_api_test.rb index 23e78ce2c..8683846f0 100644 --- a/test/integration/api_test/disabled_rest_api_test.rb +++ b/test/integration/api_test/disabled_rest_api_test.rb @@ -20,94 +20,41 @@ class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest Setting.login_required = '0' end - # Using the NewsController because it's a simple API. - context "get /news with the API disabled" do + def test_with_a_valid_api_token + @user = User.generate_with_protected! + @token = Token.generate!(:user => @user, :action => 'api') - context "in :xml format" do - context "with a valid api token" do - setup do - @user = User.generate_with_protected! - @token = Token.generate!(:user => @user, :action => 'api') - get "/news.xml?key=#{@token.value}" - end + get "/news.xml?key=#{@token.value}" + assert_response :unauthorized + assert_equal User.anonymous, User.current - should_respond_with :unauthorized - should_respond_with_content_type :xml - should "not login as the user" do - 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.xml", nil, credentials(@user.login, 'my_password') - end - - should_respond_with :unauthorized - should_respond_with_content_type :xml - 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.xml", nil, credentials(@token.value, 'X') - end - - should_respond_with :unauthorized - should_respond_with_content_type :xml - should "not login as the user" do - assert_equal User.anonymous, User.current - end - end - end - - context "in :json format" do - context "with a valid api token" do - setup do - @user = User.generate_with_protected! - @token = Token.generate!(:user => @user, :action => 'api') - get "/news.json?key=#{@token.value}" - end + get "/news.json?key=#{@token.value}" + assert_response :unauthorized + assert_equal User.anonymous, User.current + 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 + def test_with_valid_username_password_http_authentication + @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') - 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 + get "/news.xml", nil, credentials(@user.login, 'my_password') + assert_response :unauthorized + assert_equal User.anonymous, User.current - 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 + get "/news.json", nil, credentials(@user.login, 'my_password') + assert_response :unauthorized + assert_equal User.anonymous, User.current + 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 + def test_with_valid_token_http_authentication + @user = User.generate_with_protected! + @token = Token.generate!(:user => @user, :action => 'api') - 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 + get "/news.xml", nil, credentials(@token.value, 'X') + assert_response :unauthorized + assert_equal User.anonymous, User.current - end + get "/news.json", nil, credentials(@token.value, 'X') + assert_response :unauthorized + assert_equal User.anonymous, User.current end end |