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

[#54553] reworked queries for upload link

Eric Schubertf7526408febe
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb
index 85b5df7ad9a..d3b2d37e099 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb
@@ -26,51 +26,56 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud::Internal
- class DeleteEntityCommand
- Util = ::Storages::Peripherals::StorageInteraction::Nextcloud::Util
- Auth = ::Storages::Peripherals::StorageInteraction::Authentication
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ module Internal
+ class DeleteEntityCommand
+ def self.call(storage:, auth_strategy:, location:)
+ new(storage).call(auth_strategy:, location:)
+ end
- def self.call(storage:, auth_strategy:, location:)
- new(storage).call(auth_strategy:, location:)
- end
-
- def initialize(storage)
- @storage = storage
- end
+ def initialize(storage)
+ @storage = storage
+ end
- def call(auth_strategy:, location:)
- origin_user_id = Util.origin_user_id(caller: self.class, storage: @storage, auth_strategy:)
- if origin_user_id.failure?
- return origin_user_id
- end
+ def call(auth_strategy:, location:)
+ origin_user_id = Util.origin_user_id(caller: self.class, storage: @storage, auth_strategy:)
+ if origin_user_id.failure?
+ return origin_user_id
+ end
- Auth[auth_strategy].call(storage: @storage) do |http|
- handle_response http.delete(Util.join_uri_path(@storage.uri,
- "remote.php/dav/files",
- CGI.escapeURIComponent(origin_user_id.result),
- Util.escape_path(location)))
- end
- end
+ Authentication[auth_strategy].call(storage: @storage) do |http|
+ handle_response http.delete(Util.join_uri_path(@storage.uri,
+ "remote.php/dav/files",
+ CGI.escapeURIComponent(origin_user_id.result),
+ Util.escape_path(location)))
+ end
+ end
- private
+ private
- def handle_response(response)
- case response
- in { status: 200..299 }
- ServiceResult.success
- in { status: 404 }
- Util.failure(code: :not_found,
- data: Util.error_data_from_response(caller: self.class, response:),
- log_message: "Outbound request destination not found!")
- in { status: 401 }
- Util.failure(code: :unauthorized,
- data: Util.error_data_from_response(caller: self.class, response:),
- log_message: "Outbound request not authorized!")
- else
- Util.failure(code: :error,
- data: Util.error_data_from_response(caller: self.class, response:),
- log_message: "Outbound request failed with unknown error!")
+ def handle_response(response)
+ case response
+ in { status: 200..299 }
+ ServiceResult.success
+ in { status: 404 }
+ Util.failure(code: :not_found,
+ data: Util.error_data_from_response(caller: self.class, response:),
+ log_message: "Outbound request destination not found!")
+ in { status: 401 }
+ Util.failure(code: :unauthorized,
+ data: Util.error_data_from_response(caller: self.class, response:),
+ log_message: "Outbound request not authorized!")
+ else
+ Util.failure(code: :error,
+ data: Util.error_data_from_response(caller: self.class, response:),
+ log_message: "Outbound request failed with unknown error!")
+ end
+ end
+ end
+ end
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
index 256dd3711e6..31e66bfe79c 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
@@ -28,68 +28,72 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class UploadLinkQuery
- using Storages::Peripherals::ServiceResultRefinements
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ class UploadLinkQuery
+ using ServiceResultRefinements
- URI_TOKEN_REQUEST = "index.php/apps/integration_openproject/direct-upload-token"
- URI_UPLOAD_BASE_PATH = "index.php/apps/integration_openproject/direct-upload"
+ def self.call(storage:, auth_strategy:, upload_data:)
+ new(storage).call(auth_strategy:, upload_data:)
+ end
- def initialize(storage)
- @uri = storage.uri
- @configuration = storage.oauth_configuration
- end
+ def initialize(storage)
+ @storage = storage
+ end
- def self.call(storage:, user:, data:)
- new(storage).call(user:, data:)
- end
+ def call(auth_strategy:, upload_data:)
+ return upload_data_failure if invalid?(upload_data:)
+
+ Authentication[auth_strategy].call(storage: @storage) do |http|
+ response = http.post(base_uri, json: payload_from(upload_data:))
- def call(user:, data:)
- Util.token(user:, configuration: @configuration) do |token|
- if data.nil? || data["parent"].nil?
- Util.error(:error, "Data is invalid", data)
- else
- outbound_response(
- relative_path: URI_TOKEN_REQUEST,
- payload: { folder_id: data["parent"] },
- token:
- ).map do |response|
- Storages::UploadLink.new(
- URI.parse(Util.join_uri_path(@uri, URI_UPLOAD_BASE_PATH, response.token))
- )
+ handle_response(response).map do |rsp|
+ UploadLink.new(URI("#{upload_base_uri}/#{rsp[:token]}"), :post)
+ end
+ end
end
- end
- end
- end
- private
+ private
+
+ def base_uri = "#{@storage.uri}index.php/apps/integration_openproject/direct-upload-token"
- def outbound_response(relative_path:, payload:, token:)
- response = OpenProject
- .httpx
- .with(headers: { "Authorization" => "Bearer #{token.access_token}",
- "Accept" => "application/json",
- "Content-Type" => "application/json" })
- .post(
- Util.join_uri_path(@uri, relative_path),
- json: payload
- )
- case response
- in { status: 200..299 }
- # The nextcloud API returns a successful response with empty body if the authorization is missing or expired
- if response.body.present?
- ServiceResult.success(
- result: JSON.parse(response.body.to_s, object_class: OpenStruct) # rubocop:disable Style/OpenStructUse
- )
- else
- Util.error(:unauthorized, "Outbound request not authorized!")
+ def upload_base_uri = "#{@storage.uri}index.php/apps/integration_openproject/direct-upload"
+
+ def upload_data_failure
+ Util.failure(code: :error,
+ data: StorageErrorData.new(source: self.class),
+ log_message: "Invalid upload data!")
+ end
+
+ def invalid?(upload_data:)
+ upload_data.folder_id.blank? || upload_data.file_name.blank?
+ end
+
+ def payload_from(upload_data:)
+ { folder_id: upload_data.folder_id }
+ end
+
+ def handle_response(response)
+ case response
+ in { status: 200..299 }
+ ServiceResult.success(result: response.json(symbolize_keys: true))
+ in { status: 404 }
+ Util.failure(code: :not_found,
+ data: Util.error_data_from_response(caller: self.class, response:),
+ log_message: "Outbound request destination not found!")
+ in { status: 401 }
+ Util.failure(code: :unauthorized,
+ data: Util.error_data_from_response(caller: self.class, response:),
+ log_message: "Outbound request not authorized!")
+ else
+ Util.failure(code: :error,
+ data: Util.error_data_from_response(caller: self.class, response:),
+ log_message: "Outbound request failed with unknown error!")
+ end
+ end
end
- in { status: 404 }
- Util.error(:not_found, "Outbound request destination not found!", response)
- in { status: 401 }
- Util.error(:unauthorized, "Outbound request not authorized!", response)
- else
- Util.error(:error, "Outbound request failed!")
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb
index 67a38616255..6a1745cb17c 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb
@@ -28,99 +28,108 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud::Util
- using Storages::Peripherals::ServiceResultRefinements
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ module Util
+ using ServiceResultRefinements
- class << self
- def escape_path(path)
- escaped_path = path.split("/").map { |i| CGI.escapeURIComponent(i) }.join("/")
- escaped_path << "/" if path[-1] == "/"
- escaped_path
- end
+ class << self
+ def escape_path(path)
+ escaped_path = path.split("/").map { |i| CGI.escapeURIComponent(i) }.join("/")
+ escaped_path << "/" if path[-1] == "/"
+ escaped_path
+ end
- def ocs_api_request
- { headers: { "OCS-APIRequest" => "true" } }
- end
+ def ocs_api_request
+ { headers: { "OCS-APIRequest" => "true" } }
+ end
- def accept_json
- { headers: { "Accept" => "application/json" } }
- end
+ def accept_json
+ { headers: { "Accept" => "application/json" } }
+ end
- def webdav_request_with_depth(number)
- { headers: { "Depth" => number } }
- end
+ def webdav_request_with_depth(number)
+ { headers: { "Depth" => number } }
+ end
- def error(code, log_message = nil, data = nil)
- ServiceResult.failure(
- result: code, # This is needed to work with the ConnectionManager token refresh mechanism.
- errors: Storages::StorageError.new(code:, log_message:, data:)
- )
- end
+ def error(code, log_message = nil, data = nil)
+ ServiceResult.failure(
+ result: code, # This is needed to work with the ConnectionManager token refresh mechanism.
+ errors: StorageError.new(code:, log_message:, data:)
+ )
+ end
- def join_uri_path(uri, *)
- # We use `File.join` to ensure single `/` in between every part. This API will break if executed on a
- # Windows context, as it used `\` as file separators. But we anticipate that OpenProject
- # Server is not run on a Windows context.
- # URI::join cannot be used, as it behaves very different for the path parts depending on trailing slashes.
- File.join(uri.to_s, *)
- end
+ def join_uri_path(uri, *)
+ # We use `File.join` to ensure single `/` in between every part. This API will break if executed on a
+ # Windows context, as it used `\` as file separators. But we anticipate that OpenProject
+ # Server is not run on a Windows context.
+ # URI::join cannot be used, as it behaves very different for the path parts depending on trailing slashes.
+ File.join(uri.to_s, *)
+ end
- def token(user:, configuration:, &)
- connection_manager = ::OAuthClients::ConnectionManager.new(user:, configuration:)
- connection_manager.get_access_token.match(
- on_success: ->(token) do
- connection_manager.request_with_token_refresh(token) { yield token }
- end,
- on_failure: ->(_) do
- error(:unauthorized,
- "Query could not be created! No access token found!",
- Storages::StorageErrorData.new(source: connection_manager))
- end
- )
- end
+ def token(user:, configuration:, &)
+ connection_manager = OAuthClients::ConnectionManager.new(user:, configuration:)
+ connection_manager.get_access_token.match(
+ on_success: ->(token) do
+ connection_manager.request_with_token_refresh(token) { yield token }
+ end,
+ on_failure: ->(_) do
+ error(:unauthorized,
+ "Query could not be created! No access token found!",
+ StorageErrorData.new(source: connection_manager))
+ end
+ )
+ end
- def error_text_from_response(response)
- response.xml.xpath("//s:message").text
- end
+ def error_text_from_response(response)
+ response.xml.xpath("//s:message").text
+ end
- def origin_user_id(caller:, storage:, auth_strategy:)
- case auth_strategy.key
- when :basic_auth
- ServiceResult.success(result: storage.username)
- when :oauth_user_token
- origin_user_id = OAuthClientToken.where(user_id: auth_strategy.user, oauth_client: storage.oauth_client)
- .pick(:origin_user_id)
- if origin_user_id.present?
- ServiceResult.success(result: origin_user_id)
- else
- failure(code: :error,
- data: ::Storages::StorageErrorData.new(source: caller),
- log_message: "No origin user ID or user token found. Cannot execute query without user context.")
- end
- else
- failure(code: :error,
- data: ::Storages::StorageErrorData.new(source: caller),
- log_message: "No authentication strategy with user context found. " \
- "Cannot execute query without user context.")
- end
- end
+ def origin_user_id(caller:, storage:, auth_strategy:)
+ case auth_strategy.key
+ when :basic_auth
+ ServiceResult.success(result: storage.username)
+ when :oauth_user_token
+ origin_user_id = OAuthClientToken.where(user_id: auth_strategy.user, oauth_client: storage.oauth_client)
+ .pick(:origin_user_id)
+ if origin_user_id.present?
+ ServiceResult.success(result: origin_user_id)
+ else
+ failure(code: :error,
+ data: StorageErrorData.new(source: caller),
+ log_message:
+ "No origin user ID or user token found. Cannot execute query without user context.")
+ end
+ else
+ failure(code: :error,
+ data: StorageErrorData.new(source: caller),
+ log_message: "No authentication strategy with user context found. " \
+ "Cannot execute query without user context.")
+ end
+ end
- def error_data_from_response(caller:, response:)
- payload =
- case response.content_type.mime_type
- when "application/json"
- response.json
- when "text/xml", "application/xml"
- response.xml
- else
- response.body.to_s
- end
+ def error_data_from_response(caller:, response:)
+ payload =
+ case response.content_type.mime_type
+ when "application/json"
+ response.json
+ when "text/xml", "application/xml"
+ response.xml
+ else
+ response.body.to_s
+ end
- ::Storages::StorageErrorData.new(source: caller, payload:)
- end
+ StorageErrorData.new(source: caller, payload:)
+ end
- def failure(code:, data:, log_message:)
- ServiceResult.failure(result: code, errors: ::Storages::StorageError.new(code:, data:, log_message:))
+ def failure(code:, data:, log_message:)
+ ServiceResult.failure(result: code, errors: StorageError.new(code:, data:, log_message:))
+ end
+ end
+ end
+ end
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
index 787ad49efac..166eaab54bf 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
@@ -33,8 +33,6 @@ module Storages
module StorageInteraction
module OneDrive
class DeleteFolderCommand
- Auth = ::Storages::Peripherals::StorageInteraction::Authentication
-
def self.call(storage:, auth_strategy:, location:)
new(storage).call(auth_strategy:, location:)
end
@@ -44,29 +42,34 @@ module Storages
end
def call(auth_strategy:, location:)
- Auth[auth_strategy].call(storage: @storage) do |http|
- response = http.delete(
- Util.join_uri_path(@storage.uri, "/v1.0/drives/#{@storage.drive_id}/items/#{location}"))
+ Authentication[auth_strategy].call(storage: @storage) do |http|
+ handle_response http.delete(
+ Util.join_uri_path(@storage.uri, "/v1.0/drives/#{@storage.drive_id}/items/#{location}")
+ )
+ end
+ end
+
+ private
- data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
+ def handle_response(response)
+ data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
- case response
- in { status: 200..299 }
- # The service returns a 204 with an empty body
- ServiceResult.success
- in { status: 401 }
- ServiceResult.failure(result: :unauthorized,
- errors: ::Storages::StorageError.new(code: :unauthorized, data:))
- in { status: 404 }
- ServiceResult.failure(result: :not_found,
- errors: ::Storages::StorageError.new(code: :not_found, data:))
- in { status: 409 }
- ServiceResult.failure(result: :conflict,
- errors: ::Storages::StorageError.new(code: :conflict, data:))
- else
- ServiceResult.failure(result: :error,
- errors: ::Storages::StorageError.new(code: :error, data:))
- end
+ case response
+ in { status: 200..299 }
+ # The service returns a 204 with an empty body
+ ServiceResult.success
+ in { status: 401 }
+ ServiceResult.failure(result: :unauthorized,
+ errors: ::Storages::StorageError.new(code: :unauthorized, data:))
+ in { status: 404 }
+ ServiceResult.failure(result: :not_found,
+ errors: ::Storages::StorageError.new(code: :not_found, data:))
+ in { status: 409 }
+ ServiceResult.failure(result: :conflict,
+ errors: ::Storages::StorageError.new(code: :conflict, data:))
+ else
+ ServiceResult.failure(result: :error,
+ errors: ::Storages::StorageError.new(code: :error, data:))
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
index fae746357b7..ef604efcff0 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
@@ -33,26 +33,22 @@ module Storages
module StorageInteraction
module OneDrive
class UploadLinkQuery
- def initialize(storage)
- @storage = storage
- @uri = storage.uri
+ def self.call(storage:, auth_strategy:, upload_data:)
+ new(storage).call(auth_strategy:, upload_data:)
end
- def self.call(storage:, user:, data:)
- new(storage).call(user:, data:)
+ def initialize(storage)
+ @storage = storage
end
- def call(user:, data:)
- folder, filename = data.slice("parent", "file_name").values
+ def call(auth_strategy:, upload_data:)
+ return upload_data_failure if invalid?(upload_data:)
- Util.using_user_token(@storage, user) do |token|
- response = OpenProject.httpx
- .with(headers: { "Authorization" => "Bearer #{token.access_token}",
- "Content-Type" => "application/json" })
- .post(
- Util.join_uri_path(@uri, uri_path_for(folder, filename)),
- json: payload(filename)
- )
+ Authentication[auth_strategy].call(storage: @storage) do |http|
+ response = http.post(
+ Util.join_uri_path(@storage.uri, uri_path_for(upload_data.folder_id, upload_data.file_name)),
+ json: payload(upload_data.file_name)
+ )
handle_response(response)
end
@@ -60,26 +56,36 @@ module Storages
private
+ def upload_data_failure
+ Util.failure(code: :error,
+ data: StorageErrorData.new(source: self.class),
+ log_message: "Invalid upload data!")
+ end
+
+ def invalid?(upload_data:)
+ upload_data.folder_id.blank? || upload_data.file_name.blank?
+ end
+
def payload(filename)
{ item: { "@microsoft.graph.conflictBehavior" => "rename", name: filename } }
end
def handle_response(response)
- data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
+ data = StorageErrorData.new(source: self.class, payload: response)
case response
in { status: 200..299 }
upload_url = response.json(symbolize_keys: true)[:uploadUrl]
- ServiceResult.success(result: ::Storages::UploadLink.new(URI(upload_url), :put))
- in { status: 404 }
+ ServiceResult.success(result: UploadLink.new(URI(upload_url), :put))
+ in { status: 404 | 400 } # not existent parent folder in request url is responded with 400
ServiceResult.failure(result: :not_found,
- errors: ::Storages::StorageError.new(code: :not_found, data:))
+ errors: StorageError.new(code: :not_found, data:))
in { status: 401 }
ServiceResult.failure(result: :unauthorized,
- errors: ::Storages::StorageError.new(code: :unauthorized, data:))
+ errors: StorageError.new(code: :unauthorized, data:))
else
ServiceResult.failure(result: :error,
- errors: ::Storages::StorageError.new(code: :error, data:))
+ errors: StorageError.new(code: :error, data:))
end
end
diff --git a/modules/storages/app/models/storages/upload_data.rb b/modules/storages/app/models/storages/upload_data.rb
new file mode 100644
index 00000000000..979636f8c86
--- /dev/null
+++ b/modules/storages/app/models/storages/upload_data.rb
@@ -0,0 +1,31 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Storages
+ UploadData = Data.define(:folder_id, :file_name)
+end
diff --git a/modules/storages/app/models/storages/upload_link.rb b/modules/storages/app/models/storages/upload_link.rb
index 7e27db1c493..efb1b64c8ae 100644
--- a/modules/storages/app/models/storages/upload_link.rb
+++ b/modules/storages/app/models/storages/upload_link.rb
@@ -26,11 +26,6 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Storages::UploadLink
- attr_reader :destination, :method
-
- def initialize(destination = "", method = :post)
- @destination = destination
- @method = method
- end
+module Storages
+ UploadLink = Data.define(:destination, :method)
end
diff --git a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
index e2e8689a65d..107dc71a242 100644
--- a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
+++ b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
@@ -45,7 +45,7 @@ module API::V3::StorageFiles
case body.transform_keys(&:to_sym)
in { projectId: project_id, fileName: file_name, parent: parent }
authorize_in_project(:manage_file_links, project: Project.find(project_id))
- ServiceResult.success(result: { file_name:, parent: }.transform_keys(&:to_s))
+ ServiceResult.success(result: Storages::UploadData.new(folder_id: parent, file_name:))
else
ServiceResult.failure(errors: Storages::StorageError.new(code: :bad_request,
log_message: "Request body malformed!"))
@@ -53,10 +53,10 @@ module API::V3::StorageFiles
end
def fetch_upload_link
- ->(data) do
+ ->(upload_data) do
Storages::Peripherals::Registry
.resolve("#{@storage.short_provider_type}.queries.upload_link")
- .call(storage: @storage, user: current_user, data:)
+ .call(storage: @storage, auth_strategy:, upload_data:)
end
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query_spec.rb
index 30344962814..23c6825eb2a 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query_spec.rb
@@ -32,57 +32,35 @@ require "spec_helper"
require_module_spec_helper
RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::UploadLinkQuery, :webmock do
- let(:storage) { create(:nextcloud_storage, :with_oauth_client) }
- let(:token) { create(:oauth_client_token, oauth_client: storage.oauth_client) }
- let(:user) { token.user }
- let(:url) { storage.uri.to_s }
-
- let(:query_payload) { Struct.new(:parent).new(42) }
- let(:upload_token) { "valid-token" }
-
- subject(:query) { described_class }
-
- before do
- allow(Storages::Peripherals::StorageInteraction::Nextcloud::Util).to receive(:token).and_yield(token)
- stub_request(:post, "#{url}index.php/apps/integration_openproject/direct-upload-token")
- .with(body: { folder_id: query_payload.parent })
- .to_return(status: 200, body: { token: upload_token, expires_on: 1673883865 }.to_json)
+ let(:user) { create(:user) }
+ let(:storage) do
+ create(:nextcloud_storage_with_local_connection, :as_not_automatically_managed, oauth_client_token_user: user)
end
-
- it ".call requires 3 arguments: storage, user, and data" 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 data])
+ let(:auth_strategy) do
+ Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken.strategy.with_user(user)
end
- it "must return an upload link URL" do
- link = query.call(storage:, user:, data: query_payload).result
- expect(link.destination.path).to eql("/index.php/apps/integration_openproject/direct-upload/#{upload_token}")
- expect(link.destination.host).to eql(URI(url).host)
- expect(link.destination.scheme).to eql(URI(url).scheme)
- expect(link.destination.user).to be_nil
- expect(link.destination.password).to be_nil
- expect(link.method).to eq(:post)
- end
+ it_behaves_like "upload_link_query: basic query setup"
- shared_examples_for "outbound is failing" do |code, symbol|
- describe "with outbound request returning #{code}" do
- before do
- stub_request(:post, "#{url}index.php/apps/integration_openproject/direct-upload-token").and_return(status: code)
- end
+ it_behaves_like "upload_link_query: validating input data"
- it "must return :#{symbol} ServiceResult" do
- result = query.call(storage:, user:, data: query_payload)
-
- expect(result).to be_failure
- expect(result.errors.code).to be(symbol)
- end
+ context "when requesting an upload link for an existing file", vcr: "nextcloud/upload_link_success" do
+ let(:upload_data) do
+ Storages::UploadData.new(folder_id: "169", file_name: "DeathStart_blueprints.tiff")
end
+ let(:token) { "SrQJeC5zM3B5Gw64d7dEQFQpFw8YBAtZWoxeLb59AR7PpGPyoGAkAko5G6ZiZ2HA" }
+ let(:upload_url) { "https://nextcloud.local/index.php/apps/integration_openproject/direct-upload/#{token}" }
+ let(:upload_method) { :post }
+
+ it_behaves_like "upload_link_query: successful upload link response"
end
- include_examples "outbound is failing", 400, :error
- include_examples "outbound is failing", 401, :unauthorized
- include_examples "outbound is failing", 404, :not_found
- include_examples "outbound is failing", 500, :error
+ context "when requesting an upload link for a not existing file", vcr: "nextcloud/upload_link_not_found" do
+ let(:upload_data) do
+ Storages::UploadData.new(folder_id: "1337", file_name: "DeathStart_blueprints.tiff")
+ end
+ let(:error_source) { described_class }
+
+ it_behaves_like "upload_link_query: not found"
+ end
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/upload_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/upload_link_query_spec.rb
index 0b36c3d2318..414b0a1ad49 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/upload_link_query_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/upload_link_query_spec.rb
@@ -32,63 +32,47 @@ require "spec_helper"
require_module_spec_helper
RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::UploadLinkQuery, :webmock do
- let(:storage) { create(:one_drive_storage, :with_oauth_client, drive_id: "b!~bunchOfLettersAndNumb3rs") }
- let(:token) { create(:oauth_client_token, oauth_client: storage.oauth_client) }
- let(:user) { token.user }
-
- # Need to verify the actual object
- let(:query_payload) { { "parent" => "LFHLUDSILANC", "file_name" => "it_is_a_trap.flac" } }
-
- subject(:upload_query) { described_class.new(storage) }
-
- before do
- stub_request(
- :post,
- "https://graph.microsoft.com/v1.0/drives/b!~bunchOfLettersAndNumb3rs/items/LFHLUDSILANC:/it_is_a_trap.flac:/createUploadSession"
- ).with(
- headers: { "Authorization" => "Bearer #{token.access_token}", "Content-Type" => "application/json" },
- body: { item: { "@microsoft.graph.conflictBehavior" => "rename", name: query_payload["file_name"] } }
- ).to_return(
- status: 200,
- headers: { "Content-Type" => "application/json" },
- body: { uploadUrl: "https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337",
- expirationDateTime: "2015-01-29T09:21:55.523Z" }.to_json
- )
+ let(:storage) { create(:sharepoint_dev_drive_storage) }
+ let(:auth_strategy) do
+ Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthClientCredentials.strategy
end
- it ".call requires 3 arguments: storage, user, and data" do
- expect(described_class).to respond_to(:call)
+ it_behaves_like "upload_link_query: basic query setup"
- method = described_class.method(:call)
- expect(method.parameters).to contain_exactly(%i[keyreq storage], %i[keyreq user], %i[keyreq data])
- end
+ it_behaves_like "upload_link_query: validating input data"
- it "must return an upload link URL" do
- link = upload_query.call(user:, data: query_payload).result
+ context "when requesting an upload link for an existing file", vcr: "one_drive/upload_link_success" do
+ let(:upload_data) do
+ Storages::UploadData.new(folder_id: "01AZJL5PN6Y2GOVW7725BZO354PWSELRRZ", file_name: "DeathStart_blueprints.tiff")
+ end
+ let(:token) do
+ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBfZGlzcGxheW5hbWUiOiJPcGVuUHJvamVjdCBEZXYgQXBwIiwiYXVkIjoiMDAwMDA" \
+ "wMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwL2Zpbm4uc2hhcmVwb2ludC5jb21ANGQ0NGJmMzYtOWI1Ni00NWMwLTg4MDctYmJmMzg" \
+ "2ZGQwNDdmIiwiY2lkIjoiR3k0SDY0aTF2MEN6NXVxU0tDTkNodz09IiwiZW5kcG9pbnR1cmwiOiJ6cFdrZGttVmxSUEZYRG55eWVmb0thaUg" \
+ "ycFhmV0RUdmkvNTVReHVYSlAwPSIsImVuZHBvaW50dXJsTGVuZ3RoIjoiMjc3IiwiZXhwIjoiMTcxNTA5MjYxOCIsImlwYWRkciI6IjIwLjE" \
+ "5MC4xOTAuMTAwIiwiaXNsb29wYmFjayI6IlRydWUiLCJpc3MiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAiLCJuYW1" \
+ "laWQiOiI0MjYyZGYyYi03N2JiLTQ5YzItYTVkZi0yODM1NWRhNjc2ZDJANGQ0NGJmMzYtOWI1Ni00NWMwLTg4MDctYmJmMzg2ZGQwNDdmIiw" \
+ "ibmJmIjoiMTcxNTAwNjIxOCIsInJvbGVzIjoiYWxsc2l0ZXMucmVhZCBhbGxzaXRlcy53cml0ZSBhbGxmaWxlcy53cml0ZSIsInNpdGVpZCI" \
+ "6Ik1XSTBZalkxTnpZdE9UQTJaQzAwWkRrMExUaG1ORGt0Tm1Rd01HRTVOVEEzWWpVdyIsInR0IjoiMSIsInZlciI6Imhhc2hlZHByb29mdG9" \
+ "rZW4ifQ.UMqPAjuiXSt1rQgFiE0h-k3wkBZ3DmF3I3Nj_zYuYuI"
+ end
+ let(:upload_url) do
+ "https://finn.sharepoint.com/sites/openprojectfilestoragetests/_api/v2.0/drives/" \
+ "b!dmVLG22QlE2PSW0AqVB7UOhZ8n7tjkVGkgqLNnuw2OBb-brzKzZAR4DYT1k9KPXs/items/01AZJL5PKRK4XUJQQH3JHIUGK2ALGEJEK4/" \
+ "uploadSession?guid=%2789f10eb4-b8d9-4ba9-ab64-eb1e6d39b2ee%27&overwrite=False&rename=True&dc=0" \
+ "&tempauth=#{token}"
+ end
+ let(:upload_method) { :put }
- expect(link.destination).not_to be_nil
- expect(link.method).to eq(:put)
+ it_behaves_like "upload_link_query: successful upload link response"
end
- shared_examples_for "outbound is failing" do |code, symbol|
- describe "with outbound request returning #{code}" do
- before do
- stub_request(
- :post,
- "https://graph.microsoft.com/v1.0/drives/b!~bunchOfLettersAndNumb3rs/items/LFHLUDSILANC:/it_is_a_trap.flac:/createUploadSession"
- ).to_return(status: code)
- end
-
- it "must return :#{symbol} ServiceResult" do
- result = upload_query.call(user:, data: query_payload)
- expect(result).to be_failure
- expect(result.errors.code).to be(symbol)
- end
+ context "when requesting an upload link for a not existing file", vcr: "one_drive/upload_link_not_found" do
+ let(:upload_data) do
+ Storages::UploadData.new(folder_id: "04AZJL5PN6Y2GOVW7725BZO354PWSELRRZ", file_name: "DeathStart_blueprints.tiff")
end
- end
+ let(:error_source) { described_class }
- include_examples "outbound is failing", 400, :error
- include_examples "outbound is failing", 401, :unauthorized
- include_examples "outbound is failing", 404, :not_found
- include_examples "outbound is failing", 500, :error
+ it_behaves_like "upload_link_query: not found"
+ end
end
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/upload_link_not_found.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/upload_link_not_found.yml
new file mode 100644
index 00000000000..95561212f43
--- /dev/null
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/upload_link_not_found.yml
@@ -0,0 +1,81 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://nextcloud.local/index.php/apps/integration_openproject/direct-upload-token
+ body:
+ encoding: UTF-8
+ string: '{"folder_id":"1337"}'
+ headers:
+ Authorization:
+ - Bearer <BEARER TOKEN>
+ User-Agent:
+ - httpx.rb/1.2.4
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/json; charset=utf-8
+ Content-Length:
+ - '20'
+ response:
+ status:
+ code: 404
+ message: Not Found
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/json; charset=utf-8
+ Date:
+ - Mon, 06 May 2024 11:12:05 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=o33JRPalseuNRiLljFz48RATptI5WxIDBH2576Qd92Sf%2B9jkCDw%2FhDd1zftzb0J5cuM7BpwRx0jEHk0p7OtkL5WsP1VbuqaGfXYXADJYFpG2t2AmZA1YGOK%2FpK%2FpkXPx;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9a3a3251b7cbc187c00088e78e17bbff;
+ path=/; secure; HttpOnly; SameSite=Lax
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.18
+ X-Request-Id:
+ - 9fSF5aVVJdSy1S96TnLg
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '54'
+ body:
+ encoding: UTF-8
+ string: '{"error":"folder not found or not enough permissions"}'
+ recorded_at: Mon, 06 May 2024 11:12:05 GMT
+recorded_with: VCR 6.2.0
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/upload_link_success.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/upload_link_success.yml
new file mode 100644
index 00000000000..cda5daf12c6
--- /dev/null
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/upload_link_success.yml
@@ -0,0 +1,83 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://nextcloud.local/index.php/apps/integration_openproject/direct-upload-token
+ body:
+ encoding: UTF-8
+ string: '{"folder_id":"169"}'
+ headers:
+ Authorization:
+ - Bearer <BEARER TOKEN>
+ User-Agent:
+ - httpx.rb/1.2.4
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/json; charset=utf-8
+ Content-Length:
+ - '19'
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/json; charset=utf-8
+ Date:
+ - Mon, 06 May 2024 09:25:48 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=JA6XDklQ7fJ3p3ByU6FPE0zMDZWIsfKMqMVMTeYXZTxE85Mjz6dubPDY0KXgTIodJ1yvOdVecO53s7F%2BSezG8tZfXAI4IF9ZFg2u26ORsS0uj1kyqK%2FnwPVMNO%2BE7rgQ;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=5bdbb2c751d818cadef4274aa05639b9;
+ path=/; secure; HttpOnly; SameSite=Lax
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.18
+ X-Request-Id:
+ - D6jBXxuqooeclF8XBlxq
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '117'
+ body:
+ encoding: UTF-8
+ string: '{"token":"SrQJeC5zM3B5Gw64d7dEQFQpFw8YBAtZWoxeLb59AR7PpGPyoGAkAko5G6ZiZ2HA","expires_on":1714991149}'
+ recorded_at: Mon, 06 May 2024 09:25:49 GMT
+recorded_with: VCR 6.2.0
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/upload_link_not_found.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/upload_link_not_found.yml
new file mode 100644
index 00000000000..4a1b6e39648
--- /dev/null
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/upload_link_not_found.yml
@@ -0,0 +1,106 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://login.microsoftonline.com/4d44bf36-9b56-45c0-8807-bbf386dd047f/oauth2/v2.0/token
+ body:
+ encoding: ASCII-8BIT
+ string: grant_type=client_credentials&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default+offline_access&client_id=4262df2b-77bb-49c2-a5df-28355da676d2&client_secret=Vwk8Q%7EJTuPh.pAjvPiWBQBdTFMDK%7EAIwxbj9_axB
+ headers:
+ User-Agent:
+ - httpx.rb/1.2.4
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Content-Length:
+ - '201'
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-store, no-cache
+ Pragma:
+ - no-cache
+ Content-Type:
+ - application/json; charset=utf-8
+ Expires:
+ - "-1"
+ Strict-Transport-Security:
+ - max-age=31536000; includeSubDomains
+ X-Content-Type-Options:
+ - nosniff
+ P3p:
+ - CP="DSP CUR OTPi IND OTRi ONL FIN"
+ X-Ms-Request-Id:
+ - bbcb5b2b-2c31-467e-bb3d-7ddd09f70a00
+ X-Ms-Ests-Server:
+ - 2.1.17968.10 - SEC ProdSlices
+ X-Ms-Srs:
+ - 1.P
+ X-Xss-Protection:
+ - '0'
+ Set-Cookie:
+ - fpc=AlJjx-GtAfVJjLzlEBpmpwykbDoXAQAAAMXiyt0OAAAA; expires=Wed, 05-Jun-2024
+ 14:40:05 GMT; path=/; secure; HttpOnly; SameSite=None, x-ms-gateway-slice=estsfd;
+ path=/; secure; samesite=none; httponly, stsservicecookie=estsfd; path=/;
+ secure; samesite=none; httponly
+ Date:
+ - Mon, 06 May 2024 14:40:04 GMT
+ Content-Length:
+ - '1735'
+ body:
+ encoding: UTF-8
+ string: '{"token_type":"Bearer","expires_in":3599,"ext_expires_in":3599,"access_token":"<ACCESS_TOKEN>"}'
+ recorded_at: Mon, 06 May 2024 14:40:05 GMT
+- request:
+ method: post
+ uri: https://graph.microsoft.com/v1.0/drives/b!dmVLG22QlE2PSW0AqVB7UOhZ8n7tjkVGkgqLNnuw2OBb-brzKzZAR4DYT1k9KPXs/items/04AZJL5PN6Y2GOVW7725BZO354PWSELRRZ:/DeathStart_blueprints.tiff:/createUploadSession
+ body:
+ encoding: UTF-8
+ string: '{"item":{"@microsoft.graph.conflictBehavior":"rename","name":"DeathStart_blueprints.tiff"}}'
+ headers:
+ User-Agent:
+ - httpx.rb/1.2.4
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/json; charset=utf-8
+ Content-Length:
+ - '91'
+ Authorization:
+ - Bearer <BEARER TOKEN>
+ response:
+ status:
+ code: 400
+ message: Bad Request
+ headers:
+ Cache-Control:
+ - no-store, no-cache
+ Content-Type:
+ - application/json
+ Content-Encoding:
+ - gzip
+ Vary:
+ - Accept-Encoding
+ Strict-Transport-Security:
+ - max-age=31536000
+ Request-Id:
+ - 9411c047-d4e0-441c-a447-a036d36d1b23
+ Client-Request-Id:
+ - 9411c047-d4e0-441c-a447-a036d36d1b23
+ X-Ms-Ags-Diagnostic:
+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"001","RoleInstance":"FR2PEPF00000586"}}'
+ Date:
+ - Mon, 06 May 2024 14:40:04 GMT
+ body:
+ encoding: UTF-8
+ string: '{"error":{"code":"invalidRequest","message":"Invalid request","innerError":{"date":"2024-05-06T14:40:05","request-id":"9411c047-d4e0-441c-a447-a036d36d1b23","client-request-id":"9411c047-d4e0-441c-a447-a036d36d1b23"}}}'
+ recorded_at: Mon, 06 May 2024 14:40:05 GMT
+recorded_with: VCR 6.2.0
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/upload_link_success.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/upload_link_success.yml
new file mode 100644
index 00000000000..ccf0b4b6001
--- /dev/null
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/upload_link_success.yml
@@ -0,0 +1,110 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://login.microsoftonline.com/4d44bf36-9b56-45c0-8807-bbf386dd047f/oauth2/v2.0/token
+ body:
+ encoding: ASCII-8BIT
+ string: grant_type=client_credentials&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default+offline_access&client_id=4262df2b-77bb-49c2-a5df-28355da676d2&client_secret=Vwk8Q%7EJTuPh.pAjvPiWBQBdTFMDK%7EAIwxbj9_axB
+ headers:
+ User-Agent:
+ - httpx.rb/1.2.4
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Content-Length:
+ - '201'
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-store, no-cache
+ Pragma:
+ - no-cache
+ Content-Type:
+ - application/json; charset=utf-8
+ Expires:
+ - "-1"
+ Strict-Transport-Security:
+ - max-age=31536000; includeSubDomains
+ X-Content-Type-Options:
+ - nosniff
+ P3p:
+ - CP="DSP CUR OTPi IND OTRi ONL FIN"
+ X-Ms-Request-Id:
+ - 202eb04c-441d-4b12-a83c-5bea076c0400
+ X-Ms-Ests-Server:
+ - 2.1.17968.10 - FRC ProdSlices
+ X-Ms-Srs:
+ - 1.P
+ X-Xss-Protection:
+ - '0'
+ Set-Cookie:
+ - fpc=AiQhn5Bk5chBkGYr08ZixY6kbDoXAQAAAAniyt0OAAAA; expires=Wed, 05-Jun-2024
+ 14:36:57 GMT; path=/; secure; HttpOnly; SameSite=None, x-ms-gateway-slice=estsfd;
+ path=/; secure; samesite=none; httponly, stsservicecookie=estsfd; path=/;
+ secure; samesite=none; httponly
+ Date:
+ - Mon, 06 May 2024 14:36:57 GMT
+ Content-Length:
+ - '1735'
+ body:
+ encoding: UTF-8
+ string: '{"token_type":"Bearer","expires_in":3599,"ext_expires_in":3599,"access_token":"<ACCESS_TOKEN>"}'
+ recorded_at: Mon, 06 May 2024 14:36:57 GMT
+- request:
+ method: post
+ uri: https://graph.microsoft.com/v1.0/drives/b!dmVLG22QlE2PSW0AqVB7UOhZ8n7tjkVGkgqLNnuw2OBb-brzKzZAR4DYT1k9KPXs/items/01AZJL5PN6Y2GOVW7725BZO354PWSELRRZ:/DeathStart_blueprints.tiff:/createUploadSession
+ body:
+ encoding: UTF-8
+ string: '{"item":{"@microsoft.graph.conflictBehavior":"rename","name":"DeathStart_blueprints.tiff"}}'
+ headers:
+ User-Agent:
+ - httpx.rb/1.2.4
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/json; charset=utf-8
+ Content-Length:
+ - '91'
+ Authorization:
+ - Bearer <BEARER TOKEN>
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-store, no-cache
+ Content-Type:
+ - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
+ Content-Encoding:
+ - gzip
+ Location:
+ - https://graph.microsoft.com
+ Vary:
+ - Accept-Encoding
+ Strict-Transport-Security:
+ - max-age=31536000
+ Request-Id:
+ - eb072e1b-b588-40bf-b3e6-ea9228234287
+ Client-Request-Id:
+ - eb072e1b-b588-40bf-b3e6-ea9228234287
+ X-Ms-Ags-Diagnostic:
+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"001","RoleInstance":"FR2PEPF000001E9"}}'
+ Odata-Version:
+ - '4.0'
+ Date:
+ - Mon, 06 May 2024 14:36:58 GMT
+ body:
+ encoding: UTF-8
+ string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.uploadSession","expirationDateTime":"2024-05-06T14:51:58.48Z","nextExpectedRanges":["0-"],"uploadUrl":"https://finn.sharepoint.com/sites/openprojectfilestoragetests/_api/v2.0/drives/b!dmVLG22QlE2PSW0AqVB7UOhZ8n7tjkVGkgqLNnuw2OBb-brzKzZAR4DYT1k9KPXs/items/01AZJL5PKRK4XUJQQH3JHIUGK2ALGEJEK4/uploadSession?guid=''89f10eb4-b8d9-4ba9-ab64-eb1e6d39b2ee''&overwrite=False&rename=True&dc=0&tempauth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBfZGlzcGxheW5hbWUiOiJPcGVuUHJvamVjdCBEZXYgQXBwIiwiYXVkIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwL2Zpbm4uc2hhcmVwb2ludC5jb21ANGQ0NGJmMzYtOWI1Ni00NWMwLTg4MDctYmJmMzg2ZGQwNDdmIiwiY2lkIjoiR3k0SDY0aTF2MEN6NXVxU0tDTkNodz09IiwiZW5kcG9pbnR1cmwiOiJ6cFdrZGttVmxSUEZYRG55eWVmb0thaUgycFhmV0RUdmkvNTVReHVYSlAwPSIsImVuZHBvaW50dXJsTGVuZ3RoIjoiMjc3IiwiZXhwIjoiMTcxNTA5MjYxOCIsImlwYWRkciI6IjIwLjE5MC4xOTAuMTAwIiwiaXNsb29wYmFjayI6IlRydWUiLCJpc3MiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAiLCJuYW1laWQiOiI0MjYyZGYyYi03N2JiLTQ5YzItYTVkZi0yODM1NWRhNjc2ZDJANGQ0NGJmMzYtOWI1Ni00NWMwLTg4MDctYmJmMzg2ZGQwNDdmIiwibmJmIjoiMTcxNTAwNjIxOCIsInJvbGVzIjoiYWxsc2l0ZXMucmVhZCBhbGxzaXRlcy53cml0ZSBhbGxmaWxlcy53cml0ZSIsInNpdGVpZCI6Ik1XSTBZalkxTnpZdE9UQTJaQzAwWkRrMExUaG1ORGt0Tm1Rd01HRTVOVEEzWWpVdyIsInR0IjoiMSIsInZlciI6Imhhc2hlZHByb29mdG9rZW4ifQ.UMqPAjuiXSt1rQgFiE0h-k3wkBZ3DmF3I3Nj_zYuYuI"}'
+ recorded_at: Mon, 06 May 2024 14:36:58 GMT
+recorded_with: VCR 6.2.0
diff --git a/modules/storages/spec/support/shared_examples_for_adapters/upload_link_query_examples.rb b/modules/storages/spec/support/shared_examples_for_adapters/upload_link_query_examples.rb
new file mode 100644
index 00000000000..a04dab3d193
--- /dev/null
+++ b/modules/storages/spec/support/shared_examples_for_adapters/upload_link_query_examples.rb
@@ -0,0 +1,116 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+RSpec.shared_examples_for "upload_link_query: basic query setup" do
+ it "is registered as queries.upload_link" do
+ expect(Storages::Peripherals::Registry
+ .resolve("#{storage.short_provider_type}.queries.upload_link")).to eq(described_class)
+ end
+
+ it "responds to #call with correct parameters" do
+ expect(described_class).to respond_to(:call)
+
+ method = described_class.method(:call)
+ expect(method.parameters).to contain_exactly(%i[keyreq storage],
+ %i[keyreq auth_strategy],
+ %i[keyreq upload_data])
+ end
+end
+
+RSpec.shared_examples_for "upload_link_query: successful upload link response" do
+ it "returns an upload link" do
+ result = described_class.call(storage:, auth_strategy:, upload_data:)
+
+ expect(result).to be_success
+
+ response = result.result
+ expect(response).to be_a(Storages::UploadLink)
+ expect(response.destination).to be_a(URI)
+ expect(response.destination.to_s).to eq(upload_url)
+ expect(response.method).to eq(upload_method)
+ end
+end
+
+RSpec.shared_examples_for "upload_link_query: not found" do
+ it "returns a failure" do
+ result = described_class.call(storage:, auth_strategy:, upload_data:)
+
+ expect(result).to be_failure
+
+ error = result.errors
+ expect(error.code).to eq(:not_found)
+ expect(error.data.source).to eq(error_source)
+ end
+end
+
+RSpec.shared_examples_for "upload_link_query: error" do
+ it "returns a failure" do
+ result = described_class.call(storage:, auth_strategy:, upload_data:)
+
+ expect(result).to be_failure
+
+ error = result.errors
+ expect(error.code).to eq(:error)
+ expect(error.data.source).to eq(error_source)
+ end
+end
+
+RSpec.shared_examples_for "upload_link_query: validating input data" do
+ let(:upload_data) { Storages::UploadData.new(folder_id:, file_name:) }
+ let(:error_source) { described_class }
+
+ context "if folder id being empty" do
+ let(:folder_id) { "" }
+ let(:file_name) { "DeathStart_blueprints.tiff" }
+
+ it_behaves_like "upload_link_query: error"
+ end
+
+ context "if folder id being nil" do
+ let(:folder_id) { nil }
+ let(:file_name) { "DeathStart_blueprints.tiff" }
+
+ it_behaves_like "upload_link_query: error"
+ end
+
+ context "if file name being empty" do
+ let(:folder_id) { "42" }
+ let(:file_name) { "" }
+
+ it_behaves_like "upload_link_query: error"
+ end
+
+ context "if file name being nil" do
+ let(:folder_id) { "42" }
+ let(:file_name) { nil }
+
+ it_behaves_like "upload_link_query: error"
+ end
+end