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

[#61178] Extract user_query stub to a method.

Pavel Balashou3e517c617ffd
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 049ae17fb7d..096b26b63fe 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
@@ -31,9 +31,8 @@
require "spec_helper"
require_module_spec_helper
-RSpec.describe "API v3 storage files", :webmock, content_type: :json do
+RSpec.describe "API v3 storage files", :storage_server_helpers, :webmock, content_type: :json do
include API::V3::Utilities::PathHelper
- include StorageServerHelpers
let(:permissions) { %i(view_work_packages view_file_links) }
let(:project) { create(:project) }
diff --git a/modules/storages/spec/requests/api/v3/storages/storage_folders_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_folders_api_spec.rb
index fddfa2a9bdc..beeae1561a0 100644
--- a/modules/storages/spec/requests/api/v3/storages/storage_folders_api_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storage_folders_api_spec.rb
@@ -31,9 +31,8 @@
require "spec_helper"
require_module_spec_helper
-RSpec.describe "API v3 storage folders", :webmock, content_type: :json do
+RSpec.describe "API v3 storage folders", :storage_server_helpers, :webmock, content_type: :json do
include API::V3::Utilities::PathHelper
- include StorageServerHelpers
let(:permissions) { %i(view_work_packages view_file_links manage_file_links) }
let(:project) { create(:project) }
diff --git a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb
index 844a1a3d8db..013a557f046 100644
--- a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb
@@ -31,9 +31,8 @@
require "spec_helper"
require_module_spec_helper
-RSpec.describe "API v3 storages resource", :webmock, content_type: :json do
+RSpec.describe "API v3 storages resource", :storage_server_helpers, :webmock, content_type: :json do
include API::V3::Utilities::PathHelper
- include StorageServerHelpers
include UserPermissionsHelper
shared_let(:permissions) { %i(view_work_packages view_file_links) }
diff --git a/spec/requests/oauth_clients/callback_flow_spec.rb b/spec/requests/oauth_clients/callback_flow_spec.rb
index 28c27210000..8a22f004bd7 100644
--- a/spec/requests/oauth_clients/callback_flow_spec.rb
+++ b/spec/requests/oauth_clients/callback_flow_spec.rb
@@ -104,9 +104,9 @@ RSpec.describe "OAuthClient callback endpoint" do
context "with valid params" do
context "without errors" do
- it "redirects to the URL that was referenced by the state param and held by a cookie", :webmock do
- stub_request(:get, File.join(storage.host, "/ocs/v1.php/cloud/user"))
- .to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})
+ it "redirects to the URL that was referenced by the state param and held by a cookie", :storage_server_helpers,
+ :webmock do
+ stub_nextcloud_user_query(storage.host)
uri.query = URI.encode_www_form([["code", code], ["state", state]])
get uri.to_s
diff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rb
index 694f2aeb897..cbdc5f1fe07 100644
--- a/spec/services/oauth_clients/connection_manager_spec.rb
+++ b/spec/services/oauth_clients/connection_manager_spec.rb
@@ -98,7 +98,7 @@ RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model do
subject { instance.code_to_token(code) }
- context "with happy path" do
+ context "with happy path", :storage_server_helpers do
before do
# Simulate a successful authorization returning the tokens
response_body = {
@@ -111,12 +111,7 @@ RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model do
stub_request(:any, File.join(host, "/index.php/apps/oauth2/api/v1/token"))
.to_return(status: 200, body: response_body, headers: { "content-type" => "application/json; charset=utf-8" })
- stub_request(:get, File.join(host, "/ocs/v1.php/cloud/user")).with(
- headers: {
- "Authorization" => "Bearer yjTDZ...RYvRH",
- "Ocs-Apirequest" => "true"
- }
- ).to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})
+ stub_nextcloud_user_query(host)
end
it "returns a valid ClientToken object and issues an appropriate event" do
diff --git a/spec/services/remote_identities/create_service_spec.rb b/spec/services/remote_identities/create_service_spec.rb
index 0d8fb885ae3..e6f64065abb 100644
--- a/spec/services/remote_identities/create_service_spec.rb
+++ b/spec/services/remote_identities/create_service_spec.rb
@@ -4,7 +4,7 @@ require "spec_helper"
require "services/base_services/behaves_like_create_service"
-RSpec.describe RemoteIdentities::CreateService, :webmock, type: :model do
+RSpec.describe RemoteIdentities::CreateService, :storage_server_helpers, :webmock, type: :model do
let(:user) { create(:user) }
let(:storage) { create(:nextcloud_storage_configured) }
let(:oauth_config) { storage.oauth_configuration }
@@ -16,9 +16,7 @@ RSpec.describe RemoteIdentities::CreateService, :webmock, type: :model do
subject(:service) { described_class.new(user:, oauth_config:, oauth_client_token:) }
- before do
- stub_request(:get, File.join(storage.host, "/ocs/v1.php/cloud/user")).to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})
- end
+ before { stub_nextcloud_user_query(storage.host) }
describe ".call" do
it "requires a user, a oauth configuration and a rack token" do
diff --git a/modules/storages/spec/support/storage_server_helpers.rb b/spec/support/storage_server_helpers.rb
similarity index 94%
rename from modules/storages/spec/support/storage_server_helpers.rb
rename to spec/support/storage_server_helpers.rb
index c7851705ff1..d8e19ed6ab8 100644
--- a/modules/storages/spec/support/storage_server_helpers.rb
+++ b/spec/support/storage_server_helpers.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -129,6 +131,11 @@ module StorageServerHelpers
end
end
+ def stub_nextcloud_user_query(host)
+ stub_request(:get, normalize_url("#{host}/ocs/v1.php/cloud/user"))
+ .to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"))
+ end
+
def stub_outbound_storage_files_request_for(storage:, remote_identity:)
root_xml_response = build(:webdav_data)
folder1_xml_response = build(:webdav_data_folder)
@@ -152,7 +159,7 @@ module StorageServerHelpers
.to_return(status: 207, body: folder1_xml_response, headers: {})
stub_request(:get, normalize_url("#{storage.host}/ocs/v1.php/apps/integration_openproject/fileinfo/11"))
.to_return(status: 200, body: folder1_fileinfo_response.to_json, headers: {})
- stub_request(:get, normalize_url("#{storage.host}/ocs/v1.php/cloud/user")).to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"))
+ stub_nextcloud_user_query(storage.host)
stub_request(
:delete,
normalize_url("#{storage.host}/remote.php/dav/files/OpenProject/OpenProject/" \