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
[57347] Added test for failing files query on NextcloudConnectionValidator
Andreas Pfohl64d2cc25449f
diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rbindex f40bb98e75a..21cc4380e14 100644--- a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb+++ b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb@@ -54,21 +54,16 @@ module Storagesprivate- def query- @query ||= Peripherals::Registry+ def capabilities+ @capabilities ||= Peripherals::Registry.resolve("#{@storage.short_provider_type}.queries.capabilities")- .call(storage: @storage, auth_strategy:)+ .call(storage: @storage, auth_strategy: noop)enddef files@files ||= Peripherals::Registry.resolve("#{@storage.short_provider_type}.queries.files")- .call(- storage: @storage,- auth_strategy: Peripherals::Registry- .resolve("#{@storage.short_provider_type}.authentication.userless").call,- folder: ParentFolder.new(@storage.group_folder)- )+ .call(storage: @storage, auth_strategy: userless, folder: ParentFolder.new(@storage.group_folder))enddef maybe_is_not_configured@@ -81,7 +76,7 @@ module Storagesenddef host_url_not_found- return None() if query.result != :not_found+ return None() if capabilities.result != :not_foundSome(ConnectionValidation.new(type: :error,error_code: :err_host_not_found,@@ -91,12 +86,12 @@ module Storages# rubocop:disable Metrics/AbcSizedef missing_dependencies- return None() if query.failure?+ return None() if capabilities.failure?- capabilities = query.result+ capabilities_result = capabilities.result- if !capabilities.app_enabled? || (@storage.automatically_managed? && !capabilities.group_folder_enabled?)- app_name = if capabilities.app_enabled?+ if !capabilities_result.app_enabled? || (@storage.automatically_managed? && !capabilities_result.group_folder_enabled?)+ app_name = if capabilities_result.app_enabled?I18n.t("storages.dependencies.nextcloud.group_folders_app")elseI18n.t("storages.dependencies.nextcloud.integration_app")@@ -119,33 +114,33 @@ module Storages# rubocop:disable Metrics/AbcSizedef version_mismatch- return None() if query.failure?+ return None() if capabilities.failure?config = YAML.load_file(path_to_config).deep_stringify_keys!min_app_version = SemanticVersion.parse(config.dig("dependencies", "integration_app", "min_version"))min_group_folder_version = SemanticVersion.parse(config.dig("dependencies", "group_folders_app", "min_version"))- capabilities = query.result+ capabilities_result = capabilities.result- if capabilities.app_version < min_app_version+ if capabilities_result.app_version < min_app_versionSome(ConnectionValidation.new(type: :error,error_code: :err_unexpected_version,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.app_version_mismatch",- found: capabilities.app_version.to_s,+ found: capabilities_result.app_version.to_s,expected: min_app_version.to_s)))- elsif @storage.automatically_managed? && capabilities.group_folder_version < min_group_folder_version+ elsif @storage.automatically_managed? && capabilities_result.group_folder_version < min_group_folder_versionSome(ConnectionValidation.new(type: :error,error_code: :err_unexpected_version,timestamp: Time.current,description: I18n.t("storages.health.connection_validation.group_folder_version_mismatch",- found: capabilities.group_folder_version.to_s,+ found: capabilities_result.group_folder_version.to_s,expected: min_group_folder_version.to_s)))@@ -157,13 +152,13 @@ module Storages# rubocop:enable Metrics/AbcSizedef request_failed_with_unknown_error- return None() if query.success?+ return None() if capabilities.success?Rails.logger.error("Connection validation failed with unknown error:\n\t" \"storage: ##{@storage.id} #{@storage.name}\n\t" \- "status: #{query.result}\n\t" \- "response: #{query.error_payload}"+ "status: #{capabilities.result}\n\t" \+ "response: #{capabilities.error_payload}")Some(ConnectionValidation.new(type: :error,@@ -175,7 +170,15 @@ module Storages# rubocop:disable Metrics/AbcSizedef with_unexpected_contentreturn None() unless @storage.automatic_management_enabled?- return None() if files.failure?++ if files.failure?+ return Some(+ ConnectionValidation.new(type: :error,+ error_code: :err_unknown,+ timestamp: Time.current,+ description: I18n.t("storages.health.connection_validation.unknown_error"))+ )+ endexpected_folder_ids = @storage.project_storages.where(project_folder_mode: "automatic")@@ -196,7 +199,9 @@ module Storages# rubocop:enable Metrics/AbcSize- def auth_strategy = StorageInteraction::AuthenticationStrategies::Noop.strategy+ def noop = StorageInteraction::AuthenticationStrategies::Noop.strategy++ def userless = Peripherals::Registry.resolve("#{@storage.short_provider_type}.authentication.userless").calldef path_to_configRails.root.join("modules/storages/config/nextcloud_dependencies.yml")diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex bcb353b6093..3afefd17642 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -218,7 +218,7 @@ en:subtitle: Connection validationtenant_id_wrong: The configured directory (tenant) id is invalid. Please check the configuration.unexpected_content:- nextcloud: Unexpected content found in the managed folder.+ nextcloud: Unexpected content found in the managed group folder.one_drive: Unexpected content found in the drive.unknown_error: The connection could not be validated. An unknown error occurred. Please check the server logs for further information.label_error: Errordiff --git a/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb b/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rbindex e118c74800d..db6c731e860 100644--- a/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb@@ -151,7 +151,7 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator doendend- context "if the request returns unexpected files" do+ context "with configured ProjectStorage" dolet(:storage) { create(:nextcloud_storage_configured, :as_automatically_managed) }let(:project_storage) docreate(:project_storage,@@ -160,25 +160,39 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator dostorage:,project: create(:project))end- let(:files_response) do- ServiceResult.success(result: Storages::StorageFiles.new(- [- Storages::StorageFile.new(id: project_folder_id, name: "I am your father"),- Storages::StorageFile.new(id: "noooooooooo", name: "testimony_of_luke_skywalker.md")- ],- Storages::StorageFile.new(id: "root", name: "root"),- []- ))- end- before do- project_storage+ before { project_storage }++ context "if the request returns an error" do+ let(:files_response) do+ Storages::Peripherals::StorageInteraction::Nextcloud::Util.error(:error)+ end++ it "returns a validation failure" do+ expect(subject.type).to eq(:error)+ expect(subject.error_code).to eq(:err_unknown)+ expect(subject.description).to eq("The connection could not be validated. An unknown error occurred. " \+ "Please check the server logs for further information.")+ endend- it "returns a validation failure" do- expect(subject.type).to eq(:warning)- expect(subject.error_code).to eq(:wrn_unexpected_content)- expect(subject.description).to eq("Unexpected content found in the managed folder.")+ context "if the request returns unexpected files" do+ let(:files_response) do+ ServiceResult.success(result: Storages::StorageFiles.new(+ [+ Storages::StorageFile.new(id: project_folder_id, name: "I am your father"),+ Storages::StorageFile.new(id: "noooooooooo", name: "testimony_of_luke_skywalker.md")+ ],+ Storages::StorageFile.new(id: "root", name: "root"),+ []+ ))+ end++ it "returns a validation failure" do+ expect(subject.type).to eq(:warning)+ expect(subject.error_code).to eq(:wrn_unexpected_content)+ expect(subject.description).to eq("Unexpected content found in the managed group folder.")+ endendendend