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 unexpected files validation for Nextcloud storage
Andreas Pfohla979cec7d264
diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rbindex 8ea89f531d3..f40bb98e75a 100644--- a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb+++ b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb@@ -161,9 +161,9 @@ module StoragesRails.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}"+ "storage: ##{@storage.id} #{@storage.name}\n\t" \+ "status: #{query.result}\n\t" \+ "response: #{query.error_payload}")Some(ConnectionValidation.new(type: :error,@@ -184,10 +184,14 @@ module Storagesunexpected_files = files.result.files.reject { |file| expected_folder_ids.include?(file.id) }return None() if unexpected_files.empty?- Some(ConnectionValidation.new(type: :warning,- error_code: :wrn_unexpected_content,- timestamp: Time.current,- description: I18n.t("storages.health.connection_validation.unexpected_content")))+ Some(+ ConnectionValidation.new(+ type: :warning,+ error_code: :wrn_unexpected_content,+ timestamp: Time.current,+ description: I18n.t("storages.health.connection_validation.unexpected_content.nextcloud")+ )+ )end# rubocop:enable Metrics/AbcSizediff --git a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rbindex 9795fc0f2a6..478ca840985 100644--- a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb+++ b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb@@ -149,7 +149,7 @@ module StoragesSome(ConnectionValidation.new(type: :warning,error_code: :wrn_unexpected_content,timestamp: Time.current,- description: I18n.t("storages.health.connection_validation.unexpected_content")))+ description: I18n.t("storages.health.connection_validation.unexpected_content.one_drive")))end# rubocop:enable Metrics/AbcSizediff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 4fdb9f4fe6e..bcb353b6093 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -217,7 +217,9 @@ en:placeholder: Check your connection against the server.subtitle: Connection validationtenant_id_wrong: The configured directory (tenant) id is invalid. Please check the configuration.- unexpected_content: Unexpected content found in the drive.+ unexpected_content:+ nextcloud: Unexpected content found in the managed 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: Errorlabel_healthy: Healthydiff --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 1ab254fd0ed..e118c74800d 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@@ -31,7 +31,8 @@ require_module_spec_helperRSpec.describe Storages::Peripherals::NextcloudConnectionValidator dobefore do- Storages::Peripherals::Registry.stub("#{storage.short_provider_type}.queries.capabilities", ->(_) { response })+ Storages::Peripherals::Registry.stub("#{storage.short_provider_type}.queries.capabilities", ->(_) { capabilities_response })+ Storages::Peripherals::Registry.stub("#{storage.short_provider_type}.queries.files", ->(_) { files_response })endsubject { described_class.new(storage:).validate }@@ -48,7 +49,7 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator docontext "if nextcloud host url could not be found" dolet(:storage) { create(:nextcloud_storage_configured) }- let(:response) { build_failure(code: :not_found, payload: nil) }+ let(:capabilities_response) { build_failure(code: :not_found, payload: nil) }it "returns a validation failure" doexpect(subject.type).to eq(:error)@@ -64,7 +65,8 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator dolet(:app_version) { Storages::SemanticVersion.parse("2.6.3") }let(:group_folder_enabled) { true }let(:group_folder_version) { Storages::SemanticVersion.parse("17.0.1") }- let(:response) do+ let(:project_folder_id) { "1337" }+ let(:capabilities_response) doServiceResult.success(result: Storages::NextcloudCapabilities.new(app_enabled?: app_enabled,app_version:,@@ -72,6 +74,13 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator dogroup_folder_version:))end+ let(:files_response) do+ ServiceResult.success(result: Storages::StorageFiles.new(+ [],+ Storages::StorageFile.new(id: "root", name: "root"),+ []+ ))+ endit "returns a healthy validation" doexpect(subject.type).to eq(:healthy)@@ -141,11 +150,42 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator doendendend++ context "if the request returns unexpected files" do+ let(:storage) { create(:nextcloud_storage_configured, :as_automatically_managed) }+ let(:project_storage) do+ create(:project_storage,+ :as_automatically_managed,+ project_folder_id:,+ storage:,+ 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+ 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 folder.")+ end+ endendcontext "if query returns an unhandled error" dolet(:storage) { create(:nextcloud_storage_configured) }- let(:response) { build_failure(code: :error, payload: nil) }+ let(:capabilities_response) { build_failure(code: :error, payload: nil) }before doallow(Rails.logger).to receive(:error)