diff --git a/backend/config/initializers/match_live_tv.rb b/backend/config/initializers/match_live_tv.rb index c3c1830..201ab9a 100644 --- a/backend/config/initializers/match_live_tv.rb +++ b/backend/config/initializers/match_live_tv.rb @@ -1,3 +1,6 @@ +require "net/smtp" +require "openssl" + module MatchLiveTv class << self def jwt_secret @@ -102,6 +105,7 @@ module MatchLiveTv end # In produzione senza SMTP non blocca il flusso (es. collaudo): la mail si può inviare a mano. + # Errori SMTP (dominio invalido, EOF Aruba, porta chiusa) non devono far crashare la request. def deliver_mail(mail) if Rails.env.production? && !smtp_configured? Rails.logger.info("[mail] skip (SMTP assente): #{mail.subject}") @@ -110,6 +114,9 @@ module MatchLiveTv mail.deliver_now true + rescue EOFError, Net::SMTPError, Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError, OpenSSL::SSL::SSLError => e + Rails.logger.warn("[mail] delivery failed: #{mail.subject} #{e.class}: #{e.message}") + false end def privacy_controller_name diff --git a/backend/spec/requests/account_spec.rb b/backend/spec/requests/account_spec.rb index 118840c..3b34a9d 100644 --- a/backend/spec/requests/account_spec.rb +++ b/backend/spec/requests/account_spec.rb @@ -120,6 +120,17 @@ RSpec.describe "Account API", type: :request do expect(user.reload.password_reset_digest).to be_present end + it "non va in 500 se SMTP rifiuta il destinatario" do + allow_any_instance_of(ActionMailer::MessageDelivery).to receive(:deliver_now) + .and_raise(Net::SMTPFatalError.new("556 5.1.10 invalid destination domain")) + + expect { + post "/api/v1/auth/password/forgot", params: { email: user.email } + }.not_to raise_error + expect(response).to have_http_status(:ok) + expect(user.reload.password_reset_digest).to be_present + end + it "returns the same message for unknown emails" do expect { post "/api/v1/auth/password/forgot", params: { email: "nobody@example.com" }