kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
5.1 KiB
137 lines
5.1 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
10 years ago
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
14 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
14 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
10 years ago
|
require 'legacy_spec_helper'
|
||
15 years ago
|
|
||
11 years ago
|
describe 'ApiTest: DisabledRestApiTest', type: :request do
|
||
15 years ago
|
fixtures :all
|
||
|
|
||
11 years ago
|
before do
|
||
15 years ago
|
Setting.rest_api_enabled = '0'
|
||
|
Setting.login_required = '1'
|
||
|
end
|
||
|
|
||
11 years ago
|
after do
|
||
15 years ago
|
Setting.rest_api_enabled = '1'
|
||
|
Setting.login_required = '0'
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context 'get /api/v2/projects with the API disabled' do
|
||
|
context 'in :xml format' do
|
||
|
context 'with a valid api token' do
|
||
11 years ago
|
before do
|
||
9 years ago
|
@user = FactoryGirl.create(:user)
|
||
|
@token = FactoryGirl.create(:token, user: @user, action: 'api')
|
||
11 years ago
|
get "/api/v2/projects.xml?key=#{@token.value}"
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
it { is_expected.to respond_with :unauthorized }
|
||
11 years ago
|
it { should_respond_with_content_type 'application/xml' }
|
||
|
it 'should not login as the user' do
|
||
15 years ago
|
assert_equal User.anonymous, User.current
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'with a valid HTTP authentication' do
|
||
11 years ago
|
before do
|
||
9 years ago
|
@user = FactoryGirl.create(:user, password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
|
||
12 years ago
|
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'adminADMIN!')
|
||
10 years ago
|
get '/api/v2/projects.xml', nil, authorization: @authorization
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
it { is_expected.to respond_with :unauthorized }
|
||
11 years ago
|
it { should_respond_with_content_type 'application/xml' }
|
||
|
it 'should not login as the user' do
|
||
15 years ago
|
assert_equal User.anonymous, User.current
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'with a valid HTTP authentication using the API token' do
|
||
11 years ago
|
before do
|
||
9 years ago
|
@user = FactoryGirl.create(:user)
|
||
|
@token = FactoryGirl.create(:token, user: @user, action: 'api')
|
||
15 years ago
|
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X')
|
||
10 years ago
|
get '/api/v2/projects.xml', nil, authorization: @authorization
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
it { is_expected.to respond_with :unauthorized }
|
||
11 years ago
|
it { should_respond_with_content_type 'application/xml' }
|
||
|
it 'should not login as the user' do
|
||
15 years ago
|
assert_equal User.anonymous, User.current
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'in :json format' do
|
||
|
context 'with a valid api token' do
|
||
11 years ago
|
before do
|
||
9 years ago
|
@user = FactoryGirl.create(:user)
|
||
|
@token = FactoryGirl.create(:token, user: @user, action: 'api')
|
||
11 years ago
|
get "/api/v2/projects.json?key=#{@token.value}"
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
it { is_expected.to respond_with :unauthorized }
|
||
11 years ago
|
it { should_respond_with_content_type 'application/json' }
|
||
|
it 'should not login as the user' do
|
||
15 years ago
|
assert_equal User.anonymous, User.current
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'with a valid HTTP authentication' do
|
||
11 years ago
|
before do
|
||
9 years ago
|
@user = FactoryGirl.create(:user, password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
|
||
12 years ago
|
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'adminADMIN!')
|
||
10 years ago
|
get '/api/v2/projects.json', nil, authorization: @authorization
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
it { is_expected.to respond_with :unauthorized }
|
||
11 years ago
|
it { should_respond_with_content_type 'application/json' }
|
||
|
it 'should not login as the user' do
|
||
15 years ago
|
assert_equal User.anonymous, User.current
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'with a valid HTTP authentication using the API token' do
|
||
11 years ago
|
before do
|
||
9 years ago
|
@user = FactoryGirl.create(:user)
|
||
|
@token = FactoryGirl.create(:token, user: @user, action: 'api')
|
||
15 years ago
|
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'DoesNotMatter')
|
||
10 years ago
|
get '/api/v2/projects.json', nil, authorization: @authorization
|
||
15 years ago
|
end
|
||
|
|
||
10 years ago
|
it { is_expected.to respond_with :unauthorized }
|
||
11 years ago
|
it { should_respond_with_content_type 'application/json' }
|
||
|
it 'should not login as the user' do
|
||
15 years ago
|
assert_equal User.anonymous, User.current
|
||
|
end
|
||
|
end
|
||
14 years ago
|
end
|
||
15 years ago
|
end
|
||
|
end
|