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
Fix specs after rack-oauth2 update.
Pavel Balashov0614bff3482e
diff --git a/app/services/oauth_clients/connection_manager.rb b/app/services/oauth_clients/connection_manager.rbindex 91c5df084d1..dc05af51fb2 100644--- a/app/services/oauth_clients/connection_manager.rb+++ b/app/services/oauth_clients/connection_manager.rb@@ -198,14 +198,15 @@ module OAuthClients# Calls client.access_token!# Convert the various exceptions into user-friendly error strings.def request_new_token(options = {})- rack_access_token = rack_oauth_client(options)- .access_token!(:body) # Rack::OAuth2::AccessToken+ rack_access_token = rack_oauth_client(options).access_token!(:body)ServiceResult.success(result: rack_access_token)- rescue Rack::OAuth2::Client::Error => e # Handle Rack::OAuth2 specific errors+ rescue Rack::OAuth2::Client::Error, Faraday::ParsingError => eservice_result_with_error(i18n_rack_oauth2_error_message(e), e.message)rescue Timeout::Error, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,- Errno::EINVAL, Errno::ENETUNREACH, Errno::ECONNRESET, Errno::ECONNREFUSED, JSON::ParserError => e+ Errno::EINVAL, Errno::ENETUNREACH, Errno::ECONNRESET, Errno::ECONNREFUSED, JSON::ParserError,+ Faraday::ConnectionFailed => e+ # Reduce the number of exceptions in the list https://github.com/lostisland/faraday-net_http/blob/main/lib/faraday/adapter/net_http.rbservice_result_with_error("#{I18n.t('oauth_client.errors.oauth_returned_http_error')}: #{e.class}: #{e.message.to_html}")diff --git a/modules/openid_connect/lib/open_project/openid_connect/engine.rb b/modules/openid_connect/lib/open_project/openid_connect/engine.rbindex 9d390e7568c..a77856cef63 100644--- a/modules/openid_connect/lib/open_project/openid_connect/engine.rb+++ b/modules/openid_connect/lib/open_project/openid_connect/engine.rb@@ -31,7 +31,10 @@ module OpenProject::OpenIDConnect# Use OpenSSL default certificate store instead of HTTPClient's.# It's outdated and it's unclear how it's managed.OpenIDConnect.http_config do |config|- config.ssl_config.set_default_paths+ # The line does not work with new version of `rack-oauth2`(Faraday is used instead of HTTPClient).+ # No need for this config. Proof:+ # https://github.com/lostisland/faraday-net_http/blob/main/lib/faraday/adapter/net_http.rb#L175+ # config.ssl_config.set_default_pathsendOmniAuth::OpenIDConnect::Providers.configure custom_options: %i[diff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rbindex 0a7a10ccf36..afb9081fdf7 100644--- a/spec/services/oauth_clients/connection_manager_spec.rb+++ b/spec/services/oauth_clients/connection_manager_spec.rb@@ -142,7 +142,7 @@ describe OAuthClients::ConnectionManager, type: :model do# The callback endpoint calls `code_to_token(code)` with the code# received and exchanges the code for a bearer+refresh token# using a HTTP request.- describe '#code_to_token' do+ describe '#code_to_token', webmock: true dolet(:code) { "7kRGJ...jG3KZ" }subject { instance.code_to_token(code) }@@ -158,19 +158,19 @@ describe OAuthClients::ConnectionManager, type: :model douser_id: "admin"}.to_jsonstub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token'))- .to_return(status: 200, body: response_body)+ .to_return(status: 200, body: response_body, headers: { "content-type" => "application/json; charset=utf-8" })end- it 'returns a valid ClientToken object', webmock: true do+ it 'returns a valid ClientToken object' doexpect(subject.success).to be_truthyexpect(subject.result).to be_a OAuthClientTokenendend- context 'with known error', webmock: true do+ context 'with known error' dobefore dostub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token'))- .to_return(status: 400, body: { error: error_message }.to_json)+ .to_return(status: 400, body: { error: error_message }.to_json, headers: { "content-type" => "application/json; charset=utf-8" })endshared_examples 'OAuth2 error response' do@@ -195,10 +195,10 @@ describe OAuthClients::ConnectionManager, type: :model doendend- context 'with known reply invalid_grant', webmock: true do+ context 'with known reply invalid_grant' dobefore dostub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token'))- .to_return(status: 400, body: { error: "invalid_grant" }.to_json)+ .to_return(status: 400, body: { error: "invalid_grant" }.to_json, headers: { "content-type" => "application/json; charset=utf-8" })endit 'returns a specific error message' do@@ -209,10 +209,10 @@ describe OAuthClients::ConnectionManager, type: :model doendend- context 'with unknown reply', webmock: true do+ context 'with unknown reply' dobefore dostub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token'))- .to_return(status: 400, body: { error: "invalid_requesttt" }.to_json)+ .to_return(status: 400, body: { error: "invalid_requesttt" }.to_json, headers: { "content-type" => "application/json; charset=utf-8" })endit 'returns an unspecific error message' do@@ -223,7 +223,7 @@ describe OAuthClients::ConnectionManager, type: :model doendend- context 'with reply including JSON syntax error', webmock: true do+ context 'with reply including JSON syntax error' dobefore dostub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_return(@@ -235,13 +235,13 @@ describe OAuthClients::ConnectionManager, type: :model doit 'returns an unspecific error message' doexpect(subject.success).to be_falsey- expect(subject.result).to eq 'Unknown :: some: very, invalid> <json}'+ 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')endend- context 'with 500 reply without body', webmock: true do+ context 'with 500 reply without body' dobefore dostub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_return(status: 500)@@ -255,7 +255,7 @@ describe OAuthClients::ConnectionManager, type: :model doendend- context 'with bad HTTP response', webmock: true do+ context 'with bad HTTP response' dobefore dostub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_raise(Net::HTTPBadResponse)end@@ -268,7 +268,7 @@ describe OAuthClients::ConnectionManager, type: :model doendend- context 'with timeout returns internal error', webmock: true do+ context 'with timeout returns internal error' dobefore dostub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_timeoutend@@ -277,7 +277,7 @@ describe OAuthClients::ConnectionManager, type: :model doexpect(subject.success).to be_falseyexpect(subject.result).to be_nilexpect(subject.errors[:base].count).to be(1)- expect(subject.errors[:base].first).to include I18n.t('oauth_client.errors.oauth_returned_standard_error')+ expect(subject.errors[:base].first).to include I18n.t('oauth_client.errors.oauth_returned_http_error')endendend@@ -312,7 +312,7 @@ describe OAuthClients::ConnectionManager, type: :model douser_id: "admin"}.to_jsonstub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token'))- .to_return(status: 200, body: response_body)+ .to_return(status: 200, body: response_body, headers: { "content-type" => "application/json; charset=utf-8" })endit 'returns a valid ClientToken object', webmock: true do@@ -335,7 +335,7 @@ describe OAuthClients::ConnectionManager, type: :model douser_id: "admin"}.to_jsonstub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token'))- .to_return(status: 200, body: response_body)+ .to_return(status: 200, body: response_body, headers: { "content-type" => "application/json; charset=utf-8" })endit 'returns dependent error from model validation', webmock: true do@@ -349,7 +349,7 @@ describe OAuthClients::ConnectionManager, type: :model docontext 'with server error from OAuth2 provider' dobefore dostub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token'))- .to_return(status: 400, body: { error: "invalid_request" }.to_json)+ .to_return(status: 400, body: { error: "invalid_request" }.to_json, headers: { "content-type" => "application/json; charset=utf-8" })endit 'returns a server error', webmock: true do@@ -396,8 +396,8 @@ describe OAuthClients::ConnectionManager, type: :model doresponse_body2[:access_token] = "differ...RYvRH"request_url = File.join(host, '/index.php/apps/oauth2/api/v1/token')stub_request(:any, request_url).to_return(- { status: 200, body: response_body1.to_json },- { status: 200, body: response_body2.to_json }+ { status: 200, body: response_body1.to_json, headers: { "content-type" => "application/json; charset=utf-8" } },+ { status: 200, body: response_body2.to_json, headers: { "content-type" => "application/json; charset=utf-8" } })result1 = nil@@ -433,8 +433,8 @@ describe OAuthClients::ConnectionManager, type: :model doresponse_body2[:access_token] = "differ...RYvRH"request_url = File.join(host, '/index.php/apps/oauth2/api/v1/token')stub_request(:any, request_url)- .to_return(status: 200, body: response_body1.to_json).then- .to_return(status: 200, body: response_body2.to_json)+ .to_return(status: 200, body: response_body1.to_json, headers: { "content-type" => "application/json; charset=utf-8" }).then+ .to_return(status: 200, body: response_body2.to_json, headers: { "content-type" => "application/json; charset=utf-8" })result1 = nilresult2 = nil