diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb index 709e66955..df90ea57b 100644 --- a/app/controllers/registrar/sessions_controller.rb +++ b/app/controllers/registrar/sessions_controller.rb @@ -161,12 +161,10 @@ class Registrar possible_users = ApiUser.where(identity_code: idc) || User.new possible_users.each do |selected_user| - next unless selected_user.registrar.white_ips.registrar_area.include_ip?(request.ip) - - return selected_user + if selected_user.registrar.white_ips.registrar_area.include_ip?(request.ip) + return selected_user + end end - - User.new end def check_ip_restriction diff --git a/app/models/bounced_mail_address.rb b/app/models/bounced_mail_address.rb index f12c7f19c..02bb42337 100644 --- a/app/models/bounced_mail_address.rb +++ b/app/models/bounced_mail_address.rb @@ -4,25 +4,26 @@ class BouncedMailAddress < ApplicationRecord before_validation :assign_bounce_reason def assign_bounce_reason - if recipient_json - self.bounce_reason = "#{action} (#{status} #{diagnostic})" - else - self.bounce_reason = nil - end + return self.bounce_reason = nil unless recipient_json + + self.bounce_reason = "#{action} (#{status} #{diagnostic})" end def diagnostic - return nil unless recipient_json + return unless recipient_json + recipient_json['diagnosticCode'] end def action - return nil unless recipient_json + return unless recipient_json + recipient_json['action'] end def status - return nil unless recipient_json + return unless recipient_json + recipient_json['status'] end diff --git a/test/models/bounced_mail_address_test.rb b/test/models/bounced_mail_address_test.rb index 2caea7d98..0e6a62ab8 100644 --- a/test/models/bounced_mail_address_test.rb +++ b/test/models/bounced_mail_address_test.rb @@ -57,5 +57,43 @@ class BouncedMailAddressTest < ActiveSupport::TestCase end def test_creates_objects_from_sns_json + BouncedMailAddress.record(sns_bounce_payload) + + bounced_mail = BouncedMailAddress.last + assert_equal domains(:shop).registrant.email, bounced_mail.email + assert_equal 'failed', bounced_mail.action + assert_equal '5.1.1', bounced_mail.status + assert_equal 'smtp; 550 5.1.1 user unknown', bounced_mail.diagnostic + end + + def sns_bounce_payload + { + "notificationType": "Bounce", + "mail": { + "source": "noreply@registry.test", + "sourceIp": "195.43.86.5", + "messageId": "010f0174a0c7d348-ea6e2fc1-0854-4073-b71f-5cecf9b0d0b2-000000", + "sourceArn": "arn:aws:ses:us-east-2:65026820000:identity/noreply@registry.test", + "timestamp": "2020-09-18T10:34:44.000Z", + "destination": [ "#{domains(:shop).registrant.email}" ], + "sendingAccountId": "650268220000" + }, + "bounce": { + "timestamp": "2020-09-18T10:34:44.911Z", + "bounceType": "Permanent", + "feedbackId": "010f0174a0c7d4f9-27d59756-6111-4d5f-xxxx-26bee0d55fa2-000000", + "remoteMtaIp": "127.0.01", + "reportingMTA": "dsn; xxx.amazonses.com", + "bounceSubType": "General", + "bouncedRecipients": [ + { + "action": "failed", + "status": "5.1.1", + "emailAddress": "#{domains(:shop).registrant.email}", + "diagnosticCode": "smtp; 550 5.1.1 user unknown" + } + ] + } + }.as_json end end