mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 05:05:45 +02:00
Merge remote-tracking branch 'origin/master' into 1763-registrar-bulk-renew
This commit is contained in:
commit
00a65b3b01
40 changed files with 818 additions and 160 deletions
10
test/fixtures/bounced_mail_addresses.yml
vendored
Normal file
10
test/fixtures/bounced_mail_addresses.yml
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
one:
|
||||
email: bounced@registry.test
|
||||
message_id: 010f0174a0c7d348-ea6e2fc1-0854-4073-b71f-5cecf9b0d0b2-000000
|
||||
bounce_type: Permanent
|
||||
bounce_subtype: General
|
||||
action: failed
|
||||
status: '5.1.1'
|
||||
diagnostic: 'smtp; 550 5.1.1 user unknown'
|
||||
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
|
@ -50,10 +50,10 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
assert_equal(200, response.status)
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
array_of_domain_names = response_json.map { |x| x[:name] }
|
||||
array_of_domain_names = response_json[:domains].map { |x| x[:name] }
|
||||
assert(array_of_domain_names.include?('hospital.test'))
|
||||
|
||||
array_of_domain_registrars = response_json.map { |x| x[:registrar] }
|
||||
array_of_domain_registrars = response_json[:domains].map { |x| x[:registrar] }
|
||||
assert(array_of_domain_registrars.include?({name: 'Good Names', website: nil}))
|
||||
end
|
||||
|
||||
|
@ -63,12 +63,12 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal(200, response.status)
|
||||
assert_equal(2, response_json.count)
|
||||
assert_equal(2, response_json[:domains].count)
|
||||
|
||||
get '/api/v1/registrant/domains', headers: @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal(4, response_json.count)
|
||||
assert_equal(4, response_json[:domains].count)
|
||||
end
|
||||
|
||||
def test_root_does_not_accept_limit_higher_than_200
|
||||
|
|
75
test/integration/api/v1/bounces/create_test.rb
Normal file
75
test/integration/api/v1/bounces/create_test.rb
Normal file
|
@ -0,0 +1,75 @@
|
|||
require 'test_helper'
|
||||
|
||||
class BouncesApiV1CreateTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@api_key = "Basic #{ENV['api_shared_key']}"
|
||||
@headers = { "Authorization": "#{@api_key}" }
|
||||
@json_body = { "data": valid_bounce_request }.as_json
|
||||
end
|
||||
|
||||
def test_authorizes_api_request
|
||||
post api_v1_bounces_path, params: @json_body, headers: @headers
|
||||
assert_response :created
|
||||
|
||||
invalid_headers = { "Authorization": "Basic invalid_api_key" }
|
||||
post api_v1_bounces_path, params: @json_body, headers: invalid_headers
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_returns_bad_request_if_invalid_payload
|
||||
invalid_json_body = @json_body.dup
|
||||
invalid_json_body['data']['bounce']['bouncedRecipients'] = nil
|
||||
|
||||
post api_v1_bounces_path, params: invalid_json_body, headers: @headers
|
||||
assert_response :bad_request
|
||||
|
||||
invalid_json_body = 'aaaa'
|
||||
post api_v1_bounces_path, params: invalid_json_body, headers: @headers
|
||||
assert_response :bad_request
|
||||
end
|
||||
|
||||
def test_saves_new_bounce_object
|
||||
request_body = @json_body.dup
|
||||
random_mail = "#{rand(10000..99999)}@registry.test"
|
||||
request_body['data']['bounce']['bouncedRecipients'][0]['emailAddress'] = random_mail
|
||||
|
||||
post api_v1_bounces_path, params: request_body, headers: @headers
|
||||
assert_response :created
|
||||
|
||||
bounced_mail = BouncedMailAddress.last
|
||||
assert bounced_mail.email = random_mail
|
||||
assert '5.1.1', bounced_mail.status
|
||||
assert 'failed', bounced_mail.action
|
||||
end
|
||||
|
||||
def valid_bounce_request
|
||||
{
|
||||
"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": [ "bounced@registry.test" ],
|
||||
"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": "bounced@registry.test",
|
||||
"diagnosticCode": "smtp; 550 5.1.1 user unknown"
|
||||
}
|
||||
]
|
||||
}
|
||||
}.as_json
|
||||
end
|
||||
end
|
|
@ -18,7 +18,7 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
|
|||
new_registrant_email: @new_registrant.email,
|
||||
current_user_id: @user.id })
|
||||
|
||||
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
|
||||
DomainDeleteConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
|
||||
|
||||
last_registrar_notification = @domain.registrar.notifications.last
|
||||
assert_equal(last_registrar_notification.attached_obj_id, @domain.id)
|
||||
|
@ -31,7 +31,7 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
|
|||
new_registrant_email: @new_registrant.email,
|
||||
current_user_id: @user.id })
|
||||
|
||||
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED)
|
||||
DomainDeleteConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED)
|
||||
|
||||
last_registrar_notification = @domain.registrar.notifications.last
|
||||
assert_equal(last_registrar_notification.attached_obj_id, @domain.id)
|
||||
|
@ -51,7 +51,7 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
|
|||
assert @domain.registrant_delete_confirmable?(@domain.registrant_verification_token)
|
||||
assert_equal @user.id, @domain.pending_json['current_user_id']
|
||||
|
||||
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED)
|
||||
DomainDeleteConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED)
|
||||
@domain.reload
|
||||
|
||||
assert @domain.statuses.include? DomainStatus::PENDING_DELETE
|
||||
|
@ -72,7 +72,7 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
|
|||
assert @domain.registrant_delete_confirmable?(@domain.registrant_verification_token)
|
||||
assert_equal @user.id, @domain.pending_json['current_user_id']
|
||||
|
||||
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
|
||||
DomainDeleteConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
|
||||
@domain.reload
|
||||
|
||||
assert_equal ['ok'], @domain.statuses
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'serializers/registrant_api/contact'
|
|||
class SerializersRegistrantApiContactTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@contact = contacts(:william)
|
||||
@serializer = Serializers::RegistrantApi::Contact.new(@contact)
|
||||
@serializer = Serializers::RegistrantApi::Contact.new(@contact, false)
|
||||
@json = @serializer.to_json
|
||||
end
|
||||
|
||||
|
|
104
test/models/bounced_mail_address_test.rb
Normal file
104
test/models/bounced_mail_address_test.rb
Normal file
|
@ -0,0 +1,104 @@
|
|||
require 'test_helper'
|
||||
|
||||
class BouncedMailAddressTest < ActiveSupport::TestCase
|
||||
include ActionMailer::TestHelper
|
||||
|
||||
def setup
|
||||
@bounced_mail = BouncedMailAddress.new
|
||||
@bounced_mail.email = 'recipient@registry.test'
|
||||
@bounced_mail.message_id = '010f0174a0c7d348-ea6e2fc1-0854-4073-b71f-5cecf9b0d0b2-000000'
|
||||
@bounced_mail.bounce_type = 'Permanent'
|
||||
@bounced_mail.bounce_subtype = 'General'
|
||||
@bounced_mail.action = 'failed'
|
||||
@bounced_mail.status = '5.1.1'
|
||||
@bounced_mail.diagnostic = 'smtp; 550 5.1.1 user unknown'
|
||||
end
|
||||
|
||||
def test_email_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.email = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_message_id_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.message_id = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_bounce_type_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.bounce_type = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_bounce_subtype_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.bounce_subtype = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_action_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.action = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_status_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.status = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_diagnostic_is_not_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.diagnostic = nil
|
||||
assert @bounced_mail.valid?
|
||||
end
|
||||
|
||||
def test_bounce_reason_is_determined_dynamically
|
||||
assert @bounced_mail.valid?
|
||||
assert_equal 'failed (5.1.1 smtp; 550 5.1.1 user unknown)', @bounced_mail.bounce_reason
|
||||
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
|
40
test/system/admin_area/bounced_mail_addresses_test.rb
Normal file
40
test/system/admin_area/bounced_mail_addresses_test.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
require 'application_system_test_case'
|
||||
|
||||
class AdminBouncedMailAddressesTest < ApplicationSystemTestCase
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
def setup
|
||||
@bounced_mail = bounced_mail_addresses(:one)
|
||||
@original_default_language = Setting.default_language
|
||||
sign_in users(:admin)
|
||||
end
|
||||
|
||||
def teardown
|
||||
Setting.default_language = @original_default_language
|
||||
end
|
||||
|
||||
def test_shows_bounced_emails
|
||||
visit admin_bounced_mail_addresses_path
|
||||
assert_text @bounced_mail.status
|
||||
assert_text @bounced_mail.action
|
||||
assert_text @bounced_mail.diagnostic
|
||||
assert_text @bounced_mail.email
|
||||
end
|
||||
|
||||
def test_shows_detailed_bounced_email
|
||||
visit admin_bounced_mail_address_path(@bounced_mail)
|
||||
assert_text @bounced_mail.status
|
||||
assert_text @bounced_mail.action
|
||||
assert_text @bounced_mail.diagnostic
|
||||
assert_text @bounced_mail.email
|
||||
|
||||
assert_text @bounced_mail.message_id
|
||||
end
|
||||
|
||||
def test_deletes_registrar
|
||||
visit admin_bounced_mail_address_path(@bounced_mail)
|
||||
click_on 'Destroy'
|
||||
|
||||
assert_text 'Bounced mail address was successfully destroyed.'
|
||||
end
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
require 'application_system_test_case'
|
||||
|
||||
class DomainDeleteConfirmsTest < ApplicationSystemTestCase
|
||||
include ActionMailer::TestHelper
|
||||
setup do
|
||||
@user = users(:registrant)
|
||||
sign_in @user
|
||||
|
@ -13,7 +14,9 @@ class DomainDeleteConfirmsTest < ApplicationSystemTestCase
|
|||
def test_enqueues_approve_job_after_verification
|
||||
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
|
||||
|
||||
click_on 'Confirm domain delete'
|
||||
perform_enqueued_jobs do
|
||||
click_on 'Confirm domain delete'
|
||||
end
|
||||
assert_text 'Domain registrant change has successfully received.'
|
||||
|
||||
@domain.reload
|
||||
|
@ -23,7 +26,9 @@ class DomainDeleteConfirmsTest < ApplicationSystemTestCase
|
|||
def test_enqueues_reject_job_after_verification
|
||||
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
|
||||
|
||||
click_on 'Reject domain delete'
|
||||
perform_enqueued_jobs do
|
||||
click_on 'Reject domain delete'
|
||||
end
|
||||
assert_text 'Domain registrant change has been rejected successfully.'
|
||||
|
||||
@domain.reload
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue