Merge branch 'master' into log-bounced-emails

This commit is contained in:
Karl Erik Õunapuu 2020-12-04 13:46:48 +02:00 committed by GitHub
commit 4adc240b0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
141 changed files with 3748 additions and 1214 deletions

View file

@ -448,10 +448,9 @@ dispute_period_in_months:
registry_whois_disclaimer:
code: registry_whois_disclaimer
value: 'Search results may not be used for commercial, advertising, recompilation,
repackaging, redistribution, reuse, obscuring or other similar activities.'
value: "{\"en\":\"111\",\"et\":\"222\",\"ru\":\"333\"}"
group: contacts
format: string
format: hash
created_at: <%= Time.zone.parse('2010-07-05') %>
updated_at: <%= Time.zone.parse('2010-07-05') %>

View file

@ -27,8 +27,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :ok
assert_equal ({ affected_domains: %w[airport.test shop.test],
skipped_domains: [] }),
assert_equal ({ code: 1000, message: 'Command completed successfully', data: { affected_domains: %w[airport.test shop.test],
skipped_domains: [] }}),
JSON.parse(response.body, symbolize_names: true)
end
@ -42,7 +42,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
assert_response :ok
assert_equal %w[airport.test shop.test], JSON.parse(response.body,
symbolize_names: true)[:skipped_domains]
symbolize_names: true)[:data][:skipped_domains]
end
def test_keep_other_tech_contacts_intact
@ -66,10 +66,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
new_contact_id: 'william-002' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
param: 'current_contact_id',
message: 'No such contact: jack-001' } }),
assert_response :not_found
assert_equal ({ code: 2303, message: 'Object does not exist' }),
JSON.parse(response.body, symbolize_names: true)
end
@ -77,10 +75,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'non-existent',
new_contact_id: 'john-001' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
param: 'current_contact_id',
message: 'No such contact: non-existent' } }),
assert_response :not_found
assert_equal ({ code: 2303, message: 'Object does not exist' }),
JSON.parse(response.body, symbolize_names: true)
end
@ -88,10 +84,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
new_contact_id: 'non-existent' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
param: 'new_contact_id',
message: 'No such contact: non-existent' } }),
assert_response :not_found
assert_equal ({code: 2303, message: 'Object does not exist'}),
JSON.parse(response.body, symbolize_names: true)
end
@ -100,9 +94,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
new_contact_id: 'invalid' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
param: 'new_contact_id',
message: 'New contact must be valid' } }),
assert_equal ({ code: 2304, message: 'New contact must be valid', data: {} }),
JSON.parse(response.body, symbolize_names: true)
end
@ -111,8 +103,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
new_contact_id: 'william-001' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
message: 'New contact ID must be different from current contact ID' } }),
assert_equal ({ code: 2304, message: 'New contact must be different from current', data: {} }),
JSON.parse(response.body, symbolize_names: true)
end

View file

@ -12,34 +12,21 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
Setting.transfer_wait_time = @original_transfer_wait_time
end
def test_returns_domain_transfers
post '/repp/v1/domain_transfers', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 200
assert_equal ({ data: [{
type: 'domain_transfer',
attributes: {
domain_name: 'shop.test'
},
}] }),
JSON.parse(response.body, symbolize_names: true)
end
def test_creates_new_domain_transfer
assert_difference -> { @domain.transfers.size } do
post '/repp/v1/domain_transfers', params: request_params, as: :json,
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
end
end
def test_approves_automatically_if_auto_approval_is_enabled
post '/repp/v1/domain_transfers', params: request_params, as: :json,
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert @domain.transfers.last.approved?
end
def test_assigns_new_registrar
post '/repp/v1/domain_transfers', params: request_params, as: :json,
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
@domain.reload
assert_equal @new_registrar, @domain.registrar
@ -48,7 +35,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
def test_regenerates_transfer_code
@old_transfer_code = @domain.transfer_code
post '/repp/v1/domain_transfers', params: request_params, as: :json,
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
@domain.reload
refute_equal @domain.transfer_code, @old_transfer_code
@ -58,51 +45,28 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
@old_registrar = @domain.registrar
assert_difference -> { @old_registrar.notifications.count } do
post '/repp/v1/domain_transfers', params: request_params, as: :json,
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
end
end
def test_duplicates_registrant_admin_and_tech_contacts
assert_difference -> { @new_registrar.contacts.size }, 3 do
post '/repp/v1/domain_transfers', params: request_params, as: :json,
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
end
end
def test_reuses_identical_contact
post '/repp/v1/domain_transfers', params: request_params, as: :json,
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_equal 1, @new_registrar.contacts.where(name: 'William').size
end
def test_fails_if_domain_does_not_exist
post '/repp/v1/domain_transfers',
params: { data: { domainTransfers: [{ domainName: 'non-existent.test',
transferCode: 'any' }] } },
as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 400
assert_equal ({ errors: [{ title: 'non-existent.test does not exist' }] }),
JSON.parse(response.body, symbolize_names: true)
end
def test_fails_if_transfer_code_is_wrong
post '/repp/v1/domain_transfers',
params: { data: { domainTransfers: [{ domainName: 'shop.test',
transferCode: 'wrong' }] } },
as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 400
refute_equal @new_registrar, @domain.registrar
assert_equal ({ errors: [{ title: 'shop.test transfer code is wrong' }] }),
JSON.parse(response.body, symbolize_names: true)
end
private
def request_params
{ data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
{ data: { domain_transfers: [{ domain_name: 'shop.test', transfer_code: '65078d5' }] } }
end
def http_auth_key

View file

@ -60,12 +60,14 @@ class APINameserversPutTest < ApplicationIntegrationTest
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 200
assert_equal ({ data: { type: 'nameserver',
assert_equal ({ code: 1000,
message: 'Command completed successfully',
data: { type: 'nameserver',
id: 'ns55.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test',
ipv4: ['192.0.2.55'],
ipv6: ['2001:db8::55'] } },
affected_domains: ["airport.test", "shop.test"] }),
ipv6: ['2001:db8::55'] },
affected_domains: ["airport.test", "shop.test"] }}),
JSON.parse(response.body, symbolize_names: true)
end
@ -85,7 +87,7 @@ class APINameserversPutTest < ApplicationIntegrationTest
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 404
assert_equal ({ errors: [{ title: 'Hostname non-existent.test does not exist' }] }),
assert_equal ({code: 2303, message: 'Object does not exist' }),
JSON.parse(response.body, symbolize_names: true)
end
@ -96,7 +98,8 @@ class APINameserversPutTest < ApplicationIntegrationTest
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 400
assert_equal ({ errors: [{ title: 'Hostname is missing' }] }),
assert_equal ({ code: 2003,
message: 'param is missing or the value is empty: hostname' }),
JSON.parse(response.body, symbolize_names: true)
end

View file

@ -0,0 +1,297 @@
require 'test_helper'
require 'auth_token/auth_token_creator'
class RegistrantApiVerificationsTest < ApplicationIntegrationTest
def setup
super
@domain = domains(:hospital)
@registrant = @domain.registrant
@new_registrant = contacts(:jack)
@user = users(:api_bestnames)
@token = 'verysecrettoken'
@domain.update!(statuses: [DomainStatus::PENDING_UPDATE],
registrant_verification_asked_at: Time.zone.now - 1.day,
registrant_verification_token: @token)
end
def test_fetches_registrant_change_request
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 }
@domain.update(pending_json: pending_json)
@domain.reload
assert @domain.registrant_update_confirmable?(@token)
get "/api/v1/registrant/confirms/#{@domain.name_puny}/change/#{@token}"
assert_equal(200, response.status)
res = JSON.parse(response.body, symbolize_names: true)
expected_body = {
domain_name: "hospital.test",
current_registrant: {
name: @registrant.name,
ident: @registrant.ident,
country: @registrant.ident_country_code
},
new_registrant: {
name: @new_registrant.name,
ident: @new_registrant.ident,
country: @new_registrant.ident_country_code
}
}
assert_equal expected_body, res
end
def test_approves_registrant_change_request
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 }
@domain.update!(pending_json: pending_json)
@domain.reload
assert @domain.registrant_update_confirmable?(@token)
perform_enqueued_jobs do
post "/api/v1/registrant/confirms/#{@domain.name_puny}/change/#{@token}/confirmed"
assert_equal(200, response.status)
res = JSON.parse(response.body, symbolize_names: true)
expected_body = {
domain_name: @domain.name,
current_registrant: {
name: @new_registrant.name,
ident: @new_registrant.ident,
country: @new_registrant.ident_country_code
},
status: 'confirmed'
}
assert_equal expected_body, res
end
end
def test_rejects_registrant_change_request
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 }
@domain.update(pending_json: pending_json)
@domain.reload
assert @domain.registrant_update_confirmable?(@token)
post "/api/v1/registrant/confirms/#{@domain.name_puny}/change/#{@token}/rejected"
assert_equal(200, response.status)
res = JSON.parse(response.body, symbolize_names: true)
expected_body = {
domain_name: @domain.name,
current_registrant: {
name: @registrant.name,
ident: @registrant.ident,
country: @registrant.ident_country_code
},
status: 'rejected'
}
assert_equal expected_body, res
end
def test_registrant_change_requires_valid_attributes
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 }
@domain.update(pending_json: pending_json)
@domain.reload
get "/api/v1/registrant/confirms/#{@domain.name_puny}/change/123"
assert_equal 401, response.status
get "/api/v1/registrant/confirms/aohldfjg.ee/change/123"
assert_equal 404, response.status
post "/api/v1/registrant/confirms/#{@domain.name_puny}/change/#{@token}/invalidaction"
assert_equal 404, response.status
end
def test_fetches_domain_delete_request
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 }
@domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
assert @domain.registrant_delete_confirmable?(@token)
get "/api/v1/registrant/confirms/#{@domain.name_puny}/delete/#{@token}"
assert_equal(200, response.status)
res = JSON.parse(response.body, symbolize_names: true)
expected_body = {
domain_name: "hospital.test",
current_registrant: {
name: @registrant.name,
ident: @registrant.ident,
country: @registrant.ident_country_code
}
}
assert_equal expected_body, res
end
def test_approves_domain_delete_request
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 }
@domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
assert @domain.registrant_delete_confirmable?(@token)
post "/api/v1/registrant/confirms/#{@domain.name_puny}/delete/#{@token}/confirmed"
assert_equal(200, response.status)
res = JSON.parse(response.body, symbolize_names: true)
expected_body = {
domain_name: @domain.name,
current_registrant: {
name: @registrant.name,
ident: @registrant.ident,
country: @registrant.ident_country_code
},
status: 'confirmed'
}
assert_equal expected_body, res
end
def test_rejects_domain_delete_request
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 }
@domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
assert @domain.registrant_delete_confirmable?(@token)
post "/api/v1/registrant/confirms/#{@domain.name_puny}/delete/#{@token}/rejected"
assert_equal(200, response.status)
res = JSON.parse(response.body, symbolize_names: true)
expected_body = {
domain_name: @domain.name,
current_registrant: {
name: @registrant.name,
ident: @registrant.ident,
country: @registrant.ident_country_code
},
status: 'rejected'
}
assert_equal expected_body, res
end
def test_domain_delete_requires_valid_attributes
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 }
@domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
get "/api/v1/registrant/confirms/#{@domain.name_puny}/delete/123"
assert_equal 401, response.status
get "/api/v1/registrant/confirms/aohldfjg.ee/delete/123"
assert_equal 404, response.status
post "/api/v1/registrant/confirms/#{@domain.name_puny}/delete/#{@token}/invalidaction"
assert_equal 404, response.status
end
#def test_get_non_existent_domain_details_by_uuid
# get '/api/v1/registrant/domains/random-uuid', headers: @auth_headers
# assert_equal(404, response.status)
# response_json = JSON.parse(response.body, symbolize_names: true)
# assert_equal({ errors: [base: ['Domain not found']] }, response_json)
#end
#def test_root_returns_domain_list
# get '/api/v1/registrant/domains', headers: @auth_headers
# assert_equal(200, response.status)
# response_json = JSON.parse(response.body, symbolize_names: true)
# array_of_domain_names = response_json.map { |x| x[:name] }
# assert(array_of_domain_names.include?('hospital.test'))
# array_of_domain_registrars = response_json.map { |x| x[:registrar] }
# assert(array_of_domain_registrars.include?({name: 'Good Names', website: nil}))
#end
#def test_root_accepts_limit_and_offset_parameters
# get '/api/v1/registrant/domains', params: { 'limit' => 2, 'offset' => 0 },
# headers: @auth_headers
# response_json = JSON.parse(response.body, symbolize_names: true)
# assert_equal(200, response.status)
# assert_equal(2, response_json.count)
# get '/api/v1/registrant/domains', headers: @auth_headers
# response_json = JSON.parse(response.body, symbolize_names: true)
# assert_equal(4, response_json.count)
#end
#def test_root_does_not_accept_limit_higher_than_200
# get '/api/v1/registrant/domains', params: { 'limit' => 400, 'offset' => 0 },
# headers: @auth_headers
# assert_equal(400, response.status)
# response_json = JSON.parse(response.body, symbolize_names: true)
# assert_equal({ errors: [{ limit: ['parameter is out of range'] }] }, response_json)
#end
#def test_root_does_not_accept_offset_lower_than_0
# get '/api/v1/registrant/domains', params: { 'limit' => 200, 'offset' => "-10" },
# headers: @auth_headers
# assert_equal(400, response.status)
# response_json = JSON.parse(response.body, symbolize_names: true)
# assert_equal({ errors: [{ offset: ['parameter is out of range'] }] }, response_json)
#end
#def test_root_returns_401_without_authorization
# get '/api/v1/registrant/domains'
# assert_equal(401, response.status)
# json_body = JSON.parse(response.body, symbolize_names: true)
# assert_equal({ errors: [base: ['Not authorized']] }, json_body)
#end
#def test_details_returns_401_without_authorization
# get '/api/v1/registrant/domains/5edda1a5-3548-41ee-8b65-6d60daf85a37'
# assert_equal(401, response.status)
# json_body = JSON.parse(response.body, symbolize_names: true)
# assert_equal({ errors: [base: ['Not authorized']] }, json_body)
#end
end

View file

@ -44,7 +44,7 @@ class EppContactInfoBaseTest < EppTestCase
contact: xml_schema).text
end
def test_hides_password_when_current_registrar_is_not_sponsoring
def test_hides_password_and_name_when_current_registrar_is_not_sponsoring
non_sponsoring_registrar = registrars(:goodnames)
@contact.update!(registrar: non_sponsoring_registrar)
@ -70,6 +70,7 @@ class EppContactInfoBaseTest < EppTestCase
assert_epp_response :completed_successfully
response_xml = Nokogiri::XML(response.body)
assert_nil response_xml.at_xpath('//contact:authInfo', contact: xml_schema)
assert_equal 'No access', response_xml.at_xpath('//contact:name', contact: xml_schema).text
end
private

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

@ -1,64 +0,0 @@
require 'test_helper'
class EppLoginCredentialsTest < EppTestCase
def test_correct_credentials
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>
<login>
<clID>test_bestnames</clID>
<pw>testtest</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
post epp_login_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=new_session_id' }
assert EppSession.find_by(session_id: 'new_session_id')
assert_equal users(:api_bestnames), EppSession.find_by(session_id: 'new_session_id').user
assert_epp_response :completed_successfully
end
def test_already_logged_in
assert true # Handled by EPP proxy
end
def test_wrong_credentials
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>
<login>
<clID>non-existent</clID>
<pw>valid-but-wrong</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
post epp_login_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=any_random_string' }
assert_epp_response :authentication_error_server_closing_connection
end
end

View file

@ -1,32 +0,0 @@
require 'test_helper'
class EppLoginPasswordChangeTest < EppTestCase
def test_password_change
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>
<login>
<clID>test_bestnames</clID>
<pw>testtest</pw>
<newPW>new-password</newPW>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
post epp_login_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=new_session_id' }
assert_equal 'new-password', users(:api_bestnames).plain_text_password
assert_epp_response :completed_successfully
end
end

View file

@ -1,61 +0,0 @@
require 'test_helper'
class EppLoginSessionLimitTest < EppTestCase
setup do
travel_to Time.zone.parse('2010-07-05')
EppSession.delete_all
end
def test_not_reached
(EppSession.limit_per_registrar - 1).times do
EppSession.create!(session_id: SecureRandom.hex,
user: users(:api_bestnames),
updated_at: Time.zone.parse('2010-07-05'))
end
assert_difference 'EppSession.count' do
post epp_login_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=new_session_id' }
end
assert_epp_response :completed_successfully
end
def test_reached
EppSession.limit_per_registrar.times do
EppSession.create!(session_id: SecureRandom.hex,
user: users(:api_bestnames),
updated_at: Time.zone.parse('2010-07-05'))
end
assert_no_difference 'EppSession.count' do
post epp_login_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=new_session_id' }
end
assert_epp_response :authentication_error_server_closing_connection
end
private
def 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>
<login>
<clID>test_bestnames</clID>
<pw>testtest</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
end
end

View file

@ -0,0 +1,189 @@
require 'test_helper'
class EppLoginTest < EppTestCase
setup do
@original_sessions_per_registrar_setting = EppSession.sessions_per_registrar
end
teardown do
EppSession.sessions_per_registrar = @original_sessions_per_registrar_setting
end
def test_logging_in_with_correct_credentials_creates_new_session
user = users(:api_bestnames)
new_session_id = 'new-session-id'
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>
<login>
<clID>#{user.username}</clID>
<pw>#{user.plain_text_password}</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:keyrelay-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
assert_difference 'EppSession.count' do
post '/epp/session/login', params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => "session=#{new_session_id}" }
end
assert_epp_response :completed_successfully
session = EppSession.last
assert_equal new_session_id, session.session_id
assert_equal user, session.user
end
def test_user_cannot_login_again
session = epp_sessions(:api_bestnames)
user = session.user
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>
<login>
<clID>#{user.username}</clID>
<pw>#{user.plain_text_password}</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:keyrelay-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
assert_no_difference 'EppSession.count' do
post '/epp/session/login', params: { frame: request_xml },
headers: { HTTP_COOKIE: "session=#{session.session_id}" }
end
assert_epp_response :use_error
end
def test_user_cannot_login_with_wrong_credentials
user = users(:api_bestnames)
wrong_password = 'a' * ApiUser.min_password_length
assert_not_equal wrong_password, user.plain_text_password
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>
<login>
<clID>#{user.username}</clID>
<pw>#{wrong_password}</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:keyrelay-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
assert_no_difference 'EppSession.count' do
post '/epp/session/login', params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=new-session-id' }
end
assert_epp_response :authentication_error_server_closing_connection
end
def test_password_change
user = users(:api_bestnames)
new_password = 'a' * ApiUser.min_password_length
assert_not_equal new_password, user.plain_text_password
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>
<login>
<clID>#{user.username}</clID>
<pw>#{user.plain_text_password}</pw>
<newPW>#{new_password}</newPW>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:keyrelay-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
post '/epp/session/login', params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=new-session-id' }
user.reload
assert_epp_response :completed_successfully
assert_equal new_password, user.plain_text_password
end
def test_user_cannot_login_when_max_allowed_sessions_per_registrar_is_exceeded
user = users(:api_bestnames)
eliminate_effect_of_existing_epp_sessions
EppSession.sessions_per_registrar = 1
EppSession.create!(session_id: 'any', user: user)
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>
<login>
<clID>#{user.username}</clID>
<pw>#{user.plain_text_password}</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:keyrelay-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
assert_no_difference 'EppSession.count' do
post '/epp/session/login', params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=new-session-id' }
end
assert_epp_response :session_limit_exceeded_server_closing_connection
end
private
def eliminate_effect_of_existing_epp_sessions
EppSession.delete_all
end
end

View file

@ -0,0 +1,22 @@
require 'test_helper'
class ReppV1BalanceTest < ActionDispatch::IntegrationTest
def setup
@registrar = users(:api_bestnames)
token = Base64.encode64("#{@registrar.username}:#{@registrar.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_can_query_balance
get '/repp/v1/accounts/balance', headers: @auth_headers
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 @registrar.registrar.cash_account.balance.to_s, json[:data][:balance]
assert_equal @registrar.registrar.cash_account.currency, json[:data][:currency]
end
end

View file

@ -0,0 +1,63 @@
require 'test_helper'
class ReppV1BaseTest < ActionDispatch::IntegrationTest
def setup
@registrar = users(:api_bestnames)
token = Base64.encode64("#{@registrar.username}:#{@registrar.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_unauthorized_user_has_no_access
get repp_v1_contacts_path
response_json = JSON.parse(response.body, symbolize_names: true)
assert_response :unauthorized
assert_equal 'Invalid authorization information', response_json[:message]
invalid_token = Base64.encode64("nonexistant:user")
headers = { 'Authorization' => "Basic #{invalid_token}" }
get repp_v1_contacts_path, headers: headers
response_json = JSON.parse(response.body, symbolize_names: true)
assert_response :unauthorized
assert_equal 'Invalid authorization information', response_json[:message]
end
def test_authenticates_valid_user
get repp_v1_contacts_path, headers: @auth_headers
response_json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
end
def test_processes_invalid_base64_token_format_properly
token = '??as8d9sf kjsdjh klsdfjjf'
headers = { 'Authorization' => "Basic #{token}"}
get repp_v1_contacts_path, headers: headers
response_json = JSON.parse(response.body, symbolize_names: true)
assert_response :unauthorized
assert_equal 'Invalid authorization information', response_json[:message]
end
def test_takes_ip_whitelist_into_account
Setting.api_ip_whitelist_enabled = true
Setting.registrar_ip_whitelist_enabled = true
whiteip = white_ips(:one)
whiteip.update(ipv4: '1.1.1.1')
get repp_v1_contacts_path, headers: @auth_headers
response_json = JSON.parse(response.body, symbolize_names: true)
assert_response :unauthorized
assert_equal 2202, response_json[:code]
assert response_json[:message].include? 'Access denied from IP'
Setting.api_ip_whitelist_enabled = false
Setting.registrar_ip_whitelist_enabled = false
end
end

View file

@ -0,0 +1,30 @@
require 'test_helper'
class ReppV1ContactsCheckTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_code_based_check_returns_true_for_available_contact
get '/repp/v1/contacts/check/nonexistant:code', headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 'nonexistant:code', json[:data][:contact][:id]
assert_equal true, json[:data][:contact][:available]
end
def test_code_based_check_returns_true_for_available_contact
contact = contacts(:jack)
get "/repp/v1/contacts/check/#{contact.code}", headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal contact.code, json[:data][:contact][:id]
assert_equal false, json[:data][:contact][:available]
end
end

View file

@ -0,0 +1,156 @@
require 'test_helper'
class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_creates_new_contact
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111112",
"email": "donald@trumptower.com",
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "39708290069"
}
}
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
assert contact.present?
assert_equal(request_body[:contact][:name], contact.name)
assert_equal(request_body[:contact][:phone], contact.phone)
assert_equal(request_body[:contact][:email], contact.email)
assert_equal(request_body[:contact][:ident][:ident_type], contact.ident_type)
assert_equal(request_body[:contact][:ident][:ident_country_code], contact.ident_country_code)
assert_equal(request_body[:contact][:ident][:ident], contact.ident)
end
def test_removes_postal_info_when_contact_created
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111111",
"email": "donald@trump.com",
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "39708290069"
},
"addr": {
"city": "Tallinn",
"street": "Wismari 13",
"zip": "12345",
"country_code": "EE"
}
}
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1100, json[:code]
assert_equal 'Command completed successfully; Postal address data discarded', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
assert contact.present?
assert_nil contact.city
assert_nil contact.street
assert_nil contact.zip
assert_nil contact.country_code
end
def test_requires_contact_address_when_processing_enabled
Setting.address_processing = true
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111112",
"email": "donald@trumptower.com",
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "39708290069"
}
}
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2003, json[:code]
assert json[:message].include? 'param is missing or the value is empty'
Setting.address_processing = false
end
def test_validates_ident_code
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111112",
"email": "donald@trumptower.com",
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "123123123"
}
}
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2005, json[:code]
assert json[:message].include? 'Ident code does not conform to national identification number format'
end
def test_attaches_legaldoc_if_present
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111112",
"email": "donald@trumptower.com",
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "39708290069"
},
},
"legal_document": {
"type": "pdf",
"body": "#{'test' * 2000}"
}
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
assert contact.legal_documents.any?
end
end

View file

@ -0,0 +1,47 @@
require 'test_helper'
class ReppV1ContactsDeleteTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_deletes_unassociated_contact
contact = contacts(:invalid_email)
delete "/repp/v1/contacts/#{contact.code}", headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
end
def test_can_not_delete_associated_contact
contact = contacts(:john)
delete "/repp/v1/contacts/#{contact.code}", headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2305, json[:code]
assert_equal 'Object association prohibits operation [domains]', json[:message]
end
def test_handles_unknown_contact
delete "/repp/v1/contacts/definitely:unexistant", headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :not_found
end
def test_can_not_destroy_other_registrar_contact
contact = contacts(:jack)
delete "/repp/v1/contacts/#{contact.code}", headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :not_found
end
end

View file

@ -0,0 +1,55 @@
require 'test_helper'
class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_returns_registrar_contacts
get repp_v1_contacts_path, headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal @user.registrar.contacts.count, json[:total_number_of_records]
assert_equal @user.registrar.contacts.count, json[:contacts].length
assert json[:contacts][0].is_a? String
end
def test_returns_detailed_registrar_contacts
get repp_v1_contacts_path(details: true), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal @user.registrar.contacts.count, json[:total_number_of_records]
assert_equal @user.registrar.contacts.count, json[:contacts].length
assert json[:contacts][0].is_a? Hash
end
def test_respects_limit
get repp_v1_contacts_path(details: true, limit: 2), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 2, json[:contacts].length
end
def test_respects_offset
offset = 1
get repp_v1_contacts_path(details: true, offset: offset), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal (@user.registrar.contacts.count - offset), json[:contacts].length
end
end

View file

@ -0,0 +1,45 @@
require 'test_helper'
class ReppV1ContactsShowTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_returns_error_when_not_found
get repp_v1_contact_path(id: 'definitelynotexistant'), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :not_found
assert_equal 2303, json[:code]
assert_equal 'Object does not exist', json[:message]
end
def test_shows_existing_contact
contact = @user.registrar.contacts.first
get repp_v1_contact_path(id: contact.code), headers: @auth_headers
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 contact.code, json[:data][:id]
end
def test_can_not_access_out_of_scope_contacts
# Contact of registrar goodnames, we're using bestnames API credentials
contact = contacts(:jack)
get repp_v1_contact_path(id: contact.code), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :not_found
assert_equal 2303, json[:code]
assert_equal 'Object does not exist', json[:message]
end
end

View file

@ -0,0 +1,119 @@
require 'test_helper'
class ReppV1ContactsUpdateTest < ActionDispatch::IntegrationTest
def setup
@contact = contacts(:john)
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_updates_contact
request_body = {
"contact": {
"email": "donaldtrump@yandex.ru"
}
}
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
assert contact.present?
assert_equal(request_body[:contact][:email], contact.email)
end
def test_removes_postal_info_when_updated
request_body = {
"contact": {
"addr": {
"city": "Tallinn",
"street": "Wismari 13",
"zip": "12345",
"country_code": "EE"
}
}
}
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1100, json[:code]
assert_equal 'Command completed successfully; Postal address data discarded', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
assert contact.present?
assert_nil contact.city
assert_nil contact.street
assert_nil contact.zip
assert_nil contact.country_code
end
def test_can_not_change_ident_code
request_body = {
"contact": {
"name": "Donald Trumpster",
"ident": {
"ident_type": "priv",
"ident_country_code": "US",
"ident": "12345"
}
}
}
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
@contact.reload
assert_not @contact.ident == 12345
assert_response :bad_request
assert_equal 2308, json[:code]
assert json[:message].include? 'Ident update is not allowed. Consider creating new contact object'
end
def test_attaches_legaldoc_if_present
request_body = {
"contact": {
"email": "donaldtrump@yandex.ru"
},
"legal_document": {
"type": "pdf",
"body": "#{'test' * 2000}"
}
}
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
@contact.reload
assert @contact.legal_documents.any?
end
def test_returns_error_if_ident_wrong_format
request_body = {
"contact": {
"ident": "123"
}
}
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2308, json[:code]
assert_equal 'Ident update is not allowed. Consider creating new contact object', json[:message]
end
end

View file

@ -0,0 +1,65 @@
require 'test_helper'
class ReppV1DomainsContactReplacementTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_replaces_tech_contact_with_new_one
replaceable_contact = contacts(:william)
replacing_contact = contacts(:jane)
payload = {
"current_contact_id": replaceable_contact.code,
"new_contact_id": replacing_contact.code
}
patch '/repp/v1/domains/contacts', 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][:affected_domains].include? 'airport.test'
assert json[:data][:affected_domains].include? 'shop.test'
assert_empty json[:data][:skipped_domains]
end
def test_tech_contact_id_must_differ
replaceable_contact = contacts(:william)
replacing_contact = contacts(:william)
payload = {
"current_contact_id": replaceable_contact.code,
"new_contact_id": replacing_contact.code
}
patch '/repp/v1/domains/contacts', headers: @auth_headers, params: payload
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2304, json[:code]
assert_equal 'New contact must be different from current', json[:message]
end
def test_contact_codes_must_be_valid
payload = {
"current_contact_id": 'dfgsdfg',
"new_contact_id": 'vvv'
}
patch '/repp/v1/domains/contacts', headers: @auth_headers, params: payload
json = JSON.parse(response.body, symbolize_names: true)
assert_response :not_found
assert_equal 2303, json[:code]
assert_equal 'Object does not exist', json[:message]
end
end

View file

@ -0,0 +1,54 @@
require 'test_helper'
class ReppV1DomainsListTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_returns_registrar_domains
get repp_v1_domains_path, headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal @user.registrar.domains.count, json[:data][:total_number_of_records]
assert_equal @user.registrar.domains.count, json[:data][:domains].length
assert json[:data][:domains][0].is_a? String
end
def test_returns_detailed_registrar_domains
get repp_v1_domains_path(details: true), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal @user.registrar.domains.count, json[:data][:total_number_of_records]
assert_equal @user.registrar.domains.count, json[:data][:domains].length
assert json[:data][:domains][0].is_a? Hash
end
def test_respects_limit
get repp_v1_domains_path(details: true, limit: 2), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 2, json[:data][:domains].length
end
def test_respects_offset
offset = 1
get repp_v1_domains_path(details: true, offset: offset), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal (@user.registrar.domains.count - offset), json[:data][:domains].length
end
end

View file

@ -0,0 +1,40 @@
require 'test_helper'
class ReppV1DomainsTransferInfoTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@domain = domains(:shop)
@auth_headers = { 'Authorization' => token }
end
def test_can_query_domain_info
headers = @auth_headers
headers['Auth-Code'] = @domain.transfer_code
get "/repp/v1/domains/#{@domain.name}/transfer_info", headers: headers
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 @domain.name, json[:data][:domain]
assert json[:data][:registrant].present?
assert json[:data][:admin_contacts].present?
assert json[:data][:tech_contacts].present?
end
def test_respects_domain_authorization_code
headers = @auth_headers
headers['Auth-Code'] = 'jhfgifhdg'
get "/repp/v1/domains/#{@domain.name}/transfer_info", headers: headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2202, json[:code]
assert_equal 'Authorization error', json[:message]
assert_empty json[:data]
end
end

View file

@ -0,0 +1,127 @@
require 'test_helper'
class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@domain = domains(:hospital)
@auth_headers = { 'Authorization' => token }
end
def test_transfers_domain
payload = {
"data": {
"domain_transfers": [
{ "domain_name": @domain.name, "transfer_code": @domain.transfer_code }
]
}
}
post "/repp/v1/domains/transfer", 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 @domain.name, json[:data][:success][0][:domain_name]
@domain.reload
assert @domain.registrar = @user.registrar
end
def test_does_not_transfer_domain_if_not_transferable
@domain.schedule_force_delete(type: :fast_track)
payload = {
"data": {
"domain_transfers": [
{ "domain_name": @domain.name, "transfer_code": @domain.transfer_code }
]
}
}
post "/repp/v1/domains/transfer", 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 'Object status prohibits operation', json[:data][:failed][0][:errors][0][:msg]
@domain.reload
assert_not @domain.registrar == @user.registrar
end
def test_does_not_transfer_domain_with_invalid_auth_code
payload = {
"data": {
"domain_transfers": [
{ "domain_name": @domain.name, "transfer_code": "sdfgsdfg" }
]
}
}
post "/repp/v1/domains/transfer", 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 "Invalid authorization information", json[:data][:failed][0][:errors][0][:msg]
end
def test_does_not_transfer_domain_to_same_registrar
@domain.update!(registrar: @user.registrar)
payload = {
"data": {
"domain_transfers": [
{ "domain_name": @domain.name, "transfer_code": @domain.transfer_code }
]
}
}
post "/repp/v1/domains/transfer", 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 'Domain already belongs to the querying registrar', json[:data][:failed][0][:errors][0][:msg]
@domain.reload
assert @domain.registrar == @user.registrar
end
def test_does_not_transfer_domain_if_discarded
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
payload = {
"data": {
"domain_transfers": [
{ "domain_name": @domain.name, "transfer_code": @domain.transfer_code }
]
}
}
post "/repp/v1/domains/transfer", 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 'Object is not eligible for transfer', json[:data][:failed][0][:errors][0][:msg]
@domain.reload
assert_not @domain.registrar == @user.registrar
end
end

View file

@ -0,0 +1,77 @@
require 'test_helper'
class ReppV1RegistrarNameserversTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_updates_nameserver_values
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][:affected_domains].include? 'shop.test'
end
def test_nameserver_with_hostname_must_exist
payload = {
"data": {
"id": 'ns.nonexistant.test',
"type": "nameserver",
"attributes": {
"hostname": "ns1.dn.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 :not_found
assert_equal 2303, json[:code]
assert_equal 'Object does not exist', json[:message]
end
def test_ip_must_be_in_correct_format
nameserver = nameservers(:shop_ns1)
payload = {
"data": {
"id": nameserver.hostname,
"type": "nameserver",
"attributes": {
"hostname": "#{nameserver.hostname}.test",
"ipv6": ["1.1.1.1"]
}
}
}
put '/repp/v1/registrar/nameservers', headers: @auth_headers, params: payload
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert_equal 2005, json[:code]
assert_equal 'IPv6 is invalid [ipv6]', json[:message]
end
end

View file

@ -5,10 +5,6 @@ class DomainDeleteMailerTest < ActionMailer::TestCase
@domain = domains(:shop)
end
def test_force_delete_templates
assert_equal %w[private_person legal_person], DomainDeleteMailer.force_delete_templates
end
def test_delivers_confirmation_request_email
assert_equal 'shop.test', @domain.name
assert_equal 'john@inbox.test', @domain.registrant.email
@ -68,8 +64,7 @@ class DomainDeleteMailerTest < ActionMailer::TestCase
email = DomainDeleteMailer.forced(domain: @domain,
registrar: @domain.registrar,
registrant: @domain.registrant,
template_name: DomainDeleteMailer.force_delete_templates
.first).deliver_now
template_name: @domain.notification_template).deliver_now
assert_emails 1
assert_equal ['legal@registry.test'], email.from

View file

@ -8,7 +8,18 @@ class DomainExpireMailerTest < ActionMailer::TestCase
email = DomainExpireMailer.expired(domain: domain, registrar: domain.registrar).deliver_now
assert_emails 1
assert_equal 'Domeen shop.test on aegunud / Domain shop.test has expired' \
' / Срок действия домена shop.test истек', email.subject
assert_equal I18n.t("domain_expire_mailer.expired.subject", domain_name: domain.name),
email.subject
end
end
def test_delivers_domain_expiration_soft_email
domain = domains(:shop)
assert_equal 'shop.test', domain.name
email = DomainExpireMailer.expired_soft(domain: domain, registrar: domain.registrar).deliver_now
assert_emails 1
assert_equal I18n.t("domain_expire_mailer.expired_soft.subject", domain_name: domain.name),
email.subject
end
end

View file

@ -1,10 +1,11 @@
class DomainDeleteMailerPreview < ActionMailer::Preview
def self.define_forced_templates
DomainDeleteMailer.force_delete_templates.each do |template_name|
%w[private_person legal_person invalid_email].each do |template_name|
define_method "forced_#{template_name}".to_sym do
DomainDeleteMailer.forced(domain: @domain,
registrar: @domain.registrar,
registrant: @domain.registrant,
domain = Domain.first
DomainDeleteMailer.forced(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant,
template_name: template_name)
end
end
@ -12,26 +13,25 @@ class DomainDeleteMailerPreview < ActionMailer::Preview
define_forced_templates
def initialize
@domain = Domain.first
super
end
def confirmation_request
DomainDeleteMailer.confirmation_request(domain: @domain,
registrar: @domain.registrar,
registrant: @domain.registrant)
domain = Domain.first
DomainDeleteMailer.confirmation_request(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant)
end
def accepted
DomainDeleteMailer.accepted(@domain)
domain = Domain.first
DomainDeleteMailer.accepted(domain)
end
def rejected
DomainDeleteMailer.rejected(@domain)
domain = Domain.first
DomainDeleteMailer.rejected(domain)
end
def expired
DomainDeleteMailer.expired(@domain)
domain = Domain.first
DomainDeleteMailer.expired(domain)
end
end
end

View file

@ -4,4 +4,10 @@ class DomainExpireMailerPreview < ActionMailer::Preview
DomainExpireMailer.expired(domain: domain,
registrar: domain.registrar)
end
end
def expired_soft
domain = Domain.first
DomainExpireMailer.expired_soft(domain: domain,
registrar: domain.registrar)
end
end

View file

@ -1,18 +1,20 @@
require 'test_helper'
class NewDomainForceDeleteTest < ActiveSupport::TestCase
class ForceDeleteTest < ActionMailer::TestCase
setup do
@domain = domains(:shop)
Setting.redemption_grace_period = 30
ActionMailer::Base.deliveries.clear
end
def test_schedules_force_delete_fast_track
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :fast_track)
@domain.schedule_force_delete(type: :fast_track, notify_by_email: true)
@domain.reload
assert_emails 1
assert @domain.force_delete_scheduled?
assert_equal Date.parse('2010-08-20'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-07-06'), @domain.force_delete_start.to_date
@ -27,8 +29,8 @@ class NewDomainForceDeleteTest < ActiveSupport::TestCase
@domain.reload
assert @domain.force_delete_scheduled?
assert_equal Date.parse('2010-09-20'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-08-06'), @domain.force_delete_start.to_date
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
end
def test_schedules_force_delete_soft_less_than_year_ahead
@ -111,9 +113,12 @@ class NewDomainForceDeleteTest < ActiveSupport::TestCase
def test_force_delete_cannot_be_scheduled_when_a_domain_is_discarded
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
assert_raises StandardError do
@domain.schedule_force_delete(type: :fast_track)
end
result = Domains::ForceDelete::SetForceDelete.run(domain: @domain, type: :fast_track)
assert_not result.valid?
assert_not @domain.force_delete_scheduled?
message = ["Force delete procedure cannot be scheduled while a domain is discarded"]
assert_equal message, result.errors.messages[:domain]
end
def test_cancels_force_delete
@ -137,19 +142,49 @@ class NewDomainForceDeleteTest < ActiveSupport::TestCase
assert_not @domain.force_delete_scheduled?
end
def test_cancelling_force_delete_removes_statuses_that_were_set_on_force_delete
def test_force_delete_does_not_double_statuses
statuses = [
DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
]
@domain.statuses = @domain.statuses + statuses
@domain.save!
@domain.reload
@domain.schedule_force_delete(type: :fast_track)
assert_equal @domain.statuses.size, statuses.size
end
def test_cancelling_force_delete_removes_force_delete_status
@domain.schedule_force_delete(type: :fast_track)
assert @domain.statuses.include?(DomainStatus::FORCE_DELETE)
assert @domain.statuses.include?(DomainStatus::SERVER_RENEW_PROHIBITED)
assert @domain.statuses.include?(DomainStatus::SERVER_TRANSFER_PROHIBITED)
@domain.cancel_force_delete
@domain.reload
assert_empty @domain.statuses & statuses
assert_not @domain.statuses.include?(DomainStatus::FORCE_DELETE)
assert_not @domain.statuses.include?(DomainStatus::SERVER_RENEW_PROHIBITED)
assert_not @domain.statuses.include?(DomainStatus::SERVER_TRANSFER_PROHIBITED)
end
def test_cancelling_force_delete_keeps_previous_statuses
statuses = [
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
]
@domain.statuses = statuses
@domain.save!
@domain.reload
@domain.schedule_force_delete(type: :fast_track)
@domain.cancel_force_delete
@domain.reload
assert_equal @domain.statuses, statuses
end
def test_hard_force_delete_should_have_outzone_and_purge_date_with_time
@ -171,9 +206,10 @@ class NewDomainForceDeleteTest < ActiveSupport::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)
@ -191,8 +227,10 @@ class NewDomainForceDeleteTest < ActiveSupport::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
@ -206,7 +244,7 @@ class NewDomainForceDeleteTest < ActiveSupport::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)
@ -221,7 +259,7 @@ class NewDomainForceDeleteTest < ActiveSupport::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)
@ -237,7 +275,7 @@ class NewDomainForceDeleteTest < ActiveSupport::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)
@ -252,4 +290,16 @@ class NewDomainForceDeleteTest < ActiveSupport::TestCase
assert @domain.force_delete_scheduled?
assert @domain.pending_update?
end
def test_force_delete_does_not_affect_registrant_update_confirmable
@domain.schedule_force_delete(type: :soft)
@domain.registrant_verification_asked!('test', User.last.id)
@domain.save!
@domain.reload
@domain.statuses << DomainStatus::PENDING_UPDATE
assert @domain.force_delete_scheduled?
assert @domain.registrant_update_confirmable?(@domain.registrant_verification_token)
end
end

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')
@domain.schedule_force_delete(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
@ -444,6 +444,20 @@ class DomainTest < ActiveSupport::TestCase
assert_not @domain.renewable?
end
def test_renewable_if_pending_delete
assert @domain.renewable?
@domain.statuses << DomainStatus::PENDING_DELETE
assert @domain.renewable?
end
def test_not_renewable_if_pending_delete_unconfirmed
assert @domain.renewable?
@domain.statuses << DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.renewable?
end
private
def valid_domain

View file

@ -51,6 +51,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
data_management_policy_violation: 2308,
command_failed: 2400,
authentication_error_server_closing_connection: 2501,
session_limit_exceeded_server_closing_connection: 2502,
}
assert_equal codes, Epp::Response::Result::Code.codes
end
@ -82,6 +83,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase
2308 => 'Data management policy violation',
2400 => 'Command failed',
2501 => 'Authentication error; server closing connection',
2502 => 'Session limit exceeded; server closing connection',
}
assert_equal descriptions, Epp::Response::Result::Code.default_descriptions
end

View file

@ -49,15 +49,11 @@ class EppSessionTest < ActiveSupport::TestCase
end
end
def test_limit_per_registrar
assert_equal 4, EppSession.limit_per_registrar
end
def test_limit_is_per_registrar
travel_to Time.zone.parse('2010-07-05')
EppSession.delete_all
EppSession.limit_per_registrar.times do
EppSession.sessions_per_registrar.times do
EppSession.create!(session_id: SecureRandom.hex,
user: users(:api_goodnames),
updated_at: Time.zone.parse('2010-07-05'))

View file

@ -14,7 +14,7 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase
assert_equal('JOHN SMITH', user.username)
end
def test_find_or_create_by_api_data_creates_a_user_after_upcasing_input
def test_find_or_create_by_api_data_creates_a_user_with_original_name
user_data = {
ident: '37710100070',
first_name: 'John',
@ -24,6 +24,25 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase
RegistrantUser.find_or_create_by_api_data(user_data)
user = User.find_by(registrant_ident: 'EE-37710100070')
assert_equal('JOHN SMITH', user.username)
assert_equal('John Smith', user.username)
end
def test_updates_related_contacts_name_if_differs_from_e_identity
contact = contacts(:john)
contact.update(ident: '39708290276', ident_country_code: 'EE')
user_data = {
ident: '39708290276',
first_name: 'John',
last_name: 'Doe'
}
RegistrantUser.find_or_create_by_api_data(user_data)
user = User.find_by(registrant_ident: 'EE-39708290276')
assert_equal('John Doe', user.username)
contact.reload
assert_equal user.username, contact.name
end
end

View file

@ -8,7 +8,7 @@ class Whois::RecordTest < ActiveSupport::TestCase
@auction = auctions(:one)
@original_disclaimer = Setting.registry_whois_disclaimer
Setting.registry_whois_disclaimer = 'disclaimer'
Setting.registry_whois_disclaimer = JSON.generate({en: 'disclaimer'})
end
teardown do
@ -16,8 +16,8 @@ class Whois::RecordTest < ActiveSupport::TestCase
end
def test_reads_disclaimer_setting
Setting.registry_whois_disclaimer = 'test disclaimer'
assert_equal 'test disclaimer', Whois::Record.disclaimer
Setting.registry_whois_disclaimer = JSON.generate({en: 'test_disclaimer'})
assert_equal Setting.registry_whois_disclaimer, Whois::Record.disclaimer
end
def test_updates_whois_record_from_auction_when_started
@ -28,7 +28,7 @@ class Whois::RecordTest < ActiveSupport::TestCase
assert_equal ({ 'name' => 'domain.test',
'status' => ['AtAuction'],
'disclaimer' => 'disclaimer' }), @whois_record.json
'disclaimer' => { 'en' => 'disclaimer' }}), @whois_record.json
end
def test_updates_whois_record_from_auction_when_no_bids
@ -49,7 +49,7 @@ class Whois::RecordTest < ActiveSupport::TestCase
assert_equal ({ 'name' => 'domain.test',
'status' => ['PendingRegistration'],
'disclaimer' => 'disclaimer',
'disclaimer' => { 'en' => 'disclaimer' },
'registration_deadline' => registration_deadline.try(:to_s, :iso8601) }),
@whois_record.json
end
@ -64,12 +64,12 @@ class Whois::RecordTest < ActiveSupport::TestCase
assert_equal ({ 'name' => 'domain.test',
'status' => ['PendingRegistration'],
'disclaimer' => 'disclaimer',
'disclaimer' => { 'en' => 'disclaimer' },
'registration_deadline' => registration_deadline.try(:to_s, :iso8601) }),
@whois_record.json
end
def registration_deadline
Time.zone.now + 10.days
@registration_deadline ||= Time.zone.now + 10.days
end
end

View file

@ -12,10 +12,7 @@ class WhoisRecordTest < ActiveSupport::TestCase
end
def test_generated_json_has_expected_values
expected_disclaimer_text = <<-TEXT.squish
Search results may not be used for commercial, advertising, recompilation,
repackaging, redistribution, reuse, obscuring or other similar activities.
TEXT
expected_disclaimer_text = SettingEntry.find_by(code: 'registry_whois_disclaimer').retrieve
expected_partial_hash = {
disclaimer: expected_disclaimer_text,

View file

@ -42,6 +42,38 @@ class AdminAreaDomainForceDeleteTest < ApplicationSystemTestCase
find(:css, '#soft_delete').set(true)
click_link_or_button 'Force delete domain'
end
@domain.reload
assert_equal @domain.notification_template, @domain.template_name
end
def test_uses_legal_template_if_registrant_org
@domain.registrant.update(ident_type: 'org')
assert_emails 0 do
visit edit_admin_domain_url(@domain)
find(:css, '#soft_delete').set(true)
click_link_or_button 'Force delete domain'
end
@domain.reload
assert_equal @domain.notification_template, @domain.template_name
end
def test_uses_legal_template_if_invalid_email
verification = @domain.contacts.first.email_verification
verification.update(verified_at: Time.zone.now - 1.day, success: false)
assert_equal @domain.notification_template, 'invalid_email'
assert_emails 0 do
visit edit_admin_domain_url(@domain)
find(:css, '#soft_delete').set(true)
click_link_or_button 'Force delete domain'
end
@domain.reload
assert_equal @domain.notification_template, @domain.template_name
end
def test_allows_to_skip_notifying_registrant_and_admin_contacts_by_email

View file

@ -29,6 +29,16 @@ class RegistrarAreaBaseTestTest < ApplicationSystemTestCase
assert_button 'Login'
end
def test_user_can_access_when_ip_is_whitelisted_with_subnet
white_ips(:one).update!(ipv4: '127.0.0.1/32', interfaces: [WhiteIp::REGISTRAR])
Setting.registrar_ip_whitelist_enabled = true
visit new_registrar_user_session_url
assert_no_text 'Access denied from IP 127.0.0.1'
assert_button 'Login'
end
def test_user_can_access_when_ip_is_not_whitelisted_and_whitelist_is_disabled
Setting.registrar_ip_whitelist_enabled = false
WhiteIp.delete_all

View file

@ -6,9 +6,9 @@ class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
end
def test_transfer_multiple_domains_in_bulk
request_body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
request_body = { data: { domain_transfers: [{ domain_name: 'shop.test', transfer_code: '65078d5' }] } }
headers = { 'Content-type' => Mime[:json] }
request_stub = stub_request(:post, /domain_transfers/).with(body: request_body,
request_stub = stub_request(:post, /domains\/transfer/).with(body: request_body,
headers: headers,
basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{
@ -29,7 +29,7 @@ class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
def test_fail_gracefully
body = { errors: [{ title: 'epic fail' }] }.to_json
headers = { 'Content-type' => Mime[:json] }
stub_request(:post, /domain_transfers/).to_return(status: 400, body: body, headers: headers)
stub_request(:post, /domains\/transfer/).to_return(status: 400, body: body, headers: headers)
visit registrar_domains_url
click_link 'Bulk change'

View file

@ -8,6 +8,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
def test_replaces_current_registrar_nameservers
request_body = { data: { type: 'nameserver',
id: 'ns1.bestnames.test',
domains: [],
attributes: { hostname: 'new-ns.bestnames.test',
ipv4: %w[192.0.2.55 192.0.2.56],
ipv6: %w[2001:db8::55 2001:db8::56] } } }