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

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.rb
index e285d81e525..e83171c7586 100644
--- a/app/services/oauth_clients/connection_manager.rb
+++ b/app/services/oauth_clients/connection_manager.rb
@@ -201,15 +201,20 @@ module OAuthClients
rack_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 => e
service_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 => e
service_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 => e
service_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
)
end
diff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rb
index 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 do
expect(subject.success).to be_falsey
expect(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')
end
end
@@ -255,14 +255,27 @@ describe OAuthClients::ConnectionManager, type: :model do
end
end
- context 'with bad HTTP response' do
+ context 'when something is wrong with connection' do
before 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)
end
it 'returns an unspecific error message' do
expect(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 do
it 'returns an unspecific error message' do
expect(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 do
it 'returns a valid ClientToken object', webmock: true do
expect(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)
end
end