Merge branch 'master' of https://github.com/internetee/registry into 1857-covered-registry-by-tests

This commit is contained in:
Oleg Hasjanov 2021-03-02 13:42:00 +02:00
commit 6efd16aad7
25 changed files with 400 additions and 34 deletions

View file

@ -63,6 +63,23 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
assert_equal 1, @new_registrar.contacts.where(name: 'William').size
end
def test_bulk_transfer_if_domain_has_update_prohibited_status
domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED])
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :ok
assert_equal ({ code: 1000,
message: 'Command completed successfully',
data: { success: [],
failed: [{ type: "domain_transfer",
domain_name: "shop.test",
errors: [{:code=>"2304", :msg=>"Object status prohibits operation"}] }],
}}),
JSON.parse(response.body, symbolize_names: true)
end
private
def request_params

View file

@ -104,6 +104,25 @@ class APINameserversPutTest < ApplicationIntegrationTest
JSON.parse(response.body, symbolize_names: true)
end
def test_bulk_namesaervers_if_domain_update_prohibited
domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED])
params = { data: { type: 'nameserver', id: domains(:shop).nameservers.hostnames[0],
attributes: { hostname: 'ns55.bestnames.test' } } }
put '/repp/v1/registrar/nameservers', params: params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :ok
assert_equal ({ code: 1000,
message: 'Command completed successfully',
data: { type: "nameserver",
id: "ns55.bestnames.test",
attributes: {hostname: "ns55.bestnames.test"},
affected_domains: ["airport.test"],
skipped_domains: ["shop.test"]}}),
JSON.parse(response.body, symbolize_names: true)
end
def test_unauthenticated
put '/repp/v1/registrar/nameservers'
assert_response 401

View file

@ -5,9 +5,10 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
def setup
super
@domain = domains(:hospital)
@domain = domains(:airport)
@registrant = @domain.registrant
@user = users(:registrant)
domains(:metro).tech_domain_contacts.update(contact_id: @registrant.id)
@auth_headers = { 'HTTP_AUTHORIZATION' => auth_token }
end
@ -19,7 +20,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
assert_equal('hospital.test', domain[:name])
assert_equal('5edda1a5-3548-41ee-8b65-6d60daf85a37', domain[:id])
assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, domain[:registrant])
assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957', org: false}, domain[:registrant])
assert_equal([{name: 'John',
id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957',
email: 'john@inbox.test'}],
@ -57,6 +58,46 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
assert(array_of_domain_registrars.include?({name: 'Good Names', website: nil}))
end
def test_return_domain_list_with_registrants_and_admins
domains(:hospital).admin_domain_contacts.update(contact_id: contacts(:william).id)
domains(:hospital).update(registrant: contacts(:william).becomes(Registrant))
get '/api/v1/registrant/domains', headers: @auth_headers, params: { 'offset' => 0 }
assert_equal(200, response.status)
response_json = JSON.parse(response.body, symbolize_names: true)
response_json[:domains].each do |x|
if x[:registrant][:org] == false
x[:tech_contacts].each do |s|
assert_not s[:name].include?(@registrant.name)
end
end
end
end
def test_return_domain_list_with_registrants_and_admins_tech
get '/api/v1/registrant/domains', headers: @auth_headers, params: { 'offset' => 0, 'tech' => true }
assert_equal(200, response.status)
response_json = JSON.parse(response.body, symbolize_names: true)
response_json[:domains].each do |x|
if x[:name] == 'metro.test'
x[:tech_contacts].each do |s|
assert s[:name].include?(@registrant.name)
end
end
end
end
def test_domains_total_if_an_incomplete_list_is_returned
get '/api/v1/registrant/domains', headers: @auth_headers, params: { 'offset' => 0 }
assert_equal(200, response.status)
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal response_json[:domains].length, response_json[:count]
assert_equal response_json[:total], 5
end
def test_root_accepts_limit_and_offset_parameters
get '/api/v1/registrant/domains', params: { 'limit' => 2, 'offset' => 0 },
headers: @auth_headers

View file

@ -130,7 +130,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal({ name: 'Best Names', website: 'https://bestnames.test' }, response_json[:registrar])
assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, response_json[:registrant])
assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957', org: false}, response_json[:registrant])
assert_equal([{name: 'Jane',
id: '9db3de62-2414-4487-bee2-d5c155567768',
email: 'jane@mail.test'

View file

@ -27,6 +27,60 @@ class EppContactDeleteBaseTest < EppTestCase
assert_epp_response :completed_successfully
end
def test_delete_contact_with_server_delete_prohibited
contact = deletable_contact
contact.update(statuses: Contact::SERVER_DELETE_PROHIBITED)
assert contact.statuses.include? Contact::SERVER_DELETE_PROHIBITED
contact.update_columns(code: contact.code.upcase)
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>
<delete>
<contact:delete xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>#{contact.code.upcase}</contact:id>
</contact:delete>
</delete>
</command>
</epp>
XML
post epp_delete_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert Contact.exists?(id: contact.id)
assert_epp_response :object_status_prohibits_operation
end
def test_delete_contact_with_client_delete_prohibited
contact = deletable_contact
contact.update(statuses: Contact::CLIENT_DELETE_PROHIBITED)
assert contact.statuses.include? Contact::CLIENT_DELETE_PROHIBITED
contact.update_columns(code: contact.code.upcase)
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>
<delete>
<contact:delete xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>#{contact.code.upcase}</contact:id>
</contact:delete>
</delete>
</command>
</epp>
XML
post epp_delete_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert Contact.exists?(id: contact.id)
assert_epp_response :object_status_prohibits_operation
end
def test_undeletable_cannot_be_deleted
contact = contacts(:john)
assert_not contact.deletable?
@ -61,4 +115,4 @@ class EppContactDeleteBaseTest < EppTestCase
DomainContact.delete_all
contacts(:john)
end
end
end

View file

@ -133,6 +133,40 @@ class EppDomainDeleteBaseTest < EppTestCase
assert_epp_response :completed_successfully
end
def test_deletes_on_update_prohibited
assert_equal 'shop.test', @domain.name
@domain.update(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED])
Setting.request_confirmation_on_domain_deletion_enabled = false
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>
<delete>
<domain:delete xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>shop.test</domain:name>
</domain:delete>
</delete>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
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?
assert_not @domain.pending_delete_confirmation?
assert_no_emails
assert_epp_response :completed_successfully
end
def test_skips_registrant_confirmation_when_required_but_already_verified_by_registrar
assert_equal 'shop.test', @domain.name
Setting.request_confirmation_on_domain_deletion_enabled = true

View file

@ -62,6 +62,27 @@ class EppDomainUpdateBaseTest < EppTestCase
assert_epp_response :object_status_prohibits_operation
end
def test_prohibited_domain_cannot_be_updated
@domain.update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED])
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>shop.test</domain:name>
</domain:update>
</update>
</command>
</epp>
XML
post epp_update_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :object_status_prohibits_operation
end
def test_does_not_return_server_delete_prohibited_status_when_pending_update_status_is_set
@domain.update!(statuses: [DomainStatus::SERVER_DELETE_PROHIBITED,
DomainStatus::PENDING_UPDATE])
@ -123,6 +144,46 @@ class EppDomainUpdateBaseTest < EppTestCase
assert_verification_and_notification_emails
end
def test_domain_should_doesnt_have_pending_update_when_updated_registrant_with_same_idents_data
assert_not @domain.statuses.include? "pendingUpdate"
old_registrant = @domain.registrant
new_registrant = contacts(:william).becomes(Registrant)
new_registrant.update(ident: old_registrant.ident)
new_registrant.update(ident_country_code: old_registrant.ident_country_code)
new_registrant.update(ident_type: old_registrant.ident_type)
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:chg>
<domain:registrant verified="no">#{new_registrant.code}</domain:registrant>
</domain:chg>
</domain:update>
</update>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
post epp_update_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
@domain.reload
assert_epp_response :completed_successfully
assert_equal @domain.registrant, new_registrant
assert_not @domain.statuses.include? "pendingUpdate"
end
def test_requires_verification_from_current_registrant_when_not_yet_verified_by_registrar
Setting.request_confirmation_on_registrant_change_enabled = true
new_registrant = contacts(:william)

View file

@ -34,6 +34,33 @@ class ReppV1RegistrarNameserversTest < ActionDispatch::IntegrationTest
assert json[:data][:affected_domains].include? 'shop.test'
end
def test_fails_to_update_if_prohibited
domain = domains(:shop)
domain.update(statuses: [DomainStatus::CLIENT_UPDATE_PROHIBITED])
nameserver = nameservers(:shop_ns1)
payload = {
"data": {
"id": nameserver.hostname,
"type": "nameserver",
"attributes": {
"hostname": "#{nameserver.hostname}.test",
"ipv4": ["1.1.1.1"]
}
}
}
put '/repp/v1/registrar/nameservers', 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_equal({ hostname: "#{nameserver.hostname}.test", ipv4: ["1.1.1.1"] }, json[:data][:attributes])
assert_equal({ hostname: "#{nameserver.hostname}.test", ipv4: ["1.1.1.1"] }, json[:data][:attributes])
assert json[:data][:affected_domains].include? 'airport.test'
assert json[:data][:skipped_domains].include? 'shop.test'
end
def test_nameserver_with_hostname_must_exist
payload = {
"data": {

View file

@ -30,8 +30,8 @@ class SerializersRegistrantApiDomainTest < ActiveSupport::TestCase
assert_equal({name: 'Best Names', website: 'https://bestnames.test' }, @json[:registrar])
end
def test_returns_registrant_name_and_uuid
assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'},
def test_returns_registrant_name_uuid_and_org
assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957', org: false},
@json[:registrant])
end

View file

@ -234,6 +234,19 @@ class ForceDeleteTest < ActionMailer::TestCase
assert_includes(@domain.statuses, asserted_status)
end
def test_client_hold_prohibits_manual_inzone
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
travel_to Time.zone.parse('2010-08-21')
Domains::ClientHold::SetClientHold.run!
@domain.reload
@domain.statuses << DomainStatus::SERVER_MANUAL_INZONE
assert_not @domain.valid?
end
def test_force_delete_soft_year_ahead_not_sets_client_hold_before_threshold
asserted_status = DomainStatus::CLIENT_HOLD