Skip to content

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

[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.rb
index 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 Storages
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 @@ module Storages
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 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 Storages
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 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 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 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_helper
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 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator do
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 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator do
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 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator do
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 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator do
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)