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
Add Faraday::SSLError and refactor a bit.
Pavel Balashovf69a69f1d642
diff --git a/app/services/oauth_clients/connection_manager.rb b/app/services/oauth_clients/connection_manager.rbindex e285d81e525..e83171c7586 100644--- a/app/services/oauth_clients/connection_manager.rb+++ b/app/services/oauth_clients/connection_manager.rb@@ -201,15 +201,20 @@ module OAuthClientsrack_access_token = rack_oauth_client(options).access_token!(:body)ServiceResult.success(result: rack_access_token)- rescue Rack::OAuth2::Client::Error, Faraday::ParsingError => e+ rescue Rack::OAuth2::Client::Error => eservice_result_with_error(i18n_rack_oauth2_error_message(e), e.message)- rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e+ rescue Faraday::TimeoutError,+ Faraday::ConnectionFailed,+ Faraday::ParsingError,+ Faraday::SSLError => eservice_result_with_error(- "#{I18n.t('oauth_client.errors.oauth_returned_http_error')}: #{e.class}: #{e.message.to_html}"+ "#{I18n.t('oauth_client.errors.oauth_returned_http_error')}: #{e.class}: #{e.message.to_html}",+ e.message)rescue StandardError => eservice_result_with_error(- "#{I18n.t('oauth_client.errors.oauth_returned_standard_error')}: #{e.class}: #{e.message.to_html}"+ "#{I18n.t('oauth_client.errors.oauth_returned_standard_error')}: #{e.class}: #{e.message.to_html}",+ e.message)enddiff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rbindex afb9081fdf7..8e665d7c79e 100644--- a/spec/services/oauth_clients/connection_manager_spec.rb+++ b/spec/services/oauth_clients/connection_manager_spec.rb@@ -237,7 +237,7 @@ describe OAuthClients::ConnectionManager, type: :model doexpect(subject.success).to be_falseyexpect(subject.result).to eq "unexpected token at 'some: very, invalid> <json}'"expect(subject.errors[:base].count).to be(1)- expect(subject.errors[:base].first).to include I18n.t('oauth_client.errors.oauth_returned_error')+ expect(subject.errors[:base].first).to include I18n.t('oauth_client.errors.oauth_returned_http_error')endend@@ -255,14 +255,27 @@ describe OAuthClients::ConnectionManager, type: :model doendend- context 'with bad HTTP response' do+ context 'when something is wrong with connection' dobefore do- stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_raise(Net::HTTPBadResponse)+ stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_raise(Faraday::ConnectionFailed)endit 'returns an unspecific error message' doexpect(subject.success).to be_falsey- expect(subject.result).to be_nil+ expect(subject.result).to eq("Exception from WebMock")+ expect(subject.errors[:base].count).to be(1)+ expect(subject.errors[:base].first).to include I18n.t('oauth_client.errors.oauth_returned_http_error')+ end+ end++ context 'when something is wrong with SSL' do+ before do+ stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_raise(Faraday::SSLError)+ end++ it 'returns an unspecific error message' do+ expect(subject.success).to be_falsey+ expect(subject.result).to eq("Exception from WebMock")expect(subject.errors[:base].count).to be(1)expect(subject.errors[:base].first).to include I18n.t('oauth_client.errors.oauth_returned_http_error')end@@ -275,7 +288,7 @@ describe OAuthClients::ConnectionManager, type: :model doit 'returns an unspecific error message' doexpect(subject.success).to be_falsey- expect(subject.result).to be_nil+ expect(subject.result).to eq("execution expired")expect(subject.errors[:base].count).to be(1)expect(subject.errors[:base].first).to include I18n.t('oauth_client.errors.oauth_returned_http_error')end@@ -368,7 +381,7 @@ describe OAuthClients::ConnectionManager, type: :model doit 'returns a valid ClientToken object', webmock: true doexpect(subject.success).to be_falsey- expect(subject.result).to be_nil+ expect(subject.result).to eq("execution expired")expect(subject.errors.size).to be(1)endend