Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Catch exceptions on password resets creation
Browse files Browse the repository at this point in the history
It happened sometimes that there was a misconfiguration on the mailer
values and then the passwords controller raised exceptions on password
reset creation. This is bad because the user will face an empty page,
and the logs won't reflect a thing.

With this commit we will catch these exceptions and properly log it.
Furthermore, the user will be redirected to the original page.

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Dec 18, 2017
1 parent c3ba1b5 commit 9d2ba47
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def create
else
redirect_to new_user_password_path, alert: resource.errors.full_messages, float: true
end
rescue SocketError, Errno::ECONNREFUSED => e
Rails.logger.tagged("Mailer") { Rails.logger.info "Exception: #{e.message}" }
redirect_to new_user_password_path,
alert: "Something went wrong. Check the configuration of Portus",
float: true
end

# Re-implemented from Devise to respond with a proper message on error.
Expand Down
6 changes: 6 additions & 0 deletions spec/controllers/passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
expect(@user.valid_password?("12341234")).to be false
end

it "redirects on socket error and such" do
allow(User).to receive(:send_reset_password_instructions) { raise SocketError, "error" }
post :create, "user" => { "email" => @user.email }
expect(response.status).to eq 302
end

describe "LDAP support is enabled" do
before do
APP_CONFIG["ldap"] = { "enabled" => true }
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/portus/registry_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:delete) { ::Portus::Fixtures::RegistryEvent::DELETE.dup }
let(:version23) { ::Portus::Fixtures::RegistryEvent::VERSION23.dup }

it "processes all the relevant events", focus: true do
it "processes all the relevant events" do
evaluated_events = [relevant, delete, version23]
evaluated_events.each { |e| body["events"] << e }

Expand Down

0 comments on commit 9d2ba47

Please sign in to comment.