Merge branch 'master' into 1645-get-rid-of-keystores-gem

This commit is contained in:
Karl Erik Õunapuu 2020-08-13 13:02:28 +03:00 committed by GitHub
commit f13a2c2b07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 537 additions and 123 deletions

BIN
test/fixtures/files/legaldoc.pdf vendored Normal file

Binary file not shown.

View file

@ -91,8 +91,8 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
end
def test_address_is_optional_when_enabled
@contact.update!(street: 'any', zip: 'any', city: 'any', state: 'any', country_code: 'US')
Setting.address_processing = true
@contact.update!(street: 'any', zip: 'any', city: 'any', state: 'any', country_code: 'US')
patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'any' },
as: :json,

View file

@ -140,4 +140,115 @@ class EppContactCreateBaseTest < EppTestCase
end
assert_epp_response :required_parameter_missing
end
def test_does_not_save_address_when_address_processing_turned_off
name = 'new'
email = 'new@registrar.test'
phone = '+1.2'
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>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>#{name}</contact:name>
<contact:addr>
<contact:street>123 Example</contact:street>
<contact:city>Tallinn</contact:city>
<contact:sp>FFF</contact:sp>
<contact:pc>123456</contact:pc>
<contact:cc>EE</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice>#{phone}</contact:voice>
<contact:email>#{email}</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="priv" cc="US">123</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_difference 'Contact.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :completed_without_address
contact = Contact.find_by(name: name)
assert_equal name, contact.name
assert_equal email, contact.email
assert_equal phone, contact.phone
assert_not_empty contact.code
assert_nil contact.city
assert_nil contact.street
assert_nil contact.zip
assert_nil contact.country_code
assert_nil contact.state
end
def test_saves_address_when_address_processing_turned_on
Setting.address_processing = true
name = 'new'
email = 'new@registrar.test'
phone = '+1.2'
street = '123 Example'
city = 'Tallinn'
state = 'Harjumaa'
zip = '123456'
country_code = 'EE'
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>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>#{name}</contact:name>
<contact:addr>
<contact:street>#{street}</contact:street>
<contact:city>#{city}</contact:city>
<contact:sp>#{state}</contact:sp>
<contact:pc>#{zip}</contact:pc>
<contact:cc>#{country_code}</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice>#{phone}</contact:voice>
<contact:email>#{email}</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="priv" cc="US">123</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_difference 'Contact.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :completed_successfully
contact = Contact.find_by(name: name)
assert_equal name, contact.name
assert_equal email, contact.email
assert_equal phone, contact.phone
assert_not_empty contact.code
assert_equal city, contact.city
assert_equal street, contact.street
assert_equal zip, contact.zip
assert_equal country_code, contact.country_code
assert_equal state, contact.state
end
end

View file

@ -232,6 +232,99 @@ class EppContactUpdateBaseTest < EppTestCase
assert_epp_response :completed_successfully
end
def test_updates_address_when_address_processing_turned_on
@contact.update_columns(code: @contact.code.upcase)
Setting.address_processing = true
street = '123 Example'
city = 'Tallinn'
state = 'Harjumaa'
zip = '123456'
country_code = 'EE'
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>
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>#{@contact.code}</contact:id>
<contact:chg>
<contact:postalInfo>
<contact:addr>
<contact:street>#{street}</contact:street>
<contact:city>#{city}</contact:city>
<contact:sp>#{state}</contact:sp>
<contact:pc>#{zip}</contact:pc>
<contact:cc>#{country_code}</contact:cc>
</contact:addr>
</contact:postalInfo>
</contact:chg>
</contact:update>
</update>
</command>
</epp>
XML
post epp_update_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :completed_successfully
@contact.reload
assert_equal city, @contact.city
assert_equal street, @contact.street
assert_equal zip, @contact.zip
assert_equal country_code, @contact.country_code
assert_equal state, @contact.state
end
def test_does_not_update_address_when_address_processing_turned_off
@contact.update_columns(code: @contact.code.upcase)
street = '123 Example'
city = 'Tallinn'
state = 'Harjumaa'
zip = '123456'
country_code = 'EE'
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>
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>#{@contact.code}</contact:id>
<contact:chg>
<contact:postalInfo>
<contact:addr>
<contact:street>#{street}</contact:street>
<contact:city>#{city}</contact:city>
<contact:sp>#{state}</contact:sp>
<contact:pc>#{zip}</contact:pc>
<contact:cc>#{country_code}</contact:cc>
</contact:addr>
</contact:postalInfo>
</contact:chg>
</contact:update>
</update>
</command>
</epp>
XML
post epp_update_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :completed_without_address
@contact.reload
assert_nil @contact.city
assert_nil @contact.street
assert_nil @contact.zip
assert_nil @contact.country_code
assert_nil @contact.state
end
private
def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact)

View file

@ -14,6 +14,15 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
Setting.directo_monthly_number_last = 309901
end
def test_directo_json_sends_customer_as_hash
@invoice.update!(buyer_country_code: @user.address_country_code)
json_output = @invoice.as_directo_json
assert json_output['customer'].is_a? Hash
assert_equal @user.accounting_customer_code, json_output['customer']['code']
assert_equal @user.address_country_code, json_output['customer']['destination']
end
def test_xml_is_include_transaction_date
@invoice.update(total: @invoice.account_activity.bank_transaction.sum)
@invoice.account_activity.bank_transaction.update(paid_at: Time.zone.now)

View file

@ -1,17 +1,11 @@
require "test_helper"
class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
def setup
super
setup do
@legal_doc_path = 'test/fixtures/files/legaldoc.pdf'
@domain = domains(:shop)
@new_registrant = contacts(:william)
@user = users(:api_bestnames)
@domain.update!(pending_json: { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id })
end
def teardown
@ -19,6 +13,11 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
end
def test_rejected_registrant_verification_notifies_registrar
@domain.update!(pending_json: { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id })
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
last_registrar_notification = @domain.registrar.notifications.last
@ -27,10 +26,57 @@ class DomainDeleteConfirmJobTest < ActiveSupport::TestCase
end
def test_accepted_registrant_verification_notifies_registrar
@domain.update!(pending_json: { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id })
DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED)
last_registrar_notification = @domain.registrar.notifications.last
assert_equal(last_registrar_notification.attached_obj_id, @domain.id)
assert_equal(last_registrar_notification.text, 'Registrant confirmed domain deletion: shop.test')
end
def test_marks_domain_as_pending_delete_after_acceptance
epp_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp>\n <command>\n <delete>\n" \
" <delete verified=\"no\">\n <name>#{@domain.name}</name>\n </delete>\n </delete>\n <extension>\n" \
" <extdata>\n <legalDocument type=\"pdf\">#{@legal_doc_path}</legalDocument>\n" \
" </extdata>\n </extension>\n <clTRID>20alla-1594212240</clTRID>\n </command>\n</epp>\n"
@domain.registrant_verification_asked!(epp_xml, @user.id)
@domain.pending_delete!
@domain.reload
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)
@domain.reload
assert @domain.statuses.include? DomainStatus::PENDING_DELETE
assert @domain.statuses.include? DomainStatus::SERVER_HOLD
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
end
def test_clears_pending_flags_after_delete_denial
epp_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp>\n <command>\n <delete>\n" \
" <delete verified=\"no\">\n <name>#{@domain.name}</name>\n </delete>\n </delete>\n <extension>\n" \
" <extdata>\n <legalDocument type=\"pdf\">#{@legal_doc_path}</legalDocument>\n" \
" </extdata>\n </extension>\n <clTRID>20alla-1594212240</clTRID>\n </command>\n</epp>\n"
@domain.registrant_verification_asked!(epp_xml, @user.id)
@domain.pending_delete!
@domain.reload
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)
@domain.reload
assert_equal ['ok'], @domain.statuses
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE
end
end

View file

@ -7,6 +7,7 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
@domain = domains(:shop)
@new_registrant = contacts(:william)
@user = users(:api_bestnames)
@legal_doc_path = 'test/fixtures/files/legaldoc.pdf'
@domain.update!(pending_json: { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
@ -33,4 +34,34 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
assert_equal(last_registrar_notification.attached_obj_id, @domain.id)
assert_equal(last_registrar_notification.text, 'Registrant confirmed domain update: shop.test')
end
def test_changes_domain_registrant_after_approval
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"
@domain.pending_json['frame'] = epp_xml
@domain.update(pending_json: @domain.pending_json)
@domain.reload
DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED)
@domain.reload
assert_equal @domain.registrant.code, @new_registrant.code
end
def test_clears_pending_update_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"
@domain.pending_json['frame'] = epp_xml
@domain.update(pending_json: @domain.pending_json)
DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
@domain.reload
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE
end
end

View file

@ -152,6 +152,8 @@ class ContactTest < ActiveSupport::TestCase
end
def test_address
Setting.address_processing = true
address = Contact::Address.new('new street', '83746', 'new city', 'new state', 'EE')
@contact.address = address
@contact.save!
@ -238,6 +240,7 @@ class ContactTest < ActiveSupport::TestCase
end
def test_normalizes_country_code
Setting.address_processing = true
contact = Contact.new(country_code: 'us')
contact.validate
assert_equal 'US', contact.country_code

View file

@ -28,6 +28,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
codes = {
completed_successfully: 1000,
completed_successfully_action_pending: 1001,
completed_without_address: 1100,
completed_successfully_no_messages: 1300,
completed_successfully_ack_to_dequeue: 1301,
completed_successfully_ending_session: 1500,
@ -58,6 +59,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
descriptions = {
1000 => 'Command completed successfully',
1001 => 'Command completed successfully; action pending',
1100 => 'Command completed successfully; Postal address data discarded',
1300 => 'Command completed successfully; no messages',
1301 => 'Command completed successfully; ack to dequeue',
1500 => 'Command completed successfully; ending session',

View file

@ -0,0 +1,41 @@
require 'application_system_test_case'
class DomainDeleteConfirmsTest < ApplicationSystemTestCase
setup do
@user = users(:registrant)
sign_in @user
@domain = domains(:shop)
@domain.registrant_verification_asked!('<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp></epp>', @user.id)
@domain.pending_delete!
end
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'
assert_text 'Domain registrant change has successfully received.'
@domain.reload
assert_includes @domain.statuses, 'serverHold'
end
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'
assert_text 'Domain registrant change has been rejected successfully.'
@domain.reload
assert_equal ['ok'], @domain.statuses
end
def test_saves_whodunnit_info_after_verifivation
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
token = @domain.registrant_verification_token
click_on 'Confirm domain delete'
assert_text 'Domain registrant change has successfully received.'
refute RegistrantVerification.find_by(verification_token:token).updator_str.empty?
end
end

View file

@ -47,6 +47,7 @@ class ActiveSupport::TestCase
teardown do
travel_back
Setting.address_processing = false
end
end
@ -60,9 +61,14 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest
WebMock.reset!
Capybara.reset_sessions!
Capybara.use_default_driver
Setting.address_processing = false
end
end
class EppTestCase < ActionDispatch::IntegrationTest
include Assertions::EppAssertions
teardown do
Setting.address_processing = false
end
end