mirror of
https://github.com/redmine/redmine.git
synced 2026-01-26 01:10:01 +01:00
Fix RuboCop offense Rails/HttpStatus (#39889).
git-svn-id: https://svn.redmine.org/redmine/trunk@22837 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -35,7 +35,7 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
|
||||
},
|
||||
:headers => credentials('admin')
|
||||
)
|
||||
assert_response 201
|
||||
assert_response :created
|
||||
end
|
||||
ensure
|
||||
ActionController::Base.allow_forgery_protection = false
|
||||
|
||||
@@ -61,7 +61,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /attachments/:id.xml should deny access without credentials" do
|
||||
get '/attachments/7.xml'
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
test "GET /attachments/download/:id/:filename should return the attachment content" do
|
||||
@@ -72,7 +72,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /attachments/download/:id/:filename should deny access without credentials" do
|
||||
get '/attachments/download/7/archive.zip'
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
test "GET /attachments/thumbnail/:id should return the thumbnail" do
|
||||
@@ -118,7 +118,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
:params => {:attachment => {:filename => '', :description => 'updated'}},
|
||||
:headers => credentials('jsmith')
|
||||
)
|
||||
assert_response 422
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal 'application/json', response.media_type
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_include "File cannot be blank", json['errors']
|
||||
@@ -209,7 +209,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
"CONTENT_TYPE" => 'image/png'
|
||||
}.merge(credentials('jsmith'))
|
||||
)
|
||||
assert_response 406
|
||||
assert_response :not_acceptable
|
||||
end
|
||||
end
|
||||
|
||||
@@ -224,7 +224,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
|
||||
"CONTENT_TYPE" => 'application/octet-stream'
|
||||
}.merge(credentials('jsmith'))
|
||||
)
|
||||
assert_response 422
|
||||
assert_response :unprocessable_entity
|
||||
assert_select 'error', :text => /exceeds the maximum allowed file size/
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
|
||||
def test_api_should_deny_without_credentials
|
||||
get '/users/current.xml'
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
assert response.headers.has_key?('WWW-Authenticate')
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
user.password = 'my_password'
|
||||
end
|
||||
get '/users/current.xml', :headers => credentials(user.login, 'my_password')
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
def test_api_should_deny_http_basic_auth_using_username_and_wrong_password
|
||||
@@ -45,7 +45,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
user.password = 'my_password'
|
||||
end
|
||||
get '/users/current.xml', :headers => credentials(user.login, 'wrong_password')
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_api_should_deny_http_basic_auth_if_twofa_is_active
|
||||
@@ -54,61 +54,61 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
user.update(twofa_scheme: 'totp')
|
||||
end
|
||||
get '/users/current.xml', :headers => credentials(user.login, 'my_password')
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_api_should_accept_http_basic_auth_using_api_key
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'api')
|
||||
get '/users/current.xml', :headers => credentials(token.value, 'X')
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
def test_api_should_deny_http_basic_auth_using_wrong_api_key
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'feeds') # not the API key
|
||||
get '/users/current.xml', :headers => credentials(token.value, 'X')
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_api_should_accept_auth_using_api_key_as_parameter
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'api')
|
||||
get "/users/current.xml?key=#{token.value}"
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
def test_api_should_deny_auth_using_wrong_api_key_as_parameter
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'feeds') # not the API key
|
||||
get "/users/current.xml?key=#{token.value}"
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_api_should_accept_auth_using_api_key_as_request_header
|
||||
user = User.generate!
|
||||
token = Token.create!(:user => user, :action => 'api')
|
||||
get "/users/current.xml", :headers => {'X-Redmine-API-Key' => token.value.to_s}
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
def test_api_should_deny_auth_using_wrong_api_key_as_request_header
|
||||
user = User.generate!
|
||||
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 401
|
||||
assert_response :unauthorized
|
||||
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', :headers => credentials('jsmith')
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
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', :headers => {'HTTP_AUTHORIZATION' => 'Digest foo bar'}
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_invalid_utf8_credentials_should_not_trigger_an_error
|
||||
@@ -126,7 +126,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
assert_response :success
|
||||
|
||||
get '/users/current.json'
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_api_should_accept_switch_user_header_for_admin_user
|
||||
@@ -140,7 +140,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
|
||||
def test_api_should_respond_with_412_when_trying_to_switch_to_a_invalid_user
|
||||
get '/users/current', :headers => {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => 'foobar'}
|
||||
assert_response 412
|
||||
assert_response :precondition_failed
|
||||
end
|
||||
|
||||
def test_api_should_respond_with_412_when_trying_to_switch_to_a_locked_user
|
||||
@@ -148,7 +148,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
|
||||
assert user.locked?
|
||||
|
||||
get '/users/current', :headers => {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => user.login}
|
||||
assert_response 412
|
||||
assert_response :precondition_failed
|
||||
end
|
||||
|
||||
def test_api_should_not_accept_switch_user_header_for_non_admin_user
|
||||
|
||||
@@ -42,7 +42,7 @@ class Redmine::ApiTest::EnumerationsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /enumerations/invalid_subclass.xml should return 404" do
|
||||
get '/enumerations/invalid_subclass.xml'
|
||||
assert_response 404
|
||||
assert_response :not_found
|
||||
assert_equal 'application/xml', response.media_type
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /groups.xml should require authentication" do
|
||||
get '/groups.xml'
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
test "GET /groups.xml should return givable groups" do
|
||||
@@ -61,7 +61,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /groups.json should require authentication" do
|
||||
get '/groups.json'
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
test "GET /groups.json should return groups" do
|
||||
|
||||
@@ -723,7 +723,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
'/issues.json',
|
||||
:params => {:issue => {:project_id => 999, :subject => "API"}},
|
||||
:headers => credentials('jsmith'))
|
||||
assert_response 422
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "POST /issues.json with invalid project_id and any assigned_to_id should respond with 422" do
|
||||
@@ -737,7 +737,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
}
|
||||
},
|
||||
:headers => credentials('jsmith'))
|
||||
assert_response 422
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "POST /issues.json with invalid project_id and any fixed_version_id should respond with 422" do
|
||||
@@ -751,7 +751,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
||||
}
|
||||
},
|
||||
:headers => credentials('jsmith'))
|
||||
assert_response 422
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "PUT /issues/:id.xml" do
|
||||
|
||||
@@ -63,7 +63,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /time_entries/:id.xml with invalid id should 404" do
|
||||
get '/time_entries/999.xml', :headers => credentials('jsmith')
|
||||
assert_response 404
|
||||
assert_response :not_found
|
||||
end
|
||||
|
||||
test "POST /time_entries.xml with issue_id should create time entry" do
|
||||
@@ -211,7 +211,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
|
||||
'/time_entries/2.xml',
|
||||
:params => {:time_entry => {:hours => '2.3', :comments => 'API Update'}},
|
||||
:headers => credentials('dlopper'))
|
||||
assert_response 403
|
||||
assert_response :forbidden
|
||||
end
|
||||
|
||||
test "DELETE /time_entries/:id.xml should destroy time entry" do
|
||||
|
||||
@@ -261,7 +261,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
|
||||
test "GET /users/current.xml should require authentication" do
|
||||
get '/users/current.xml'
|
||||
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
test "GET /users/current.xml should return current user" do
|
||||
|
||||
@@ -26,7 +26,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
|
||||
get '/projects/ecookbook/wiki/index.xml'
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
assert_equal 'application/xml', response.media_type
|
||||
assert_select 'wiki_pages[type=array]' do
|
||||
assert_select 'wiki_page', :count => Wiki.find(1).pages.count
|
||||
@@ -45,7 +45,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
|
||||
get '/projects/ecookbook/wiki/CookBook_documentation.xml'
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
assert_equal 'application/xml', response.media_type
|
||||
assert_select 'wiki_page' do
|
||||
assert_select 'title', :text => 'CookBook_documentation'
|
||||
@@ -60,7 +60,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
|
||||
get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
assert_equal 'application/xml', response.media_type
|
||||
assert_select 'wiki_page' do
|
||||
assert_select 'title', :text => 'Page_with_an_inline_image'
|
||||
@@ -75,13 +75,13 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
|
||||
test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
|
||||
get '/projects/ecookbook/wiki/Invalid_Page.xml', :headers => credentials('jsmith')
|
||||
assert_response 404
|
||||
assert_response :not_found
|
||||
assert_equal 'application/xml', response.media_type
|
||||
end
|
||||
|
||||
test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
|
||||
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
assert_equal 'application/xml', response.media_type
|
||||
assert_select 'wiki_page' do
|
||||
assert_select 'title', :text => 'CookBook_documentation'
|
||||
@@ -98,7 +98,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
Role.anonymous.remove_permission! :view_wiki_edits
|
||||
|
||||
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
|
||||
assert_response 401
|
||||
assert_response :unauthorized
|
||||
assert_equal 'application/xml', response.media_type
|
||||
end
|
||||
|
||||
@@ -130,7 +130,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
WikiContentVersion.find_by_id(2).update(author_id: nil)
|
||||
|
||||
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
|
||||
assert_response 200
|
||||
assert_response :ok
|
||||
assert_equal 'application/xml', response.media_type
|
||||
assert_select 'wiki_page' do
|
||||
assert_select 'author', 0
|
||||
@@ -176,7 +176,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
},
|
||||
:headers => credentials('jsmith')
|
||||
)
|
||||
assert_response 409
|
||||
assert_response :conflict
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -194,7 +194,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
},
|
||||
:headers => credentials('jsmith')
|
||||
)
|
||||
assert_response 201
|
||||
assert_response :created
|
||||
end
|
||||
end
|
||||
|
||||
@@ -227,7 +227,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
},
|
||||
:headers => credentials('jsmith')
|
||||
)
|
||||
assert_response 201
|
||||
assert_response :created
|
||||
end
|
||||
end
|
||||
|
||||
@@ -251,7 +251,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
||||
},
|
||||
:headers => credentials('jsmith')
|
||||
)
|
||||
assert_response 201
|
||||
assert_response :created
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user