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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Making more tests pass
Marcello Rocha3519239d48eb
diff --git a/app/controllers/oauth_clients_controller.rb b/app/controllers/oauth_clients_controller.rbindex 9a44a805efc..b7be42bcc58 100644--- a/app/controllers/oauth_clients_controller.rb+++ b/app/controllers/oauth_clients_controller.rb@@ -126,7 +126,10 @@ class OAuthClientsController < ApplicationControllerenddef set_connection_manager- @connection_manager = OAuthClients::ConnectionManager.new(user: User.current, oauth_client: @oauth_client)+ @connection_manager = OAuthClients::ConnectionManager.new(+ user: User.current,+ configuration: @oauth_client.integration.oauth_configuration+ )enddef find_oauth_clientdiff --git a/app/services/oauth_clients/connection_manager.rb b/app/services/oauth_clients/connection_manager.rbindex 9bca7971b75..d5fc4b27191 100644--- a/app/services/oauth_clients/connection_manager.rb+++ b/app/services/oauth_clients/connection_manager.rb@@ -140,7 +140,8 @@ module OAuthClientsoauth_client_token = get_existing_tokenreturn :failed_authorization unless oauth_client_token- case @config.authorization_state_check(oauth_client_token.access_token)+ state = @config.authorization_state_check(oauth_client_token.access_token)+ case statewhen :success:connectedwhen :refresh_needed@@ -153,7 +154,7 @@ module OAuthClients:errorendelse- response+ stateendrescue StandardError:errordiff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rbindex ac96b749369..cc7014961da 100644--- a/spec/services/oauth_clients/connection_manager_spec.rb+++ b/spec/services/oauth_clients/connection_manager_spec.rb@@ -36,11 +36,12 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true dolet(:host) { "https://example.org" }let(:storage) { create(:nextcloud_storage, :with_oauth_client, host: "#{host}/") }let(:oauth_client) { storage.oauth_client }+ let(:configuration) { storage.oauth_configuration }let(:scope) { [:all] } # OAuth2 resources to access, specific to providerlet(:oauth_client_token) { create(:oauth_client_token, oauth_client:, user:) }- let(:instance) { described_class.new(user:, configuration: storage.oauth_configuration) }+ let(:instance) { described_class.new(user:, configuration:) }# The get_authorization_uri method returns the OAuth2 authorization URI as a string. That URI is the starting point for# a user to grant OpenProject access to Nextcloud.@@ -494,8 +495,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true docontext 'with access token valid' docontext 'without other errors or exceptions' dobefore do- stub_request(:get, File.join(host, OAuthClients::ConnectionManager::AUTHORIZATION_CHECK_PATH))- .to_return(status: 200)+ allow(configuration).to receive(:authorization_state_check).and_return(:success)endit 'returns :connected' do@@ -505,8 +505,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true docontext 'with some other error or exception' dobefore do- stub_request(:get, File.join(host, OAuthClients::ConnectionManager::AUTHORIZATION_CHECK_PATH))- .to_timeout+ allow(configuration).to receive(:authorization_state_check).and_return(:error)endit 'returns :error' do@@ -519,45 +518,34 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true dolet(:new_oauth_client_token) { create(:oauth_client_token) }let(:refresh_service_result) { ServiceResult.success }- shared_examples 'refresh' do |code|- before do- stub_request(:get, File.join(host, OAuthClients::ConnectionManager::AUTHORIZATION_CHECK_PATH))- .to_return(status: code)- allow(instance).to receive(:refresh_token).and_return(refresh_service_result)- end-- context 'with valid refresh token' do- it 'refreshes the access token and returns :connected' do- expect(subject).to eq :connected- expect(instance).to have_received(:refresh_token)- end- end-- context 'with invalid refresh token' do- let(:refresh_service_result) { ServiceResult.failure(result: 'invalid_request') }+ before do+ allow(configuration).to receive(:authorization_state_check).and_return(:refresh_needed)+ allow(instance).to receive(:refresh_token).and_return(refresh_service_result)+ end- it 'refreshes the access token and returns :failed_authorization' do- expect(subject).to eq :failed_authorization- expect(instance).to have_received(:refresh_token)- end+ context 'with valid refresh token' do+ it 'refreshes the access token and returns :connected' do+ expect(subject).to eq :connected+ expect(instance).to have_received(:refresh_token)end+ end- context 'with some other error while refreshing access token' do- let(:refresh_service_result) { ServiceResult.failure }+ context 'with invalid refresh token' do+ let(:refresh_service_result) { ServiceResult.failure(result: 'invalid_request') }- it 'returns :error' do- expect(subject).to eq :error- expect(instance).to have_received(:refresh_token)- end+ it 'refreshes the access token and returns :failed_authorization' do+ expect(subject).to eq :failed_authorization+ expect(instance).to have_received(:refresh_token)endend- context 'when Uanthorized is returned' do- it_behaves_like 'refresh', 401- end+ context 'with some other error while refreshing access token' do+ let(:refresh_service_result) { ServiceResult.failure }- context 'when Forbidded is returned' do- it_behaves_like 'refresh', 403+ it 'returns :error' do+ expect(subject).to eq :error+ expect(instance).to have_received(:refresh_token)+ endendendenddiff --git a/spec/services/oauth_clients/one_drive_connection_manager_spec.rb b/spec/services/oauth_clients/one_drive_connection_manager_spec.rbindex 930960dd0fd..305d87c9df8 100644--- a/spec/services/oauth_clients/one_drive_connection_manager_spec.rb+++ b/spec/services/oauth_clients/one_drive_connection_manager_spec.rb@@ -36,7 +36,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true dolet(:token) { create(:oauth_client_token, oauth_client: storage.oauth_client, user:) }subject(:connection_manager) do- OAuthClients::ConnectionManager.new(user:, oauth_client: nil, configuration: storage.oauth_configuration)+ described_class.new(user:, configuration: storage.oauth_configuration)enddescribe '#get_authorization_uri' do