2025-05-05 09:29:55 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-07-24 17:42:26 +02:00
|
|
|
#-- copyright
|
2020-01-15 11:31:26 +01:00
|
|
|
# OpenProject is an open source project management software.
|
2024-07-30 13:42:36 +02:00
|
|
|
# Copyright (C) the OpenProject GmbH
|
2014-07-24 17:42:26 +02:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License version 3.
|
|
|
|
|
#
|
|
|
|
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
2021-01-13 17:47:45 +01:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2014-07-24 17:42:26 +02:00
|
|
|
# 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.
|
|
|
|
|
#
|
2021-09-02 21:49:06 +02:00
|
|
|
# See COPYRIGHT and LICENSE files for more details.
|
2014-07-24 17:42:26 +02:00
|
|
|
#++
|
|
|
|
|
|
2014-07-15 16:19:14 +02:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
2023-05-31 12:15:15 +02:00
|
|
|
RSpec.describe SysController, with_settings: { sys_api_enabled: true } do
|
2021-02-11 16:02:18 +01:00
|
|
|
let(:commit_role) do
|
2023-10-05 15:28:31 +02:00
|
|
|
create(:project_role, permissions: %i[commit_access browse_repository])
|
2021-02-11 16:02:18 +01:00
|
|
|
end
|
2023-10-05 15:28:31 +02:00
|
|
|
let(:browse_role) { create(:project_role, permissions: [:browse_repository]) }
|
|
|
|
|
let(:guest_role) { create(:project_role, permissions: []) }
|
2014-07-21 16:04:41 +02:00
|
|
|
let(:valid_user_password) { "Top Secret Password" }
|
2021-02-11 16:02:18 +01:00
|
|
|
let(:valid_user) do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:user,
|
2022-02-02 21:48:06 +01:00
|
|
|
login: "johndoe",
|
|
|
|
|
password: valid_user_password,
|
|
|
|
|
password_confirmation: valid_user_password)
|
2021-02-11 16:02:18 +01:00
|
|
|
end
|
2014-07-21 16:04:41 +02:00
|
|
|
|
2015-08-11 15:04:52 +02:00
|
|
|
let(:api_key) { "12345678" }
|
|
|
|
|
|
|
|
|
|
let(:public) { false }
|
2022-01-24 19:22:35 +01:00
|
|
|
let(:project) { create(:project, public:) }
|
2021-05-04 16:55:34 +02:00
|
|
|
let!(:repository_project) do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:project, public: false, members: { valid_user => [browse_role] })
|
2021-05-04 16:55:34 +02:00
|
|
|
end
|
2015-08-11 15:04:52 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:non_member, permissions: [:browse_repository])
|
2014-07-21 16:04:41 +02:00
|
|
|
DeletedUser.first # creating it first in order to avoid problems with should_receive
|
|
|
|
|
|
2015-08-11 15:04:52 +02:00
|
|
|
allow(Setting).to receive(:sys_api_key).and_return(api_key)
|
2016-04-25 09:06:13 +02:00
|
|
|
|
|
|
|
|
Rails.cache.clear
|
|
|
|
|
RequestStore.clear!
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "svn" do
|
2022-01-24 19:22:35 +01:00
|
|
|
let!(:repository) { create(:repository_subversion, project:) }
|
2015-08-11 15:04:52 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
describe "repo_auth" do
|
|
|
|
|
context "for valid login, but no access to repo_auth" do
|
|
|
|
|
before do
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: "without-access",
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
it "responds 403 not allowed" do
|
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
expect(response.body).to eq("Not allowed")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for valid login and user has read permission (role reporter) for project" do
|
|
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:member,
|
2022-02-02 21:48:06 +01:00
|
|
|
user: valid_user,
|
|
|
|
|
roles: [browse_role],
|
|
|
|
|
project:)
|
2015-08-11 15:04:52 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
it "responds 200 okay dokay for GET" do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
it "responds 403 not allowed for POST" do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "POST" }
|
2014-07-15 16:19:14 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for valid login and user has rw permission (role developer) for project" do
|
|
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:member,
|
2022-02-02 21:48:06 +01:00
|
|
|
user: valid_user,
|
|
|
|
|
roles: [commit_role],
|
|
|
|
|
project:)
|
2014-07-21 16:04:41 +02:00
|
|
|
valid_user.save
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 200 okay dokay for GET" do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 200 okay dokay for POST" do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "POST" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for invalid login and user has role manager for project" do
|
|
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:member,
|
2022-02-02 21:48:06 +01:00
|
|
|
user: valid_user,
|
|
|
|
|
roles: [commit_role],
|
|
|
|
|
project:)
|
2014-07-21 16:04:41 +02:00
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password + "made invalid"
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 401 auth required" do
|
|
|
|
|
expect(response.code).to eq("401")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for valid login and user is not member for project" do
|
|
|
|
|
before do
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 403 not allowed" do
|
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for valid login and project is public" do
|
2015-08-11 15:04:52 +02:00
|
|
|
let(:public) { true }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
2015-08-11 15:04:52 +02:00
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
random_project = create(:project, public: false)
|
|
|
|
|
create(:member,
|
2022-02-02 21:48:06 +01:00
|
|
|
user: valid_user,
|
|
|
|
|
roles: [browse_role],
|
|
|
|
|
project: random_project)
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 200 OK" do
|
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for invalid credentials" do
|
|
|
|
|
before do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: "any-repo",
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 401 auth required" do
|
|
|
|
|
expect(response.code).to eq("401")
|
|
|
|
|
expect(response.body).to eq("Authorization required")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for invalid api key" do
|
|
|
|
|
it "responds 403 for valid username/password" do
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: "not_the_api_key",
|
|
|
|
|
repository: "any-repo",
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
expect(response.body)
|
|
|
|
|
.to eq("Access denied. Repository management WS is disabled or key is invalid.")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 403 for invalid username/password" do
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
"invalid",
|
|
|
|
|
"invalid"
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: "not_the_api_key",
|
|
|
|
|
repository: "any-repo",
|
|
|
|
|
method: "GET" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
expect(response.body)
|
|
|
|
|
.to eq("Access denied. Repository management WS is disabled or key is invalid.")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
end
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "git" do
|
2022-01-24 19:22:35 +01:00
|
|
|
let!(:repository) { create(:repository_git, project:) }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
describe "repo_auth" do
|
|
|
|
|
context "for valid login, but no access to repo_auth" do
|
|
|
|
|
before do
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: "without-access",
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
it "responds 403 not allowed" do
|
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
expect(response.body).to eq("Not allowed")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for valid login and user has read permission (role reporter) for project" do
|
|
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:member,
|
2022-02-02 21:48:06 +01:00
|
|
|
user: valid_user,
|
|
|
|
|
roles: [browse_role],
|
|
|
|
|
project:)
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 200 okay dokay for read-only access" do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-15 16:19:14 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
expect(response.code).to eq("200")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
it "responds 403 not allowed for write (push)" do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "POST",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git/#{project.identifier}/git-receive-pack",
|
|
|
|
|
location: "/git" }
|
2014-07-15 16:19:14 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for valid login and user has rw permission (role developer) for project" do
|
|
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:member,
|
2022-02-02 21:48:06 +01:00
|
|
|
user: valid_user,
|
|
|
|
|
roles: [commit_role],
|
|
|
|
|
project:)
|
2014-07-21 16:04:41 +02:00
|
|
|
valid_user.save
|
2015-08-11 15:04:52 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 200 okay dokay for GET" do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 200 okay dokay for POST" do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "POST",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git/#{project.identifier}/git-receive-pack",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for invalid login and user has role manager for project" do
|
|
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:member,
|
2022-02-02 21:48:06 +01:00
|
|
|
user: valid_user,
|
|
|
|
|
roles: [commit_role],
|
|
|
|
|
project:)
|
2015-08-11 15:04:52 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password + "made invalid"
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 401 auth required" do
|
|
|
|
|
expect(response.code).to eq("401")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for valid login and user is not member for project" do
|
|
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
project = create(:project, public: false)
|
2014-07-21 16:04:41 +02:00
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 403 not allowed" do
|
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for valid login and project is public" do
|
2015-08-11 15:04:52 +02:00
|
|
|
let(:public) { true }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
before do
|
2022-01-24 19:22:35 +01:00
|
|
|
random_project = create(:project, public: false)
|
|
|
|
|
create(:member,
|
2022-02-02 21:48:06 +01:00
|
|
|
user: valid_user,
|
|
|
|
|
roles: [browse_role],
|
|
|
|
|
project: random_project)
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: project.identifier,
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 200 OK" do
|
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for invalid credentials" do
|
|
|
|
|
before do
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: api_key,
|
|
|
|
|
repository: "any-repo",
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 401 auth required" do
|
|
|
|
|
expect(response.code).to eq("401")
|
|
|
|
|
expect(response.body).to eq("Authorization required")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
2014-07-21 16:04:41 +02:00
|
|
|
context "for invalid api key" do
|
|
|
|
|
it "responds 403 for valid username/password" do
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: "not_the_api_key",
|
|
|
|
|
repository: "any-repo",
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
expect(response.body)
|
|
|
|
|
.to eq("Access denied. Repository management WS is disabled or key is invalid.")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "responds 403 for invalid username/password" do
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
"invalid",
|
|
|
|
|
"invalid"
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
post "repo_auth", params: { key: "not_the_api_key",
|
|
|
|
|
repository: "any-repo",
|
|
|
|
|
method: "GET",
|
|
|
|
|
git_smart_http: "1",
|
|
|
|
|
uri: "/git",
|
|
|
|
|
location: "/git" }
|
2014-07-21 16:04:41 +02:00
|
|
|
|
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
|
expect(response.body)
|
|
|
|
|
.to eq("Access denied. Repository management WS is disabled or key is invalid.")
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
end
|
2014-07-21 16:04:41 +02:00
|
|
|
end
|
2024-12-06 09:14:42 +01:00
|
|
|
|
|
|
|
|
describe "#fetch_changesets" do
|
|
|
|
|
let(:params) { { id: repository_project.identifier } }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
request.env["HTTP_AUTHORIZATION"] =
|
|
|
|
|
ActionController::HttpAuthentication::Basic.encode_credentials(
|
|
|
|
|
valid_user.login,
|
|
|
|
|
valid_user_password
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
allow_any_instance_of(Repository::Subversion).to receive(:fetch_changesets).and_return(true)
|
|
|
|
|
|
|
|
|
|
get "fetch_changesets", params: params.merge({ key: api_key })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "with a project identifier" do
|
|
|
|
|
it "is successful" do
|
|
|
|
|
expect(response)
|
|
|
|
|
.to have_http_status(:ok)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "without a project identifier" do
|
|
|
|
|
let(:params) { {} }
|
|
|
|
|
|
|
|
|
|
it "is successful" do
|
|
|
|
|
expect(response)
|
|
|
|
|
.to have_http_status(:ok)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "for an unknown project" do
|
|
|
|
|
let(:params) { { id: 0 } }
|
|
|
|
|
|
|
|
|
|
it "returns 404" do
|
|
|
|
|
expect(response)
|
|
|
|
|
.to have_http_status(:not_found)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when disabled", with_settings: { sys_api_enabled?: false } do
|
|
|
|
|
it "is 403 forbidden" do
|
|
|
|
|
expect(response)
|
|
|
|
|
.to have_http_status(:forbidden)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-07-15 16:19:14 +02:00
|
|
|
end
|