Merge remote-tracking branch 'origin/master' into repp-domains

This commit is contained in:
Karl Erik Õunapuu 2020-12-29 12:47:50 +02:00
commit 221e4ba578
No known key found for this signature in database
GPG key ID: C9DD647298A34764
140 changed files with 2575 additions and 731 deletions

View 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) %>

View file

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

View 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

View file

@ -35,7 +35,6 @@ class EppDomainDeleteBaseTest < EppTestCase
XML
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
# binding.pry
assert_includes Domain.find_by(name: 'invalid.test').statuses, DomainStatus::PENDING_DELETE_CONFIRMATION
assert_epp_response :completed_successfully_action_pending
end
@ -90,7 +89,9 @@ class EppDomainDeleteBaseTest < EppTestCase
</epp>
XML
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
perform_enqueued_jobs do
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
@domain.reload
assert @domain.registrant_verification_asked?
@ -121,7 +122,9 @@ class EppDomainDeleteBaseTest < EppTestCase
</epp>
XML
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
perform_enqueued_jobs do
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
@domain.reload
assert_not @domain.registrant_verification_asked?
@ -152,7 +155,9 @@ class EppDomainDeleteBaseTest < EppTestCase
</epp>
XML
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
perform_enqueued_jobs do
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
@domain.reload
assert_not @domain.registrant_verification_asked?

View file

@ -503,6 +503,30 @@ class EppDomainUpdateBaseTest < EppTestCase
assert_not_includes(@domain.statuses, DomainStatus::CLIENT_HOLD)
end
def test_update_domain_returns_error_when_removing_unassigned_status
assert_not_includes(@domain.statuses, DomainStatus::CLIENT_HOLD)
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<update>
<domain:update xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{@domain.name}</domain:name>
<domain:rem>
<domain:status s="clientHold"/>
</domain:rem>
</domain:update>
</update>
</command>
</epp>
XML
post epp_update_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
@domain.reload
assert_epp_response :object_does_not_exist
end
private
def assert_verification_and_notification_emails

View file

@ -0,0 +1,91 @@
require 'test_helper'
class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest
def setup
travel_to Time.zone.parse('2010-07-05 10:30')
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_renews_domains
payload = {
"domains": [
'shop.test',
'airport.test',
'library.test'
],
"renew_period": "1y"
}
assert_changes -> { Domain.find_by(name: 'shop.test').valid_to } do
assert_changes -> { Domain.find_by(name: 'airport.test').valid_to } do
assert_changes -> { Domain.find_by(name: 'library.test').valid_to } do
post "/repp/v1/domains/renew/bulk", headers: @auth_headers, params: payload
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
assert json[:data][:updated_domains].include? 'shop.test'
assert json[:data][:updated_domains].include? 'airport.test'
assert json[:data][:updated_domains].include? 'library.test'
end
end
end
end
def test_throws_error_when_domain_not_renewable
payload = {
"domains": [
'invalid.test',
],
"renew_period": "1y"
}
assert_no_changes -> { Domain.find_by(name: 'invalid.test').valid_to } do
post "/repp/v1/domains/renew/bulk", headers: @auth_headers, params: payload
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2002, json[:code]
assert_equal 'Domain renew error for invalid.test', json[:message]
end
end
def test_throws_error_when_not_enough_balance
billing_prices(:renew_one_year).update(price_cents: 99999999)
payload = {
"domains": [
'invalid.test',
],
"renew_period": "1y"
}
assert_no_changes -> { Domain.find_by(name: 'invalid.test').valid_to } do
post "/repp/v1/domains/renew/bulk", headers: @auth_headers, params: payload
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2002, json[:code]
assert_equal 'Not enough funds for renew domains', json[:message]
end
end
def test_throws_error_if_invalid_renew_period
payload = {
"domains": [
'shop.test'
],
"renew_period": "nope"
}
post "/repp/v1/domains/renew/bulk", headers: @auth_headers, params: payload
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2005, json[:code]
assert_equal 'Invalid renew period', json[:message]
end
end

View file

@ -0,0 +1,25 @@
require 'test_helper'
class DomainDeleteTest < ActiveSupport::TestCase
setup do
@domain = domains(:shop)
end
def test_discards_domains_with_past_delete_date
@domain.update!(delete_date: '2010-07-04')
travel_to Time.zone.parse('2010-07-05')
Domains::Delete::DoDelete.run(domain: @domain)
assert @domain.destroyed?
end
def test_sends_notification
@domain.update!(delete_date: '2010-07-04')
travel_to Time.zone.parse('2010-07-05')
assert_difference '@domain.registrar.notifications.count', 1 do
Domains::Delete::DoDelete.run(domain: @domain)
end
end
end

View file

@ -0,0 +1,28 @@
require 'test_helper'
class StartTest < ActiveSupport::TestCase
include ActionMailer::TestHelper
setup do
@domain = domains(:shop)
@domain.update(expire_time: Time.zone.now - 1.day)
ActionMailer::Base.deliveries.clear
end
def test_sets_expired
job_count = lambda do
QueJob.where("args->>0 = '#{@domain.id}'", job_class: DomainExpireEmailJob.name).count
end
assert_difference job_count, 1 do
perform_enqueued_jobs do
DomainCron.start_expire_period
end
end
@domain.reload
assert @domain.statuses.include?(DomainStatus::EXPIRED)
assert_equal @domain.outzone_at, @domain.expire_time + Domain.expire_warning_period
assert_equal @domain.delete_date, (@domain.outzone_at + Domain.redemption_grace_period).to_date
end
end

View file

@ -0,0 +1,25 @@
require 'test_helper'
class StartTest < ActiveSupport::TestCase
setup do
@domain = domains(:shop)
@domain.update(outzone_time: Time.zone.now - 1.day)
end
def test_sets_server_hold
DomainCron.start_redemption_grace_period
@domain.reload
assert @domain.statuses.include?(DomainStatus::SERVER_HOLD)
end
def test_doesnt_sets_server_hold_if_not_outzone
@domain.update(outzone_time: nil)
@domain.reload
DomainCron.start_redemption_grace_period
@domain.reload
assert_not @domain.statuses.include?(DomainStatus::SERVER_HOLD)
end
end

View file

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

View file

@ -21,7 +21,7 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
end
def test_rejected_registrant_verification_notifies_registrar
DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
last_registrar_notification = @domain.registrar.notifications.last
assert_equal(last_registrar_notification.attached_obj_id, @domain.id)
@ -29,7 +29,7 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
end
def test_accepted_registrant_verification_notifies_registrar
DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED)
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED)
last_registrar_notification = @domain.registrar.notifications.last
assert_equal(last_registrar_notification.attached_obj_id, @domain.id)
@ -47,10 +47,11 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
@domain.update(pending_json: @domain.pending_json)
@domain.reload
DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED)
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED)
@domain.reload
assert_equal @domain.registrant.code, @new_registrant.code
assert @domain.statuses.include? DomainStatus::OK
end
def test_clears_pending_update_after_denial
@ -63,10 +64,92 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
@domain.pending_json['frame'] = parsed_frame
@domain.update(pending_json: @domain.pending_json)
DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
@domain.reload
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE
end
def test_protects_statuses_after_denial
epp_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp>\n <command>\n <update>\n <update>\n <name>#{@domain.name}</name>\n" \
" <chg>\n <registrant>#{@new_registrant.code}</registrant>\n </chg>\n </update>\n </update>\n <extension>\n <update/>\n" \
" <extdata>\n <legalDocument type=\"pdf\">#{@legal_doc_path}</legalDocument>\n </extdata>\n" \
" </extension>\n <clTRID>20alla-1594199756</clTRID>\n </command>\n</epp>\n"
parsed_frame = Deserializers::Xml::DomainUpdate.new(Nokogiri::XML(epp_xml), @domain.registrar.id).call
@domain.pending_json['frame'] = parsed_frame
@domain.update(pending_json: @domain.pending_json)
@domain.update(statuses: [DomainStatus::DELETE_CANDIDATE, DomainStatus::DISPUTED])
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
@domain.reload
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE
assert @domain.statuses.include? DomainStatus::DELETE_CANDIDATE
assert @domain.statuses.include? DomainStatus::DISPUTED
end
def test_protects_statuses_after_confirm
epp_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp>\n <command>\n <update>\n <update>\n <name>#{@domain.name}</name>\n" \
" <chg>\n <registrant>#{@new_registrant.code}</registrant>\n </chg>\n </update>\n </update>\n <extension>\n <update/>\n" \
" <extdata>\n <legalDocument type=\"pdf\">#{@legal_doc_path}</legalDocument>\n </extdata>\n" \
" </extension>\n <clTRID>20alla-1594199756</clTRID>\n </command>\n</epp>\n"
parsed_frame = Deserializers::Xml::DomainUpdate.new(Nokogiri::XML(epp_xml), @domain.registrar.id).call
@domain.pending_json['frame'] = parsed_frame
@domain.update(pending_json: @domain.pending_json)
@domain.update(statuses: [DomainStatus::DELETE_CANDIDATE, DomainStatus::DISPUTED])
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED)
@domain.reload
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE
assert @domain.statuses.include? DomainStatus::DELETE_CANDIDATE
assert @domain.statuses.include? DomainStatus::DISPUTED
end
def test_clears_pending_update_and_inactive_after_denial
epp_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp>\n <command>\n <update>\n <update>\n <name>#{@domain.name}</name>\n" \
" <chg>\n <registrant>#{@new_registrant.code}</registrant>\n </chg>\n </update>\n </update>\n <extension>\n <update/>\n" \
" <extdata>\n <legalDocument type=\"pdf\">#{@legal_doc_path}</legalDocument>\n </extdata>\n" \
" </extension>\n <clTRID>20alla-1594199756</clTRID>\n </command>\n</epp>\n"
parsed_frame = Deserializers::Xml::DomainUpdate.new(Nokogiri::XML(epp_xml), @domain.registrar.id).call
@domain.pending_json['frame'] = parsed_frame
@domain.update(pending_json: @domain.pending_json)
@domain.update(statuses: [DomainStatus::PENDING_UPDATE])
@domain.nameservers.destroy_all
@domain.reload
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
@domain.reload
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE
assert_not @domain.statuses.include? DomainStatus::PENDING_UPDATE
assert @domain.statuses.include? DomainStatus::INACTIVE
end
def test_clears_pending_update_and_sets_ok_after_denial
epp_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp>\n <command>\n <update>\n <update>\n <name>#{@domain.name}</name>\n" \
" <chg>\n <registrant>#{@new_registrant.code}</registrant>\n </chg>\n </update>\n </update>\n <extension>\n <update/>\n" \
" <extdata>\n <legalDocument type=\"pdf\">#{@legal_doc_path}</legalDocument>\n </extdata>\n" \
" </extension>\n <clTRID>20alla-1594199756</clTRID>\n </command>\n</epp>\n"
parsed_frame = Deserializers::Xml::DomainUpdate.new(Nokogiri::XML(epp_xml), @domain.registrar.id).call
@domain.pending_json['frame'] = parsed_frame
@domain.update(pending_json: @domain.pending_json)
@domain.update(statuses: [DomainStatus::OK, DomainStatus::PENDING_UPDATE])
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::REJECTED)
@domain.reload
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE
assert_not @domain.statuses.include? DomainStatus::PENDING_UPDATE
assert @domain.statuses.include? DomainStatus::OK
end
end

View file

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

View 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

View file

@ -113,7 +113,7 @@ class ForceDeleteTest < ActionMailer::TestCase
def test_force_delete_cannot_be_scheduled_when_a_domain_is_discarded
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
result = ForceDeleteInteraction::SetForceDelete.run(domain: @domain, type: :fast_track)
result = Domains::ForceDelete::SetForceDelete.run(domain: @domain, type: :fast_track)
assert_not result.valid?
assert_not @domain.force_delete_scheduled?
@ -206,9 +206,10 @@ class ForceDeleteTest < ActionMailer::TestCase
@domain.schedule_force_delete(type: :soft)
travel_to Time.zone.parse('2010-08-21')
DomainCron.start_client_hold
Domains::ClientHold::SetClientHold.run!
@domain.reload
assert_emails 1
assert_equal(@domain.purge_date.to_date, @domain.force_delete_date.to_date)
assert_equal(@domain.outzone_date.to_date, @domain.force_delete_start.to_date +
Setting.expire_warning_period.days)
@ -226,8 +227,10 @@ class ForceDeleteTest < ActionMailer::TestCase
@domain.schedule_force_delete(type: :soft)
travel_to Time.zone.parse('2010-08-21')
DomainCron.start_client_hold
Domains::ClientHold::SetClientHold.run!
@domain.reload
assert_emails 1
assert_includes(@domain.statuses, asserted_status)
end
@ -241,7 +244,7 @@ class ForceDeleteTest < ActionMailer::TestCase
@domain.schedule_force_delete(type: :soft)
travel_to Time.zone.parse('2010-07-06')
DomainCron.start_client_hold
Domains::ClientHold::SetClientHold.run!
@domain.reload
assert_not_includes(@domain.statuses, asserted_status)
@ -256,7 +259,7 @@ class ForceDeleteTest < ActionMailer::TestCase
@domain.schedule_force_delete(type: :fast_track)
travel_to Time.zone.parse('2010-07-25')
DomainCron.start_client_hold
Domains::ClientHold::SetClientHold.run!
@domain.reload
assert_includes(@domain.statuses, asserted_status)
@ -272,7 +275,7 @@ class ForceDeleteTest < ActionMailer::TestCase
@domain.schedule_force_delete(type: :fast_track)
travel_to Time.zone.parse('2010-07-06')
DomainCron.start_client_hold
Domains::ClientHold::SetClientHold.run!
@domain.reload
assert_not_includes(@domain.statuses, asserted_status)

View file

@ -19,7 +19,9 @@ class DomainCronTest < ActiveSupport::TestCase
registrant_verification_token: 'test',
statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
DomainCron.clean_expired_pendings
perform_enqueued_jobs do
DomainCron.clean_expired_pendings
end
assert_emails 1
end
@ -84,7 +86,9 @@ class DomainCronTest < ActiveSupport::TestCase
assert @domain.pending_update?
@domain.reload
DomainCron.clean_expired_pendings
perform_enqueued_jobs do
DomainCron.clean_expired_pendings
end
@domain.reload
assert_not @domain.pending_update?

View file

@ -414,7 +414,7 @@ class DomainTest < ActiveSupport::TestCase
force_delete_date: nil)
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-07-05')
ForceDeleteInteraction::SetForceDelete.run!(domain: @domain, type: :fast_track)
Domains::ForceDelete::SetForceDelete.run!(domain: @domain, type: :fast_track)
assert(@domain.force_delete_scheduled?)
other_registrant = Registrant.find_by(code: 'jane-001')
@domain.pending_json['new_registrant_id'] = other_registrant.id

View file

@ -70,6 +70,6 @@ class Whois::RecordTest < ActiveSupport::TestCase
end
def registration_deadline
Time.zone.now + 10.days
@registration_deadline ||= Time.zone.now + 10.days
end
end

View 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

View file

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

View file

@ -0,0 +1,70 @@
require 'application_system_test_case'
class BulkRenewTest < ApplicationSystemTestCase
setup do
@registrar = users(:api_bestnames).registrar
@price = billing_prices(:renew_one_year)
end
def test_shows_domain_list
sign_in users(:api_bestnames)
travel_to Time.zone.parse('2010-07-05 10:30')
visit new_registrar_bulk_change_url
click_link('Bulk renew')
assert_text 'Current balance'
page.has_css?('#registrar_balance', text:
ApplicationController.helpers.number_to_currency(@registrar.balance))
select '1 year', from: 'Period'
click_button 'Filter'
@registrar.domains.pluck(:name).each do |domain_name|
assert_text domain_name
end
end
def test_makes_bulk_renew
sign_in users(:api_bestnames)
travel_to Time.zone.parse('2010-07-05 10:30')
req_body = { domains: ["shop.test", "airport.test", "library.test", "invalid.test"], renew_period: "1y" }
stub_request(:post, "#{ENV['repp_url']}domains/renew/bulk").with(body: req_body)
.to_return(status: 400, body: {
code: 2304,
message: "Domain renew error for invalid.test",
data: {}
}.to_json)
visit new_registrar_bulk_change_url
click_link('Bulk renew')
select '1 year', from: 'Period'
click_button 'Filter'
click_button 'Renew'
assert_text 'Domain renew error for invalid.test'
end
def test_bulk_renew_checks_balance
sign_in users(:api_bestnames)
@price.update(price_cents: 99999999)
travel_to Time.zone.parse('2010-07-05 10:30')
req_body = { domains: ["shop.test", "airport.test", "library.test", "invalid.test"], renew_period: "1y" }
stub_request(:post, "#{ENV['repp_url']}domains/renew/bulk").with(body: req_body)
.to_return(status: 400, body: {
code: 2304,
message: "Not enough funds for renew domains",
data: {}
}.to_json)
visit new_registrar_bulk_change_url
click_link('Bulk renew')
select '1 year', from: 'Period'
click_button 'Filter'
click_button 'Renew'
assert_text 'Not enough funds for renew domains'
end
end

View file

@ -11,9 +11,9 @@ class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
request_stub = stub_request(:post, /domains\/transfer/).with(body: request_body,
headers: headers,
basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{
type: 'domain_transfer'
}] }.to_json, status: 200)
.to_return(body: { data: { success: [{ type: 'domain_transfer', domain_name: 'shop.test' }],
failed: []
} }.to_json, status: 200)
visit registrar_domains_url
click_link 'Bulk change'
@ -27,7 +27,7 @@ class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
end
def test_fail_gracefully
body = { errors: [{ title: 'epic fail' }] }.to_json
body = { message: 'epic fail' }.to_json
headers = { 'Content-type' => Mime[:json] }
stub_request(:post, /domains\/transfer/).to_return(status: 400, body: body, headers: headers)

View file

@ -15,10 +15,12 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body,
headers: { 'Content-type' => Mime[:json] },
basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{
type: 'nameserver',
id: 'new-ns.bestnames.test'}],
affected_domains: ["airport.test", "shop.test"]}.to_json, status: 200)
.to_return(body: { data: {
type: 'nameserver',
id: 'new-ns.bestnames.test',
affected_domains: ["airport.test", "shop.test"]
}
}.to_json, status: 200)
visit registrar_domains_url
click_link 'Bulk change'
@ -38,7 +40,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
def test_fails_gracefully
stub_request(:put, /registrar\/nameservers/).to_return(status: 400,
body: { errors: [{ title: 'epic fail' }] }.to_json,
body: { message: 'epic fail' }.to_json,
headers: { 'Content-type' => Mime[:json] })
visit registrar_domains_url

View file

@ -9,8 +9,8 @@ class RegistrarAreaTechContactBulkChangeTest < ApplicationSystemTestCase
request_stub = stub_request(:patch, /domains\/contacts/)
.with(body: { current_contact_id: 'william-001', new_contact_id: 'john-001' },
basic_auth: ['test_bestnames', 'testtest'])
.to_return(body: { affected_domains: %w[foo.test bar.test],
skipped_domains: %w[baz.test qux.test] }.to_json,
.to_return(body: { data: { affected_domains: %w[foo.test bar.test],
skipped_domains: %w[baz.test qux.test] } }.to_json,
status: 200)
visit registrar_domains_url
@ -30,7 +30,7 @@ class RegistrarAreaTechContactBulkChangeTest < ApplicationSystemTestCase
def test_fails_gracefully
stub_request(:patch, /domains\/contacts/)
.to_return(status: 400,
body: { error: { message: 'epic fail' } }.to_json,
body: { message: 'epic fail' }.to_json,
headers: { 'Content-type' => Mime[:json] })
visit registrar_domains_url

View file

@ -6,6 +6,7 @@ if ENV['COVERAGE']
add_filter '/lib/core_monkey_patches/'
add_filter '/lib/daemons/'
add_filter '/lib/gem_monkey_patches/'
add_filter '/lib/tasks/'
end
end