From 21e553679c44483e0a7b0db5238407b45c3f08fe Mon Sep 17 00:00:00 2001 From: Andreas Pfohl Date: Fri, 6 Sep 2024 11:24:09 +0200 Subject: [PATCH] [57347] Added test for unexpected files validation for Nextcloud storage --- .../nextcloud_connection_validator.rb | 18 ++++--- .../one_drive_connection_validator.rb | 2 +- modules/storages/config/locales/en.yml | 4 +- .../nextcloud_connection_validator_spec.rb | 48 +++++++++++++++++-- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb index 8ea89f531d38..f40bb98e75ab 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 @@ def request_failed_with_unknown_error 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}" + "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 @@ def with_unexpected_content unexpected_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/AbcSize diff --git a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb index 9795fc0f2a68..478ca840985c 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 @@ def drive_with_unexpected_content Some(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/AbcSize diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml index 4fdb9f4fe6ee..bcb353b60933 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 validation tenant_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: Error label_healthy: Healthy diff --git a/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb b/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb index 1ab254fd0ed4..e118c74800d7 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 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator do before 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 }) end subject { described_class.new(storage:).validate } @@ -48,7 +49,7 @@ context "if nextcloud host url could not be found" do let(: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" do expect(subject.type).to eq(:error) @@ -64,7 +65,8 @@ let(: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) do ServiceResult.success(result: Storages::NextcloudCapabilities.new( app_enabled?: app_enabled, app_version:, @@ -72,6 +74,13 @@ group_folder_version: )) end + let(:files_response) do + ServiceResult.success(result: Storages::StorageFiles.new( + [], + Storages::StorageFile.new(id: "root", name: "root"), + [] + )) + end it "returns a healthy validation" do expect(subject.type).to eq(:healthy) @@ -141,11 +150,42 @@ end end end + + 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 + end end context "if query returns an unhandled error" do let(:storage) { create(:nextcloud_storage_configured) } - let(:response) { build_failure(code: :error, payload: nil) } + let(:capabilities_response) { build_failure(code: :error, payload: nil) } before do allow(Rails.logger).to receive(:error)