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

[chore] replaced :not_authorized with :unauthorized

Eric Schubert639c258dc197
diff --git a/app/services/oauth_clients/connection_manager.rb b/app/services/oauth_clients/connection_manager.rb
index a523134e421..eefce9cd2f3 100644
--- a/app/services/oauth_clients/connection_manager.rb
+++ b/app/services/oauth_clients/connection_manager.rb
@@ -162,10 +162,10 @@ module OAuthClients
def request_with_token_refresh(oauth_client_token)
# `yield` needs to returns a ServiceResult:
# success: result= any object with data
- # failure: result= :error or :not_authorized
+ # failure: result= :error or :unauthorized
yield_service_result = yield(oauth_client_token)
- if yield_service_result.failure? && yield_service_result.result == :not_authorized
+ if yield_service_result.failure? && yield_service_result.result == :unauthorized
refresh_service_result = refresh_token
if refresh_service_result.failure?
failed_service_result = ServiceResult.failure(result: :error)
diff --git a/modules/storages/app/common/storages/peripherals/storage_error_helper.rb b/modules/storages/app/common/storages/peripherals/storage_error_helper.rb
index 2dfdb342c29..541cb4e7bb4 100644
--- a/modules/storages/app/common/storages/peripherals/storage_error_helper.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_error_helper.rb
@@ -42,20 +42,5 @@ module Storages::Peripherals
raise API::Errors::InternalError.new
end
end
-
- def error_to_code(error)
- case error.code
- when :bad_request
- 400
- when :not_authorized
- 401
- when :forbidden
- 403
- when :not_found
- 404
- else
- 500
- end
- end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb
index 9deed6e918a..f1c65488869 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb
@@ -71,7 +71,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPMethodNotAllowed
Util.error(:not_allowed)
when Net::HTTPUnauthorized
- Util.error(:not_authorized)
+ Util.error(:unauthorized)
when Net::HTTPNotFound
Util.error(:not_found)
when Net::HTTPConflict
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb
index 7b353f151dd..9956a28663c 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb
@@ -88,7 +88,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPSuccess
Util.error(:conflict, 'Destination folder already exists.')
when Net::HTTPUnauthorized
- Util.error(:not_authorized, "Not authorized (validate_destination)")
+ Util.error(:unauthorized, "unauthorized (validate_destination)")
when Net::HTTPNotFound
ServiceResult.success(result: urls)
else
@@ -111,7 +111,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPCreated
ServiceResult.success(message: 'Folder was successfully copied')
when Net::HTTPUnauthorized
- Util.error(:not_authorized, "Not authorized (copy_folder)")
+ Util.error(:unauthorized, "Unauthorized (copy_folder)")
when Net::HTTPNotFound
Util.error(:not_found, "Project folder not found (copy_folder)")
when Net::HTTPConflict
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb
index 81b07c2255f..363322e8111 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb
@@ -58,7 +58,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
Util.error(:not_allowed)
end
when Net::HTTPUnauthorized
- Util.error(:not_authorized)
+ Util.error(:unauthorized)
when Net::HTTPNotFound
Util.error(:not_found)
when Net::HTTPConflict
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
index 01d3fb13283..e9a8c56ed69 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
@@ -61,18 +61,18 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPNotFound
Util.error(:not_found, 'Outbound request destination not found!', response)
when Net::HTTPUnauthorized
- Util.error(:not_authorized, 'Outbound request not authorized!', response)
+ Util.error(:unauthorized, 'Outbound request not authorized!', response)
else
Util.error(:error, 'Outbound request failed!')
end
end
- service_result.bind do |response|
+ service_result.bind do |resp|
# The nextcloud API returns a successful response with empty body if the authorization is missing or expired
- if response.body.blank?
- Util.error(:not_authorized, 'Outbound request not authorized!')
+ if resp.body.blank?
+ Util.error(:unauthorized, 'Outbound request not authorized!')
else
- ServiceResult.success(result: response.body)
+ ServiceResult.success(result: resp.body)
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb
index eefa8e18dd4..85d4d8384b8 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb
@@ -67,7 +67,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPNotFound
Util.error(:not_found, 'Outbound request destination not found!', response)
when Net::HTTPUnauthorized
- Util.error(:not_authorized, 'Outbound request not authorized!', response)
+ Util.error(:unauthorized, 'Outbound request not authorized!', response)
else
Util.error(:error, 'Outbound request failed!')
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb
index cd9bcaba857..1fe1dde5782 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb
@@ -76,7 +76,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPNotFound
Util.error(:not_found, 'Outbound request destination not found!', response)
when Net::HTTPUnauthorized
- Util.error(:not_authorized, 'Outbound request not authorized!', response)
+ Util.error(:unauthorized, 'Outbound request not authorized!', response)
else
Util.error(:error, 'Outbound request failed!')
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
index 61531659d17..4c22a48461b 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
@@ -58,7 +58,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPNotFound
Util.error(:not_found)
when Net::HTTPUnauthorized
- Util.error(:not_authorized)
+ Util.error(:unauthorized)
else
Util.error(:error)
end
@@ -90,7 +90,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
xml['d'].getcontenttype
xml['d'].getlastmodified
xml['oc'].permissions
- xml['oc'].send(:"owner-display-name")
+ xml['oc'].send(:'owner-display-name')
end
end
end.to_xml
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb
index b6ebf4b870b..1ccb379fb34 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb
@@ -55,7 +55,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPMethodNotAllowed
Util.error(:not_allowed)
when Net::HTTPUnauthorized
- Util.error(:not_authorized)
+ Util.error(:unauthorized)
when Net::HTTPNotFound
Util.error(:not_found)
when Net::HTTPConflict
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 dc22281ccf9..04c7e8ab72e 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
@@ -53,7 +53,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Internal
when Net::HTTPNotFound
UTIL.error(:not_found)
when Net::HTTPUnauthorized
- UTIL.error(:not_authorized)
+ UTIL.error(:unauthorized)
else
UTIL.error(:error)
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb
index a2104e3084a..200f904d2b3 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb
@@ -122,7 +122,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Internal
when Net::HTTPMethodNotAllowed
UTIL.error(:not_allowed)
when Net::HTTPUnauthorized
- UTIL.error(:not_authorized)
+ UTIL.error(:unauthorized)
when Net::HTTPNotFound
UTIL.error(:not_found)
else
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb
index c97eb4e3e4d..00568b2716b 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb
@@ -72,7 +72,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPMethodNotAllowed
Util.error(:not_allowed)
when Net::HTTPUnauthorized
- Util.error(:not_authorized)
+ Util.error(:unauthorized)
when Net::HTTPNotFound
Util.error(:not_found)
when Net::HTTPConflict
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb
index 59b1aeaddda..f9f2d7b1fc6 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb
@@ -55,7 +55,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPNotFound
Util.error(:not_found)
when Net::HTTPUnauthorized
- Util.error(:not_authorized)
+ Util.error(:unauthorized)
else
Util.error(:error)
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
index 2660bc0511f..8530e81fbd5 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
@@ -54,21 +54,21 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
) do
xml['d'].set do
xml['d'].prop do
- xml['nc'].send(:"acl-list") do
+ xml['nc'].send(:'acl-list') do
groups_permissions.each do |group, group_permissions|
xml['nc'].acl do
- xml['nc'].send(:"acl-mapping-type", 'group')
- xml['nc'].send(:"acl-mapping-id", group)
- xml['nc'].send(:"acl-mask", '31')
- xml['nc'].send(:"acl-permissions", group_permissions.to_s)
+ xml['nc'].send(:'acl-mapping-type', 'group')
+ xml['nc'].send(:'acl-mapping-id', group)
+ xml['nc'].send(:'acl-mask', '31')
+ xml['nc'].send(:'acl-permissions', group_permissions.to_s)
end
end
users_permissions.each do |user, user_permissions|
xml['nc'].acl do
- xml['nc'].send(:"acl-mapping-type", 'user')
- xml['nc'].send(:"acl-mapping-id", user)
- xml['nc'].send(:"acl-mask", '31')
- xml['nc'].send(:"acl-permissions", user_permissions.to_s)
+ xml['nc'].send(:'acl-mapping-type', 'user')
+ xml['nc'].send(:'acl-mapping-id', user)
+ xml['nc'].send(:'acl-mask', '31')
+ xml['nc'].send(:'acl-permissions', user_permissions.to_s)
end
end
end
@@ -97,7 +97,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
when Net::HTTPNotFound
Util.error(:not_found)
when Net::HTTPUnauthorized
- Util.error(:not_authorized)
+ Util.error(:unauthorized)
else
Util.error(:error)
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 63ebc9afaac..d0dd7ad4956 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
@@ -83,12 +83,12 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
result: JSON.parse(response.body, object_class: OpenStruct) # rubocop:disable Style/OpenStructUse
)
else
- Util.error(:not_authorized, 'Outbound request not authorized!')
+ Util.error(:unauthorized, 'Outbound request not authorized!')
end
when Net::HTTPNotFound
Util.error(:not_found, 'Outbound request destination not found!', response)
when Net::HTTPUnauthorized
- Util.error(:not_authorized, 'Outbound request not authorized!', response)
+ Util.error(:unauthorized, 'Outbound request not authorized!', response)
else
Util.error(:error, 'Outbound request failed!')
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 dd75ef27e7c..ab6b269d3a1 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
@@ -57,13 +57,13 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Util
File.join(uri.to_s, *)
end
- def token(user:, configuration:, &block)
+ 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) { block.call(token) }
+ connection_manager.request_with_token_refresh(token) { yield token }
end,
- on_failure: ->(_) { error(:not_authorized, 'Query could not be created! No access token found!') }
+ on_failure: ->(_) { error(:unauthorized, 'Query could not be created! No access token found!') }
)
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/file_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/file_info_query.rb
index 42b062e081a..642c9e67f8e 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/file_info_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/file_info_query.rb
@@ -73,8 +73,8 @@ module Storages
ServiceResult.failure(result: :forbidden,
errors: ::Storages::StorageError.new(code: :forbidden, data: json))
when Net::HTTPUnauthorized
- ServiceResult.failure(result: :not_authorized,
- errors: ::Storages::StorageError.new(code: :not_authorized, data: json))
+ ServiceResult.failure(result: :unauthorized,
+ errors: ::Storages::StorageError.new(code: :unauthorized, data: json))
else
ServiceResult.failure(result: :error,
errors: ::Storages::StorageError.new(code: :error, data: json))
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb
index d7a971a52a2..9426560f9c2 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb
@@ -71,7 +71,7 @@ module Storages
StorageFileInfo.new(
id: file_id,
status: storage_error.data.dig(:error, :code),
- status_code: error_to_code(storage_error)
+ status_code: Rack::Utils::SYMBOL_TO_STATUS_CODE[storage_error.code]
)
end
end
diff --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.rb
index 9dc79cbc072..4fb6e569923 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
@@ -68,7 +68,7 @@ module Storages
when Net::HTTPNotFound
ServiceResult.failure(result: :not_found, errors: ::Storages::StorageError.new(code: :not_found))
when Net::HTTPUnauthorized
- ServiceResult.failure(result: :not_authorized, errors: ::Storages::StorageError.new(code: :not_authorized))
+ ServiceResult.failure(result: :unauthorized, errors: ::Storages::StorageError.new(code: :unauthorized))
else
ServiceResult.failure(result: :error, errors: ::Storages::StorageError.new(code: :error))
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb
index 71b25846131..8f413f9a56e 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb
@@ -48,9 +48,9 @@ module Storages::Peripherals::StorageInteraction::OneDrive::Util
end,
on_failure: ->(_) do
ServiceResult.failure(
- result: :not_authorized,
+ result: :unauthorized,
errors: ::Storages::StorageError.new(
- code: :not_authorized,
+ code: :unauthorized,
log_message: 'Query could not be created! No access token found!'
)
)
diff --git a/modules/storages/spec/common/storages/peripherals/registry_spec.rb b/modules/storages/spec/common/storages/peripherals/registry_spec.rb
index ccbd089d6d1..2b598e8f245 100644
--- a/modules/storages/spec/common/storages/peripherals/registry_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/registry_spec.rb
@@ -120,10 +120,10 @@ RSpec.describe Storages::Peripherals::Registry, :webmock do
allow(instance).to receive(:get_access_token).and_return(ServiceResult.failure)
end
- it 'must return ":not_authorized" ServiceResult' do
+ it 'must return ":unauthorized" ServiceResult' do
result = registry.resolve('queries.nextcloud.download_link').call(storage:, user:, file_link:)
expect(result).to be_failure
- expect(result.errors.code).to be(:not_authorized)
+ expect(result.errors.code).to be(:unauthorized)
end
end
@@ -132,10 +132,10 @@ RSpec.describe Storages::Peripherals::Registry, :webmock do
stub_request(:post, "#{url}/ocs/v2.php/apps/dav/api/v1/direct").to_return(status: 200, body: '')
end
- it 'must return :not_authorized ServiceResult' do
+ it 'must return :unauthorized ServiceResult' do
result = registry.resolve('queries.nextcloud.download_link').call(user:, file_link:, storage:)
expect(result).to be_failure
- expect(result.errors.code).to be(:not_authorized)
+ expect(result.errors.code).to be(:unauthorized)
end
end
@@ -154,7 +154,7 @@ RSpec.describe Storages::Peripherals::Registry, :webmock do
end
include_examples 'outbound is failing', 404, :not_found
- include_examples 'outbound is failing', 401, :not_authorized
+ include_examples 'outbound is failing', 401, :unauthorized
include_examples 'outbound is failing', 500, :error
end
@@ -266,10 +266,10 @@ RSpec.describe Storages::Peripherals::Registry, :webmock do
allow(instance).to receive(:get_access_token).and_return(ServiceResult.failure)
end
- it 'must return ":not_authorized" ServiceResult' do
+ it 'must return ":unauthorized" ServiceResult' do
result = registry.resolve('queries.nextcloud.files').call(folder: parent, user:, storage:)
expect(result).to be_failure
- expect(result.errors.code).to be(:not_authorized)
+ expect(result.errors.code).to be(:unauthorized)
end
end
end
@@ -289,7 +289,7 @@ RSpec.describe Storages::Peripherals::Registry, :webmock do
end
include_examples 'outbound is failing', 404, :not_found
- include_examples 'outbound is failing', 401, :not_authorized
+ include_examples 'outbound is failing', 401, :unauthorized
include_examples 'outbound is failing', 500, :error
end
@@ -339,10 +339,10 @@ RSpec.describe Storages::Peripherals::Registry, :webmock do
allow(instance).to receive(:get_access_token).and_return(ServiceResult.failure)
end
- it 'must return ":not_authorized" ServiceResult' do
+ it 'must return ":unauthorized" ServiceResult' do
result = registry.resolve('queries.nextcloud.upload_link').call(storage:, user:, data: query_payload)
expect(result).to be_failure
- expect(result.errors.code).to be(:not_authorized)
+ expect(result.errors.code).to be(:unauthorized)
end
end
@@ -361,7 +361,7 @@ RSpec.describe Storages::Peripherals::Registry, :webmock do
end
include_examples 'outbound is failing', 400, :error
- include_examples 'outbound is failing', 401, :not_authorized
+ include_examples 'outbound is failing', 401, :unauthorized
include_examples 'outbound is failing', 404, :not_found
include_examples 'outbound is failing', 500, :error
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/files_info_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/files_info_query_spec.rb
index 78beffc58b6..d40f992e679 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/files_info_query_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/files_info_query_spec.rb
@@ -96,7 +96,7 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::FilesInfoQu
it 'must return an error when called' do
subject.call(user:, file_ids:).match(
on_success: ->(file_infos) { fail "Expected failure, got #{file_infos}" },
- on_failure: ->(error) { expect(error.code).to eq(:not_authorized) }
+ on_failure: ->(error) { expect(error.code).to eq(:unauthorized) }
)
end
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb
index 88623d72fb0..9434c35deac 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/files_query_spec.rb
@@ -118,8 +118,8 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesQuery,
storage_files = described_class.call(storage:, user:, folder: nil)
expect(storage_files).to be_failure
- expect(storage_files.result).to eq(:not_authorized)
- expect(storage_files.errors.to_s).to eq(Storages::StorageError.new(code: :not_authorized).to_s)
+ expect(storage_files.result).to eq(:unauthorized)
+ expect(storage_files.errors.to_s).to eq(Storages::StorageError.new(code: :unauthorized).to_s)
end
end
end
diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb
index 36b513d9ff0..3f99c781ff3 100644
--- a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb
+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb
@@ -130,7 +130,7 @@ RSpec.describe 'API v3 file links resource' do
context 'when all embedded file link elements are valid' do
it_behaves_like 'API V3 collection response', 2, 2, 'FileLink' do
- let(:elements) { Storages::FileLink.all.order(id: :asc) }
+ let(:elements) { Storages::FileLink.order(id: :asc) }
let(:expected_status_code) { 201 }
end
@@ -267,7 +267,7 @@ RSpec.describe 'API v3 file links resource' do
context 'when all embedded file link elements are valid' do
it_behaves_like 'API V3 collection response', 2, 2, 'FileLink' do
- let(:elements) { Storages::FileLink.all.order(id: :asc) }
+ let(:elements) { Storages::FileLink.order(id: :asc) }
let(:expected_status_code) { 201 }
end
@@ -330,7 +330,7 @@ RSpec.describe 'API v3 file links resource' do
end
it_behaves_like 'API V3 collection response', 2, 2, 'FileLink' do
- let(:elements) { Storages::FileLink.all.order(id: :asc) }
+ let(:elements) { Storages::FileLink.order(id: :asc) }
let(:expected_status_code) { 201 }
end
@@ -354,7 +354,7 @@ RSpec.describe 'API v3 file links resource' do
end
it_behaves_like 'API V3 collection response', 3, 3, 'FileLink' do
- let(:elements) { Storages::FileLink.all.order(id: :asc) }
+ let(:elements) { Storages::FileLink.order(id: :asc) }
let(:expected_status_code) { 201 }
end
@@ -580,7 +580,7 @@ RSpec.describe 'API v3 file links resource' do
end
describe 'due to authorization failure' do
- let(:error) { :not_authorized }
+ let(:error) { :unauthorized }
it { expect(subject.status).to be(500) }
end
diff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
index 5e019ef4b54..bb3ad7f2ce9 100644
--- a/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb
@@ -139,7 +139,7 @@ RSpec.describe 'API v3 storage files', :webmock, content_type: :json do
end
context 'with authorization failure' do
- let(:error) { :not_authorized }
+ let(:error) { :unauthorized }
it { expect(last_response.status).to be(500) }
end
@@ -291,7 +291,7 @@ RSpec.describe 'API v3 storage files', :webmock, content_type: :json do
end
describe 'due to authorization failure' do
- let(:error) { :not_authorized }
+ let(:error) { :unauthorized }
it { expect(last_response.status).to be(500) }
end
diff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rb
index b0ed6dcfdd8..e6a4179cd92 100644
--- a/spec/services/oauth_clients/connection_manager_spec.rb
+++ b/spec/services/oauth_clients/connection_manager_spec.rb
@@ -30,7 +30,7 @@
require 'spec_helper'
-RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
+RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model do
let(:user) { create(:user) }
let(:host) { "https://example.org" }
@@ -145,7 +145,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
# The callback endpoint calls `code_to_token(code)` with the code
# received and exchanges the code for a bearer+refresh token
# using a HTTP request.
- describe '#code_to_token', webmock: true do
+ describe '#code_to_token', :webmock do
let(:code) { "7kRGJ...jG3KZ" }
subject { instance.code_to_token(code) }
@@ -176,7 +176,9 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
context 'with known error' do
before do
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token'))
- .to_return(status: 400, body: { error: error_message }.to_json, headers: { "content-type" => "application/json; charset=utf-8" })
+ .to_return(status: 400,
+ body: { error: error_message }.to_json,
+ headers: { "content-type" => "application/json; charset=utf-8" })
end
shared_examples 'OAuth2 error response' do
@@ -204,7 +206,9 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
context 'with known reply invalid_grant' do
before do
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token'))
- .to_return(status: 400, body: { error: "invalid_grant" }.to_json, headers: { "content-type" => "application/json; charset=utf-8" })
+ .to_return(status: 400,
+ body: { error: "invalid_grant" }.to_json,
+ headers: { "content-type" => "application/json; charset=utf-8" })
end
it 'returns a specific error message' do
@@ -218,7 +222,9 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
context 'with unknown reply' do
before do
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token'))
- .to_return(status: 400, body: { error: "invalid_requesttt" }.to_json, headers: { "content-type" => "application/json; charset=utf-8" })
+ .to_return(status: 400,
+ body: { error: "invalid_requesttt" }.to_json,
+ headers: { "content-type" => "application/json; charset=utf-8" })
end
it 'returns an unspecific error message' do
@@ -334,7 +340,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
.to_return(status: 200, body: response_body, headers: { "content-type" => "application/json; charset=utf-8" })
end
- it 'returns a valid ClientToken object', webmock: true do
+ it 'returns a valid ClientToken object', :webmock do
expect(subject.success).to be_truthy
expect(subject.result).to be_a OAuthClientToken
expect(subject.result.access_token).to eq("xyjTDZ...RYvRH")
@@ -357,7 +363,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
.to_return(status: 200, body: response_body, headers: { "content-type" => "application/json; charset=utf-8" })
end
- it 'returns dependent error from model validation', webmock: true do
+ it 'returns dependent error from model validation', :webmock do
expect(subject.success).to be_falsey
expect(subject.errors.size).to be(1)
end
@@ -366,10 +372,12 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
context 'with server error from OAuth2 provider' do
before do
stub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token'))
- .to_return(status: 400, body: { error: "invalid_request" }.to_json, headers: { "content-type" => "application/json; charset=utf-8" })
+ .to_return(status: 400,
+ body: { error: "invalid_request" }.to_json,
+ headers: { "content-type" => "application/json; charset=utf-8" })
end
- it 'returns a server error', webmock: true do
+ it 'returns a server error', :webmock do
expect(subject.success).to be_falsey
expect(subject.errors.size).to be(1)
end
@@ -382,7 +390,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
.to_timeout
end
- it 'returns a valid ClientToken object', webmock: true do
+ it 'returns a valid ClientToken object', :webmock do
expect(subject.success).to be_falsey
expect(subject.result).to eq("execution expired")
expect(subject.errors.size).to be(1)
@@ -445,9 +453,10 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
response_body2 = response_body1.dup
response_body2[:access_token] = "differ...RYvRH"
request_url = File.join(host, '/index.php/apps/oauth2/api/v1/token')
+ headers = { "content-type" => "application/json; charset=utf-8" }
stub_request(:any, request_url)
- .to_return(status: 200, body: response_body1.to_json, headers: { "content-type" => "application/json; charset=utf-8" }).then
- .to_return(status: 200, body: response_body2.to_json, headers: { "content-type" => "application/json; charset=utf-8" })
+ .to_return(status: 200, body: response_body1.to_json, headers:).then
+ .to_return(status: 200, body: response_body2.to_json, headers:)
result1 = nil
result2 = nil
@@ -473,7 +482,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
end
context 'when token is fresh' do
- it 'does not send refresh request and respond with existing token', webmock: true do
+ it 'does not send refresh request and respond with existing token', :webmock do
expect(subject.success).to be_truthy
expect(subject.result).to eq(oauth_client_token)
expect { subject }.not_to change(oauth_client_token, :access_token)
@@ -491,7 +500,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
end
end
- context 'with access token present', webmock: true do
+ context 'with access token present', :webmock do
before do
oauth_client_token
end
@@ -554,7 +563,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
end
end
- context 'with both invalid access token and refresh token', webmock: true do
+ context 'with both invalid access token and refresh token', :webmock do
it 'returns :failed_authorization' do
expect(subject).to eq :failed_authorization
end
@@ -593,19 +602,19 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
end
end
- context 'with yield returning :not_authorized and the refresh returning a with a success' do
- let(:yield_service_result) { ServiceResult.failure(result: :not_authorized) }
+ context 'with yield returning :unauthorized and the refresh returning a with a success' do
+ let(:yield_service_result) { ServiceResult.failure(result: :unauthorized) }
it 'returns a ServiceResult with success, without refresh' do
expect(subject.success).to be_falsey
- expect(subject.result).to be :not_authorized
+ expect(subject.result).to be :unauthorized
expect(instance).to have_received(:refresh_token)
expect(oauth_client_token).to have_received(:reload)
end
end
- context 'with yield returning :not_authorized and the refresh returning with a :failure' do
- let(:yield_service_result) { ServiceResult.failure(result: :not_authorized) }
+ context 'with yield returning :unauthorized and the refresh returning with a :failure' do
+ let(:yield_service_result) { ServiceResult.failure(result: :unauthorized) }
let(:refresh_service_result) { ServiceResult.failure }
it 'returns a ServiceResult with success, without refresh' do
@@ -616,9 +625,9 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true do
end
end
- context 'with yield returning :not_authorized first time and :success the second time' do
+ context 'with yield returning :unauthorized first time and :success the second time' do
let(:yield_double_object) { Object.new }
- let(:yield_service_result1) { ServiceResult.failure(result: :not_authorized) }
+ let(:yield_service_result1) { ServiceResult.failure(result: :unauthorized) }
let(:yield_service_result2) { ServiceResult.success }
let(:refresh_service_result) { ServiceResult.success }