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
[#56030] improve detection of wrong drive ids
Eric Schubert68950d0a5d07
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.rbindex 70f749b328a..4f97eea30f8 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@@ -70,15 +70,31 @@ module Storagesdescription: I18n.t("storages.health.connection_validation.not_configured")))end+ # rubocop:disable Metrics/AbcSizedef drive_id_wrong- return None() if query.result != :not_found+ return None() if query.success?- Some(ConnectionValidation.new(type: :error,- error_code: :err_drive_invalid,- timestamp: Time.current,- description: I18n.t("storages.health.connection_validation.drive_id_wrong")))+ validation_for_invalid_drive = ConnectionValidation.new(+ type: :error,+ error_code: :err_drive_invalid,+ timestamp: Time.current,+ description: I18n.t("storages.health.connection_validation.drive_id_wrong")+ )++ error_code = query.result+ return Some(validation_for_invalid_drive) if error_code == :not_found++ payload = query.error_payload+ return None() unless error_code == :error && payload.present? && payload.dig(:error, :code) == "invalidRequest"++ malformed_drive_id_string = "provided drive id appears to be malformed" # invalidRequest+ return None() unless payload.dig(:error, :message).include?(malformed_drive_id_string)++ Some(validation_for_invalid_drive)end+ # rubocop:enable Metrics/AbcSize+def tenant_id_wrongreturn None() if query.result != :unauthorizeddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rbindex 4c0d64d7cca..51a7896a2db 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb@@ -41,12 +41,11 @@ module Storagesdef initialize(storage)@storage = storage- @uri = storage.urienddef call(auth_strategy:, folder:)Authentication[auth_strategy].call(storage: @storage) do |http|- call = http.get(Util.join_uri_path(@uri, children_uri_path_for(folder) + FIELDS))+ call = http.get(Util.join_uri_path(@storage.uri, children_uri_path_for(folder) + FIELDS))response = handle_response(call, :value)if response.result.empty?@@ -59,10 +58,14 @@ module Storagesprivate+ # rubocop:disable Metrics/AbcSizedef handle_response(response, map_value)case responsein { status: 200..299 }ServiceResult.success(result: response.json(symbolize_keys: true).fetch(map_value))+ in { status: 400 }+ ServiceResult.failure(result: :error,+ errors: Util.storage_error(response:, code: :error, source: self.class))in { status: 404 }ServiceResult.failure(result: :not_found,errors: Util.storage_error(response:, code: :not_found, source: self.class))@@ -78,6 +81,8 @@ module Storagesendend+ # rubocop:enable Metrics/AbcSize+def storage_files(json_files)files = json_files.map { |json| Util.storage_file_from_json(json) }@@ -86,7 +91,7 @@ module Storagesenddef empty_response(http, folder)- response = http.get(Util.join_uri_path(@uri, location_uri_path_for(folder) + FIELDS))+ response = http.get(Util.join_uri_path(@storage.uri, location_uri_path_for(folder) + FIELDS))handle_response(response, :id).map do |parent_location_id|empty_storage_files(folder.path, parent_location_id)enddiff --git a/modules/storages/app/contracts/storages/storages/one_drive_contract.rb b/modules/storages/app/contracts/storages/storages/one_drive_contract.rbindex f83fccf6307..40dafef17e3 100644--- a/modules/storages/app/contracts/storages/storages/one_drive_contract.rb+++ b/modules/storages/app/contracts/storages/storages/one_drive_contract.rb@@ -35,6 +35,8 @@ module Storages::Storagesattribute :tenant_idvalidates :tenant_id, format: { with: /\A(?:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}|consumers)\z/i }attribute :drive_id- validates :drive_id, presence: true, allow_nil: true+ # GRAPH API considers drive ids of 16 characters or shorter as personal drive ids. Those are not supported,+ # and allowing them lead to unexpected behavior.+ validates :drive_id, presence: true, allow_nil: true, length: { minimum: 17 }endenddiff --git a/modules/storages/spec/common/storages/peripherals/one_drive_connection_validator_spec.rb b/modules/storages/spec/common/storages/peripherals/one_drive_connection_validator_spec.rbindex 6aed3e2cf69..861b616571b 100644--- a/modules/storages/spec/common/storages/peripherals/one_drive_connection_validator_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/one_drive_connection_validator_spec.rb@@ -98,6 +98,24 @@ RSpec.describe Storages::Peripherals::OneDriveConnectionValidator doendend+ context "if the storage's drive id is malformed" do+ let(:error_payload) do+ {+ error: {+ code: "invalidRequest",+ message: "The provided drive id appears to be malformed, or does not represent a valid drive."+ }+ }+ end+ let(:response) { build_failure(code: :error, payload: error_payload) }++ it "returns a validation failure" do+ expect(subject.type).to eq(:error)+ expect(subject.error_code).to eq(:err_drive_invalid)+ expect(subject.description).to eq("The configured drive id could not be found. Please check the configuration.")+ end+ end+context "if the request fails with an unknown error" dolet(:response) { build_failure(code: :error, payload: nil) }diff --git a/modules/storages/spec/contracts/storages/storages/one_drive_contract_spec.rb b/modules/storages/spec/contracts/storages/storages/one_drive_contract_spec.rbindex b40600e4aa9..6f5b28e3e9b 100644--- a/modules/storages/spec/contracts/storages/storages/one_drive_contract_spec.rb+++ b/modules/storages/spec/contracts/storages/storages/one_drive_contract_spec.rb@@ -49,13 +49,33 @@ RSpec.describe Storages::Storages::OneDriveContract, :storage_server_helpers, :wendend+ context "with tenant that is no UUID" do+ let(:storage) { build(:one_drive_storage, tenant_id: "123") }++ it "is invalid" do+ expect(contract).not_to be_valid++ expect(contract.errors[:tenant_id]).to eq(["is invalid."])+ end+ end+context "with blank Drive ID" dolet(:storage) { build(:one_drive_storage, drive_id: "") }it "is invalid" doexpect(contract).not_to be_valid- expect(contract.errors[:drive_id]).to eq(["can't be blank."])+ expect(contract.errors[:drive_id]).to eq(["can't be blank.", "is too short (minimum is 17 characters)."])+ end+ end++ context "with short Drive ID" do+ let(:storage) { build(:one_drive_storage, drive_id: "1234567890") }++ it "is invalid" do+ expect(contract).not_to be_valid++ expect(contract.errors[:drive_id]).to eq(["is too short (minimum is 17 characters)."])endendend