Introduce custom assertion

This commit is contained in:
Artur Beljajev 2019-09-03 18:15:58 +03:00
parent 5939da366e
commit 348e6e5d7a
54 changed files with 378 additions and 389 deletions

View file

@ -1,22 +1,27 @@
module EPP module Epp
class Response class Response
attr_accessor :results attr_reader :results
def self.from_xml(xml) def self.xml(xml)
xml_doc = Nokogiri::XML(xml) xml_doc = Nokogiri::XML(xml)
response = new
result_elements = xml_doc.css('result') result_elements = xml_doc.css('result')
results = []
result_elements.each do |result_element| result_elements.each do |result_element|
response.results << Result.new(result_element[:code].to_s, result_element.text.strip) code_value = result_element[:code]
code = Result::Code.new(code_value)
results << Result.new(code: code)
end end
response new(results: results)
end end
def initialize def initialize(results:)
@results = [] @results = results
end
def code?(code)
results.any? { |result| result.code == code }
end end
end end
end end

View file

@ -1,27 +1,10 @@
module EPP module Epp
class Response class Response
class Result class Result
CODE_TO_TYPE = { attr_reader :code
'1000' => :success,
'1001' => :success_pending,
'1300' => :success_empty_queue,
'1301' => :success_dequeue,
'2001' => :syntax_error,
'2003' => :required_param_missing,
'2005' => :param_syntax_error,
'2308' => :data_management_policy_violation
}
attr_accessor :code def initialize(code:)
attr_accessor :message
def initialize(code, message)
@code = code @code = code
@message = message
end
def self.codes
CODE_TO_TYPE
end end
end end
end end

View file

@ -0,0 +1,81 @@
module Epp
class Response
class Result
class Code
attr_reader :value
KEY_TO_VALUE = {
completed_successfully: 1000,
completed_successfully_action_pending: 1001,
completed_successfully_no_messages: 1300,
completed_successfully_ack_to_dequeue: 1301,
completed_successfully_ending_session: 1500,
unknown_command: 2000,
syntax_error: 2001,
use_error: 2002,
required_parameter_missing: 2003,
parameter_value_range_error: 2004,
parameter_value_syntax_error: 2005,
billing_failure: 2104,
object_is_not_eligible_for_renewal: 2105,
authorization_error: 2201,
invalid_authorization_information: 2202,
object_does_not_exist: 2303,
object_status_prohibits_operation: 2304,
object_association_prohibits_operation: 2305,
parameter_value_policy_error: 2306,
data_management_policy_violation: 2308,
authentication_error_server_closing_connection: 2501,
}.freeze
private_constant :KEY_TO_VALUE
DEFAULT_DESCRIPTIONS = {
1000 => 'Command completed successfully',
1001 => 'Command completed successfully; action pending',
1300 => 'Command completed successfully; no messages',
1301 => 'Command completed successfully; ack to dequeue',
1500 => 'Command completed successfully; ending session',
2000 => 'Unknown command',
2001 => 'Command syntax error',
2002 => 'Command use error',
2003 => 'Required parameter missing',
2004 => 'Parameter value range error',
2005 => 'Parameter value syntax error',
2104 => 'Billing failure',
2105 => 'Object is not eligible for renewal',
2201 => 'Authorization error',
2202 => 'Invalid authorization information',
2303 => 'Object does not exist',
2304 => 'Object status prohibits operation',
2305 => 'Object association prohibits operation',
2306 => 'Parameter value policy error',
2308 => 'Data management policy violation',
2501 => 'Authentication error; server closing connection',
}.freeze
private_constant :DEFAULT_DESCRIPTIONS
def self.codes
KEY_TO_VALUE
end
def self.default_descriptions
DEFAULT_DESCRIPTIONS
end
def self.key(key)
new(KEY_TO_VALUE[key])
end
def initialize(value)
value = value.to_i
raise ArgumentError, "Invalid value: #{value}" unless KEY_TO_VALUE.value?(value)
@value = value
end
def ==(other)
value == other.value
end
end
end
end
end

View file

@ -1,21 +0,0 @@
require 'rails_helper'
RSpec.describe EPP::Response::Result, db: false do
# https://tools.ietf.org/html/rfc5730#section-3
describe '::codes' do
it 'returns codes' do
codes = {
'1000' => :success,
'1001' => :success_pending,
'1300' => :success_empty_queue,
'1301' => :success_dequeue,
'2001' => :syntax_error,
'2003' => :required_param_missing,
'2005' => :param_syntax_error,
'2308' => :data_management_policy_violation
}
expect(described_class.codes).to eq(codes)
end
end
end

View file

@ -8,8 +8,6 @@ require 'support/requests/session_helpers'
require 'support/requests/epp_helpers' require 'support/requests/epp_helpers'
require 'support/features/session_helpers' require 'support/features/session_helpers'
require 'support/matchers/alias_attribute' require 'support/matchers/alias_attribute'
require 'support/matchers/epp/code'
require 'support/matchers/epp/have_result'
require 'support/capybara' require 'support/capybara'
require 'support/devise' require 'support/devise'
@ -30,7 +28,6 @@ RSpec.configure do |config|
config.include AbstractController::Translation, type: :feature config.include AbstractController::Translation, type: :feature
config.include AbstractController::Translation, type: :mailer config.include AbstractController::Translation, type: :mailer
config.include Requests::EPPHelpers, epp: true config.include Requests::EPPHelpers, epp: true
config.include Matchers::EPP, epp: true
config.include Devise::Test::IntegrationHelpers, type: :feature config.include Devise::Test::IntegrationHelpers, type: :feature
config.include Devise::Test::IntegrationHelpers, type: :request config.include Devise::Test::IntegrationHelpers, type: :request

View file

@ -52,7 +52,7 @@ RSpec.describe 'EPP contact:create' do
specify do specify do
request request
expect(epp_response).to have_result(:success) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -86,8 +86,7 @@ RSpec.describe 'EPP contact:create' do
specify do specify do
request request
expect(epp_response).to have_result(:required_param_missing, expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:required_parameter_missing))).to be_truthy
'Required parameter missing: extension > extdata > ident [ident]')
end end
end end
@ -130,9 +129,7 @@ RSpec.describe 'EPP contact:create' do
specify do specify do
request request
expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy
message = 'Ident code does not conform to national identification number format of Germany'
expect(epp_response).to have_result(:param_syntax_error, message)
end end
end end
@ -174,8 +171,7 @@ RSpec.describe 'EPP contact:create' do
specify do specify do
request request
expect(epp_response).to have_result(:param_syntax_error, expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy
'Ident code does not conform to registration number format of Germany')
end end
end end
@ -209,8 +205,7 @@ RSpec.describe 'EPP contact:create' do
specify do specify do
request request
expect(epp_response).to have_result(:required_param_missing, expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:required_parameter_missing))).to be_truthy
'Required ident attribute missing: cc')
end end
end end
@ -244,7 +239,7 @@ RSpec.describe 'EPP contact:create' do
specify do specify do
request request
expect(epp_response).to have_result(:syntax_error) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:syntax_error))).to be_truthy
end end
end end
@ -285,8 +280,7 @@ RSpec.describe 'EPP contact:create' do
specify do specify do
request request
expect(epp_response).to have_result(:param_syntax_error, expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy
'Ident type "priv" is invalid for Germany')
end end
end end
end end

View file

@ -4,7 +4,7 @@ RSpec.shared_examples 'EPP contact phone' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -13,7 +13,7 @@ RSpec.shared_examples 'EPP contact phone' do
specify do specify do
request request
expect(response).to have_code_of(2005) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy
end end
end end
@ -22,7 +22,7 @@ RSpec.shared_examples 'EPP contact phone' do
specify do specify do
request request
expect(response).to have_code_of(2005) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy
end end
end end
end end

View file

@ -45,7 +45,7 @@ RSpec.describe 'EPP contact:update' do
specify do specify do
request request
expect(epp_response).to have_result(:success) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -78,9 +78,7 @@ RSpec.describe 'EPP contact:update' do
specify do specify do
request request
expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:data_management_policy_violation))).to be_truthy
expect(epp_response).to have_result(:data_management_policy_violation,
t('epp.contacts.errors.valid_ident'))
end end
end end
end end
@ -138,7 +136,7 @@ RSpec.describe 'EPP contact:update' do
specify do specify do
request request
expect(epp_response).to have_result(:success) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -190,9 +188,7 @@ RSpec.describe 'EPP contact:update' do
specify do specify do
request request
expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:data_management_policy_violation))).to be_truthy
expect(epp_response).to have_result(:data_management_policy_violation,
t('epp.contacts.errors.ident_update'))
end end
end end
end end

View file

@ -49,7 +49,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -62,7 +62,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(2104) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:billing_failure))).to be_truthy
end end
end end
end end

View file

@ -54,7 +54,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
end end

View file

@ -64,7 +64,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(2308) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:data_management_policy_violation))).to be_truthy
end end
end end
@ -103,7 +103,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
end end

View file

@ -57,7 +57,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -103,7 +103,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
end end

View file

@ -50,7 +50,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -61,7 +61,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(2104) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:billing_failure))).to be_truthy
end end
end end
end end

View file

@ -61,7 +61,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -93,7 +93,7 @@ RSpec.describe 'EPP domain:create', settings: false do
specify do specify do
request request
expect(response).to have_code_of(2003) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:required_parameter_missing))).to be_truthy
end end
end end
end end

View file

@ -51,7 +51,7 @@ RSpec.describe 'EPP domain:renew' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -86,7 +86,7 @@ RSpec.describe 'EPP domain:renew' do
specify do specify do
request request
expect(response).to have_code_of(2104) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:billing_failure))).to be_truthy
end end
end end
end end

View file

@ -50,7 +50,7 @@ RSpec.describe 'EPP domain:renew', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
end end

View file

@ -51,7 +51,7 @@ RSpec.describe 'EPP domain:renew' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -83,7 +83,7 @@ RSpec.describe 'EPP domain:renew' do
specify do specify do
request request
expect(response).to have_code_of(2306) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_policy_error))).to be_truthy
end end
end end
end end

View file

@ -51,7 +51,7 @@ RSpec.describe 'EPP domain:renew', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -88,7 +88,7 @@ RSpec.describe 'EPP domain:renew', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
end end

View file

@ -51,7 +51,7 @@ RSpec.describe 'EPP domain:renew', settings: false do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
end end
@ -62,7 +62,7 @@ RSpec.describe 'EPP domain:renew', settings: false do
specify do specify do
request request
expect(response).to have_code_of(2104) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:billing_failure))).to be_truthy
end end
end end
end end

View file

@ -42,7 +42,7 @@ RSpec.describe 'EPP domain:update' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
it 'keeps same registrant' do it 'keeps same registrant' do
@ -87,7 +87,7 @@ RSpec.describe 'EPP domain:update' do
specify do specify do
request request
expect(response).to have_code_of(1001) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully_action_pending))).to be_truthy
end end
it 'does not change registrant without confirmation' do it 'does not change registrant without confirmation' do
@ -143,7 +143,7 @@ RSpec.describe 'EPP domain:update' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
it 'keeps same registrant' do it 'keeps same registrant' do
@ -188,7 +188,7 @@ RSpec.describe 'EPP domain:update' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
it 'changes registrant without confirmation' do it 'changes registrant without confirmation' do

View file

@ -43,7 +43,7 @@ RSpec.describe 'EPP domain:update' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
it 'changes registrant' do it 'changes registrant' do
@ -86,7 +86,7 @@ RSpec.describe 'EPP domain:update' do
specify do specify do
request request
expect(response).to have_code_of(1001) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully_action_pending))).to be_truthy
end end
it 'does not change registrant' do it 'does not change registrant' do
@ -135,7 +135,7 @@ RSpec.describe 'EPP domain:update' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
it 'changes registrant' do it 'changes registrant' do
@ -178,7 +178,7 @@ RSpec.describe 'EPP domain:update' do
specify do specify do
request request
expect(response).to have_code_of(1000) expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy
end end
it 'changes registrant' do it 'changes registrant' do

View file

@ -1,39 +0,0 @@
module Matchers
module EPP
class Code
def initialize(expected)
@expected = expected
end
def matches?(response)
@xml = response.body
actual == expected
end
def failure_message
"Expected EPP code of #{expected}, got #{actual} (#{code_description})"
end
def description
"should have EPP code of #{expected}"
end
private
attr_reader :xml
attr_reader :expected
def actual
xml_document.xpath('//xmlns:result').first['code'].to_i
end
def code_description
xml_document.css('result msg').text
end
def xml_document
@xml_document ||= Nokogiri::XML(xml)
end
end
end
end

View file

@ -1,37 +0,0 @@
module Matchers
module EPP
class HaveResultMatcher
def initialize(expected)
@expected = expected
end
def matches?(target)
@target = target
if @expected.message.present?
@target.results.any? { |result| result.code == @expected.code && result.message == @expected.message }
else
@target.results.any? { |result| result.code == @expected.code }
end
end
def failure_message
"expected #{@target.results} to have result #{@expected.inspect}"
end
def failure_message_when_negated
"expected #{@target.results} not to have result #{@expected.inspect}"
end
def description
"should have EPP code of #{@expected}"
end
end
def have_result(type, message = nil)
code = ::EPP::Response::Result.codes.key(type)
result = ::EPP::Response::Result.new(code, message)
HaveResultMatcher.new(result)
end
end
end

View file

@ -1,15 +1,7 @@
module Requests module Requests
module EPPHelpers module EPPHelpers
def have_code_of(*args)
Matchers::EPP::Code.new(*args)
end
def valid_legal_document def valid_legal_document
Base64.encode64('a' * 5000) Base64.encode64('a' * 5000)
end end
def epp_response
EPP::Response.from_xml(response.body)
end
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppContactCheckBaseTest < ActionDispatch::IntegrationTest class EppContactCheckBaseTest < EppTestCase
setup do setup do
@contact = contacts(:john) @contact = contacts(:john)
end end
@ -24,8 +24,7 @@ class EppContactCheckBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal 'john-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text assert_equal 'john-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppContactCreateBaseTest < ActionDispatch::IntegrationTest class EppContactCreateBaseTest < EppTestCase
def test_creates_new_contact_with_minimum_required_parameters def test_creates_new_contact_with_minimum_required_parameters
request_xml = <<-XML request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
@ -28,9 +28,7 @@ class EppContactCreateBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully
assert_equal '1000', response_xml.at_css('result')[:code]
contact = Contact.last contact = Contact.last
assert_not_empty contact.code assert_not_empty contact.code
assert_equal 'New', contact.name assert_equal 'New', contact.name

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest class EppContactDeleteBaseTest < EppTestCase
def test_deletes_contact def test_deletes_contact
contact = deletable_contact contact = deletable_contact
@ -23,9 +23,7 @@ class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest
assert_difference 'Contact.count', -1 do assert_difference 'Contact.count', -1 do
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
end end
def test_undeletable_cannot_be_deleted def test_undeletable_cannot_be_deleted
@ -51,8 +49,7 @@ class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest
assert_no_difference 'Contact.count' do assert_no_difference 'Contact.count' do
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :object_association_prohibits_operation
assert_equal '2305', response_xml.at_css('result')[:code]
end end
private private

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppContactInfoBaseTest < ActionDispatch::IntegrationTest class EppContactInfoBaseTest < EppTestCase
setup do setup do
@contact = contacts(:john) @contact = contacts(:john)
end end
@ -32,8 +32,7 @@ class EppContactInfoBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal 'JOHN-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text assert_equal 'JOHN-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text
assert_equal 'ok', response_xml.at_xpath('//contact:status', contact: xml_schema)['s'] assert_equal 'ok', response_xml.at_xpath('//contact:status', contact: xml_schema)['s']
assert_equal 'john@inbox.test', response_xml.at_xpath('//contact:email', contact: xml_schema) assert_equal 'john@inbox.test', response_xml.at_xpath('//contact:email', contact: xml_schema)
@ -62,8 +61,7 @@ class EppContactInfoBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) assert_epp_response :object_does_not_exist
assert_equal '2303', response_xml.at_css('result')[:code]
end end
private private

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppContactUpdateBaseTest < ActionDispatch::IntegrationTest class EppContactUpdateBaseTest < EppTestCase
include ActionMailer::TestHelper include ActionMailer::TestHelper
setup do setup do
@ -40,9 +40,7 @@ class EppContactUpdateBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
@contact.reload @contact.reload
response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
assert_equal 'new name', @contact.name assert_equal 'new name', @contact.name
assert_equal 'new-email@inbox.test', @contact.email assert_equal 'new-email@inbox.test', @contact.email
assert_equal '+123.4', @contact.phone assert_equal '+123.4', @contact.phone
@ -158,8 +156,7 @@ class EppContactUpdateBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) assert_epp_response :object_does_not_exist
assert_equal '2303', response_xml.at_css('result')[:code]
end end
private private

View file

@ -1,7 +1,7 @@
# encoding: UTF-8 # encoding: UTF-8
require 'test_helper' require 'test_helper'
class EppDomainCheckAuctionTest < ApplicationIntegrationTest class EppDomainCheckAuctionTest < EppTestCase
setup do setup do
@auction = auctions(:one) @auction = auctions(:one)
@idn_auction = auctions(:idn) @idn_auction = auctions(:idn)
@ -31,8 +31,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end end
@ -56,8 +55,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end end
@ -81,8 +79,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end end
@ -106,8 +103,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Awaiting payment', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'Awaiting payment', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end end
@ -131,8 +127,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal '1', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal '1', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_nil response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd') assert_nil response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainCheckBaseTest < ApplicationIntegrationTest class EppDomainCheckBaseTest < EppTestCase
def test_returns_valid_response def test_returns_valid_response
request_xml = <<-XML request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
@ -18,8 +18,7 @@ class EppDomainCheckBaseTest < ApplicationIntegrationTest
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal 'some.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'some.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end end

View file

@ -1,7 +1,7 @@
# encoding: UTF-8 # encoding: UTF-8
require 'test_helper' require 'test_helper'
class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest class EppDomainCreateAuctionIdnTest < EppTestCase
def setup def setup
super super
@ -46,11 +46,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest
@idn_auction.reload @idn_auction.reload
refute @idn_auction.domain_registered? refute @idn_auction.domain_registered?
assert_epp_response :required_parameter_missing
response_xml = Nokogiri::XML(response.body)
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element is required',
response_xml.at_css('result msg').text
end end
def test_domain_with_unicode_idn_cannot_be_registered_without_registration_code def test_domain_with_unicode_idn_cannot_be_registered_without_registration_code
@ -84,11 +80,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest
@idn_auction.reload @idn_auction.reload
refute @idn_auction.domain_registered? refute @idn_auction.domain_registered?
assert_epp_response :required_parameter_missing
response_xml = Nokogiri::XML(response.body)
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element is required',
response_xml.at_css('result msg').text
end end
def test_domain_with_ascii_idn_cannot_be_registered_without_winning_the_auction def test_domain_with_ascii_idn_cannot_be_registered_without_winning_the_auction
@ -121,11 +113,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest
@idn_auction.reload @idn_auction.reload
refute @idn_auction.domain_registered? refute @idn_auction.domain_registered?
assert_epp_response :parameter_value_policy_error
response_xml = Nokogiri::XML(response.body)
assert_equal '2306', response_xml.at_css('result')[:code]
assert_equal 'Parameter value policy error: domain is at auction',
response_xml.at_css('result msg').text
end end
def test_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction def test_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction
@ -195,11 +183,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest
@idn_auction.reload @idn_auction.reload
refute @idn_auction.domain_registered? refute @idn_auction.domain_registered?
assert_epp_response :parameter_value_policy_error
response_xml = Nokogiri::XML(response.body)
assert_equal '2306', response_xml.at_css('result')[:code]
assert_equal 'Parameter value policy error: domain is at auction',
response_xml.at_css('result msg').text
end end
def test_registers_unicode_domain_with_correct_registration_code_when_payment_is_received def test_registers_unicode_domain_with_correct_registration_code_when_payment_is_received
@ -235,10 +219,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest
@idn_auction.reload @idn_auction.reload
assert @idn_auction.domain_registered? assert @idn_auction.domain_registered?
assert Domain.where(name: @idn_auction.domain).exists? assert Domain.where(name: @idn_auction.domain).exists?
assert_epp_response :completed_successfully
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_registers_ascii_domain_with_correct_registration_code_when_payment_is_received def test_registers_ascii_domain_with_correct_registration_code_when_payment_is_received
@ -274,9 +255,6 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest
@idn_auction.reload @idn_auction.reload
assert @idn_auction.domain_registered? assert @idn_auction.domain_registered?
assert Domain.where(name: @idn_auction.domain).exists? assert Domain.where(name: @idn_auction.domain).exists?
assert_epp_response :completed_successfully
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainCreateAuctionTest < ApplicationIntegrationTest class EppDomainCreateAuctionTest < EppTestCase
setup do setup do
@auction = auctions(:one) @auction = auctions(:one)
Domain.release_to_auction = true Domain.release_to_auction = true
@ -33,9 +33,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest
assert_difference 'Domain.count' do assert_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_registers_domain_with_correct_registration_code_after_another_auction_when_payment_is_received def test_registers_domain_with_correct_registration_code_after_another_auction_when_payment_is_received
@ -72,9 +70,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest
assert_difference 'Domain.count' do assert_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_registers_domain_with_correct_registration_code_when_payment_is_received def test_registers_domain_with_correct_registration_code_when_payment_is_received
@ -109,10 +105,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest
@auction.reload @auction.reload
assert @auction.domain_registered? assert @auction.domain_registered?
assert_epp_response :completed_successfully
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_domain_cannot_be_registered_without_registration_code def test_domain_cannot_be_registered_without_registration_code
@ -141,10 +134,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest
assert_no_difference 'Domain.count' do assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :required_parameter_missing
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element is required',
response_xml.at_css('result msg').text
end end
def test_domain_cannot_be_registered_with_wrong_registration_code def test_domain_cannot_be_registered_with_wrong_registration_code
@ -176,10 +166,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest
assert_no_difference 'Domain.count' do assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :invalid_authorization_information
assert_equal '2202', response_xml.at_css('result')[:code]
assert_equal 'Invalid authorization information; invalid reserved>pw value',
response_xml.at_css('result msg').text
end end
def test_domain_cannot_be_registered_when_payment_is_not_received def test_domain_cannot_be_registered_when_payment_is_not_received
@ -210,10 +197,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest
assert_no_difference 'Domain.count' do assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :required_parameter_missing
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element required for reserved domains',
response_xml.at_css('result msg').text
end end
def test_domain_cannot_be_registered_when_at_auction def test_domain_cannot_be_registered_when_at_auction
@ -240,9 +224,6 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest
assert_no_difference 'Domain.count' do assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
response_xml = Nokogiri::XML(response.body) assert_epp_response :parameter_value_policy_error
assert_equal '2306', response_xml.at_css('result')[:code]
assert_equal 'Parameter value policy error: domain is at auction',
response_xml.at_css('result msg').text
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainCreateBaseTest < ApplicationIntegrationTest class EppDomainCreateBaseTest < EppTestCase
def test_domain_can_be_registered_with_required_attributes_only def test_domain_can_be_registered_with_required_attributes_only
request_xml = <<-XML request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
@ -28,9 +28,6 @@ class EppDomainCreateBaseTest < ApplicationIntegrationTest
domain = Domain.last domain = Domain.last
assert_equal 'new.test', domain.name assert_equal 'new.test', domain.name
assert_equal contacts(:john).becomes(Registrant), domain.registrant assert_equal contacts(:john).becomes(Registrant), domain.registrant
assert_epp_response :completed_successfully
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainCreateNameserversTest < ApplicationIntegrationTest class EppDomainCreateNameserversTest < EppTestCase
# Glue record requirement # Glue record requirement
def test_nameserver_ip_address_is_required_if_hostname_is_under_the_same_domain def test_nameserver_ip_address_is_required_if_hostname_is_under_the_same_domain
request_xml = <<-XML request_xml = <<-XML
@ -30,6 +30,6 @@ class EppDomainCreateNameserversTest < ApplicationIntegrationTest
assert_no_difference 'Domain.count' do assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
end end
assert_equal '2003', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :required_parameter_missing
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainCreateReservedTest < ApplicationIntegrationTest class EppDomainCreateReservedTest < EppTestCase
setup do setup do
@reserved_domain = reserved_domains(:one) @reserved_domain = reserved_domains(:one)
end end
@ -34,10 +34,7 @@ class EppDomainCreateReservedTest < ApplicationIntegrationTest
assert_difference 'Domain.count' do assert_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
assert_epp_response :completed_successfully
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_registering_reserved_domain_regenerates_registration_code def test_registering_reserved_domain_regenerates_registration_code
@ -101,11 +98,7 @@ class EppDomainCreateReservedTest < ApplicationIntegrationTest
assert_no_difference 'Domain.count' do assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
assert_epp_response :invalid_authorization_information
response_xml = Nokogiri::XML(response.body)
assert_equal '2202', response_xml.at_css('result')[:code]
assert_equal 'Invalid authorization information; invalid reserved>pw value',
response_xml.at_css('result msg').text
end end
def test_domain_cannot_be_registered_without_registration_code def test_domain_cannot_be_registered_without_registration_code
@ -133,10 +126,6 @@ class EppDomainCreateReservedTest < ApplicationIntegrationTest
assert_no_difference 'Domain.count' do assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
assert_epp_response :required_parameter_missing
response_xml = Nokogiri::XML(response.body)
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element required for reserved domains',
response_xml.at_css('result msg').text
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainCreateTransferCodeTest < ApplicationIntegrationTest class EppDomainCreateTransferCodeTest < EppTestCase
setup do setup do
travel_to Time.zone.parse('2010-07-05') travel_to Time.zone.parse('2010-07-05')
end end
@ -28,8 +28,7 @@ class EppDomainCreateTransferCodeTest < ApplicationIntegrationTest
post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
refute_empty Domain.find_by(name: 'brandnew.test').transfer_code refute_empty Domain.find_by(name: 'brandnew.test').transfer_code
assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_honors_custom def test_honors_custom
@ -58,7 +57,6 @@ class EppDomainCreateTransferCodeTest < ApplicationIntegrationTest
post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_equal '1058ad73', Domain.find_by(name: 'brandnew.test').transfer_code assert_equal '1058ad73', Domain.find_by(name: 'brandnew.test').transfer_code
assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest class EppDomainDeleteBaseTest < EppTestCase
include ActionMailer::TestHelper include ActionMailer::TestHelper
setup do setup do
@ -36,8 +36,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_includes Domain.find_by(name: 'invalid.test').statuses, DomainStatus::PENDING_DELETE_CONFIRMATION assert_includes Domain.find_by(name: 'invalid.test').statuses, DomainStatus::PENDING_DELETE_CONFIRMATION
assert_equal '1001', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :completed_successfully_action_pending
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_discarded_domain_cannot_be_deleted def test_discarded_domain_cannot_be_deleted
@ -65,7 +64,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest
assert_no_difference 'Domain.count' do assert_no_difference 'Domain.count' do
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :object_is_not_eligible_for_renewal
end end
def test_requests_registrant_confirmation_when_required def test_requests_registrant_confirmation_when_required
@ -96,8 +95,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest
assert @domain.registrant_verification_asked? assert @domain.registrant_verification_asked?
assert @domain.pending_delete_confirmation? assert @domain.pending_delete_confirmation?
assert_emails 1 assert_emails 1
response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully_action_pending
assert_equal '1001', response_xml.at_css('result')[:code]
end end
def test_skips_registrant_confirmation_when_not_required def test_skips_registrant_confirmation_when_not_required
@ -128,8 +126,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest
assert_not @domain.registrant_verification_asked? assert_not @domain.registrant_verification_asked?
assert_not @domain.pending_delete_confirmation? assert_not @domain.pending_delete_confirmation?
assert_no_emails assert_no_emails
response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully
assert_equal '1000', response_xml.at_css('result')[:code]
end end
def test_skips_registrant_confirmation_when_required_but_already_verified_by_registrar def test_skips_registrant_confirmation_when_required_but_already_verified_by_registrar
@ -160,8 +157,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest
assert_not @domain.registrant_verification_asked? assert_not @domain.registrant_verification_asked?
assert_not @domain.pending_delete_confirmation? assert_not @domain.pending_delete_confirmation?
assert_no_emails assert_no_emails
response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully
assert_equal '1000', response_xml.at_css('result')[:code]
end end
def test_legal_document_is_required def test_legal_document_is_required
@ -182,10 +178,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) assert_epp_response :required_parameter_missing
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing: extension > extdata > legalDocument [legal_document]',
response_xml.at_css('result msg').text
end end
def test_domain_cannot_be_deleted_when_explicitly_prohibited_by_registrar def test_domain_cannot_be_deleted_when_explicitly_prohibited_by_registrar
@ -212,9 +205,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) assert_epp_response :object_status_prohibits_operation
assert_equal '2304', response_xml.at_css('result')[:code]
assert_equal 'Domain status prohibits operation', response_xml.at_css('result msg').text
end end
def test_domain_not_found def test_domain_not_found
@ -240,8 +231,6 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) assert_epp_response :object_does_not_exist
assert_equal '2303', response_xml.at_css('result')[:code]
assert_equal 'Domain not found', response_xml.at_css('result msg').text
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainRenewTest < ApplicationIntegrationTest class EppDomainRenewTest < EppTestCase
self.use_transactional_fixtures = false self.use_transactional_fixtures = false
setup do setup do
@ -26,7 +26,6 @@ class EppDomainRenewTest < ApplicationIntegrationTest
assert_no_changes -> { domains(:invalid).valid_to } do assert_no_changes -> { domains(:invalid).valid_to } do
post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end end
assert_equal '2304', Nokogiri::XML(response.body).at_css('result')[:code], assert_epp_response :object_status_prohibits_operation
Nokogiri::XML(response.body).css('result').text
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainUpdateTest < ApplicationIntegrationTest class EppDomainUpdateTest < EppTestCase
def setup def setup
@domain = domains(:shop) @domain = domains(:shop)
end end
@ -27,8 +27,7 @@ class EppDomainUpdateTest < ApplicationIntegrationTest
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
@domain.reload @domain.reload
assert_equal 'f0ff7d17b0', @domain.transfer_code assert_equal 'f0ff7d17b0', @domain.transfer_code
assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_discarded_domain_cannot_be_updated def test_discarded_domain_cannot_be_updated
@ -48,6 +47,6 @@ class EppDomainUpdateTest < ApplicationIntegrationTest
XML XML
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :object_is_not_eligible_for_renewal
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainInfoBaseTest < ApplicationIntegrationTest class EppDomainInfoBaseTest < EppTestCase
def test_returns_valid_response def test_returns_valid_response
assert_equal 'john-001', contacts(:john).code assert_equal 'john-001', contacts(:john).code
domains(:shop).update_columns(statuses: [DomainStatus::OK], domains(:shop).update_columns(statuses: [DomainStatus::OK],
@ -24,8 +24,7 @@ class EppDomainInfoBaseTest < ApplicationIntegrationTest
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, response_xml.css('result').size
assert_equal 'shop.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'shop.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
assert_equal 'ok', response_xml.at_xpath('//domain:status', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['s'] assert_equal 'ok', response_xml.at_xpath('//domain:status', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['s']
assert_equal 'john-001', response_xml.at_xpath('//domain:registrant', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'john-001', response_xml.at_xpath('//domain:registrant', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
@ -125,8 +124,6 @@ class EppDomainInfoBaseTest < ApplicationIntegrationTest
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body) assert_epp_response :object_does_not_exist
assert_equal '2303', response_xml.at_css('result')[:code]
assert_equal 'Domain not found', response_xml.at_css('result msg').text
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainTransferBaseTest < ApplicationIntegrationTest class EppDomainTransferBaseTest < EppTestCase
def test_non_existent_domain def test_non_existent_domain
request_xml = <<-XML request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
@ -19,6 +19,7 @@ class EppDomainTransferBaseTest < ApplicationIntegrationTest
XML XML
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
assert_equal '2303', Nokogiri::XML(response.body).at_css('result')[:code]
assert_epp_response :object_does_not_exist
end end
end end

View file

@ -1,11 +1,10 @@
require 'test_helper' require 'test_helper'
class EppDomainTransferQueryTest < ApplicationIntegrationTest class EppDomainTransferQueryTest < EppTestCase
def test_returns_domain_transfer_details def test_returns_domain_transfer_details
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
xml_doc = Nokogiri::XML(response.body) xml_doc = Nokogiri::XML(response.body)
assert_equal '1000', xml_doc.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, xml_doc.css('result').size
assert_equal 'shop.test', xml_doc.xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'shop.test', xml_doc.xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
assert_equal 'serverApproved', xml_doc.xpath('//domain:trStatus', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'serverApproved', xml_doc.xpath('//domain:trStatus', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
assert_equal 'goodnames', xml_doc.xpath('//domain:reID', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'goodnames', xml_doc.xpath('//domain:reID', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
@ -30,13 +29,15 @@ class EppDomainTransferQueryTest < ApplicationIntegrationTest
XML XML
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_equal '2201', Nokogiri::XML(response.body).at_css('result')[:code]
# https://github.com/internetee/registry/issues/686
assert_epp_response :authorization_error
end end
def test_no_domain_transfer def test_no_domain_transfer
domains(:shop).transfers.delete_all domains(:shop).transfers.delete_all
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_equal '2303', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :object_does_not_exist
end end
private private

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppDomainTransferRequestTest < ApplicationIntegrationTest class EppDomainTransferRequestTest < EppTestCase
def setup def setup
@domain = domains(:shop) @domain = domains(:shop)
@new_registrar = registrars(:goodnames) @new_registrar = registrars(:goodnames)
@ -14,8 +14,7 @@ class EppDomainTransferRequestTest < ApplicationIntegrationTest
def test_transfers_domain_at_once def test_transfers_domain_at_once
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_creates_new_domain_transfer def test_creates_new_domain_transfer
@ -77,7 +76,7 @@ class EppDomainTransferRequestTest < ApplicationIntegrationTest
domains(:shop).reload domains(:shop).reload
assert_equal registrars(:bestnames), domains(:shop).registrar assert_equal registrars(:bestnames), domains(:shop).registrar
assert_equal '2304', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :object_status_prohibits_operation
end end
def test_discarded_domain_cannot_be_transferred def test_discarded_domain_cannot_be_transferred
@ -87,15 +86,14 @@ class EppDomainTransferRequestTest < ApplicationIntegrationTest
@domain.reload @domain.reload
assert_equal registrars(:bestnames), @domain.registrar assert_equal registrars(:bestnames), @domain.registrar
assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :object_is_not_eligible_for_renewal
end end
def test_same_registrar def test_same_registrar
assert_no_difference -> { @domain.transfers.size } do assert_no_difference -> { @domain.transfers.size } do
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
end end
assert_epp_response :use_error
assert_equal '2002', Nokogiri::XML(response.body).at_css('result')[:code]
end end
def test_wrong_transfer_code def test_wrong_transfer_code
@ -118,7 +116,9 @@ class EppDomainTransferRequestTest < ApplicationIntegrationTest
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
@domain.reload @domain.reload
refute_equal @new_registrar, @domain.registrar refute_equal @new_registrar, @domain.registrar
assert_equal '2201', Nokogiri::XML(response.body).at_css('result')[:code]
# https://github.com/internetee/registry/issues/686
assert_epp_response :authorization_error
end end
private private

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppLoginCredentialsTest < ApplicationIntegrationTest class EppLoginCredentialsTest < EppTestCase
def test_correct_credentials def test_correct_credentials
request_xml = <<-XML request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
@ -27,8 +27,7 @@ class EppLoginCredentialsTest < ApplicationIntegrationTest
post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' } post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' }
assert EppSession.find_by(session_id: '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_equal users(:api_bestnames), EppSession.find_by(session_id: 'new_session_id').user
assert Nokogiri::XML(response.body).at_css('result[code="1000"]') assert_epp_response :completed_successfully
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_already_logged_in def test_already_logged_in
@ -58,7 +57,8 @@ class EppLoginCredentialsTest < ApplicationIntegrationTest
</epp> </epp>
XML XML
post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=any_random_string' } post '/epp/session/login', { frame: request_xml }, 'HTTP_COOKIE' => 'session=any_random_string'
assert Nokogiri::XML(response.body).at_css('result[code="2501"]')
assert_epp_response :authentication_error_server_closing_connection
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppLoginPasswordChangeTest < ActionDispatch::IntegrationTest class EppLoginPasswordChangeTest < EppTestCase
def test_password_change def test_password_change
request_xml = <<-XML request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
@ -27,7 +27,6 @@ class EppLoginPasswordChangeTest < ActionDispatch::IntegrationTest
post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' } post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' }
assert_equal 'new-password', users(:api_bestnames).plain_text_password assert_equal 'new-password', users(:api_bestnames).plain_text_password
assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppLoginSessionLimitTest < ApplicationIntegrationTest class EppLoginSessionLimitTest < EppTestCase
setup do setup do
travel_to Time.zone.parse('2010-07-05') travel_to Time.zone.parse('2010-07-05')
EppSession.delete_all EppSession.delete_all
@ -16,9 +16,7 @@ class EppLoginSessionLimitTest < ApplicationIntegrationTest
assert_difference 'EppSession.count' do assert_difference 'EppSession.count' do
post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' } post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' }
end end
assert_epp_response :completed_successfully
assert Nokogiri::XML(response.body).at_css('result[code="1000"]')
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_reached def test_reached
@ -31,8 +29,7 @@ class EppLoginSessionLimitTest < ApplicationIntegrationTest
assert_no_difference 'EppSession.count' do assert_no_difference 'EppSession.count' do
post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' } post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' }
end end
assert_epp_response :authentication_error_server_closing_connection
assert Nokogiri::XML(response.body).at_css('result[code="2501"]')
end end
private private

View file

@ -1,10 +1,9 @@
require 'test_helper' require 'test_helper'
class EppLogoutTest < ApplicationIntegrationTest class EppLogoutTest < EppTestCase
def test_success_response def test_success_response
post '/epp/session/logout', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } post '/epp/session/logout', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert Nokogiri::XML(response.body).at_css('result[code="1500"]') assert_epp_response :completed_successfully_ending_session
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end end
def test_ends_current_session def test_ends_current_session
@ -19,7 +18,7 @@ class EppLogoutTest < ApplicationIntegrationTest
def test_anonymous_user def test_anonymous_user
post '/epp/session/logout', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=non-existent' } post '/epp/session/logout', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=non-existent' }
assert Nokogiri::XML(response.body).at_css('result[code="2201"]') assert_epp_response :authorization_error
end end
private private

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class EppPollTest < ApplicationIntegrationTest class EppPollTest < EppTestCase
setup do setup do
@notification = notifications(:complete) @notification = notifications(:complete)
end end
@ -18,8 +18,7 @@ class EppPollTest < ApplicationIntegrationTest
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
xml_doc = Nokogiri::XML(response.body) xml_doc = Nokogiri::XML(response.body)
assert_equal 1301.to_s, xml_doc.at_css('result')[:code] assert_epp_response :completed_successfully_ack_to_dequeue
assert_equal 1, xml_doc.css('result').size
assert_equal 2.to_s, xml_doc.at_css('msgQ')[:count] assert_equal 2.to_s, xml_doc.at_css('msgQ')[:count]
assert_equal @notification.id.to_s, xml_doc.at_css('msgQ')[:id] assert_equal @notification.id.to_s, xml_doc.at_css('msgQ')[:id]
assert_equal Time.zone.parse('2010-07-05').utc.xmlschema, xml_doc.at_css('msgQ qDate').text assert_equal Time.zone.parse('2010-07-05').utc.xmlschema, xml_doc.at_css('msgQ qDate').text
@ -63,9 +62,7 @@ class EppPollTest < ApplicationIntegrationTest
XML XML
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
xml_doc = Nokogiri::XML(response.body) assert_epp_response :completed_successfully_no_messages
assert_equal 1300.to_s, xml_doc.at_css('result')[:code]
assert_equal 1, xml_doc.css('result').size
end end
def test_mark_as_read def test_mark_as_read
@ -85,8 +82,7 @@ class EppPollTest < ApplicationIntegrationTest
xml_doc = Nokogiri::XML(response.body) xml_doc = Nokogiri::XML(response.body)
assert notification.read? assert notification.read?
assert_equal 1000.to_s, xml_doc.at_css('result')[:code] assert_epp_response :completed_successfully
assert_equal 1, xml_doc.css('result').size
assert_equal 1.to_s, xml_doc.at_css('msgQ')[:count] assert_equal 1.to_s, xml_doc.at_css('msgQ')[:count]
assert_equal notification.id.to_s, xml_doc.at_css('msgQ')[:id] assert_equal notification.id.to_s, xml_doc.at_css('msgQ')[:id]
end end
@ -105,9 +101,8 @@ class EppPollTest < ApplicationIntegrationTest
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
notification.reload notification.reload
xml_doc = Nokogiri::XML(response.body)
assert notification.unread? assert notification.unread?
assert_equal 2303.to_s, xml_doc.at_css('result')[:code] assert_epp_response :object_does_not_exist
end end
def test_notification_not_found def test_notification_not_found
@ -121,7 +116,6 @@ class EppPollTest < ApplicationIntegrationTest
XML XML
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
xml_doc = Nokogiri::XML(response.body) assert_epp_response :object_does_not_exist
assert_equal 2303.to_s, xml_doc.at_css('result')[:code]
end end
end end

View file

@ -0,0 +1,84 @@
require 'test_helper'
class EppResponseResultCodeTest < ActiveSupport::TestCase
def test_creates_code_by_key
key = :completed_successfully
assert_includes Epp::Response::Result::Code.codes.keys, key
assert_kind_of Epp::Response::Result::Code, Epp::Response::Result::Code.key(key)
end
def test_creates_new_code_by_string_value
code_value = Epp::Response::Result::Code.codes.values.first
code = Epp::Response::Result::Code.new(code_value.to_s)
assert_equal code_value, code.value
end
def test_invalid_code_value
invalid_code_value = 0000
refute_includes Epp::Response::Result::Code.codes.values, invalid_code_value
e = assert_raises ArgumentError do
Epp::Response::Result::Code.new(invalid_code_value)
end
assert_equal "Invalid value: #{invalid_code_value}", e.message
end
def test_returns_code_values
codes = {
completed_successfully: 1000,
completed_successfully_action_pending: 1001,
completed_successfully_no_messages: 1300,
completed_successfully_ack_to_dequeue: 1301,
completed_successfully_ending_session: 1500,
unknown_command: 2000,
syntax_error: 2001,
use_error: 2002,
required_parameter_missing: 2003,
parameter_value_range_error: 2004,
parameter_value_syntax_error: 2005,
billing_failure: 2104,
object_is_not_eligible_for_renewal: 2105,
authorization_error: 2201,
invalid_authorization_information: 2202,
object_does_not_exist: 2303,
object_status_prohibits_operation: 2304,
object_association_prohibits_operation: 2305,
parameter_value_policy_error: 2306,
data_management_policy_violation: 2308,
authentication_error_server_closing_connection: 2501,
}
assert_equal codes, Epp::Response::Result::Code.codes
end
def test_returns_default_descriptions
descriptions = {
1000 => 'Command completed successfully',
1001 => 'Command completed successfully; action pending',
1300 => 'Command completed successfully; no messages',
1301 => 'Command completed successfully; ack to dequeue',
1500 => 'Command completed successfully; ending session',
2000 => 'Unknown command',
2001 => 'Command syntax error',
2002 => 'Command use error',
2003 => 'Required parameter missing',
2004 => 'Parameter value range error',
2005 => 'Parameter value syntax error',
2104 => 'Billing failure',
2105 => 'Object is not eligible for renewal',
2201 => 'Authorization error',
2202 => 'Invalid authorization information',
2303 => 'Object does not exist',
2304 => 'Object status prohibits operation',
2305 => 'Object association prohibits operation',
2306 => 'Parameter value policy error',
2308 => 'Data management policy violation',
2501 => 'Authentication error; server closing connection',
}
assert_equal descriptions, Epp::Response::Result::Code.default_descriptions
end
def test_equality
assert_equal Epp::Response::Result::Code.new(1000), Epp::Response::Result::Code.new(1000)
end
end

View file

@ -0,0 +1,5 @@
require 'test_helper'
class EppResponseResultTest < ActiveSupport::TestCase
end

View file

@ -0,0 +1,29 @@
require 'test_helper'
class EppResponseTest < ActiveSupport::TestCase
def test_creates_new_response_from_xml_doc
xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="lib/schemas/epp-ee-1.0.xsd">
<response>
<result code="1000">
<msg>any</msg>
</result>
</response>
</epp>
XML
assert_kind_of Epp::Response, Epp::Response.xml(xml)
end
def test_code_predicate
present_code = Epp::Response::Result::Code.key(:completed_successfully)
absent_code = Epp::Response::Result::Code.key(:required_parameter_missing)
result = Epp::Response::Result.new(code: present_code)
response = Epp::Response.new(results: [result])
assert response.code?(present_code)
assert_not response.code?(absent_code)
end
end

View file

@ -0,0 +1,14 @@
module Assertions
module EppAssertions
def assert_epp_response(code_key, message = nil)
assert epp_response.code?(Epp::Response::Result::Code.key(code_key)), message
end
private
def epp_response
@epp_response = Epp::Response.xml(response.body) unless @epp_response
@epp_response
end
end
end

View file

@ -11,6 +11,7 @@ require 'capybara/rails'
require 'capybara/minitest' require 'capybara/minitest'
require 'webmock/minitest' require 'webmock/minitest'
require 'support/rails5_assertions' # Remove once upgraded to Rails 5 require 'support/rails5_assertions' # Remove once upgraded to Rails 5
require 'support/assertions/epp_assertions'
Setting.address_processing = false Setting.address_processing = false
Setting.registry_country_code = 'US' Setting.registry_country_code = 'US'
@ -57,3 +58,7 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest
Capybara.use_default_driver Capybara.use_default_driver
end end
end end
class EppTestCase < ActionDispatch::IntegrationTest
include Assertions::EppAssertions
end