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

[#53369] fixed unit test setup

Eric Schubert821c91ce02eb
diff --git a/app/controllers/oauth_clients_controller.rb b/app/controllers/oauth_clients_controller.rb
index 48389a335a4..0dc0bfb1d6e 100644
--- a/app/controllers/oauth_clients_controller.rb
+++ b/app/controllers/oauth_clients_controller.rb
@@ -78,25 +78,22 @@ class OAuthClientsController < ApplicationController
handle_absent_oauth_client unless oauth_client
- connection_manager = OAuthClients::ConnectionManager.new(
- user: User.current,
- configuration: oauth_client.integration.oauth_configuration
- )
-
+ storage = oauth_client.integration
# check if the origin is the same
- destination_url = if params.fetch(:destination_url, '').start_with?(root_url)
+ destination_url = if params.fetch(:destination_url, "").start_with?(root_url)
params[:destination_url]
else
root_url
end
auth_state = ::Storages::Peripherals::StorageInteraction::Authentication
- .authorization_state(storage: oauth_client.integration, user: User.current)
+ .authorization_state(storage:, user: User.current)
+
if auth_state == :connected
redirect_to(destination_url)
else
nonce = SecureRandom.uuid
cookies["oauth_state_#{nonce}"] = { value: { href: destination_url, storageId: storage_id }.to_json, expires: 1.hour }
- redirect_to(connection_manager.get_authorization_uri(state: nonce))
+ redirect_to(storage.oauth_configuration.authorization_uri(state: nonce))
end
end
@@ -105,8 +102,8 @@ class OAuthClientsController < ApplicationController
private
def handle_absent_oauth_client
- flash[:error] = [I18n.t('oauth_client.errors.oauth_client_not_found'),
- I18n.t('oauth_client.errors.oauth_client_not_found_explanation')]
+ flash[:error] = [I18n.t("oauth_client.errors.oauth_client_not_found"),
+ I18n.t("oauth_client.errors.oauth_client_not_found_explanation")]
if User.current.admin?
redirect_to admin_settings_storages_path
@@ -128,9 +125,9 @@ class OAuthClientsController < ApplicationController
service_result.errors = service_result.errors.to_active_model_errors
end
- flash[:error] = ["#{t(:'oauth_client.errors.oauth_authorization_code_grant_had_errors')}:"]
+ flash[:error] = ["#{t(:"oauth_client.errors.oauth_authorization_code_grant_had_errors")}:"]
service_result.errors.each do |error|
- flash[:error] << "#{t(:'oauth_client.errors.oauth_reported')}: #{error.full_message}"
+ flash[:error] << "#{t(:"oauth_client.errors.oauth_reported")}: #{error.full_message}"
end
end
@@ -141,8 +138,8 @@ class OAuthClientsController < ApplicationController
@code = params[:code]
if @code.blank?
- flash[:error] = [I18n.t('oauth_client.errors.oauth_code_not_present'),
- I18n.t('oauth_client.errors.oauth_code_not_present_explanation')]
+ flash[:error] = [I18n.t("oauth_client.errors.oauth_code_not_present"),
+ I18n.t("oauth_client.errors.oauth_code_not_present_explanation")]
redirect_user_or_admin(get_redirect_uri) do
# If the current user is an admin, we send her directly to the
@@ -164,8 +161,8 @@ class OAuthClientsController < ApplicationController
else
# To protect against CSRF we cancel this request. There was either no
# state parameter given, or there was no corresponding cookie present.
- flash[:error] = [I18n.t('oauth_client.errors.oauth_state_not_present'),
- I18n.t('oauth_client.errors.oauth_state_not_present_explanation')]
+ flash[:error] = [I18n.t("oauth_client.errors.oauth_state_not_present"),
+ I18n.t("oauth_client.errors.oauth_state_not_present_explanation")]
redirect_user_or_admin(nil) do
# Guide the user to the settings that she needs to edit/fix.
@@ -200,11 +197,11 @@ class OAuthClientsController < ApplicationController
# This happens during admin setup if the user forgot to update the return_uri
# on the Authorization Server (i.e. Nextcloud) after updating the OpenProject
# side with a new client_id and client_secret.
- flash[:error] = [I18n.t('oauth_client.errors.oauth_client_not_found'),
- I18n.t('oauth_client.errors.oauth_client_not_found_explanation')]
+ flash[:error] = [I18n.t("oauth_client.errors.oauth_client_not_found"),
+ I18n.t("oauth_client.errors.oauth_client_not_found_explanation")]
redirect_user_or_admin(get_redirect_uri) do
- # Something must be wrong in the storage's setup
+ # Something must be wrong in the storage"s setup
redirect_to admin_settings_storages_path
end
end
@@ -217,7 +214,7 @@ class OAuthClientsController < ApplicationController
if User.current.admin && redirect_uri && (nextcloud? || one_drive?)
yield
elsif redirect_uri
- flash[:error] = [t(:'oauth_client.errors.oauth_issue_contact_admin')]
+ flash[:error] = [t(:"oauth_client.errors.oauth_issue_contact_admin")]
redirect_to redirect_uri
else
redirect_to root_url
diff --git a/modules/storages/app/controllers/storages/admin/project_storages_controller.rb b/modules/storages/app/controllers/storages/admin/project_storages_controller.rb
index 890f7307b04..9f97c9e249a 100644
--- a/modules/storages/app/controllers/storages/admin/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/project_storages_controller.rb
@@ -60,6 +60,7 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsController
# Show a HTML page with a form in order to create a new ProjectStorage
# Called by: When a user clicks on the "+New" button in Project -> Settings -> File Storages
+ # rubocop:disable Metrics/AbcSize
def new
@available_storages = available_storages
project_folder_mode = Storages::ProjectStorage.project_folder_modes.values.find do |mode|
@@ -76,6 +77,8 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsController
render template: "/storages/project_settings/new"
end
+ # rubocop:enable Metrics/AbcSize
+
# Create a new ProjectStorage object.
# Called by: The new page above with form-data from that form.
def create
@@ -113,7 +116,7 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsController
end
end
- # Edit page is very similar to new page, except that we don"t need to set
+ # Edit page is very similar to new page, except that we don't need to set
# default attribute values because the object already exists
# Called by: Global app/config/routes.rb to serve Web page
def edit
@@ -149,7 +152,7 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsController
end
# Purpose: Destroy a ProjectStorage object
- # Called by: By pressing a "Delete" icon in the Project"s settings ProjectStorages page
+ # Called by: By pressing a "Delete" icon in the Project's settings ProjectStorages page
# It redirects back to the list of ProjectStorages in the project
def destroy
# The complex logic for deleting associated objects was moved into a service:
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 31011698613..fccff3ac72d 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
@@ -26,10 +26,10 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-require 'spec_helper'
+require "spec_helper"
require_module_spec_helper
-RSpec.describe 'API v3 storages resource', :webmock, content_type: :json do
+RSpec.describe "API v3 storages resource", :webmock, content_type: :json do
include API::V3::Utilities::PathHelper
include StorageServerHelpers
include UserPermissionsHelper
@@ -42,9 +42,7 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json do
end
shared_let(:user_without_project) { create(:user) }
shared_let(:admin) { create(:admin) }
- shared_let(:oauth_application) { create(:oauth_application) }
- shared_let(:oauth_client) { create(:oauth_client) }
- shared_let(:storage) { create(:nextcloud_storage, creator: user_with_permissions, oauth_application:, oauth_client:) }
+ shared_let(:storage) { create(:nextcloud_storage_configured, creator: user_with_permissions) }
shared_let(:project_storage) { create(:project_storage, project:, storage:) }
let(:current_user) { user_with_permissions }
@@ -55,65 +53,61 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json do
end
before do
- Storages::Peripherals::Registry.stub(
- "#{storage.short_provider_type}.queries.auth_check",
- ->(_) { auth_check_result }
- )
-
+ Storages::Peripherals::Registry.stub("nextcloud.queries.auth_check", ->(_) { auth_check_result })
login_as current_user
end
- shared_examples_for 'successful storage response' do |as_admin: false|
- include_examples 'successful response'
+ shared_examples_for "successful storage response" do |as_admin: false|
+ include_examples "successful response"
- describe 'response body' do
+ describe "response body" do
subject { last_response.body }
- it { is_expected.to be_json_eql('Storage'.to_json).at_path('_type') }
- it { is_expected.to be_json_eql(storage.id.to_json).at_path('id') }
+ it { is_expected.to be_json_eql("Storage".to_json).at_path("_type") }
+ it { is_expected.to be_json_eql(storage.id.to_json).at_path("id") }
if as_admin
- it { is_expected.to have_json_path('_embedded/oauthApplication') }
+ it { is_expected.to have_json_path("_embedded/oauthApplication") }
else
- it { is_expected.not_to have_json_path('_embedded/oauthApplication') }
+ it { is_expected.not_to have_json_path("_embedded/oauthApplication") }
end
end
end
- describe 'GET /api/v3/storages' do
+ describe "GET /api/v3/storages" do
let(:path) { api_v3_paths.storages }
let!(:another_storage) { create(:nextcloud_storage) }
subject(:last_response) { get path }
- context 'as admin' do
+ context "as admin" do
let(:current_user) { admin }
- describe 'gets the storage collection and returns it' do
+ describe "gets the storage collection and returns it" do
subject { last_response.body }
- it_behaves_like 'API V3 collection response', 2, 2, 'Storage', 'Collection' do
+ it_behaves_like "API V3 collection response", 2, 2, "Storage", "Collection" do
let(:elements) { [another_storage, storage] }
end
end
end
- context 'as non-admin' do
- describe 'gets the storage collection of storages linked to visible projects with correct permissions' do
+ context "as non-admin" do
+ describe "gets the storage collection of storages linked to visible projects with correct permissions" do
subject { last_response.body }
- it_behaves_like 'API V3 collection response', 1, 1, 'Storage', 'Collection' do
+ it_behaves_like "API V3 collection response", 1, 1, "Storage", "Collection" do
let(:elements) { [storage] }
end
end
end
end
- describe 'POST /api/v3/storages' do
+ describe "POST /api/v3/storages" do
let(:path) { api_v3_paths.storages }
- let(:host) { 'https://example.nextcloud.local' }
- let(:name) { 'APIStorage' }
- let(:type) { 'urn:openproject-org:api:v3:storages:Nextcloud' }
+ let(:host) { "https://example.nextcloud.local" }
+ let(:name) { "APIStorage" }
+ let(:type) { "urn:openproject-org:api:v3:storages:Nextcloud" }
let(:params) do
{
name:,
@@ -134,32 +128,32 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json do
post path, params.to_json
end
- context 'as admin' do
+ context "as admin" do
let(:current_user) { admin }
- describe 'creates a storage and returns it' do
+ describe "creates a storage and returns it" do
subject { last_response.body }
- it_behaves_like 'successful response', 201
+ it_behaves_like "successful response", 201
- it { is_expected.to have_json_path('_embedded/oauthApplication/clientSecret') }
+ it { is_expected.to have_json_path("_embedded/oauthApplication/clientSecret") }
end
- context 'with applicationPassword' do
+ context "with applicationPassword" do
let(:params) do
super().merge(
- applicationPassword: 'myappsecret'
+ applicationPassword: "myappsecret"
)
end
subject { last_response.body }
- it_behaves_like 'successful response', 201
+ it_behaves_like "successful response", 201
- it { is_expected.to be_json_eql('true').at_path('hasApplicationPassword') }
+ it { is_expected.to be_json_eql("true").at_path("hasApplicationPassword") }
end
- context 'with applicationPassword as null' do
+ context "with applicationPassword as null" do
let(:params) do
super().merge(
applicationPassword: nil
@@ -168,164 +162,164 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json do
subject { last_response.body }
- it_behaves_like 'successful response', 201
+ it_behaves_like "successful response", 201
- it { is_expected.to be_json_eql('false').at_path('hasApplicationPassword') }
+ it { is_expected.to be_json_eql("false").at_path("hasApplicationPassword") }
end
- context 'if missing a mandatory value' do
+ context "if missing a mandatory value" do
let(:params) do
{
- name: 'APIStorage',
+ name: "APIStorage",
_links: {
- type: { href: 'urn:openproject-org:api:v3:storages:Nextcloud' }
+ type: { href: "urn:openproject-org:api:v3:storages:Nextcloud" }
}
}
end
- it_behaves_like 'constraint violation' do
+ it_behaves_like "constraint violation" do
let(:message) { "Host is not a valid URL" }
end
end
end
- context 'as non-admin' do
- it_behaves_like 'unauthorized access'
+ context "as non-admin" do
+ it_behaves_like "unauthorized access"
end
end
- describe 'GET /api/v3/storages/:storage_id' do
+ describe "GET /api/v3/storages/:storage_id" do
let(:path) { api_v3_paths.storage(storage.id) }
- context 'if user belongs to a project using the given storage' do
+ context "if user belongs to a project using the given storage" do
subject { last_response.body }
- it_behaves_like 'successful storage response'
+ it_behaves_like "successful storage response"
- context 'if user is missing permission view_file_links' do
+ context "if user is missing permission view_file_links" do
before(:all) { remove_permissions(user_with_permissions, :view_file_links) }
after(:all) { add_permissions(user_with_permissions, :view_file_links) }
- it_behaves_like 'not found'
+ it_behaves_like "not found"
end
- context 'if no storage with that id exists' do
+ context "if no storage with that id exists" do
let(:path) { api_v3_paths.storage(1337) }
- it_behaves_like 'not found'
+ it_behaves_like "not found"
end
end
- context 'if user has :manage_storages_in_project permission in any project' do
+ context "if user has :manage_storages_in_project permission in any project" do
let(:permissions) { %i(manage_storages_in_project) }
- it_behaves_like 'successful storage response'
+ it_behaves_like "successful storage response"
end
- context 'as admin' do
+ context "as admin" do
let(:current_user) { admin }
- it_behaves_like 'successful storage response', as_admin: true
+ it_behaves_like "successful storage response", as_admin: true
subject { last_response.body }
- it { is_expected.not_to have_json_path('_embedded/oauthApplication/clientSecret') }
+ it { is_expected.not_to have_json_path("_embedded/oauthApplication/clientSecret") }
end
- context 'when OAuth authorization server is involved' do
- shared_examples 'a storage authorization result' do |expected:, has_authorize_link:|
+ context "when OAuth authorization server is involved" do
+ shared_examples "a storage authorization result" do |expected:, has_authorize_link:|
subject { last_response.body }
it "returns #{expected}" do
- expect(subject).to be_json_eql(expected.to_json).at_path('_links/authorizationState/href')
+ expect(subject).to be_json_eql(expected.to_json).at_path("_links/authorizationState/href")
end
it "has #{has_authorize_link ? '' : 'no'} authorize link" do
if has_authorize_link
- expect(subject).to have_json_path('_links/authorize/href')
+ expect(subject).to have_json_path("_links/authorize/href")
else
- expect(subject).not_to have_json_path('_links/authorize/href')
+ expect(subject).not_to have_json_path("_links/authorize/href")
end
end
end
- context 'when authorization succeeds and storage is connected' do
+ context "when authorization succeeds and storage is connected" do
let(:auth_check_result) { ServiceResult.success }
- include_examples 'a storage authorization result',
+ include_examples "a storage authorization result",
expected: API::V3::Storages::URN_CONNECTION_CONNECTED,
has_authorize_link: false
end
- context 'when authorization fails' do
+ context "when authorization fails" do
let(:auth_check_result) { ServiceResult.failure(errors: Storages::StorageError.new(code: :unauthorized)) }
- include_examples 'a storage authorization result',
+ include_examples "a storage authorization result",
expected: API::V3::Storages::URN_CONNECTION_AUTH_FAILED,
has_authorize_link: true
end
- context 'when authorization fails with an error' do
+ context "when authorization fails with an error" do
let(:auth_check_result) { ServiceResult.failure(errors: Storages::StorageError.new(code: :error)) }
- include_examples 'a storage authorization result',
+ include_examples "a storage authorization result",
expected: API::V3::Storages::URN_CONNECTION_ERROR,
has_authorize_link: false
end
end
end
- describe 'PATCH /api/v3/storages/:storage_id' do
+ describe "PATCH /api/v3/storages/:storage_id" do
let(:path) { api_v3_paths.storage(storage.id) }
- let(:name) { 'A new storage name' }
+ let(:name) { "A new storage name" }
let(:params) { { name: } }
subject(:last_response) do
patch path, params.to_json
end
- context 'as non-admin' do
- context 'if user belongs to a project using the given storage' do
- it_behaves_like 'unauthorized access'
+ context "as non-admin" do
+ context "if user belongs to a project using the given storage" do
+ it_behaves_like "unauthorized access"
end
- context 'if user does not belong to a project using the given storage' do
+ context "if user does not belong to a project using the given storage" do
let(:current_user) { user_without_project }
- it_behaves_like 'not found'
+ it_behaves_like "not found"
end
end
- context 'as admin' do
+ context "as admin" do
let(:current_user) { admin }
- describe 'patches the storage and returns it' do
+ describe "patches the storage and returns it" do
subject { last_response.body }
- it_behaves_like 'successful response'
+ it_behaves_like "successful response"
- it { is_expected.to be_json_eql(name.to_json).at_path('name') }
+ it { is_expected.to be_json_eql(name.to_json).at_path("name") }
end
- context 'with applicationPassword' do
+ context "with applicationPassword" do
let(:params) do
super().merge(
- applicationPassword: 'myappsecret'
+ applicationPassword: "myappsecret"
)
end
before do
- mock_nextcloud_application_credentials_validation(storage.host, password: 'myappsecret')
+ mock_nextcloud_application_credentials_validation(storage.host, password: "myappsecret")
end
subject { last_response.body }
- it_behaves_like 'successful response'
+ it_behaves_like "successful response"
- it { is_expected.to be_json_eql('true').at_path('hasApplicationPassword') }
+ it { is_expected.to be_json_eql("true").at_path("hasApplicationPassword") }
end
- context 'with applicationPassword as null' do
+ context "with applicationPassword as null" do
let(:params) do
super().merge(
applicationPassword: nil
@@ -334,30 +328,30 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json do
subject { last_response.body }
- it_behaves_like 'successful response'
+ it_behaves_like "successful response"
- it { is_expected.to be_json_eql('false').at_path('hasApplicationPassword') }
+ it { is_expected.to be_json_eql("false").at_path("hasApplicationPassword") }
end
- context 'with invalid applicationPassword' do
+ context "with invalid applicationPassword" do
let(:params) do
super().merge(
- applicationPassword: '123'
+ applicationPassword: "123"
)
end
before do
- mock_nextcloud_application_credentials_validation(storage.host, password: '123', response_code: 401)
+ mock_nextcloud_application_credentials_validation(storage.host, password: "123", response_code: 401)
end
subject { last_response.body }
- it { is_expected.to be_json_eql('Password is not valid.'.to_json).at_path('message') }
+ it { is_expected.to be_json_eql("Password is not valid.".to_json).at_path("message") }
end
end
end
- describe 'DELETE /api/v3/storages/:storage_id' do
+ describe "DELETE /api/v3/storages/:storage_id" do
let(:path) { api_v3_paths.storage(storage.id) }
let(:delete_folder_url) do
"#{storage.host}/remote.php/dav/files/#{storage.username}/#{project_storage.managed_project_folder_path.chop}/"
@@ -374,72 +368,72 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json do
deletion_request_stub
end
- context 'as admin' do
+ context "as admin" do
let(:current_user) { admin }
- it_behaves_like 'successful no content response'
+ it_behaves_like "successful no content response"
end
- context 'as non-admin' do
- context 'if user belongs to a project using the given storage' do
- it_behaves_like 'unauthorized access'
+ context "as non-admin" do
+ context "if user belongs to a project using the given storage" do
+ it_behaves_like "unauthorized access"
- it 'does not request project folder deletion' do
+ it "does not request project folder deletion" do
expect(deletion_request_stub).not_to have_been_requested
end
end
- context 'if user does not belong to a project using the given storage' do
+ context "if user does not belong to a project using the given storage" do
let(:current_user) { user_without_project }
- it_behaves_like 'not found'
+ it_behaves_like "not found"
- it 'does not request project folder deletion' do
+ it "does not request project folder deletion" do
expect(deletion_request_stub).not_to have_been_requested
end
end
end
end
- describe 'GET /api/v3/storages/:storage_id/open' do
+ describe "GET /api/v3/storages/:storage_id/open" do
let(:path) { api_v3_paths.storage_open(storage.id) }
- let(:location) { 'https://deathstar.storage.org/files' }
+ let(:location) { "https://deathstar.storage.org/files" }
before do
Storages::Peripherals::Registry.stub(
- 'nextcloud.queries.open_storage',
+ "nextcloud.queries.open_storage",
->(_) { ServiceResult.success(result: location) }
)
end
- context 'as admin' do
+ context "as admin" do
let(:current_user) { admin }
- it_behaves_like 'redirect response'
+ it_behaves_like "redirect response"
end
- context 'if user belongs to a project using the given storage' do
- it_behaves_like 'redirect response'
+ context "if user belongs to a project using the given storage" do
+ it_behaves_like "redirect response"
- context 'if user is missing permission view_file_links' do
+ context "if user is missing permission view_file_links" do
before(:all) { remove_permissions(user_with_permissions, :view_file_links) }
after(:all) { add_permissions(user_with_permissions, :view_file_links) }
- it_behaves_like 'not found'
+ it_behaves_like "not found"
end
- context 'if no storage with that id exists' do
- let(:path) { api_v3_paths.storage_open('1337') }
+ context "if no storage with that id exists" do
+ let(:path) { api_v3_paths.storage_open("1337") }
- it_behaves_like 'not found'
+ it_behaves_like "not found"
end
end
end
- describe 'POST /api/v3/storages/:storage_id/oauth_client_credentials' do
+ describe "POST /api/v3/storages/:storage_id/oauth_client_credentials" do
let(:path) { api_v3_paths.storage_oauth_client_credentials(storage.id) }
- let(:client_id) { 'myl1ttlecl13ntidii' }
- let(:client_secret) { 'th3v3rys3cr3tcl13nts3cr3t' }
+ let(:client_id) { "myl1ttlecl13ntidii" }
+ let(:client_secret) { "th3v3rys3cr3tcl13nts3cr3t" }
let(:params) do
{
clientId: client_id,
@@ -451,41 +445,41 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json do
post path, params.to_json
end
- context 'as non-admin' do
- context 'if user belongs to a project using the given storage' do
- it_behaves_like 'unauthorized access'
+ context "as non-admin" do
+ context "if user belongs to a project using the given storage" do
+ it_behaves_like "unauthorized access"
end
- context 'if user does not belong to a project using the given storage' do
+ context "if user does not belong to a project using the given storage" do
let(:current_user) { user_without_project }
- it_behaves_like 'not found'
+ it_behaves_like "not found"
end
end
- context 'as admin' do
+ context "as admin" do
let(:current_user) { admin }
- describe 'creates new oauth client secrets' do
+ describe "creates new oauth client secrets" do
subject { last_response.body }
- it_behaves_like 'successful response', 201
+ it_behaves_like "successful response", 201
- it { is_expected.to be_json_eql('OAuthClientCredentials'.to_json).at_path('_type') }
- it { is_expected.to be_json_eql(client_id.to_json).at_path('clientId') }
- it { is_expected.to be_json_eql(true.to_json).at_path('confidential') }
- it { is_expected.not_to have_json_path('clientSecret') }
+ it { is_expected.to be_json_eql("OAuthClientCredentials".to_json).at_path("_type") }
+ it { is_expected.to be_json_eql(client_id.to_json).at_path("clientId") }
+ it { is_expected.to be_json_eql(true.to_json).at_path("confidential") }
+ it { is_expected.not_to have_json_path("clientSecret") }
end
- context 'if request body is invalid' do
+ context "if request body is invalid" do
let(:params) do
{
- clientSecret: 'only_an_id'
+ clientSecret: "only_an_id"
}
end
- it_behaves_like 'constraint violation' do
- let(:message) { 'Client ID can\'t be blank.' }
+ it_behaves_like "constraint violation" do
+ let(:message) { "Client ID can't be blank." }
end
end
end
diff --git a/modules/storages/spec/requests/storages/project_settings/oauth_access_grant_flow_spec.rb b/modules/storages/spec/requests/storages/project_settings/oauth_access_grant_flow_spec.rb
index 86647c0c511..41f5f901ede 100644
--- a/modules/storages/spec/requests/storages/project_settings/oauth_access_grant_flow_spec.rb
+++ b/modules/storages/spec/requests/storages/project_settings/oauth_access_grant_flow_spec.rb
@@ -62,7 +62,7 @@ RSpec.describe "GET /projects/:project_id/settings/project_storages/:id/oauth_ac
context "when user is logged in" do
before { login_as(user) }
- context 'when user is not "connected"' do
+ context "when user is not 'connected'" do
let(:nonce) { "57a17c3f-b2ed-446e-9dd8-651ba3aec37d" }
let(:redirect_uri) do
CGI.escape("#{OpenProject::Application.root_url}/oauth_clients/#{storage.oauth_client.client_id}/callback")
@@ -90,19 +90,11 @@ RSpec.describe "GET /projects/:project_id/settings/project_storages/:id/oauth_ac
end
end
- context 'when user is "connected"' do
+ context "when user is 'connected'" do
shared_let(:oauth_client_token) { create(:oauth_client_token, oauth_client: storage.oauth_client, user:) }
before do
- oauth_client_token
- stub_request(:get, "#{storage.host}/ocs/v1.php/cloud/user")
- .with(
- headers: {
- "Accept" => "application/json",
- "Authorization" => "Bearer #{oauth_client_token.access_token}",
- "Ocs-Apirequest" => "true"
- }
- ).to_return(status: 200, body: "", headers: {})
+ Storages::Peripherals::Registry.stub("nextcloud.queries.auth_check", ->(_) { ServiceResult.success })
end
it "redirects to destination_url" do