OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Validate storage url only if changed and use short timeouts
Christophe Bliardba156354b90a
diff --git a/modules/storages/app/contracts/storages/storages/base_contract.rb b/modules/storages/app/contracts/storages/storages/base_contract.rbindex e85aa889381..9658dcf2cb6 100644--- a/modules/storages/app/contracts/storages/storages/base_contract.rb+++ b/modules/storages/app/contracts/storages/storages/base_contract.rb@@ -64,6 +64,8 @@ module Storages::Storagesenddef validate_host_reachable+ return unless model.host_changed?+response = request_capabilitiesunless response.is_a? Net::HTTPSuccess@@ -95,6 +97,9 @@ module Storages::Storagesrequest["Accept"] = "application/json"req_options = {+ max_retries: 0,+ open_timeout: 5, # seconds+ read_timeout: 3, # secondsuse_ssl: uri.scheme == "https"}diff --git a/modules/storages/spec/contracts/storages/storages/base_contract_spec.rb b/modules/storages/spec/contracts/storages/storages/base_contract_spec.rbnew file mode 100644index 00000000000..4c0d48a415b--- /dev/null+++ b/modules/storages/spec/contracts/storages/storages/base_contract_spec.rb@@ -0,0 +1,47 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# 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:+# 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.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require_relative '../../../spec_helper'++describe Storages::Storages::BaseContract, :storage_server_helpers, webmock: true do+ let(:current_user) { create(:admin) }+ let(:storage_host) { 'https://host1.example.com' }+ let(:storage) { build(:storage, host: storage_host) }+ let(:contract) { described_class.new(storage, current_user) }++ it 'checks the storage url only when changed' do+ request = mock_server_capabilities_response(storage_host)+ contract.valid?+ expect(request).to have_been_made.once++ WebMock.reset_executed_requests!+ storage.save+ contract.valid?+ expect(request).not_to have_been_made+ end+enddiff --git a/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb b/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rbindex 006ce130abb..59bd18645dd 100644--- a/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb+++ b/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb@@ -117,6 +117,11 @@ shared_examples_for 'storage contract', :storage_server_helpers, webmock: true dendcontext 'when provider_type is nextcloud' do+ before do+ # simulate host value changed to have GET request sent to check host URL validity+ storage.host_will_change!+ end+context 'when response code is a 404 NOT FOUND' dolet(:host_response_code) { '404' }