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

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