Fix CC issues

This commit is contained in:
Karl Erik Õunapuu 2020-09-18 14:49:27 +03:00
parent 7d8c24533a
commit 64308e1104
No known key found for this signature in database
GPG key ID: C9DD647298A34764
3 changed files with 50 additions and 13 deletions

View file

@ -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

View file

@ -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

View file

@ -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