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

Better error messages

Oliver Güntheraa6a06657892
diff --git a/app/controllers/omni_auth_login_controller.rb b/app/controllers/omni_auth_login_controller.rb
index 74dad853055..bfc027e2289 100644
--- a/app/controllers/omni_auth_login_controller.rb
+++ b/app/controllers/omni_auth_login_controller.rb
@@ -55,12 +55,22 @@ class OmniAuthLoginController < ApplicationController
end
def failure
- logger.warn(params[:message]) if params[:message]
- show_error I18n.t(:error_external_authentication_failed)
+ log_omniauth_failure
+ show_error I18n.t(:error_external_authentication_failed, message: omniauth_error)
end
private
+ def log_omniauth_failure
+ type = request.env["omniauth.error.type"] || "internal"
+ logger.warn "OmniAuth authentication failed (Error #{type}): #{omniauth_error}"
+ end
+
+ def omniauth_error
+ message = request.env["omniauth.error"] || request.env["omniauth.error.type"] || request.env["omniauth.error.message"]
+ message&.to_s || "Unknown error"
+ end
+
def redirect_omniauth_register_modal(user, auth_hash)
# Store a timestamp so we can later make sure that authentication information can
# only be reused for a short time.
diff --git a/config/locales/en.yml b/config/locales/en.yml
index cd25d99c6a0..f124410b7ef 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1748,7 +1748,7 @@ en:
Can't rename "%{old_name}" to "%{new_name}" due to a conflict in the resulting menu item
with the existing menu item "%{existing_caption}" (%{existing_identifier}).
- error_external_authentication_failed: "An error occurred during external authentication. Please try again."
+ error_external_authentication_failed: "An error occurred during external authentication: %{message}"
error_attribute_not_highlightable: "Attribute(s) not highlightable: %{attributes}"
events:
diff --git a/modules/auth_saml/spec/requests/saml_provider_callback_spec.rb b/modules/auth_saml/spec/requests/saml_provider_callback_spec.rb
index 7af02bacc02..a78a8a3a05c 100644
--- a/modules/auth_saml/spec/requests/saml_provider_callback_spec.rb
+++ b/modules/auth_saml/spec/requests/saml_provider_callback_spec.rb
@@ -29,7 +29,9 @@
require "spec_helper"
require "rack/test"
-RSpec.describe "SAML provider callback", with_ee: %i[openid_providers] do
+RSpec.describe "SAML provider callback",
+ type: :rails_request,
+ with_ee: %i[openid_providers] do
include Rack::Test::Methods
include API::V3::Utilities::PathHelper
@@ -79,10 +81,11 @@ RSpec.describe "SAML provider callback", with_ee: %i[openid_providers] do
}
end
- shared_examples "request fails" do
+ shared_examples "request fails" do |message|
it "redirects to the failure page" do
expect(subject.status).to eq(302)
- expect(subject.headers["Location"]).to eq("/auth/failure?message=invalid_ticket&strategy=saml")
+ follow_redirect!
+ expect(last_response.body).to have_text message
end
end
@@ -98,13 +101,13 @@ RSpec.describe "SAML provider callback", with_ee: %i[openid_providers] do
end
end
- it_behaves_like "request fails"
+ it_behaves_like "request fails", "Current time is earlier than NotBefore condition"
end
context "with an invalid fingerprint" do
let(:fingerprint) { "invalid" }
- it_behaves_like "request fails"
+ it_behaves_like "request fails", "Fingerprint mismatch"
end
context "with a RelayState present" do
diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rb
index b7ff40174c3..c5519cfd7b6 100644
--- a/spec/controllers/concerns/omniauth_login_spec.rb
+++ b/spec/controllers/concerns/omniauth_login_spec.rb
@@ -484,9 +484,10 @@ RSpec.describe OmniAuthLoginController, :skip_2fa_stage do # rubocop:disable RSp
it "logs a warn message" do
allow(Rails.logger).to receive(:warn)
- post :failure, params: { message: "invalid_credentials" }
+ request.env["omniauth.error"] = "invalid_credentials"
+ post :failure
- expect(Rails.logger).to have_received(:warn).with("invalid_credentials")
+ expect(Rails.logger).to have_received(:warn).with(/invalid_credentials/)
end
end
end