Skip to content

Commit

Permalink
added tests for epp and repp request domain cration
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Oct 19, 2023
1 parent f57dc1d commit 2272e9e
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/fixtures/bsa_protected_domains.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
one:
order_id: 1
suborder_id: 1
domain_name: example1.ee
domain_name: example1.test
state: 2
registration_code: 1234567890
create_date: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
Expand All @@ -10,7 +10,7 @@ one:
two:
order_id: 2
suborder_id: 2
domain_name: example2.ee
domain_name: example2.test
state: 2
registration_code: 0987654321
create_date: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
Expand Down
97 changes: 97 additions & 0 deletions test/integration/epp/domain/create/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class EppDomainCreateBaseTest < EppTestCase
setup do
adapter = ENV["shunter_default_adapter"].constantize.new
adapter&.clear!

@bsa_domain = bsa_protected_domains(:one)
end

def test_illegal_chars_in_dns_key
Expand Down Expand Up @@ -937,4 +939,99 @@ def test_returns_error_response_if_throttled
ENV["shunter_default_threshold"] = '10000'
ENV["shunter_enabled"] = 'false'
end


def test_domain_cannnot_be_created_if_it_in_bsa_protected_list_through_epp
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
<command>
<create>
<domain:create xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.2')}">
<domain:name>#{@bsa_domain.domain_name}</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis', for_version: '1.0')}">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML

assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :required_parameter_missing
end

def test_bsa_protected_domain_can_be_created_with_valid_registration_code_through_epp
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
<command>
<create>
<domain:create xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.2')}">
<domain:name>#{@bsa_domain.domain_name}</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis', for_version: '1.0')}">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>#{@bsa_domain.registration_code}</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML

assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :completed_successfully
end

def test_bsa_protected_domain_cannot_be_created_with_invalid_registration_code_through_epp
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
<command>
<create>
<domain:create xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.2')}">
<domain:name>#{@bsa_domain.domain_name}</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis', for_version: '1.0')}">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>invalid</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML

assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml

assert_epp_response :invalid_authorization_information
end
end
69 changes: 69 additions & 0 deletions test/integration/repp/v1/domains/create_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ReppV1DomainsCreateTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
@domain = domains(:shop)
@bsa_domain = bsa_protected_domains(:one)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"

Expand Down Expand Up @@ -134,4 +135,72 @@ def test_creates_new_domain_with_desired_transfer_code
assert @user.registrar.domains.find_by(name: 'domeener.test').present?
assert_equal 'ABADIATS', @user.registrar.domains.find_by(name: 'domeener.test').transfer_code
end

def test_domain_cannnot_be_created_if_it_in_bsa_protected_list
@auth_headers['Content-Type'] = 'application/json'
contact = contacts(:john)

payload = {
domain: {
name: @bsa_domain.domain_name,
registrant: contact.code,
period: 1,
period_unit: 'y'
}
}

post "/repp/v1/domains", headers: @auth_headers, params: payload.to_json
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2003, json[:code]
assert_equal 'Required parameter missing; reserved>pw element required for reserved domains', json[:message]

refute @user.registrar.domains.find_by(name: @bsa_domain.domain_name).present?
end

def test_bsa_protected_domain_can_be_created_with_valid_registration_code
@auth_headers['Content-Type'] = 'application/json'
contact = contacts(:john)

payload = {
domain: {
name: @bsa_domain.domain_name,
registrant: contact.code,
reserved_pw: @bsa_domain.registration_code,
period: 1,
period_unit: 'y'
}
}

post "/repp/v1/domains", headers: @auth_headers, params: payload.to_json
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]

assert @user.registrar.domains.find_by(name: @bsa_domain.domain_name).present?
end

def test_bsa_protected_domain_cannot_be_created_with_invalid_registration_code
@auth_headers['Content-Type'] = 'application/json'
contact = contacts(:john)

payload = {
domain: {
name: @bsa_domain.domain_name,
registrant: contact.code,
reserved_pw: 'invalid_registration_code',
period: 1,
period_unit: 'y'
}
}

post "/repp/v1/domains", headers: @auth_headers, params: payload.to_json
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2202, json[:code]
assert_equal 'Invalid authorization information; invalid reserved>pw value', json[:message]

refute @user.registrar.domains.find_by(name: @bsa_domain.domain_name).present?
end
end

0 comments on commit 2272e9e

Please sign in to comment.