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

[#53622] fixed unit tests

Eric Schuberta2e052421e33
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb
index 5a74dcdc87d..fa40a136097 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb
@@ -33,14 +33,14 @@ module Storages
module StorageInteraction
module Nextcloud
class OpenFileLinkQuery
- def initialize(storage)
- @storage = storage.uri
- end
-
def self.call(storage:, auth_strategy:, file_id:, open_location: false)
new(storage).call(auth_strategy:, file_id:, open_location:)
end
+ def initialize(storage)
+ @storage = storage
+ end
+
# rubocop:disable Lint/UnusedMethodArgument
def call(auth_strategy:, file_id:, open_location: false)
location_flag = open_location ? 0 : 1
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb
index 6eaa679f052..498d2a8a8fc 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb
@@ -61,13 +61,13 @@ module Storages
ServiceResult.success(result: response.json(symbolize_keys: true))
in { status: 404 }
ServiceResult.failure(result: :not_found,
- errors: Util.storage_error(response:, code: :not_found, source: self))
+ errors: Util.storage_error(response:, code: :not_found, source: self.class))
in { status: 403 }
ServiceResult.failure(result: :forbidden,
- errors: Util.storage_error(response:, code: :forbidden, source: self))
+ errors: Util.storage_error(response:, code: :forbidden, source: self.class))
in { status: 401 }
ServiceResult.failure(result: :unauthorized,
- errors: Util.storage_error(response:, code: :unauthorized, source: self))
+ errors: Util.storage_error(response:, code: :unauthorized, source: self.class))
else
data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
ServiceResult.failure(result: :error, errors: ::Storages::StorageError.new(code: :error, data:))
diff --git a/modules/storages/lib/api/v3/file_links/file_links_open_api.rb b/modules/storages/lib/api/v3/file_links/file_links_open_api.rb
index 2368aaf8e0a..a5370269f03 100644
--- a/modules/storages/lib/api/v3/file_links/file_links_open_api.rb
+++ b/modules/storages/lib/api/v3/file_links/file_links_open_api.rb
@@ -33,7 +33,7 @@ class API::V3::FileLinks::FileLinksOpenAPI < API::OpenProjectAPI
resources :open do
get do
- auth_strategy = Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
+ auth_strategy = Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
.strategy
.with_user(current_user)
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query_spec.rb
index 584f7ce1ee7..757647cc4e4 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query_spec.rb
@@ -33,23 +33,26 @@ require_module_spec_helper
RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::OpenFileLinkQuery do
let(:storage) { create(:nextcloud_storage, host: "https://example.com") }
- let(:user) { create(:user) }
let(:file_id) { "1337" }
+ let(:auth_strategy) { Storages::Peripherals::StorageInteraction::AuthenticationStrategies::BasicAuth.strategy }
it "responds to .call" do
expect(described_class).to respond_to(:call)
method = described_class.method(:call)
- expect(method.parameters).to contain_exactly(%i[keyreq storage], %i[keyreq user], %i[keyreq file_id], %i[key open_location])
+ expect(method.parameters).to contain_exactly(%i[keyreq storage],
+ %i[keyreq auth_strategy],
+ %i[keyreq file_id],
+ %i[key open_location])
end
it "returns the url for opening the file on storage" do
- url = described_class.call(storage:, user:, file_id:).result
+ url = described_class.call(storage:, auth_strategy:, file_id:).result
expect(url).to eq("#{storage.host}/index.php/f/#{file_id}?openfile=1")
end
it "returns the url for opening the file's location on storage" do
- url = described_class.call(storage:, user:, file_id:, open_location: true).result
+ url = described_class.call(storage:, auth_strategy:, file_id:, open_location: true).result
expect(url).to eq("#{storage.host}/index.php/f/#{file_id}?openfile=0")
end
@@ -57,7 +60,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::OpenFileLin
let(:storage) { create(:nextcloud_storage, host: "https://example.com/html") }
it "returns the url for opening the file on storage" do
- url = described_class.call(storage:, user:, file_id:).result
+ url = described_class.call(storage:, auth_strategy:, file_id:).result
expect(url).to eq("#{storage.host}/index.php/f/#{file_id}?openfile=1")
end
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb
index b8fec04296c..296eb94e5b3 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb
@@ -57,26 +57,5 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::OpenStorageQ
expect(call.result).to eq("https://finn.sharepoint.com/sites/openprojectfilestoragetests/VCR")
end
end
-
- context "with not existent oauth token" do
- let(:user_without_token) { create(:user) }
- let(:auth_strategy) do
- Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
- .strategy
- .with_user(user_without_token)
- end
-
- it "must return unauthorized when called" do
- result = subject.call(auth_strategy:)
- expect(result).to be_failure
- expect(result.error_source)
- .to be(Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken)
-
- result.match(
- on_failure: ->(error) { expect(error.code).to eq(:unauthorized) },
- on_success: ->(file_infos) { fail "Expected failure, got #{file_infos}" }
- )
- end
- end
end
end