From ea5c443ffbc565844cba684072f46dd4b3f595d0 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 23 Jan 2015 18:44:59 +0200 Subject: [PATCH 01/34] Db does not truncate between tests --- spec/epp/domain_spec.rb | 2684 ++++++++++++++++++++------------------- spec/rails_helper.rb | 26 +- spec/support/epp.rb | 44 +- 3 files changed, 1404 insertions(+), 1350 deletions(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 0f019a776..28f0828fe 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' describe 'EPP Domain', epp: true do + before do # we don't really care about the code validations here, it's done in models # dynamic Contact.code just makes it harder to test EPP @@ -19,433 +20,331 @@ describe 'EPP Domain', epp: true do before(:each) { create_settings } - context 'with valid user' do - before(:each) do - Fabricate(:epp_user, username: 'zone', registrar: zone) - Fabricate(:epp_user, username: 'elkdata', registrar: elkdata) - end + before(:all) do - it 'returns error if contact does not exists' do - Fabricate(:contact, code: 'jd1234') + @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) + @zone = Fabricate(:registrar) + Fabricate(:epp_user, username: 'zone', registrar: @zone) + Fabricate(:epp_user, username: 'elkdata', registrar: @elkdata) - response = epp_request(domain_create_xml, :xml) + Contact.skip_callback(:create, :before, :generate_code) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Contact was not found') - expect(response[:results][0][:value]).to eq('sh8013') + @example_ee = Fabricate(:domain, name: 'example.ee', registrar: @zone, dnskeys: []) - expect(response[:results][1][:result_code]).to eq('2303') - expect(response[:results][1][:msg]).to eq('Contact was not found') - expect(response[:results][1][:value]).to eq('sh801333') + Fabricate(:contact, code: 'citizen_1234') + Fabricate(:contact, code: 'sh8013') + Fabricate(:contact, code: 'sh801333') + @juridical_contact = Fabricate(:contact, code: 'juridical_1234', ident_type: 'ico') + Fabricate(:reserved_domain) + + @uniq_no = Proc.new { @i ||= 0; @i += 1 } + end + + it 'returns error if contact does not exists' do + response = epp_request(domain_create_xml({ + registrant: { value: 'citizen_1234' }, + _anonymus: [ + { contact: { value: 'citizen_1234', attrs: { type: 'admin' } } }, + { contact: { value: 'sh1111', attrs: { type: 'tech' } } }, + { contact: { value: 'sh2222', attrs: { type: 'tech' } } } + ] + }), :xml) + + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:msg]).to eq('Contact was not found') + expect(response[:results][0][:value]).to eq('sh1111') + + expect(response[:results][1][:result_code]).to eq('2303') + expect(response[:results][1][:msg]).to eq('Contact was not found') + expect(response[:results][1][:value]).to eq('sh2222') + + expect(response[:clTRID]).to eq('ABC-12345') + + log = ApiLog::EppLog.last(4) + + expect(log.length).to eq(4) + expect(log[0].request_command).to eq('hello') + expect(log[0].request_successful).to eq(true) + + expect(log[1].request_command).to eq('login') + expect(log[1].request_successful).to eq(true) + expect(log[1].api_user_name).to eq('zone') + expect(log[1].api_user_registrar).to eq('Registrar OÜ') + + expect(log[2].request_command).to eq('create') + expect(log[2].request_object).to eq('domain') + expect(log[2].request_successful).to eq(false) + expect(log[2].api_user_name).to eq('zone') + expect(log[2].api_user_registrar).to eq('Registrar OÜ') + expect(log[2].request).not_to be_blank + expect(log[2].response).not_to be_blank + + expect(log[3].request_command).to eq('logout') + expect(log[3].request_successful).to eq(true) + expect(log[3].api_user_name).to eq('zone') + expect(log[3].api_user_registrar).to eq('Registrar OÜ') + end + + it 'validates required parameters' do + epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') + xml = epp_xml.create({ + name: { value: 'test.ee' } + }) + + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('2003') + expect(response[:results][0][:msg]).to eq('Required parameter missing: ns') + + expect(response[:results][1][:result_code]).to eq('2003') + expect(response[:results][1][:msg]).to eq('Required parameter missing: registrant') + + expect(response[:results][2][:result_code]).to eq('2003') + expect(response[:results][2][:msg]).to eq('Required parameter missing: ns > hostAttr') + + expect(response[:results][3][:result_code]).to eq('2003') + expect(response[:results][3][:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') + end + + context 'with citizen as an owner' do + # before(:each) do + # Fabricate(:contact, code: 'citizen_1234') + # Fabricate(:contact, code: 'sh8013') + # Fabricate(:contact, code: 'sh801333') + # end + + it 'creates a domain' do + response = epp_request(domain_create_xml({ + name: { value: 'uniq.ee' } + }), :xml) + d = Domain.last + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + + cre_data = response[:parsed].css('creData') + + expect(cre_data.css('name').text).to eq('uniq.ee') + expect(cre_data.css('crDate').text).to eq(d.created_at.to_time.utc.to_s) + expect(cre_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) expect(response[:clTRID]).to eq('ABC-12345') - log = ApiLog::EppLog.all + expect(d.registrar.name).to eq('Registrar OÜ') + expect(d.tech_contacts.count).to eq 2 + expect(d.admin_contacts.count).to eq 1 - expect(log.length).to eq(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) + expect(d.nameservers.count).to eq(2) + expect(d.auth_info).not_to be_empty - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('zone') - expect(log[1].api_user_registrar).to eq('Registrar OÜ') + expect(d.dnskeys.count).to eq(1) - expect(log[2].request_command).to eq('create') - expect(log[2].request_object).to eq('domain') - expect(log[2].request_successful).to eq(false) - expect(log[2].api_user_name).to eq('zone') - expect(log[2].api_user_registrar).to eq('Registrar OÜ') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank + key = d.dnskeys.last - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('zone') - expect(log[3].api_user_registrar).to eq('Registrar OÜ') + expect(key.ds_alg).to eq(3) + expect(key.ds_key_tag).to_not be_blank + + expect(key.ds_digest_type).to eq(Setting.ds_algorithm) + expect(key.flags).to eq(257) + expect(key.protocol).to eq(3) + expect(key.alg).to eq(5) + expect(key.public_key).to eq('AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8') end - it 'validates required parameters' do - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - xml = epp_xml.create({ - name: { value: 'test.ee' } + it 'creates a domain with legal document' do + response = epp_request(domain_create_xml_with_legal_doc, :xml) + + expect(response[:msg]).to eq('Command completed successfully') + expect(response[:result_code]).to eq('1000') + d = Domain.last + expect(d.legal_documents.count).to eq(1) + end + + it 'creates ria.ee with valid ds record' do + xml = domain_create_xml({ + name: { value: 'ria.ee' } + }, { + _anonymus: [ + { keyData: { + flags: { value: '257' }, + protocol: { value: '3' }, + alg: { value: '8' }, + pubKey: { value: 'AwEAAaOf5+lz3ftsL+0CCvfJbhUF/NVsNh8BKo61oYs5fXVbuWDiH872 '\ + 'LC8uKDO92TJy7Q4TF9XMAKMMlf1GMAxlRspD749SOCTN00sqfWx1OMTu '\ + 'a28L1PerwHq7665oDJDKqR71btcGqyLKhe2QDvCdA0mENimF1NudX1BJ '\ + 'DDFi6oOZ0xE/0CuveB64I3ree7nCrwLwNs56kXC4LYoX3XdkOMKiJLL/ '\ + 'MAhcxXa60CdZLoRtTEW3z8/oBq4hEAYMCNclpbd6y/exScwBxFTdUfFk '\ + 'KsdNcmvai1lyk9vna0WQrtpYpHKMXvY9LFHaJxCOLR4umfeQ42RuTd82 lqfU6ClMeXs=' } + } + } + ] + }) + + epp_request(xml, :xml) + d = Domain.last + ds = d.dnskeys.last + expect(ds.ds_digest).to eq('0B62D1BC64EFD1EE652FB102BDF1011BF514CCD9A1A0CFB7472AEA3B01F38C92') + end + + it 'validates nameserver ipv4 when in same zone as domain' do + xml = domain_create_xml({ + name: { value: 'uniq3.ee' }, + ns: [ + { + hostAttr: [ + { hostName: { value: 'ns1.uniq3.ee' } } + ] + }, + { + hostAttr: { + hostName: { value: 'ns2.uniq3.ee' } + } + } + ] }) response = epp_request(xml, :xml) - - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][0][:msg]).to eq('Required parameter missing: ns') - - expect(response[:results][1][:result_code]).to eq('2003') - expect(response[:results][1][:msg]).to eq('Required parameter missing: registrant') - - expect(response[:results][2][:result_code]).to eq('2003') - expect(response[:results][2][:msg]).to eq('Required parameter missing: ns > hostAttr') - - expect(response[:results][3][:result_code]).to eq('2003') - expect(response[:results][3][:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') + expect(response[:result_code]).to eq('2306') + expect(response[:msg]).to eq('IPv4 is missing') end - context 'with citizen as an owner' do - before(:each) do - Fabricate(:contact, code: 'jd1234') - Fabricate(:contact, code: 'sh8013') - Fabricate(:contact, code: 'sh801333') + it 'does not create duplicate domain' do + epp_request(domain_create_xml({ + name: { value: 'uniq2.ee' } + }), :xml) + response = epp_request(domain_create_xml({ + name: { value: 'uniq2.ee' } + }), :xml) + + expect(response[:result_code]).to eq('2302') + expect(response[:msg]).to eq('Domain name already exists') + expect(response[:clTRID]).to eq('ABC-12345') + end + + it 'does not create reserved domain' do + xml = domain_create_xml(name: { value: '1162.ee' }) + + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2302') + expect(response[:msg]).to eq('Domain name is reserved or restricted') + expect(response[:clTRID]).to eq('ABC-12345') + end + + it 'does not create domain without contacts and registrant' do + xml = domain_create_xml(contacts: [], registrant: false) + + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('2003') + expect(response[:results][0][:msg]).to eq('Required parameter missing: registrant') + end + + it 'does not create domain without nameservers' do + xml = domain_create_xml(ns: []) + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2003') + expect(response[:msg]).to eq('Required parameter missing: ns') + end + + it 'does not create domain with too many nameservers' do + nameservers = [] + 14.times do |i| + nameservers << { + hostAttr: { + hostName: { value: "ns#{i}.example.net" } + } + } end - it 'creates a domain' do - response = epp_request(domain_create_xml, :xml) - d = Domain.first + xml = domain_create_xml({ + ns: nameservers + }) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2004') + expect(response[:msg]).to eq('Nameservers count must be between 2-11') + end - cre_data = response[:parsed].css('creData') - - expect(cre_data.css('name').text).to eq('example.ee') - expect(cre_data.css('crDate').text).to eq(d.created_at.to_time.utc.to_s) - expect(cre_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) - - expect(response[:clTRID]).to eq('ABC-12345') - - expect(d.registrar.name).to eq('Registrar OÜ') - expect(d.tech_contacts.count).to eq 2 - expect(d.admin_contacts.count).to eq 1 - - expect(d.nameservers.count).to eq(2) - expect(d.auth_info).not_to be_empty - - expect(d.dnskeys.count).to eq(1) - - key = d.dnskeys.first - - expect(key.ds_alg).to eq(3) - expect(key.ds_key_tag).to_not be_blank - - expect(key.ds_digest_type).to eq(Setting.ds_algorithm) - expect(key.flags).to eq(257) - expect(key.protocol).to eq(3) - expect(key.alg).to eq(5) - expect(key.public_key).to eq('AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8') - end - - it 'creates a domain with legal document' do - response = epp_request(domain_create_xml_with_legal_doc, :xml) - - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - d = Domain.first - expect(d.legal_documents.count).to eq(1) - end - - it 'creates ria.ee with valid ds record' do - xml = domain_create_xml({ - name: { value: 'ria.ee' } - }, { - _anonymus: [ - { keyData: { - flags: { value: '257' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'AwEAAaOf5+lz3ftsL+0CCvfJbhUF/NVsNh8BKo61oYs5fXVbuWDiH872 '\ - 'LC8uKDO92TJy7Q4TF9XMAKMMlf1GMAxlRspD749SOCTN00sqfWx1OMTu '\ - 'a28L1PerwHq7665oDJDKqR71btcGqyLKhe2QDvCdA0mENimF1NudX1BJ '\ - 'DDFi6oOZ0xE/0CuveB64I3ree7nCrwLwNs56kXC4LYoX3XdkOMKiJLL/ '\ - 'MAhcxXa60CdZLoRtTEW3z8/oBq4hEAYMCNclpbd6y/exScwBxFTdUfFk '\ - 'KsdNcmvai1lyk9vna0WQrtpYpHKMXvY9LFHaJxCOLR4umfeQ42RuTd82 lqfU6ClMeXs=' } - } - } - ] - }) - - epp_request(xml, :xml) - d = Domain.first - ds = d.dnskeys.first - expect(ds.ds_digest).to eq('0B62D1BC64EFD1EE652FB102BDF1011BF514CCD9A1A0CFB7472AEA3B01F38C92') - end - - it 'validates nameserver ipv4 when in same zone as domain' do - xml = domain_create_xml({ - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.ee' } } - ] - }, - { - hostAttr: { - hostName: { value: 'ns2.example.ee' } - } - } - ] - }) - - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('IPv4 is missing') - end - - it 'does not create duplicate domain' do - epp_request(domain_create_xml, :xml) - response = epp_request(domain_create_xml, :xml) - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Domain name already exists') - expect(response[:clTRID]).to eq('ABC-12345') - end - - it 'does not create reserved domain' do - Fabricate(:reserved_domain) - - xml = domain_create_xml(name: { value: '1162.ee' }) - - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Domain name is reserved or restricted') - expect(response[:clTRID]).to eq('ABC-12345') - end - - it 'does not create domain without contacts and registrant' do - xml = domain_create_xml(contacts: [], registrant: false) - - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][0][:msg]).to eq('Required parameter missing: registrant') - end - - it 'does not create domain without nameservers' do - xml = domain_create_xml(ns: []) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2003') - expect(response[:msg]).to eq('Required parameter missing: ns') - end - - it 'does not create domain with too many nameservers' do - nameservers = [] - 14.times do |i| - nameservers << { + it 'returns error when invalid nameservers are present' do + xml = domain_create_xml({ + ns: [ + { hostAttr: { - hostName: { value: "ns#{i}.example.net" } + hostName: { value: 'invalid1-' } + } + }, + { + hostAttr: { + hostName: { value: '-invalid2' } } } - end - xml = domain_create_xml(ns: nameservers) + ] + }) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2004') - expect(response[:msg]).to eq('Nameservers count must be between 2-11') - end + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2005') + expect(response[:msg]).to eq('Hostname is invalid') + end - it 'returns error when invalid nameservers are present' do - xml = domain_create_xml({ - ns: [ - { - hostAttr: { - hostName: { value: 'invalid1-' } - } - }, - { - hostAttr: { - hostName: { value: '-invalid2' } - } - } - ] - }) + it 'checks hostAttr presence' do + xml = domain_create_xml({ + ns: [ + { + hostObj: { value: 'ns1.example.ee' } + }, + { + hostObj: { value: 'ns2.example.ee' } + } + ] + }) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2005') - expect(response[:msg]).to eq('Hostname is invalid') - end + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2003') + expect(response[:msg]).to eq('Required parameter missing: ns > hostAttr') + end - it 'checks hostAttr presence' do - xml = domain_create_xml({ - ns: [ - { - hostObj: { value: 'ns1.example.ee' } - }, - { - hostObj: { value: 'ns2.example.ee' } - } - ] - }) + it 'creates domain with nameservers with ips' do + epp_request(domain_create_with_host_attrs, :xml) + expect(Domain.last.nameservers.count).to eq(2) + ns = Domain.last.nameservers.first + expect(ns.ipv4).to eq('192.0.2.2') + expect(ns.ipv6).to eq('1080:0:0:0:8:800:200C:417A') + end - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2003') - expect(response[:msg]).to eq('Required parameter missing: ns > hostAttr') - end + it 'returns error when nameserver has invalid ips' do + domain_count = Domain.count + nameserver_count = Nameserver.count + response = epp_request(domain_create_with_invalid_ns_ip_xml, :xml) + expect(response[:results][0][:result_code]).to eq '2005' + expect(response[:results][0][:msg]).to eq 'IPv4 is invalid' + expect(response[:results][0][:value]).to eq '192.0.2.2.invalid' + expect(response[:results][1][:result_code]).to eq '2005' + expect(response[:results][1][:msg]).to eq 'IPv6 is invalid' + expect(response[:results][1][:value]).to eq 'INVALID_IPV6' + # ensure nothing gets saved to db: + expect(Domain.count).to eq(domain_count) + expect(Nameserver.count).to eq(nameserver_count) + end - it 'creates domain with nameservers with ips' do - epp_request(domain_create_with_host_attrs, :xml) - expect(Domain.first.nameservers.count).to eq(2) - ns = Domain.first.nameservers.first - expect(ns.ipv4).to eq('192.0.2.2') - expect(ns.ipv6).to eq('1080:0:0:0:8:800:200C:417A') - end + it 'creates a domain with period in days' do + xml = domain_create_xml(period_value: 365, period_unit: 'd') - it 'returns error when nameserver has invalid ips' do - response = epp_request(domain_create_with_invalid_ns_ip_xml, :xml) - expect(response[:results][0][:result_code]).to eq '2005' - expect(response[:results][0][:msg]).to eq 'IPv4 is invalid' - expect(response[:results][0][:value]).to eq '192.0.2.2.invalid' - expect(response[:results][1][:result_code]).to eq '2005' - expect(response[:results][1][:msg]).to eq 'IPv6 is invalid' - expect(response[:results][1][:value]).to eq 'INVALID_IPV6' - expect(Domain.count).to eq(0) - expect(Nameserver.count).to eq(0) - end + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + expect(Domain.first.valid_to).to eq(Date.today + 1.year) + end - it 'creates a domain with period in days' do - xml = domain_create_xml(period_value: 365, period_unit: 'd') + it 'does not create a domain with invalid period' do + xml = domain_create_xml({ + period: { value: '367', attrs: { unit: 'd' } } + }) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(Domain.first.valid_to).to eq(Date.today + 1.year) - end + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('2004') + expect(response[:results][0][:msg]).to eq('Period must add up to 1, 2 or 3 years') + expect(response[:results][0][:value]).to eq('367') + end - it 'does not create a domain with invalid period' do - xml = domain_create_xml({ - period: { value: '367', attrs: { unit: 'd' } } - }) - - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2004') - expect(response[:results][0][:msg]).to eq('Period must add up to 1, 2 or 3 years') - expect(response[:results][0][:value]).to eq('367') - end - - it 'creates a domain with multiple dnskeys' do - xml = domain_create_xml({}, { - _anonymus: [ - { keyData: { - flags: { value: '257' }, - protocol: { value: '3' }, - alg: { value: '3' }, - pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } - } - }, - { - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '254' }, - pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } - } - } - ] - }) - - epp_request(xml, :xml) - d = Domain.first - - expect(d.dnskeys.count).to eq(3) - - key_1 = d.dnskeys[0] - expect(key_1.ds_key_tag).to_not be_blank - expect(key_1.ds_alg).to eq(3) - expect(key_1.ds_digest_type).to eq(Setting.ds_algorithm) - - expect(d.dnskeys.pluck(:flags)).to match_array([257, 0, 256]) - expect(d.dnskeys.pluck(:protocol)).to match_array([3, 3, 3]) - expect(d.dnskeys.pluck(:alg)).to match_array([3, 5, 254]) - expect(d.dnskeys.pluck(:public_key)).to match_array(%w( - AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8 - 700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f - 841936717ae427ace63c28d04918569a841936717ae427ace63c28d0 - )) - end - - it 'does not create a domain when dnskeys are invalid' do - - xml = domain_create_xml({}, { - _anonymus: [ - { keyData: { - flags: { value: '250' }, - protocol: { value: '4' }, - alg: { value: '9' }, - pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } - } - }, - { - keyData: { - flags: { value: '1' }, - protocol: { value: '3' }, - alg: { value: '10' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '5' }, - alg: { value: '254' }, - pubKey: { value: '' } - } - } - ] - }) - - response = epp_request(xml, :xml) - - expect(response[:results][0][:msg]).to eq('Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255') - expect(response[:results][0][:value]).to eq('9') - - expect(response[:results][1][:msg]).to eq('Valid protocols are: 3') - expect(response[:results][1][:value]).to eq('4') - - expect(response[:results][2][:msg]).to eq('Valid flags are: 0, 256, 257') - expect(response[:results][2][:value]).to eq('250') - - expect(response[:results][3][:msg]).to eq('Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255') - expect(response[:results][3][:value]).to eq('10') - - expect(response[:results][4][:msg]).to eq('Valid flags are: 0, 256, 257') - expect(response[:results][4][:value]).to eq('1') - - expect(response[:results][5][:msg]).to eq('Public key is missing') - - expect(response[:results][6][:msg]).to eq('Valid protocols are: 3') - expect(response[:results][6][:value]).to eq('5') - end - - it 'does not create a domain with two identical dnskeys' do - xml = domain_create_xml({}, { - _anonymus: [ - { keyData: { - flags: { value: '257' }, - protocol: { value: '3' }, - alg: { value: '3' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }] - }) - - response = epp_request(xml, :xml) - - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Public key already exists') - expect(response[:results][0][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') - end - - it 'validated dnskeys count' do - Setting.dnskeys_max_count = 1 - - xml = domain_create_xml({}, { + it 'creates a domain with multiple dnskeys' do + xml = domain_create_xml({}, { _anonymus: [ { keyData: { flags: { value: '257' }, @@ -461,993 +360,1138 @@ describe 'EPP Domain', epp: true do alg: { value: '5' }, pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } } + }, + { + keyData: { + flags: { value: '256' }, + protocol: { value: '3' }, + alg: { value: '254' }, + pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } + } + } + ] + }) + + epp_request(xml, :xml) + d = Domain.last + + expect(d.dnskeys.count).to eq(3) + + key_1 = d.dnskeys[0] + expect(key_1.ds_key_tag).to_not be_blank + expect(key_1.ds_alg).to eq(3) + expect(key_1.ds_digest_type).to eq(Setting.ds_algorithm) + + expect(d.dnskeys.pluck(:flags)).to match_array([257, 0, 256]) + expect(d.dnskeys.pluck(:protocol)).to match_array([3, 3, 3]) + expect(d.dnskeys.pluck(:alg)).to match_array([3, 5, 254]) + expect(d.dnskeys.pluck(:public_key)).to match_array(%w( + AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8 + 700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f + 841936717ae427ace63c28d04918569a841936717ae427ace63c28d0 + )) + end + + it 'does not create a domain when dnskeys are invalid' do + + xml = domain_create_xml({}, { + _anonymus: [ + { keyData: { + flags: { value: '250' }, + protocol: { value: '4' }, + alg: { value: '9' }, + pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } + } + }, + { + keyData: { + flags: { value: '1' }, + protocol: { value: '3' }, + alg: { value: '10' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } + } + }, + { + keyData: { + flags: { value: '256' }, + protocol: { value: '5' }, + alg: { value: '254' }, + pubKey: { value: '' } + } + } + ] + }) + + response = epp_request(xml, :xml) + + expect(response[:results][0][:msg]).to eq('Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255') + expect(response[:results][0][:value]).to eq('9') + + expect(response[:results][1][:msg]).to eq('Valid protocols are: 3') + expect(response[:results][1][:value]).to eq('4') + + expect(response[:results][2][:msg]).to eq('Valid flags are: 0, 256, 257') + expect(response[:results][2][:value]).to eq('250') + + expect(response[:results][3][:msg]).to eq('Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255') + expect(response[:results][3][:value]).to eq('10') + + expect(response[:results][4][:msg]).to eq('Valid flags are: 0, 256, 257') + expect(response[:results][4][:value]).to eq('1') + + expect(response[:results][5][:msg]).to eq('Public key is missing') + + expect(response[:results][6][:msg]).to eq('Valid protocols are: 3') + expect(response[:results][6][:value]).to eq('5') + end + + it 'does not create a domain with two identical dnskeys' do + xml = domain_create_xml({}, { + _anonymus: [ + { keyData: { + flags: { value: '257' }, + protocol: { value: '3' }, + alg: { value: '3' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } + } + }, + { + keyData: { + flags: { value: '0' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } + } + }] + }) + + response = epp_request(xml, :xml) + + expect(response[:result_code]).to eq('2302') + expect(response[:msg]).to eq('Public key already exists') + expect(response[:results][0][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') + end + + it 'validated dnskeys count' do + Setting.dnskeys_max_count = 1 + + xml = domain_create_xml({}, { + _anonymus: [ + { keyData: { + flags: { value: '257' }, + protocol: { value: '3' }, + alg: { value: '3' }, + pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } + } + }, + { + keyData: { + flags: { value: '0' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } + } + }] + }) + + response = epp_request(xml, :xml) + + expect(response[:result_code]).to eq('2004') + expect(response[:msg]).to eq('DNS keys count must be between 0-1') + end + + it 'creates domain with ds data' do + xml = domain_create_xml({}, { + _anonymus: [ + { dsData: { + keyTag: { value: '12345' }, + alg: { value: '3' }, + digestType: { value: '1' }, + digest: { value: '49FD46E6C4B45C55D4AC' } + } }] }) - response = epp_request(xml, :xml) + epp_request(xml, :xml) - expect(response[:result_code]).to eq('2004') - expect(response[:msg]).to eq('DNS keys count must be between 0-1') - end + d = Domain.last + ds = d.dnskeys.first + expect(ds.ds_key_tag).to eq('12345') + expect(ds.ds_alg).to eq(3) + expect(ds.ds_digest_type).to eq(1) + expect(ds.ds_digest).to eq('49FD46E6C4B45C55D4AC') + expect(ds.flags).to be_nil + expect(ds.protocol).to be_nil + expect(ds.alg).to be_nil + expect(ds.public_key).to be_nil + end - it 'creates domain with ds data' do - xml = domain_create_xml({}, { - _anonymus: [ - { dsData: { - keyTag: { value: '12345' }, - alg: { value: '3' }, - digestType: { value: '1' }, - digest: { value: '49FD46E6C4B45C55D4AC' } + it 'creates domain with ds data with key' do + xml = domain_create_xml({}, { + _anonymus: [ + { dsData: { + keyTag: { value: '12345' }, + alg: { value: '3' }, + digestType: { value: '1' }, + digest: { value: '49FD46E6C4B45C55D4AC' }, + keyData: { + flags: { value: '0' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } } - }] - }) + } + }] + }) - epp_request(xml, :xml) + epp_request(xml, :xml) - d = Domain.first - ds = d.dnskeys.first - expect(ds.ds_key_tag).to eq('12345') - expect(ds.ds_alg).to eq(3) - expect(ds.ds_digest_type).to eq(1) - expect(ds.ds_digest).to eq('49FD46E6C4B45C55D4AC') - expect(ds.flags).to be_nil - expect(ds.protocol).to be_nil - expect(ds.alg).to be_nil - expect(ds.public_key).to be_nil - end + d = Domain.last + ds = d.dnskeys.first + expect(ds.ds_key_tag).to eq('12345') + expect(ds.ds_alg).to eq(3) + expect(ds.ds_digest_type).to eq(1) + expect(ds.ds_digest).to eq('49FD46E6C4B45C55D4AC') + expect(ds.flags).to eq(0) + expect(ds.protocol).to eq(3) + expect(ds.alg).to eq(5) + expect(ds.public_key).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') + end - it 'creates domain with ds data with key' do - xml = domain_create_xml({}, { - _anonymus: [ - { dsData: { - keyTag: { value: '12345' }, - alg: { value: '3' }, - digestType: { value: '1' }, - digest: { value: '49FD46E6C4B45C55D4AC' }, - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } + it 'prohibits dsData with key' do + Setting.ds_data_with_key_allowed = false + + xml = domain_create_xml({}, { + _anonymus: [ + { dsData: { + keyTag: { value: '12345' }, + alg: { value: '3' }, + digestType: { value: '1' }, + digest: { value: '49FD46E6C4B45C55D4AC' }, + keyData: { + flags: { value: '0' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } } - }] - }) + } + }] + }) - epp_request(xml, :xml) + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2306') + expect(response[:msg]).to eq('dsData object with key data is not allowed') + end - d = Domain.first - ds = d.dnskeys.first - expect(ds.ds_key_tag).to eq('12345') - expect(ds.ds_alg).to eq(3) - expect(ds.ds_digest_type).to eq(1) - expect(ds.ds_digest).to eq('49FD46E6C4B45C55D4AC') - expect(ds.flags).to eq(0) - expect(ds.protocol).to eq(3) - expect(ds.alg).to eq(5) - expect(ds.public_key).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') - end + it 'prohibits dsData' do + Setting.ds_data_allowed = false - it 'prohibits dsData with key' do - Setting.ds_data_with_key_allowed = false - - xml = domain_create_xml({}, { - _anonymus: [ - { dsData: { - keyTag: { value: '12345' }, - alg: { value: '3' }, - digestType: { value: '1' }, - digest: { value: '49FD46E6C4B45C55D4AC' }, - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } + xml = domain_create_xml({}, { + _anonymus: [ + { dsData: { + keyTag: { value: '12345' }, + alg: { value: '3' }, + digestType: { value: '1' }, + digest: { value: '49FD46E6C4B45C55D4AC' }, + keyData: { + flags: { value: '0' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } } - }] - }) + } + }] + }) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('dsData object with key data is not allowed') - end + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2306') + expect(response[:msg]).to eq('dsData object is not allowed') + end - it 'prohibits dsData' do - Setting.ds_data_allowed = false + it 'prohibits keyData' do + Setting.key_data_allowed = false - xml = domain_create_xml({}, { - _anonymus: [ - { dsData: { - keyTag: { value: '12345' }, - alg: { value: '3' }, - digestType: { value: '1' }, - digest: { value: '49FD46E6C4B45C55D4AC' }, - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } + xml = domain_create_xml({}, { + _anonymus: [ + keyData: { + flags: { value: '0' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } + }] + }) + + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2306') + expect(response[:msg]).to eq('keyData object is not allowed') + end + end + + context 'with juridical persion as an owner' do + it 'creates a domain with contacts' do + xml = domain_create_xml({ + registrant: { value: 'juridical_1234' }, + _anonymus: [ + { contact: { value: 'sh8013', attrs: { type: 'admin' } } } + ] + }) + + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + expect(response[:clTRID]).to eq('ABC-12345') + + expect(Domain.last.tech_contacts.count).to eq 1 + expect(Domain.last.admin_contacts.count).to eq 1 + + tech_contact = Domain.last.tech_contacts.first + expect(tech_contact.code).to eq('juridical_1234') + end + + it 'does not create a domain without admin contact' do + domain_count = Domain.count + domain_contact_count = DomainContact.count + xml = domain_create_xml({ + registrant: { value: 'juridical_1234' }, + _anonymus: [ + { contact: { value: 'sh8013', attrs: { type: 'tech' } } } + ] + }) + + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2004') + expect(response[:msg]).to eq('Admin contacts count must be between 1-10') + expect(response[:clTRID]).to eq('ABC-12345') + + expect(Domain.count).to eq domain_count + expect(DomainContact.count).to eq domain_contact_count + end + + it 'cannot assign juridical person as admin contact' do + xml = domain_create_xml({ + registrant: { value: 'juridical_1234' }, + _anonymus: [ + { contact: { value: 'juridical_1234', attrs: { type: 'admin' } } } + ] + }) + + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2306') + expect(response[:msg]).to eq('Admin contact can be only citizen') + end + end + + context 'with valid domain' do + before(:each) { Fabricate(:domain, name: next_domain_name, registrar: @zone, dnskeys: []) } + let(:domain) { Domain.last } + + ### TRANSFER ### + it 'transfers a domain' do + domain.registrar = @zone + domain.save + + pw = domain.auth_info + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: pw } } + }) + response = epp_request(xml, :xml, :elkdata) + + domain.reload + dtl = domain.domain_transfers.last + + trn_data = response[:parsed].css('trnData') + expect(trn_data.css('name').text).to eq(domain.name) + expect(trn_data.css('trStatus').text).to eq('serverApproved') + expect(trn_data.css('reID').text).to eq('123') + expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) + expect(trn_data.css('acID').text).to eq('12345678') + expect(trn_data.css('acDate').text).to eq(dtl.transferred_at.to_time.utc.to_s) + expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + + expect(domain.registrar).to eq(@elkdata) + + Setting.transfer_wait_time = 1 + + domain.reload + pw = domain.auth_info + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: pw } } + }) # request with new password + + response = epp_request(xml, :xml, :zone) + trn_data = response[:parsed].css('trnData') + + domain.reload + dtl = domain.domain_transfers.last + + expect(domain.domain_transfers.count).to eq(2) + + expect(trn_data.css('name').text).to eq(domain.name) + expect(trn_data.css('trStatus').text).to eq('pending') + expect(trn_data.css('reID').text).to eq('12345678') + expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) + expect(trn_data.css('acDate').text).to eq(dtl.wait_until.to_time.utc.to_s) + expect(trn_data.css('acID').text).to eq('123') + expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + + expect(domain.registrar).to eq(@elkdata) + + # should return same data if pending already + response = epp_request(xml, :xml, :zone) + trn_data = response[:parsed].css('trnData') + + expect(domain.domain_transfers.count).to eq(2) + expect(trn_data.css('name').text).to eq(domain.name) + expect(trn_data.css('trStatus').text).to eq('pending') + expect(trn_data.css('reID').text).to eq('12345678') + expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) + expect(trn_data.css('acDate').text).to eq(dtl.wait_until.to_time.utc.to_s) + expect(trn_data.css('acID').text).to eq('123') + expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + + expect(domain.registrar).to eq(@elkdata) + + # should show up in other registrar's poll + + response = epp_request(epp_xml.session.poll, :xml, :elkdata) + expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') + msg_q = response[:parsed].css('msgQ') + expect(msg_q.css('qDate').text).to_not be_blank + expect(msg_q.css('msg').text).to eq('Transfer requested.') + expect(msg_q.first['id']).to_not be_blank + expect(msg_q.first['count']).to eq('1') + + xml = epp_xml.session.poll(poll: { + value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } + }) + + response = epp_request(xml, :xml, :elkdata) + expect(response[:msg]).to eq('Command completed successfully') + msg_q = response[:parsed].css('msgQ') + expect(msg_q.first['id']).to_not be_blank + expect(msg_q.first['count']).to eq('0') + end + + it 'creates a domain transfer with legal document' do + Setting.transfer_wait_time = 1 + expect(domain.legal_documents.count).to eq(0) + pw = domain.auth_info + xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }, 'query', { + _anonymus: [ + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'pdf' } + } + ] + }) + + response = epp_request(xml, :xml, :elkdata) + expect(response[:result_code]).to eq('1000') + expect(domain.legal_documents.count).to eq(1) + + log = ApiLog::EppLog.all + + expect(log.length).to eq(4) + expect(log[0].request_command).to eq('hello') + expect(log[0].request_successful).to eq(true) + + expect(log[1].request_command).to eq('login') + expect(log[1].request_successful).to eq(true) + expect(log[1].api_user_name).to eq('elkdata') + expect(log[1].api_user_registrar).to eq('Elkdata') + + expect(log[2].request_command).to eq('transfer') + expect(log[2].request_object).to eq('domain') + expect(log[2].request_successful).to eq(true) + expect(log[2].api_user_name).to eq('elkdata') + expect(log[2].api_user_registrar).to eq('Elkdata') + expect(log[2].request).not_to be_blank + expect(log[2].response).not_to be_blank + + expect(log[3].request_command).to eq('logout') + expect(log[3].request_successful).to eq(true) + expect(log[3].api_user_name).to eq('elkdata') + expect(log[3].api_user_registrar).to eq('Elkdata') + + response = epp_request(xml, :xml, :elkdata) + expect(response[:result_code]).to eq('1000') + expect(domain.legal_documents.count).to eq(1) # does not add another legal document + end + + it 'approves the transfer request' do + domain.domain_transfers.create({ + status: DomainTransfer::PENDING, + transfer_requested_at: Time.zone.now, + transfer_to: @elkdata, + transfer_from: @zone + }) + + xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve') + response = epp_request(xml, :xml, :zone) + domain.reload + dtl = domain.domain_transfers.last + + trn_data = response[:parsed].css('trnData') + + expect(trn_data.css('name').text).to eq('example.ee') + expect(trn_data.css('trStatus').text).to eq('clientApproved') + expect(trn_data.css('reID').text).to eq('123') + expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) + expect(trn_data.css('acID').text).to eq('12345678') + expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + end + + it 'rejects a domain transfer' do + domain.domain_transfers.create({ + status: DomainTransfer::PENDING, + transfer_requested_at: Time.zone.now, + transfer_to: @elkdata, + transfer_from: @zone + }) + + pw = domain.auth_info + xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }, 'reject', { + _anonymus: [ + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'pdf' } + } + ] + }) + + response = epp_request(xml, :xml, :elkdata) + expect(response[:result_code]).to eq('2304') + expect(response[:msg]).to eq('Transfer can be rejected only by current registrar') + expect(domain.legal_documents.count).to eq(0) + + response = epp_request(xml, :xml, :zone) + expect(response[:result_code]).to eq('1000') + expect(domain.pending_transfer).to be_nil + expect(domain.legal_documents.count).to eq(1) + end + + it 'prohibits wrong registrar from approving transfer' do + domain.domain_transfers.create({ + status: DomainTransfer::PENDING, + transfer_requested_at: Time.zone.now, + transfer_to: @elkdata, + transfer_from: @zone + }) + + xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve') + response = epp_request(xml, :xml, :elkdata) + expect(response[:result_code]).to eq('2304') + expect(response[:msg]).to eq('Transfer can be approved only by current domain registrar') + end + + it 'does not transfer with invalid pw' do + xml = domain_transfer_xml({ authInfo: { pw: { value: 'test' } } }) + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('2201') + expect(response[:msg]).to eq('Authorization error') + end + + it 'ignores transfer when owner registrar requests transfer' do + pw = domain.auth_info + xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }) + response = epp_request(xml, :xml, :zone) + + expect(response[:result_code]).to eq('2002') + expect(response[:msg]).to eq('Domain already belongs to the querying registrar') + end + + it 'returns an error for incorrect op attribute' do + response = epp_request(domain_transfer_xml({}, 'bla'), :xml, :zone) + expect(response[:result_code]).to eq('2306') + expect(response[:msg]).to eq('Attribute op is invalid') + end + + it 'creates new pw after successful transfer' do + pw = domain.auth_info + xml = domain_transfer_xml(pw: pw) + epp_request(xml, :xml, :elkdata) # transfer domain + response = epp_request(xml, :xml, :elkdata) # attempt second transfer + expect(response[:result_code]).to eq('2201') + expect(response[:msg]).to eq('Authorization error') + end + + ### UPDATE ### + it 'updates a domain' do + Fabricate(:contact, code: 'mak21') + existing_pw = Domain.first.auth_info + + xml_params = { + chg: [ + registrant: { value: 'mak21' } + ] + } + + response = epp_request(domain_update_xml(xml_params, {}, { + _anonymus: [ + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'pdf' } + } + ] + }), :xml) + + expect(response[:results][0][:result_code]).to eq('1000') + + d = Domain.last + + expect(d.owner_contact_code).to eq('mak21') + expect(d.auth_info).to eq(existing_pw) + end + + it 'updates domain and adds objects' do + xml = domain_update_xml({ + add: [ + { + ns: [ + { + hostAttr: [ + { hostName: { value: 'ns1.example.com' } } + ] + }, + { + hostAttr: [ + { hostName: { value: 'ns2.example.com' } } + ] } - }] - }) - - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('dsData object is not allowed') - end - - it 'prohibits keyData' do - Setting.key_data_allowed = false - - xml = domain_create_xml({}, { + ] + }, _anonymus: [ - keyData: { + { contact: { value: 'mak21', attrs: { type: 'tech' } } }, + { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, + { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } + ] + ] + }, { + add: [ + { keyData: { flags: { value: '0' }, protocol: { value: '3' }, alg: { value: '5' }, pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - }] - }) + } + }, + { + keyData: { + flags: { value: '256' }, + protocol: { value: '3' }, + alg: { value: '254' }, + pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } + } + } + ] + }) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('keyData object is not allowed') - end + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:msg]).to eq('Contact was not found') + + Fabricate(:contact, code: 'mak21') + + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('1000') + + d = Domain.first + + new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count + expect(new_ns_count).to eq(2) + + new_contact = d.tech_contacts.find_by(code: 'mak21') + expect(new_contact).to be_truthy + + expect(d.domain_statuses.count).to eq(2) + expect(d.domain_statuses.first.description).to eq('Payment overdue.') + expect(d.domain_statuses.first.value).to eq('clientHold') + + expect(d.domain_statuses.last.value).to eq('clientUpdateProhibited') + expect(d.dnskeys.count).to eq(2) + + response = epp_request(xml, :xml) + + expect(response[:results][0][:result_code]).to eq('2302') + expect(response[:results][0][:msg]).to eq('Nameserver already exists on this domain') + expect(response[:results][0][:value]).to eq('ns1.example.com') + + expect(response[:results][1][:result_code]).to eq('2302') + expect(response[:results][1][:msg]).to eq('Nameserver already exists on this domain') + expect(response[:results][1][:value]).to eq('ns2.example.com') + + expect(response[:results][2][:result_code]).to eq('2302') + expect(response[:results][2][:msg]).to eq('Contact already exists on this domain') + expect(response[:results][2][:value]).to eq('mak21') + + expect(response[:results][3][:msg]).to eq('Status already exists on this domain') + expect(response[:results][3][:value]).to eq('clientHold') + + expect(response[:results][4][:msg]).to eq('Status already exists on this domain') + expect(response[:results][4][:value]).to eq('clientUpdateProhibited') + + expect(response[:results][5][:msg]).to eq('Public key already exists') + expect(response[:results][5][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') + + expect(response[:results][6][:msg]).to eq('Public key already exists') + expect(response[:results][6][:value]).to eq('841936717ae427ace63c28d04918569a841936717ae427ace63c28d0') + + expect(d.domain_statuses.count).to eq(2) end - context 'with juridical persion as an owner' do - before(:each) do - Fabricate(:contact, code: 'jd1234', ident_type: 'ico') - Fabricate(:contact, code: 'sh8013') - Fabricate(:contact, code: 'sh801333') - end + it 'updates a domain and removes objects' do + Fabricate(:contact, code: 'mak21') - it 'creates a domain with contacts' do - xml = domain_create_xml({ - _anonymus: [ - { contact: { value: 'sh8013', attrs: { type: 'admin' } } } - ] - }) - - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(response[:clTRID]).to eq('ABC-12345') - - expect(Domain.first.tech_contacts.count).to eq 1 - expect(Domain.first.admin_contacts.count).to eq 1 - - tech_contact = Domain.first.tech_contacts.first - expect(tech_contact.code).to eq('jd1234') - end - - it 'does not create a domain without admin contact' do - xml = domain_create_xml({ - _anonymus: [ - { contact: { value: 'sh8013', attrs: { type: 'tech' } } } - ] - }) - - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2004') - expect(response[:msg]).to eq('Admin contacts count must be between 1-10') - expect(response[:clTRID]).to eq('ABC-12345') - - expect(Domain.count).to eq 0 - expect(DomainContact.count).to eq 0 - end - - it 'cannot assign juridical person as admin contact' do - xml = domain_create_xml({ - _anonymus: [ - { contact: { value: 'jd1234', attrs: { type: 'admin' } } } - ] - }) - - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('Admin contact can be only citizen') - end - end - - context 'with valid domain' do - before(:each) { Fabricate(:domain, name: 'example.ee', registrar: zone, dnskeys: []) } - let(:domain) { Domain.first } - - ### TRANSFER ### - it 'transfers a domain' do - pw = domain.auth_info - xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }) - response = epp_request(xml, :xml, :elkdata) - - domain.reload - dtl = domain.domain_transfers.last - - trn_data = response[:parsed].css('trnData') - expect(trn_data.css('name').text).to eq('example.ee') - expect(trn_data.css('trStatus').text).to eq('serverApproved') - expect(trn_data.css('reID').text).to eq('123') - expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) - expect(trn_data.css('acID').text).to eq('12345678') - expect(trn_data.css('acDate').text).to eq(dtl.transferred_at.to_time.utc.to_s) - expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) - - expect(domain.registrar).to eq(elkdata) - - Setting.transfer_wait_time = 1 - - domain.reload - pw = domain.auth_info - xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }) # request with new password - - response = epp_request(xml, :xml, :zone) - trn_data = response[:parsed].css('trnData') - - domain.reload - dtl = domain.domain_transfers.last - - expect(domain.domain_transfers.count).to eq(2) - - expect(trn_data.css('name').text).to eq('example.ee') - expect(trn_data.css('trStatus').text).to eq('pending') - expect(trn_data.css('reID').text).to eq('12345678') - expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) - expect(trn_data.css('acDate').text).to eq(dtl.wait_until.to_time.utc.to_s) - expect(trn_data.css('acID').text).to eq('123') - expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) - - expect(domain.registrar).to eq(elkdata) - - # should return same data if pending already - response = epp_request(xml, :xml, :zone) - trn_data = response[:parsed].css('trnData') - - expect(domain.domain_transfers.count).to eq(2) - expect(trn_data.css('name').text).to eq('example.ee') - expect(trn_data.css('trStatus').text).to eq('pending') - expect(trn_data.css('reID').text).to eq('12345678') - expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) - expect(trn_data.css('acDate').text).to eq(dtl.wait_until.to_time.utc.to_s) - expect(trn_data.css('acID').text).to eq('123') - expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) - - expect(domain.registrar).to eq(elkdata) - - # should show up in other registrar's poll - - response = epp_request(epp_xml.session.poll, :xml, :elkdata) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - msg_q = response[:parsed].css('msgQ') - expect(msg_q.css('qDate').text).to_not be_blank - expect(msg_q.css('msg').text).to eq('Transfer requested.') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('1') - - xml = epp_xml.session.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) - - response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Command completed successfully') - msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('0') - end - - it 'creates a domain transfer with legal document' do - Setting.transfer_wait_time = 1 - expect(domain.legal_documents.count).to eq(0) - pw = domain.auth_info - xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }, 'query', { - _anonymus: [ - legalDocument: { - value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('1000') - expect(domain.legal_documents.count).to eq(1) - - log = ApiLog::EppLog.all - - expect(log.length).to eq(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) - - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('elkdata') - expect(log[1].api_user_registrar).to eq('Elkdata') - - expect(log[2].request_command).to eq('transfer') - expect(log[2].request_object).to eq('domain') - expect(log[2].request_successful).to eq(true) - expect(log[2].api_user_name).to eq('elkdata') - expect(log[2].api_user_registrar).to eq('Elkdata') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank - - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('elkdata') - expect(log[3].api_user_registrar).to eq('Elkdata') - - response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('1000') - expect(domain.legal_documents.count).to eq(1) # does not add another legal document - end - - it 'approves the transfer request' do - domain.domain_transfers.create({ - status: DomainTransfer::PENDING, - transfer_requested_at: Time.zone.now, - transfer_to: elkdata, - transfer_from: zone - }) - - xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve') - response = epp_request(xml, :xml, :zone) - domain.reload - dtl = domain.domain_transfers.last - - trn_data = response[:parsed].css('trnData') - - expect(trn_data.css('name').text).to eq('example.ee') - expect(trn_data.css('trStatus').text).to eq('clientApproved') - expect(trn_data.css('reID').text).to eq('123') - expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) - expect(trn_data.css('acID').text).to eq('12345678') - expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) - end - - it 'rejects a domain transfer' do - domain.domain_transfers.create({ - status: DomainTransfer::PENDING, - transfer_requested_at: Time.zone.now, - transfer_to: elkdata, - transfer_from: zone - }) - - pw = domain.auth_info - xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }, 'reject', { - _anonymus: [ - legalDocument: { - value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('2304') - expect(response[:msg]).to eq('Transfer can be rejected only by current registrar') - expect(domain.legal_documents.count).to eq(0) - - response = epp_request(xml, :xml, :zone) - expect(response[:result_code]).to eq('1000') - expect(domain.pending_transfer).to be_nil - expect(domain.legal_documents.count).to eq(1) - end - - it 'prohibits wrong registrar from approving transfer' do - domain.domain_transfers.create({ - status: DomainTransfer::PENDING, - transfer_requested_at: Time.zone.now, - transfer_to: elkdata, - transfer_from: zone - }) - - xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve') - response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('2304') - expect(response[:msg]).to eq('Transfer can be approved only by current domain registrar') - end - - it 'does not transfer with invalid pw' do - xml = domain_transfer_xml({ authInfo: { pw: { value: 'test' } } }) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2201') - expect(response[:msg]).to eq('Authorization error') - end - - it 'ignores transfer when owner registrar requests transfer' do - pw = domain.auth_info - xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }) - response = epp_request(xml, :xml, :zone) - - expect(response[:result_code]).to eq('2002') - expect(response[:msg]).to eq('Domain already belongs to the querying registrar') - end - - it 'returns an error for incorrect op attribute' do - response = epp_request(domain_transfer_xml({}, 'bla'), :xml, :zone) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('Attribute op is invalid') - end - - it 'creates new pw after successful transfer' do - pw = domain.auth_info - xml = domain_transfer_xml(pw: pw) - epp_request(xml, :xml, :elkdata) # transfer domain - response = epp_request(xml, :xml, :elkdata) # attempt second transfer - expect(response[:result_code]).to eq('2201') - expect(response[:msg]).to eq('Authorization error') - end - - ### UPDATE ### - it 'updates a domain' do - Fabricate(:contact, code: 'mak21') - existing_pw = Domain.first.auth_info - - xml_params = { - chg: [ - registrant: { value: 'mak21' } - ] - } - - response = epp_request(domain_update_xml(xml_params, {}, { - _anonymus: [ - legalDocument: { - value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', - attrs: { type: 'pdf' } - } - ] - }), :xml) - - expect(response[:results][0][:result_code]).to eq('1000') - - d = Domain.last - - expect(d.owner_contact_code).to eq('mak21') - expect(d.auth_info).to eq(existing_pw) - end - - it 'updates domain and adds objects' do - xml = domain_update_xml({ - add: [ - { - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.com' } } - ] - }, - { - hostAttr: [ - { hostName: { value: 'ns2.example.com' } } - ] - } - ] - }, - _anonymus: [ - { contact: { value: 'mak21', attrs: { type: 'tech' } } }, - { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, - { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } - ] - ] - }, { - add: [ - { keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '254' }, - pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } - } - } - ] - }) - - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Contact was not found') - - Fabricate(:contact, code: 'mak21') - - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('1000') - - d = Domain.first - - new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count - expect(new_ns_count).to eq(2) - - new_contact = d.tech_contacts.find_by(code: 'mak21') - expect(new_contact).to be_truthy - - expect(d.domain_statuses.count).to eq(2) - expect(d.domain_statuses.first.description).to eq('Payment overdue.') - expect(d.domain_statuses.first.value).to eq('clientHold') - - expect(d.domain_statuses.last.value).to eq('clientUpdateProhibited') - expect(d.dnskeys.count).to eq(2) - - response = epp_request(xml, :xml) - - expect(response[:results][0][:result_code]).to eq('2302') - expect(response[:results][0][:msg]).to eq('Nameserver already exists on this domain') - expect(response[:results][0][:value]).to eq('ns1.example.com') - - expect(response[:results][1][:result_code]).to eq('2302') - expect(response[:results][1][:msg]).to eq('Nameserver already exists on this domain') - expect(response[:results][1][:value]).to eq('ns2.example.com') - - expect(response[:results][2][:result_code]).to eq('2302') - expect(response[:results][2][:msg]).to eq('Contact already exists on this domain') - expect(response[:results][2][:value]).to eq('mak21') - - expect(response[:results][3][:msg]).to eq('Status already exists on this domain') - expect(response[:results][3][:value]).to eq('clientHold') - - expect(response[:results][4][:msg]).to eq('Status already exists on this domain') - expect(response[:results][4][:value]).to eq('clientUpdateProhibited') - - expect(response[:results][5][:msg]).to eq('Public key already exists') - expect(response[:results][5][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') - - expect(response[:results][6][:msg]).to eq('Public key already exists') - expect(response[:results][6][:value]).to eq('841936717ae427ace63c28d04918569a841936717ae427ace63c28d0') - - expect(d.domain_statuses.count).to eq(2) - end - - it 'updates a domain and removes objects' do - Fabricate(:contact, code: 'mak21') - - xml = domain_update_xml({ - add: [ - { - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.com' } } - ] - }, - { - hostAttr: [ - { hostName: { value: 'ns2.example.com' } } - ] - } - ] - }, - _anonymus: [ - { contact: { value: 'mak21', attrs: { type: 'tech' } } }, - { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, - { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } - ] - ] - }, { - add: [ - { keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '254' }, - pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } - } - } - ] - }) - - epp_request(xml, :xml) - d = Domain.last - expect(d.dnskeys.count).to eq(2) - - xml = domain_update_xml({ - rem: [ - { - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.com' } } - ] - } - ] - }, - _anonymus: [ - { contact: { value: 'mak21', attrs: { type: 'tech' } } }, - { status: { value: '', attrs: { s: 'clientHold' } } } - ] - ] - }, { - rem: [ - { keyData: { - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - } - ] - }) - - epp_request(xml, :xml) - - expect(d.dnskeys.count).to eq(1) - - expect(d.domain_statuses.count).to eq(1) - expect(d.domain_statuses.first.value).to eq('clientUpdateProhibited') - - rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com') - expect(rem_ns).to be_falsey - - rem_cnt = d.tech_contacts.find_by(code: 'mak21') - expect(rem_cnt).to be_falsey - - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Contact was not found') - expect(response[:results][0][:value]).to eq('mak21') - - expect(response[:results][1][:result_code]).to eq('2303') - expect(response[:results][1][:msg]).to eq('Nameserver was not found') - expect(response[:results][1][:value]).to eq('ns1.example.com') - - expect(response[:results][2][:result_code]).to eq('2303') - expect(response[:results][2][:msg]).to eq('Status was not found') - expect(response[:results][2][:value]).to eq('clientHold') - end - - it 'does not remove server statuses' do - d = Domain.last - d.domain_statuses.create(value: DomainStatus::SERVER_HOLD) - - xml = domain_update_xml({ - rem: [ - _anonymus: [ - { status: { value: '', attrs: { s: 'serverHold' } } } - ] - ] - }) - - response = epp_request(xml, :xml) - - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Status was not found') - expect(response[:results][0][:value]).to eq('serverHold') - end - - it 'does not add duplicate objects to domain' do - d = Domain.first - c = d.admin_contacts.first - n = d.nameservers.first - - xml = domain_update_xml({ - add: { + xml = domain_update_xml({ + add: [ + { ns: [ { hostAttr: [ - { hostName: { value: n.hostname } } + { hostName: { value: 'ns1.example.com' } } + ] + }, + { + hostAttr: [ + { hostName: { value: 'ns2.example.com' } } ] } - ], - _anonymus: [ - { contact: { value: c.code, attrs: { type: 'admin' } } } ] + }, + _anonymus: [ + { contact: { value: 'mak21', attrs: { type: 'tech' } } }, + { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, + { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } + ] + ] + }, { + add: [ + { keyData: { + flags: { value: '0' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } + } + }, + { + keyData: { + flags: { value: '256' }, + protocol: { value: '3' }, + alg: { value: '254' }, + pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } + } } - }) + ] + }) - epp_request(xml, :xml) - response = epp_request(xml, :xml) + epp_request(xml, :xml) + d = Domain.last + expect(d.dnskeys.count).to eq(2) - expect(response[:results][0][:result_code]).to eq('2302') - expect(response[:results][0][:msg]).to eq('Nameserver already exists on this domain') - expect(response[:results][0][:value]).to eq(n.hostname) + xml = domain_update_xml({ + rem: [ + { + ns: [ + { + hostAttr: [ + { hostName: { value: 'ns1.example.com' } } + ] + } + ] + }, + _anonymus: [ + { contact: { value: 'mak21', attrs: { type: 'tech' } } }, + { status: { value: '', attrs: { s: 'clientHold' } } } + ] + ] + }, { + rem: [ + { keyData: { + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } + } + } + ] + }) - expect(response[:results][1][:result_code]).to eq('2302') - expect(response[:results][1][:msg]).to eq('Contact already exists on this domain') - expect(response[:results][1][:value]).to eq(c.code) - end + epp_request(xml, :xml) - it 'cannot change registrant without legal document' do - Fabricate(:contact, code: 'mak21') + expect(d.dnskeys.count).to eq(1) - xml_params = { - chg: [ - registrant: { value: 'mak21' } + expect(d.domain_statuses.count).to eq(1) + expect(d.domain_statuses.first.value).to eq('clientUpdateProhibited') + + rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com') + expect(rem_ns).to be_falsey + + rem_cnt = d.tech_contacts.find_by(code: 'mak21') + expect(rem_cnt).to be_falsey + + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:msg]).to eq('Contact was not found') + expect(response[:results][0][:value]).to eq('mak21') + + expect(response[:results][1][:result_code]).to eq('2303') + expect(response[:results][1][:msg]).to eq('Nameserver was not found') + expect(response[:results][1][:value]).to eq('ns1.example.com') + + expect(response[:results][2][:result_code]).to eq('2303') + expect(response[:results][2][:msg]).to eq('Status was not found') + expect(response[:results][2][:value]).to eq('clientHold') + end + + it 'does not remove server statuses' do + d = Domain.last + d.domain_statuses.create(value: DomainStatus::SERVER_HOLD) + + xml = domain_update_xml({ + rem: [ + _anonymus: [ + { status: { value: '', attrs: { s: 'serverHold' } } } + ] + ] + }) + + response = epp_request(xml, :xml) + + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:msg]).to eq('Status was not found') + expect(response[:results][0][:value]).to eq('serverHold') + end + + it 'does not add duplicate objects to domain' do + d = Domain.first + c = d.admin_contacts.first + n = d.nameservers.first + + xml = domain_update_xml({ + add: { + ns: [ + { + hostAttr: [ + { hostName: { value: n.hostname } } + ] + } + ], + _anonymus: [ + { contact: { value: c.code, attrs: { type: 'admin' } } } ] } + }) - response = epp_request(domain_update_xml(xml_params), :xml) - expect(response[:results][0][:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') - expect(response[:results][0][:result_code]).to eq('2003') - end + epp_request(xml, :xml) + response = epp_request(xml, :xml) - it 'does not assign invalid status to domain' do - xml = domain_update_xml({ - add: [ - status: { value: '', attrs: { s: 'invalidStatus' } } - ] - }) + expect(response[:results][0][:result_code]).to eq('2302') + expect(response[:results][0][:msg]).to eq('Nameserver already exists on this domain') + expect(response[:results][0][:value]).to eq(n.hostname) - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Status was not found') - expect(response[:results][0][:value]).to eq('invalidStatus') - end - - ### RENEW ### - it 'renews a domain' do - exp_date = (Date.today + 1.year) - xml = epp_xml.domain.renew( - name: { value: 'example.ee' }, - curExpDate: { value: exp_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_request(xml, :xml) - ex_date = response[:parsed].css('renData exDate').text - name = response[:parsed].css('renData name').text - expect(ex_date).to eq("#{(exp_date + 1.year)} 00:00:00 UTC") - expect(name).to eq('example.ee') - end - - it 'returns an error when given and current exp dates do not match' do - xml = epp_xml.domain.renew( - name: { value: 'example.ee' }, - curExpDate: { value: '2016-08-07' }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2306') - expect(response[:results][0][:msg]).to eq('Given and current expire dates do not match') - end - - it 'returns an error when period is invalid' do - exp_date = (Date.today + 1.year) - - xml = epp_xml.domain.renew( - name: { value: 'example.ee' }, - curExpDate: { value: exp_date.to_s }, - period: { value: '4', attrs: { unit: 'y' } } - ) - - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2004') - expect(response[:results][0][:msg]).to eq('Period must add up to 1, 2 or 3 years') - expect(response[:results][0][:value]).to eq('4') - end - - ### INFO ### - it 'returns domain info' do - d = Domain.first - d.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.') - d.nameservers.build(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') - - d.dnskeys.build( - ds_key_tag: '123', - ds_alg: 3, - ds_digest_type: 1, - ds_digest: 'abc', - flags: 257, - protocol: 3, - alg: 3, - public_key: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' - ) - - d.dnskeys.build( - ds_key_tag: '123', - ds_alg: 3, - ds_digest_type: 1, - ds_digest: 'abc', - flags: 0, - protocol: 3, - alg: 5, - public_key: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - ) - - d.save - - xml = domain_info_xml(name: { value: 'Example.ee' }) - - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('1000') - expect(response[:results][0][:msg]).to eq('Command completed successfully') - - inf_data = response[:parsed].css('resData infData') - expect(inf_data.css('name').text).to eq('example.ee') - expect(inf_data.css('status').text).to eq('Payment overdue.') - expect(inf_data.css('status').first[:s]).to eq('clientHold') - expect(inf_data.css('registrant').text).to eq(d.owner_contact_code) - - admin_contacts_from_request = inf_data.css('contact[type="admin"]').map(&:text) - admin_contacts_existing = d.admin_contacts.pluck(:code) - - expect(admin_contacts_from_request).to eq(admin_contacts_existing) - - hosts_from_request = inf_data.css('hostName').map(&:text) - hosts_existing = d.nameservers.pluck(:hostname) - - expect(hosts_from_request).to eq(hosts_existing) - - ns1 = inf_data.css('hostAttr').last - - expect(ns1.css('hostName').last.text).to eq('ns1.example.com') - expect(ns1.css('hostAddr').first.text).to eq('192.168.1.1') - expect(ns1.css('hostAddr').last.text).to eq('1080:0:0:0:8:800:200C:417A') - expect(inf_data.css('crDate').text).to eq(d.created_at.to_time.utc.to_s) - expect(inf_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) - expect(inf_data.css('pw').text).to eq(d.auth_info) - - ds_data_1 = response[:parsed].css('dsData')[0] - - expect(ds_data_1.css('keyTag').first.text).to eq('123') - expect(ds_data_1.css('alg').first.text).to eq('3') - expect(ds_data_1.css('digestType').first.text).to eq('1') - expect(ds_data_1.css('digest').first.text).to eq('abc') - - dnskey_1 = ds_data_1.css('keyData')[0] - expect(dnskey_1.css('flags').first.text).to eq('257') - expect(dnskey_1.css('protocol').first.text).to eq('3') - expect(dnskey_1.css('alg').first.text).to eq('3') - expect(dnskey_1.css('pubKey').first.text).to eq('AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8') - - ds_data_2 = response[:parsed].css('dsData')[1] - - dnskey_2 = ds_data_2.css('keyData')[0] - expect(dnskey_2.css('flags').first.text).to eq('0') - expect(dnskey_2.css('protocol').first.text).to eq('3') - expect(dnskey_2.css('alg').first.text).to eq('5') - expect(dnskey_2.css('pubKey').first.text).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') - - d.touch - - response = epp_request(domain_info_xml, :xml) - inf_data = response[:parsed].css('resData infData') - - expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s) - end - - it 'returns error when domain can not be found' do - response = epp_request(domain_info_xml(name: { value: 'test.ee' }), :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Domain not found') - end - - it 'sets ok status by default' do - response = epp_request(domain_info_xml, :xml) - inf_data = response[:parsed].css('resData infData') - expect(inf_data.css('status').first[:s]).to eq('ok') - end - - it 'can not see other registrar domains' do - response = epp_request(domain_info_xml, :xml, :elkdata) - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Domain exists but belongs to other registrar') - end - - ### DELETE ### - it 'deletes domain' do - expect(DomainContact.count).to eq(2) - - response = epp_request(epp_xml.domain.delete({ - name: { value: 'example.ee' } - }, { - _anonymus: [ - legalDocument: { - value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', - attrs: { type: 'pdf' } - } - ] - }), :xml) - - expect(response[:result_code]).to eq('1000') - - expect(Domain.first).to eq(nil) - expect(DomainContact.count).to eq(0) - end - - it 'does not delete domain with specific status' do - d = Domain.first - d.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED) - - response = epp_request(epp_xml.domain.delete({ - name: { value: 'example.ee' } - }, { - _anonymus: [ - legalDocument: { - value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', - attrs: { type: 'pdf' } - } - ] - }), :xml) - - expect(response[:result_code]).to eq('2304') - expect(response[:msg]).to eq('Domain status prohibits operation') - end - - it 'does not delete domain without legal document' do - response = epp_request(epp_xml.domain.delete(name: { value: 'example.ee' }), :xml) - expect(response[:result_code]).to eq('2003') - expect(response[:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') - end + expect(response[:results][1][:result_code]).to eq('2302') + expect(response[:results][1][:msg]).to eq('Contact already exists on this domain') + expect(response[:results][1][:value]).to eq(c.code) end - ### CHECK ### - it 'checks a domain' do - response = epp_request(domain_check_xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + it 'cannot change registrant without legal document' do + Fabricate(:contact, code: 'mak21') - domain = response[:parsed].css('resData chkData cd name').first - expect(domain.text).to eq('example.ee') - expect(domain[:avail]).to eq('1') + xml_params = { + chg: [ + registrant: { value: 'mak21' } + ] + } - Fabricate(:domain, name: 'example.ee', registrar: zone) - - response = epp_request(domain_check_xml, :xml) - domain = response[:parsed].css('resData chkData cd').first - name = domain.css('name').first - reason = domain.css('reason').first - - expect(name.text).to eq('example.ee') - expect(name[:avail]).to eq('0') - expect(reason.text).to eq('in use') + response = epp_request(domain_update_xml(xml_params), :xml) + expect(response[:results][0][:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') + expect(response[:results][0][:result_code]).to eq('2003') end - it 'checks multiple domains' do - xml = domain_check_xml({ - _anonymus: [ - { name: { value: 'one.ee' } }, - { name: { value: 'two.ee' } }, - { name: { value: 'three.ee' } } + it 'does not assign invalid status to domain' do + xml = domain_update_xml({ + add: [ + status: { value: '', attrs: { s: 'invalidStatus' } } ] }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - - domain = response[:parsed].css('resData chkData cd name').first - expect(domain.text).to eq('one.ee') - expect(domain[:avail]).to eq('1') - - domain = response[:parsed].css('resData chkData cd name').last - expect(domain.text).to eq('three.ee') - expect(domain[:avail]).to eq('1') + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:msg]).to eq('Status was not found') + expect(response[:results][0][:value]).to eq('invalidStatus') end - it 'checks invalid format domain' do - xml = domain_check_xml({ - _anonymus: [ - { name: { value: 'one.ee' } }, - { name: { value: 'notcorrectdomain' } } - ] - }) + ### RENEW ### + it 'renews a domain' do + exp_date = (Date.today + 1.year) + xml = epp_xml.domain.renew( + name: { value: 'example.ee' }, + curExpDate: { value: exp_date.to_s }, + period: { value: '1', attrs: { unit: 'y' } } + ) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - - domain = response[:parsed].css('resData chkData cd name').first - expect(domain.text).to eq('one.ee') - expect(domain[:avail]).to eq('1') - - domain = response[:parsed].css('resData chkData cd').last - name = domain.css('name').first - reason = domain.css('reason').first - - expect(name.text).to eq('notcorrectdomain') - expect(name[:avail]).to eq('0') - expect(reason.text).to eq('invalid format') + ex_date = response[:parsed].css('renData exDate').text + name = response[:parsed].css('renData name').text + expect(ex_date).to eq("#{(exp_date + 1.year)} 00:00:00 UTC") + expect(name).to eq('example.ee') end + it 'returns an error when given and current exp dates do not match' do + xml = epp_xml.domain.renew( + name: { value: 'example.ee' }, + curExpDate: { value: '2016-08-07' }, + period: { value: '1', attrs: { unit: 'y' } } + ) + + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('2306') + expect(response[:results][0][:msg]).to eq('Given and current expire dates do not match') + end + + it 'returns an error when period is invalid' do + exp_date = (Date.today + 1.year) + + xml = epp_xml.domain.renew( + name: { value: 'example.ee' }, + curExpDate: { value: exp_date.to_s }, + period: { value: '4', attrs: { unit: 'y' } } + ) + + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('2004') + expect(response[:results][0][:msg]).to eq('Period must add up to 1, 2 or 3 years') + expect(response[:results][0][:value]).to eq('4') + end + + ### INFO ### + it 'returns domain info' do + d = Domain.first + d.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.') + d.nameservers.build(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') + + d.dnskeys.build( + ds_key_tag: '123', + ds_alg: 3, + ds_digest_type: 1, + ds_digest: 'abc', + flags: 257, + protocol: 3, + alg: 3, + public_key: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' + ) + + d.dnskeys.build( + ds_key_tag: '123', + ds_alg: 3, + ds_digest_type: 1, + ds_digest: 'abc', + flags: 0, + protocol: 3, + alg: 5, + public_key: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' + ) + + d.save + + xml = domain_info_xml(name: { value: 'Example.ee' }) + + response = epp_request(xml, :xml) + expect(response[:results][0][:result_code]).to eq('1000') + expect(response[:results][0][:msg]).to eq('Command completed successfully') + + inf_data = response[:parsed].css('resData infData') + expect(inf_data.css('name').text).to eq('example.ee') + expect(inf_data.css('status').text).to eq('Payment overdue.') + expect(inf_data.css('status').first[:s]).to eq('clientHold') + expect(inf_data.css('registrant').text).to eq(d.owner_contact_code) + + admin_contacts_from_request = inf_data.css('contact[type="admin"]').map(&:text) + admin_contacts_existing = d.admin_contacts.pluck(:code) + + expect(admin_contacts_from_request).to eq(admin_contacts_existing) + + hosts_from_request = inf_data.css('hostName').map(&:text) + hosts_existing = d.nameservers.pluck(:hostname) + + expect(hosts_from_request).to eq(hosts_existing) + + ns1 = inf_data.css('hostAttr').last + + expect(ns1.css('hostName').last.text).to eq('ns1.example.com') + expect(ns1.css('hostAddr').first.text).to eq('192.168.1.1') + expect(ns1.css('hostAddr').last.text).to eq('1080:0:0:0:8:800:200C:417A') + expect(inf_data.css('crDate').text).to eq(d.created_at.to_time.utc.to_s) + expect(inf_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) + expect(inf_data.css('pw').text).to eq(d.auth_info) + + ds_data_1 = response[:parsed].css('dsData')[0] + + expect(ds_data_1.css('keyTag').first.text).to eq('123') + expect(ds_data_1.css('alg').first.text).to eq('3') + expect(ds_data_1.css('digestType').first.text).to eq('1') + expect(ds_data_1.css('digest').first.text).to eq('abc') + + dnskey_1 = ds_data_1.css('keyData')[0] + expect(dnskey_1.css('flags').first.text).to eq('257') + expect(dnskey_1.css('protocol').first.text).to eq('3') + expect(dnskey_1.css('alg').first.text).to eq('3') + expect(dnskey_1.css('pubKey').first.text).to eq('AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8') + + ds_data_2 = response[:parsed].css('dsData')[1] + + dnskey_2 = ds_data_2.css('keyData')[0] + expect(dnskey_2.css('flags').first.text).to eq('0') + expect(dnskey_2.css('protocol').first.text).to eq('3') + expect(dnskey_2.css('alg').first.text).to eq('5') + expect(dnskey_2.css('pubKey').first.text).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') + + d.touch + + response = epp_request(domain_info_xml, :xml) + inf_data = response[:parsed].css('resData infData') + + expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s) + end + + it 'returns error when domain can not be found' do + response = epp_request(domain_info_xml(name: { value: 'test.ee' }), :xml) + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:msg]).to eq('Domain not found') + end + + it 'sets ok status by default' do + response = epp_request(domain_info_xml, :xml) + inf_data = response[:parsed].css('resData infData') + expect(inf_data.css('status').first[:s]).to eq('ok') + end + + it 'can not see other registrar domains' do + response = epp_request(domain_info_xml, :xml, :elkdata) + expect(response[:result_code]).to eq('2302') + expect(response[:msg]).to eq('Domain exists but belongs to other registrar') + end + + ### DELETE ### + it 'deletes domain' do + expect(DomainContact.count).to eq(2) + + response = epp_request(epp_xml.domain.delete({ + name: { value: 'example.ee' } + }, { + _anonymus: [ + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'pdf' } + } + ] + }), :xml) + + expect(response[:result_code]).to eq('1000') + + expect(Domain.first).to eq(nil) + expect(DomainContact.count).to eq(0) + end + + it 'does not delete domain with specific status' do + d = Domain.first + d.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED) + + response = epp_request(epp_xml.domain.delete({ + name: { value: 'example.ee' } + }, { + _anonymus: [ + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'pdf' } + } + ] + }), :xml) + + expect(response[:result_code]).to eq('2304') + expect(response[:msg]).to eq('Domain status prohibits operation') + end + + it 'does not delete domain without legal document' do + response = epp_request(epp_xml.domain.delete(name: { value: 'example.ee' }), :xml) + expect(response[:result_code]).to eq('2003') + expect(response[:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') + end end + + ### CHECK ### + it 'checks a domain' do + response = epp_request(domain_check_xml({ + _anonymus: [ + { name: { value: 'one.ee' } } + ] + }), :xml) + + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + + domain = response[:parsed].css('resData chkData cd name').first + expect(domain.text).to eq('one.ee') + expect(domain[:avail]).to eq('1') + + response = epp_request(domain_check_xml({ + _anonymus: [ + { name: { value: 'example.ee' } } + ] + }), :xml) + domain = response[:parsed].css('resData chkData cd').first + name = domain.css('name').first + reason = domain.css('reason').first + + expect(name.text).to eq('example.ee') + expect(name[:avail]).to eq('0') + expect(reason.text).to eq('in use') + end + + it 'checks multiple domains' do + xml = domain_check_xml({ + _anonymus: [ + { name: { value: 'one.ee' } }, + { name: { value: 'two.ee' } }, + { name: { value: 'three.ee' } } + ] + }) + + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + + domain = response[:parsed].css('resData chkData cd name').first + expect(domain.text).to eq('one.ee') + expect(domain[:avail]).to eq('1') + + domain = response[:parsed].css('resData chkData cd name').last + expect(domain.text).to eq('three.ee') + expect(domain[:avail]).to eq('1') + end + + it 'checks invalid format domain' do + xml = domain_check_xml({ + _anonymus: [ + { name: { value: 'one.ee' } }, + { name: { value: 'notcorrectdomain' } } + ] + }) + + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + + domain = response[:parsed].css('resData chkData cd name').first + expect(domain.text).to eq('one.ee') + expect(domain[:avail]).to eq('1') + + domain = response[:parsed].css('resData chkData cd').last + name = domain.css('name').first + reason = domain.css('reason').first + + expect(name.text).to eq('notcorrectdomain') + expect(name[:avail]).to eq('0') + expect(reason.text).to eq('invalid format') + end + end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6854b17dd..2b5d2c858 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -34,8 +34,10 @@ RSpec.configure do |config| config.before(:suite) do ActiveRecord::Base.establish_connection :api_log_test DatabaseCleaner.strategy = :deletion + DatabaseCleaner.clean ActiveRecord::Base.establish_connection :test DatabaseCleaner.strategy = :truncation + DatabaseCleaner.clean end config.before(:each) do @@ -54,21 +56,21 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :truncation end - config.before(:each) do - ActiveRecord::Base.establish_connection :api_log_test - DatabaseCleaner.start + # config.before(:each) do + # ActiveRecord::Base.establish_connection :api_log_test + # DatabaseCleaner.start - ActiveRecord::Base.establish_connection :test - DatabaseCleaner.start - end + # ActiveRecord::Base.establish_connection :test + # DatabaseCleaner.start + # end - config.after(:each) do - ActiveRecord::Base.establish_connection :api_log_test - DatabaseCleaner.clean + # config.after(:each) do + # ActiveRecord::Base.establish_connection :api_log_test + # DatabaseCleaner.clean - ActiveRecord::Base.establish_connection :test - DatabaseCleaner.clean - end + # ActiveRecord::Base.establish_connection :test + # DatabaseCleaner.clean + # end Capybara.javascript_driver = :poltergeist diff --git a/spec/support/epp.rb b/spec/support/epp.rb index 52250d63c..5a3e1f29b 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -67,11 +67,15 @@ module Epp puts r[:parsed].to_s end + def next_domain_name + "example#{@uniq_no.call}.ee" + end + ### REQUEST TEMPLATES ### def domain_info_xml(xml_params = {}) defaults = { - name: { value: 'example.ee', attrs: { hosts: 'all' } }, + name: { value: next_domain_name, attrs: { hosts: 'all' } }, authInfo: { pw: { value: '2fooBAR' } } @@ -86,7 +90,7 @@ module Epp # rubocop: disable Metrics/MethodLength def domain_create_xml(xml_params = {}, dnssec_params = {}) defaults = { - name: { value: 'example.ee' }, + name: { value: next_domain_name }, period: { value: '1', attrs: { unit: 'y' } }, ns: [ { @@ -102,7 +106,7 @@ module Epp } } ], - registrant: { value: 'jd1234' }, + registrant: { value: 'citizen_1234' }, _anonymus: [ { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, @@ -138,11 +142,9 @@ module Epp epp_xml.create(xml_params, dnssec_params, custom_params) end - def domain_create_xml_with_legal_doc - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - - epp_xml.create({ - name: { value: 'example.ee' }, + def domain_create_xml_with_legal_doc(xml_params = {}) + defaults = { + name: { value: next_domain_name }, period: { value: '1', attrs: { unit: 'y' } }, ns: [ { @@ -158,13 +160,19 @@ module Epp } } ], - registrant: { value: 'jd1234' }, + registrant: { value: 'citizen_1234' }, _anonymus: [ { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, { contact: { value: 'sh801333', attrs: { type: 'tech' } } } ] - }, {}, { + } + + xml_params = defaults.deep_merge(xml_params) + + epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') + + epp_xml.create(xml_params, {}, { _anonymus: [ legalDocument: { value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', @@ -176,7 +184,7 @@ module Epp def domain_create_with_invalid_ns_ip_xml xml_params = { - name: { value: 'example.ee' }, + name: { value: next_domain_name }, period: { value: '1', attrs: { unit: 'y' } }, ns: [ { @@ -192,7 +200,7 @@ module Epp } } ], - registrant: { value: 'jd1234' }, + registrant: { value: 'citizen_1234' }, _anonymus: [ { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, @@ -220,7 +228,7 @@ module Epp def domain_create_with_host_attrs xml_params = { - name: { value: 'example.ee' }, + name: { value: next_domain_name }, period: { value: '1', attrs: { unit: 'y' } }, ns: [ { @@ -236,7 +244,7 @@ module Epp } } ], - registrant: { value: 'jd1234' }, + registrant: { value: 'citizen_1234' }, _anonymus: [ { contact: { value: 'sh8013', attrs: { type: 'admin' } } }, { contact: { value: 'sh8013', attrs: { type: 'tech' } } }, @@ -264,7 +272,7 @@ module Epp def domain_update_xml(xml_params = {}, dnssec_params = {}, custom_params = {}) defaults = { - name: { value: 'example.ee' } + name: { value: next_domain_name } } xml_params = defaults.deep_merge(xml_params) @@ -275,7 +283,7 @@ module Epp def domain_check_xml(xml_params = {}) defaults = { _anonymus: [ - { name: { value: 'example.ee' } } + { name: { value: next_domain_name } } ] } xml_params = defaults.deep_merge(xml_params) @@ -285,9 +293,9 @@ module Epp def domain_transfer_xml(xml_params = {}, op = 'query', custom_params = {}) defaults = { - name: { value: 'example.ee' }, + name: { value: next_domain_name }, authInfo: { - pw: { value: '98oiewslkfkd', attrs: { roid: 'JD1234-REP' } } + pw: { value: '98oiewslkfkd', attrs: { roid: 'citizen_1234-REP' } } } } From 4c1736a1c7939b5ac64ce0551aa430c1de6f0a5a Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 14:32:50 +0200 Subject: [PATCH 02/34] Domain spec refactor --- spec/epp/domain_spec.rb | 279 ++++++++++++++----------- spec/fabricators/contact_fabricator.rb | 4 +- 2 files changed, 154 insertions(+), 129 deletions(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 28f0828fe..7c20c8676 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -113,8 +113,9 @@ describe 'EPP Domain', epp: true do # end it 'creates a domain' do + dn = next_domain_name response = epp_request(domain_create_xml({ - name: { value: 'uniq.ee' } + name: { value: dn } }), :xml) d = Domain.last expect(response[:result_code]).to eq('1000') @@ -122,7 +123,7 @@ describe 'EPP Domain', epp: true do cre_data = response[:parsed].css('creData') - expect(cre_data.css('name').text).to eq('uniq.ee') + expect(cre_data.css('name').text).to eq(dn) expect(cre_data.css('crDate').text).to eq(d.created_at.to_time.utc.to_s) expect(cre_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) @@ -185,17 +186,18 @@ describe 'EPP Domain', epp: true do end it 'validates nameserver ipv4 when in same zone as domain' do + dn = next_domain_name xml = domain_create_xml({ - name: { value: 'uniq3.ee' }, + name: { value: dn }, ns: [ { hostAttr: [ - { hostName: { value: 'ns1.uniq3.ee' } } + { hostName: { value: "ns1.#{dn}" } } ] }, { hostAttr: { - hostName: { value: 'ns2.uniq3.ee' } + hostName: { value: "ns2.#{dn}" } } } ] @@ -207,11 +209,12 @@ describe 'EPP Domain', epp: true do end it 'does not create duplicate domain' do + dn = next_domain_name epp_request(domain_create_xml({ - name: { value: 'uniq2.ee' } + name: { value: dn } }), :xml) response = epp_request(domain_create_xml({ - name: { value: 'uniq2.ee' } + name: { value: dn } }), :xml) expect(response[:result_code]).to eq('2302') @@ -778,7 +781,10 @@ describe 'EPP Domain', epp: true do Setting.transfer_wait_time = 1 expect(domain.legal_documents.count).to eq(0) pw = domain.auth_info - xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }, 'query', { + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: pw } } + }, 'query', { _anonymus: [ legalDocument: { value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', @@ -788,12 +794,12 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml, :elkdata) + expect(response[:result_code]).to eq('1000') expect(domain.legal_documents.count).to eq(1) - log = ApiLog::EppLog.all + log = ApiLog::EppLog.last(4) - expect(log.length).to eq(4) expect(log[0].request_command).to eq('hello') expect(log[0].request_successful).to eq(true) @@ -828,14 +834,17 @@ describe 'EPP Domain', epp: true do transfer_from: @zone }) - xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve') + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: domain.auth_info } } + }, 'approve') response = epp_request(xml, :xml, :zone) domain.reload dtl = domain.domain_transfers.last trn_data = response[:parsed].css('trnData') - expect(trn_data.css('name').text).to eq('example.ee') + expect(trn_data.css('name').text).to eq(domain.name) expect(trn_data.css('trStatus').text).to eq('clientApproved') expect(trn_data.css('reID').text).to eq('123') expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) @@ -852,7 +861,10 @@ describe 'EPP Domain', epp: true do }) pw = domain.auth_info - xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }, 'reject', { + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: pw } } + }, 'reject', { _anonymus: [ legalDocument: { value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', @@ -862,8 +874,8 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('2304') expect(response[:msg]).to eq('Transfer can be rejected only by current registrar') + expect(response[:result_code]).to eq('2304') expect(domain.legal_documents.count).to eq(0) response = epp_request(xml, :xml, :zone) @@ -880,14 +892,21 @@ describe 'EPP Domain', epp: true do transfer_from: @zone }) - xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve') + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: domain.auth_info } } + }, 'approve') + response = epp_request(xml, :xml, :elkdata) expect(response[:result_code]).to eq('2304') expect(response[:msg]).to eq('Transfer can be approved only by current domain registrar') end it 'does not transfer with invalid pw' do - xml = domain_transfer_xml({ authInfo: { pw: { value: 'test' } } }) + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: 'test' } } + }) response = epp_request(xml, :xml) expect(response[:result_code]).to eq('2201') expect(response[:msg]).to eq('Authorization error') @@ -895,7 +914,10 @@ describe 'EPP Domain', epp: true do it 'ignores transfer when owner registrar requests transfer' do pw = domain.auth_info - xml = domain_transfer_xml({ authInfo: { pw: { value: pw } } }) + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: pw } } + }) response = epp_request(xml, :xml, :zone) expect(response[:result_code]).to eq('2002') @@ -910,7 +932,11 @@ describe 'EPP Domain', epp: true do it 'creates new pw after successful transfer' do pw = domain.auth_info - xml = domain_transfer_xml(pw: pw) + xml = domain_transfer_xml({ + name: { value: domain.name }, + authInfo: { pw: { value: pw } } + }) + epp_request(xml, :xml, :elkdata) # transfer domain response = epp_request(xml, :xml, :elkdata) # attempt second transfer expect(response[:result_code]).to eq('2201') @@ -919,12 +945,12 @@ describe 'EPP Domain', epp: true do ### UPDATE ### it 'updates a domain' do - Fabricate(:contact, code: 'mak21') - existing_pw = Domain.first.auth_info + existing_pw = Domain.last.auth_info xml_params = { + name: { value: domain.name }, chg: [ - registrant: { value: 'mak21' } + registrant: { value: 'citizen_1234' } ] } @@ -941,12 +967,13 @@ describe 'EPP Domain', epp: true do d = Domain.last - expect(d.owner_contact_code).to eq('mak21') + expect(d.owner_contact_code).to eq('citizen_1234') expect(d.auth_info).to eq(existing_pw) end it 'updates domain and adds objects' do xml = domain_update_xml({ + name: { value: domain.name }, add: [ { ns: [ @@ -997,7 +1024,7 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml) expect(response[:results][0][:result_code]).to eq('1000') - d = Domain.first + d = Domain.last new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count expect(new_ns_count).to eq(2) @@ -1042,9 +1069,8 @@ describe 'EPP Domain', epp: true do end it 'updates a domain and removes objects' do - Fabricate(:contact, code: 'mak21') - xml = domain_update_xml({ + name: { value: domain.name }, add: [ { ns: [ @@ -1061,7 +1087,7 @@ describe 'EPP Domain', epp: true do ] }, _anonymus: [ - { contact: { value: 'mak21', attrs: { type: 'tech' } } }, + { contact: { value: 'citizen_1234', attrs: { type: 'tech' } } }, { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } ] @@ -1091,6 +1117,7 @@ describe 'EPP Domain', epp: true do expect(d.dnskeys.count).to eq(2) xml = domain_update_xml({ + name: { value: domain.name }, rem: [ { ns: [ @@ -1102,7 +1129,7 @@ describe 'EPP Domain', epp: true do ] }, _anonymus: [ - { contact: { value: 'mak21', attrs: { type: 'tech' } } }, + { contact: { value: 'citizen_1234', attrs: { type: 'tech' } } }, { status: { value: '', attrs: { s: 'clientHold' } } } ] ] @@ -1125,13 +1152,13 @@ describe 'EPP Domain', epp: true do rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com') expect(rem_ns).to be_falsey - rem_cnt = d.tech_contacts.find_by(code: 'mak21') + rem_cnt = d.tech_contacts.find_by(code: 'citizen_1234') expect(rem_cnt).to be_falsey response = epp_request(xml, :xml) expect(response[:results][0][:result_code]).to eq('2303') expect(response[:results][0][:msg]).to eq('Contact was not found') - expect(response[:results][0][:value]).to eq('mak21') + expect(response[:results][0][:value]).to eq('citizen_1234') expect(response[:results][1][:result_code]).to eq('2303') expect(response[:results][1][:msg]).to eq('Nameserver was not found') @@ -1147,6 +1174,7 @@ describe 'EPP Domain', epp: true do d.domain_statuses.create(value: DomainStatus::SERVER_HOLD) xml = domain_update_xml({ + name: { value: domain.name }, rem: [ _anonymus: [ { status: { value: '', attrs: { s: 'serverHold' } } } @@ -1162,11 +1190,12 @@ describe 'EPP Domain', epp: true do end it 'does not add duplicate objects to domain' do - d = Domain.first + d = Domain.last c = d.admin_contacts.first n = d.nameservers.first xml = domain_update_xml({ + name: { value: domain.name }, add: { ns: [ { @@ -1194,11 +1223,10 @@ describe 'EPP Domain', epp: true do end it 'cannot change registrant without legal document' do - Fabricate(:contact, code: 'mak21') - xml_params = { + name: { value: domain.name }, chg: [ - registrant: { value: 'mak21' } + registrant: { value: 'citizen_1234' } ] } @@ -1209,6 +1237,7 @@ describe 'EPP Domain', epp: true do it 'does not assign invalid status to domain' do xml = domain_update_xml({ + name: { value: domain.name }, add: [ status: { value: '', attrs: { s: 'invalidStatus' } } ] @@ -1224,7 +1253,7 @@ describe 'EPP Domain', epp: true do it 'renews a domain' do exp_date = (Date.today + 1.year) xml = epp_xml.domain.renew( - name: { value: 'example.ee' }, + name: { value: domain.name }, curExpDate: { value: exp_date.to_s }, period: { value: '1', attrs: { unit: 'y' } } ) @@ -1233,13 +1262,13 @@ describe 'EPP Domain', epp: true do ex_date = response[:parsed].css('renData exDate').text name = response[:parsed].css('renData name').text expect(ex_date).to eq("#{(exp_date + 1.year)} 00:00:00 UTC") - expect(name).to eq('example.ee') + expect(name).to eq(domain.name) end it 'returns an error when given and current exp dates do not match' do xml = epp_xml.domain.renew( - name: { value: 'example.ee' }, - curExpDate: { value: '2016-08-07' }, + name: { value: domain.name }, + curExpDate: { value: '2200-08-07' }, period: { value: '1', attrs: { unit: 'y' } } ) @@ -1252,7 +1281,7 @@ describe 'EPP Domain', epp: true do exp_date = (Date.today + 1.year) xml = epp_xml.domain.renew( - name: { value: 'example.ee' }, + name: { value: domain.name }, curExpDate: { value: exp_date.to_s }, period: { value: '4', attrs: { unit: 'y' } } ) @@ -1265,11 +1294,10 @@ describe 'EPP Domain', epp: true do ### INFO ### it 'returns domain info' do - d = Domain.first - d.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.') - d.nameservers.build(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') + domain.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.') + domain.nameservers.build(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') - d.dnskeys.build( + domain.dnskeys.build( ds_key_tag: '123', ds_alg: 3, ds_digest_type: 1, @@ -1280,7 +1308,7 @@ describe 'EPP Domain', epp: true do public_key: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' ) - d.dnskeys.build( + domain.dnskeys.build( ds_key_tag: '123', ds_alg: 3, ds_digest_type: 1, @@ -1291,27 +1319,27 @@ describe 'EPP Domain', epp: true do public_key: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' ) - d.save + domain.save - xml = domain_info_xml(name: { value: 'Example.ee' }) + xml = domain_info_xml(name: { value: domain.name }) response = epp_request(xml, :xml) expect(response[:results][0][:result_code]).to eq('1000') expect(response[:results][0][:msg]).to eq('Command completed successfully') inf_data = response[:parsed].css('resData infData') - expect(inf_data.css('name').text).to eq('example.ee') + expect(inf_data.css('name').text).to eq(domain.name) expect(inf_data.css('status').text).to eq('Payment overdue.') expect(inf_data.css('status').first[:s]).to eq('clientHold') - expect(inf_data.css('registrant').text).to eq(d.owner_contact_code) + expect(inf_data.css('registrant').text).to eq(domain.owner_contact_code) admin_contacts_from_request = inf_data.css('contact[type="admin"]').map(&:text) - admin_contacts_existing = d.admin_contacts.pluck(:code) + admin_contacts_existing = domain.admin_contacts.pluck(:code) expect(admin_contacts_from_request).to eq(admin_contacts_existing) hosts_from_request = inf_data.css('hostName').map(&:text) - hosts_existing = d.nameservers.pluck(:hostname) + hosts_existing = domain.nameservers.pluck(:hostname) expect(hosts_from_request).to eq(hosts_existing) @@ -1320,9 +1348,9 @@ describe 'EPP Domain', epp: true do expect(ns1.css('hostName').last.text).to eq('ns1.example.com') expect(ns1.css('hostAddr').first.text).to eq('192.168.1.1') expect(ns1.css('hostAddr').last.text).to eq('1080:0:0:0:8:800:200C:417A') - expect(inf_data.css('crDate').text).to eq(d.created_at.to_time.utc.to_s) - expect(inf_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) - expect(inf_data.css('pw').text).to eq(d.auth_info) + expect(inf_data.css('crDate').text).to eq(domain.created_at.to_time.utc.to_s) + expect(inf_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + expect(inf_data.css('pw').text).to eq(domain.auth_info) ds_data_1 = response[:parsed].css('dsData')[0] @@ -1345,12 +1373,12 @@ describe 'EPP Domain', epp: true do expect(dnskey_2.css('alg').first.text).to eq('5') expect(dnskey_2.css('pubKey').first.text).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') - d.touch + domain.touch - response = epp_request(domain_info_xml, :xml) + response = epp_request(domain_info_xml(name: { value: domain.name }), :xml) inf_data = response[:parsed].css('resData infData') - expect(inf_data.css('upDate').text).to eq(d.updated_at.to_time.utc.to_s) + expect(inf_data.css('upDate').text).to eq(domain.updated_at.to_time.utc.to_s) end it 'returns error when domain can not be found' do @@ -1360,23 +1388,21 @@ describe 'EPP Domain', epp: true do end it 'sets ok status by default' do - response = epp_request(domain_info_xml, :xml) + response = epp_request(domain_info_xml(name: { value: domain.name }), :xml) inf_data = response[:parsed].css('resData infData') expect(inf_data.css('status').first[:s]).to eq('ok') end it 'can not see other registrar domains' do - response = epp_request(domain_info_xml, :xml, :elkdata) + response = epp_request(domain_info_xml(name: { value: domain.name }), :xml, :elkdata) expect(response[:result_code]).to eq('2302') expect(response[:msg]).to eq('Domain exists but belongs to other registrar') end ### DELETE ### it 'deletes domain' do - expect(DomainContact.count).to eq(2) - response = epp_request(epp_xml.domain.delete({ - name: { value: 'example.ee' } + name: { value: domain.name } }, { _anonymus: [ legalDocument: { @@ -1388,16 +1414,14 @@ describe 'EPP Domain', epp: true do expect(response[:result_code]).to eq('1000') - expect(Domain.first).to eq(nil) - expect(DomainContact.count).to eq(0) + expect(Domain.find_by(name: domain.name)).to eq(nil) end it 'does not delete domain with specific status' do - d = Domain.first - d.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED) + domain.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED) response = epp_request(epp_xml.domain.delete({ - name: { value: 'example.ee' } + name: { value: domain.name } }, { _anonymus: [ legalDocument: { @@ -1416,82 +1440,83 @@ describe 'EPP Domain', epp: true do expect(response[:result_code]).to eq('2003') expect(response[:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') end - end - ### CHECK ### - it 'checks a domain' do - response = epp_request(domain_check_xml({ - _anonymus: [ - { name: { value: 'one.ee' } } - ] - }), :xml) + ### CHECK ### + it 'checks a domain' do + response = epp_request(domain_check_xml({ + _anonymus: [ + { name: { value: 'one.ee' } } + ] + }), :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') - domain = response[:parsed].css('resData chkData cd name').first - expect(domain.text).to eq('one.ee') - expect(domain[:avail]).to eq('1') + res_data = response[:parsed].css('resData chkData cd name').first + expect(res_data.text).to eq('one.ee') + expect(res_data[:avail]).to eq('1') - response = epp_request(domain_check_xml({ - _anonymus: [ - { name: { value: 'example.ee' } } - ] - }), :xml) - domain = response[:parsed].css('resData chkData cd').first - name = domain.css('name').first - reason = domain.css('reason').first + response = epp_request(domain_check_xml({ + _anonymus: [ + { name: { value: domain.name } } + ] + }), :xml) + res_data = response[:parsed].css('resData chkData cd').first + name = res_data.css('name').first + reason = res_data.css('reason').first - expect(name.text).to eq('example.ee') - expect(name[:avail]).to eq('0') - expect(reason.text).to eq('in use') - end + expect(name.text).to eq(domain.name) + expect(name[:avail]).to eq('0') + expect(reason.text).to eq('in use') + end - it 'checks multiple domains' do - xml = domain_check_xml({ - _anonymus: [ - { name: { value: 'one.ee' } }, - { name: { value: 'two.ee' } }, - { name: { value: 'three.ee' } } - ] - }) + it 'checks multiple domains' do + xml = domain_check_xml({ + _anonymus: [ + { name: { value: 'one.ee' } }, + { name: { value: 'two.ee' } }, + { name: { value: 'three.ee' } } + ] + }) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') - domain = response[:parsed].css('resData chkData cd name').first - expect(domain.text).to eq('one.ee') - expect(domain[:avail]).to eq('1') + res_data = response[:parsed].css('resData chkData cd name').first + expect(res_data.text).to eq('one.ee') + expect(res_data[:avail]).to eq('1') - domain = response[:parsed].css('resData chkData cd name').last - expect(domain.text).to eq('three.ee') - expect(domain[:avail]).to eq('1') - end + res_data = response[:parsed].css('resData chkData cd name').last + expect(res_data.text).to eq('three.ee') + expect(res_data[:avail]).to eq('1') + end - it 'checks invalid format domain' do - xml = domain_check_xml({ - _anonymus: [ - { name: { value: 'one.ee' } }, - { name: { value: 'notcorrectdomain' } } - ] - }) + it 'checks invalid format domain' do + xml = domain_check_xml({ + _anonymus: [ + { name: { value: 'one.ee' } }, + { name: { value: 'notcorrectdomain' } } + ] + }) - response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response = epp_request(xml, :xml) + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') - domain = response[:parsed].css('resData chkData cd name').first - expect(domain.text).to eq('one.ee') - expect(domain[:avail]).to eq('1') + res_data = response[:parsed].css('resData chkData cd name').first + expect(res_data.text).to eq('one.ee') + expect(res_data[:avail]).to eq('1') - domain = response[:parsed].css('resData chkData cd').last - name = domain.css('name').first - reason = domain.css('reason').first + res_data = response[:parsed].css('resData chkData cd').last + name = res_data.css('name').first + reason = res_data.css('reason').first + + expect(name.text).to eq('notcorrectdomain') + expect(name[:avail]).to eq('0') + expect(reason.text).to eq('invalid format') + end - expect(name.text).to eq('notcorrectdomain') - expect(name[:avail]).to eq('0') - expect(reason.text).to eq('invalid format') end end diff --git a/spec/fabricators/contact_fabricator.rb b/spec/fabricators/contact_fabricator.rb index 6bd604e79..17dfcf637 100644 --- a/spec/fabricators/contact_fabricator.rb +++ b/spec/fabricators/contact_fabricator.rb @@ -1,9 +1,9 @@ Fabricator(:contact) do - name Faker::Name.name + name { sequence(:hostname) { |i| "#{Faker::Name.name}#{i}" } } phone '+372.12345678' email Faker::Internet.email ident '37605030299' - code { "sh#{Faker::Number.number(4)}" } + code { "sh#{Faker::Number.number(8)}" } ident_type 'op' auth_info 'ccds4324pok' address From 418695ccc7cb68f0afb8c7c567ecf193b7e78fbd Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 15:16:16 +0200 Subject: [PATCH 03/34] Remove redundant lines --- spec/epp/domain_spec.rb | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 7c20c8676..58cbd8c02 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1,27 +1,13 @@ require 'rails_helper' describe 'EPP Domain', epp: true do - - before do - # we don't really care about the code validations here, it's done in models - # dynamic Contact.code just makes it harder to test EPP - Contact.skip_callback(:create, :before, :generate_code) - end - - after do - Contact.set_callback(:create, :before, :generate_code) - end - let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) } let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) } - let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) } - let(:zone) { Fabricate(:registrar) } let(:epp_xml) { EppXml.new(cl_trid: 'ABC-12345') } before(:each) { create_settings } before(:all) do - @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) @zone = Fabricate(:registrar) Fabricate(:epp_user, username: 'zone', registrar: @zone) @@ -29,15 +15,13 @@ describe 'EPP Domain', epp: true do Contact.skip_callback(:create, :before, :generate_code) - @example_ee = Fabricate(:domain, name: 'example.ee', registrar: @zone, dnskeys: []) - Fabricate(:contact, code: 'citizen_1234') Fabricate(:contact, code: 'sh8013') Fabricate(:contact, code: 'sh801333') - @juridical_contact = Fabricate(:contact, code: 'juridical_1234', ident_type: 'ico') + Fabricate(:contact, code: 'juridical_1234', ident_type: 'ico') Fabricate(:reserved_domain) - @uniq_no = Proc.new { @i ||= 0; @i += 1 } + @uniq_no = proc { @i ||= 0; @i += 1 } end it 'returns error if contact does not exists' do From bfb86702330affe1ae9f9f9134e913b442110e20 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 16:08:25 +0200 Subject: [PATCH 04/34] Refactor keyrelay specs --- spec/epp/domain_spec.rb | 6 - spec/epp/keyrelay_spec.rb | 268 +++++++++++++++++++------------------- spec/rails_helper.rb | 20 ++- 3 files changed, 154 insertions(+), 140 deletions(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 58cbd8c02..0f081568f 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -90,12 +90,6 @@ describe 'EPP Domain', epp: true do end context 'with citizen as an owner' do - # before(:each) do - # Fabricate(:contact, code: 'citizen_1234') - # Fabricate(:contact, code: 'sh8013') - # Fabricate(:contact, code: 'sh801333') - # end - it 'creates a domain' do dn = next_domain_name response = epp_request(domain_create_xml({ diff --git a/spec/epp/keyrelay_spec.rb b/spec/epp/keyrelay_spec.rb index 62d5bc300..7e23faa66 100644 --- a/spec/epp/keyrelay_spec.rb +++ b/spec/epp/keyrelay_spec.rb @@ -3,161 +3,167 @@ require 'rails_helper' describe 'EPP Keyrelay', epp: true do let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) } let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) } - let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) } - let(:zone) { Fabricate(:registrar) } - let(:domain) { Fabricate(:domain, name: 'example.ee', registrar: zone, dnskeys: [Fabricate.build(:dnskey)]) } let(:epp_xml) { EppXml::Keyrelay.new } before(:each) { create_settings } - context 'with valid user' do - before(:each) do - Fabricate(:epp_user, username: 'zone', registrar: zone) - Fabricate(:epp_user, username: 'elkdata', registrar: elkdata) - end + before(:all) do + @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) + @zone = Fabricate(:registrar) + Fabricate(:epp_user, username: 'zone', registrar: @zone) + Fabricate(:epp_user, username: 'elkdata', registrar: @elkdata) - it 'makes a keyrelay request' do - xml = epp_xml.keyrelay({ - name: { value: 'example.ee' }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: domain.auth_info } - }, - expiry: { - relative: { value: 'P1M13D' } - } - }) + @uniq_no = proc { @i ||= 0; @i += 1 } + end - response = epp_request(xml, :xml, :elkdata) + before(:each) { Fabricate(:domain, name: next_domain_name, registrar: @zone, dnskeys: [Fabricate.build(:dnskey)]) } + let(:domain) { Domain.last } - expect(response[:msg]).to eq('Command completed successfully') - expect(response[:result_code]).to eq('1000') + it 'makes a keyrelay request' do + xml = epp_xml.keyrelay({ + name: { value: domain.name }, + keyData: { + flags: { value: '256' }, + protocol: { value: '3' }, + alg: { value: '8' }, + pubKey: { value: 'cmlraXN0aGViZXN0' } + }, + authInfo: { + pw: { value: domain.auth_info } + }, + expiry: { + relative: { value: 'P1M13D' } + } + }) - expect(zone.messages.queued.count).to eq(1) + response = epp_request(xml, :xml, :elkdata) - log = ApiLog::EppLog.all + expect(response[:msg]).to eq('Command completed successfully') + expect(response[:result_code]).to eq('1000') - expect(log.length).to eq(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) + expect(@zone.messages.queued.count).to eq(1) - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('elkdata') - expect(log[1].api_user_registrar).to eq('Elkdata') + log = ApiLog::EppLog.all - expect(log[2].request_command).to eq('keyrelay') - expect(log[2].request_object).to eq('keyrelay') - expect(log[2].request_successful).to eq(true) - expect(log[2].api_user_name).to eq('elkdata') - expect(log[2].api_user_registrar).to eq('Elkdata') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank + expect(log.length).to eq(4) + expect(log[0].request_command).to eq('hello') + expect(log[0].request_successful).to eq(true) - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('elkdata') - expect(log[3].api_user_registrar).to eq('Elkdata') - end + expect(log[1].request_command).to eq('login') + expect(log[1].request_successful).to eq(true) + expect(log[1].api_user_name).to eq('elkdata') + expect(log[1].api_user_registrar).to eq('Elkdata') - it 'returns an error when parameters are missing' do - xml = epp_xml.keyrelay({ - name: { value: 'example.ee' }, - keyData: { - flags: { value: '' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: domain.auth_info } - }, - expiry: { - relative: { value: 'Invalid Expiry' } - } - }) + expect(log[2].request_command).to eq('keyrelay') + expect(log[2].request_object).to eq('keyrelay') + expect(log[2].request_successful).to eq(true) + expect(log[2].api_user_name).to eq('elkdata') + expect(log[2].api_user_registrar).to eq('Elkdata') + expect(log[2].request).not_to be_blank + expect(log[2].response).not_to be_blank - response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Required parameter missing: flags') + expect(log[3].request_command).to eq('logout') + expect(log[3].request_successful).to eq(true) + expect(log[3].api_user_name).to eq('elkdata') + expect(log[3].api_user_registrar).to eq('Elkdata') + end - expect(zone.messages.queued.count).to eq(0) - end + it 'returns an error when parameters are missing' do + msg_count = @zone.messages.queued.count + xml = epp_xml.keyrelay({ + name: { value: domain.name }, + keyData: { + flags: { value: '' }, + protocol: { value: '3' }, + alg: { value: '8' }, + pubKey: { value: 'cmlraXN0aGViZXN0' } + }, + authInfo: { + pw: { value: domain.auth_info } + }, + expiry: { + relative: { value: 'Invalid Expiry' } + } + }) - it 'returns an error on invalid relative expiry' do - xml = epp_xml.keyrelay({ - name: { value: 'example.ee' }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: domain.auth_info } - }, - expiry: { - relative: { value: 'Invalid Expiry' } - } - }) + response = epp_request(xml, :xml, :elkdata) + expect(response[:msg]).to eq('Required parameter missing: flags') - response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Expiry relative must be compatible to ISO 8601') - expect(response[:results][0][:value]).to eq('Invalid Expiry') + expect(@zone.messages.queued.count).to eq(msg_count) + end - expect(zone.messages.queued.count).to eq(0) - end + it 'returns an error on invalid relative expiry' do + msg_count = @zone.messages.queued.count + xml = epp_xml.keyrelay({ + name: { value: domain.name }, + keyData: { + flags: { value: '256' }, + protocol: { value: '3' }, + alg: { value: '8' }, + pubKey: { value: 'cmlraXN0aGViZXN0' } + }, + authInfo: { + pw: { value: domain.auth_info } + }, + expiry: { + relative: { value: 'Invalid Expiry' } + } + }) - it 'returns an error on invalid absolute expiry' do - xml = epp_xml.keyrelay({ - name: { value: 'example.ee' }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: domain.auth_info } - }, - expiry: { - absolute: { value: 'Invalid Absolute' } - } - }) + response = epp_request(xml, :xml, :elkdata) + expect(response[:msg]).to eq('Expiry relative must be compatible to ISO 8601') + expect(response[:results][0][:value]).to eq('Invalid Expiry') - response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Expiry absolute must be compatible to ISO 8601') - expect(response[:results][0][:value]).to eq('Invalid Absolute') + expect(@zone.messages.queued.count).to eq(msg_count) + end - expect(zone.messages.queued.count).to eq(0) - end + it 'returns an error on invalid absolute expiry' do + msg_count = @zone.messages.queued.count + xml = epp_xml.keyrelay({ + name: { value: domain.name }, + keyData: { + flags: { value: '256' }, + protocol: { value: '3' }, + alg: { value: '8' }, + pubKey: { value: 'cmlraXN0aGViZXN0' } + }, + authInfo: { + pw: { value: domain.auth_info } + }, + expiry: { + absolute: { value: 'Invalid Absolute' } + } + }) - it 'does not allow both relative and absolute' do - xml = epp_xml.keyrelay({ - name: { value: 'example.ee' }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: domain.auth_info } - }, - expiry: { - relative: { value: 'P1D' }, - absolute: { value: '2014-12-23' } - } - }) + response = epp_request(xml, :xml, :elkdata) + expect(response[:msg]).to eq('Expiry absolute must be compatible to ISO 8601') + expect(response[:results][0][:value]).to eq('Invalid Absolute') - response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Exactly one parameter required: expiry > relative or expiry > absolute') + expect(@zone.messages.queued.count).to eq(msg_count) + end - expect(zone.messages.queued.count).to eq(0) - end + it 'does not allow both relative and absolute' do + msg_count = @zone.messages.queued.count + xml = epp_xml.keyrelay({ + name: { value: domain.name }, + keyData: { + flags: { value: '256' }, + protocol: { value: '3' }, + alg: { value: '8' }, + pubKey: { value: 'cmlraXN0aGViZXN0' } + }, + authInfo: { + pw: { value: domain.auth_info } + }, + expiry: { + relative: { value: 'P1D' }, + absolute: { value: '2014-12-23' } + } + }) + + response = epp_request(xml, :xml, :elkdata) + expect(response[:msg]).to eq('Exactly one parameter required: expiry > relative or expiry > absolute') + + expect(@zone.messages.queued.count).to eq(msg_count) end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 2b5d2c858..cddf961f6 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -31,13 +31,11 @@ RSpec.configure do |config| # instead of true. config.use_transactional_fixtures = false - config.before(:suite) do + config.before(:all) do ActiveRecord::Base.establish_connection :api_log_test DatabaseCleaner.strategy = :deletion - DatabaseCleaner.clean ActiveRecord::Base.establish_connection :test DatabaseCleaner.strategy = :truncation - DatabaseCleaner.clean end config.before(:each) do @@ -48,6 +46,22 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :truncation end + config.before(:all, epp: true) do + ActiveRecord::Base.establish_connection :api_log_test + DatabaseCleaner.clean + + ActiveRecord::Base.establish_connection :test + DatabaseCleaner.clean + end + + config.after(:all, epp: true) do + ActiveRecord::Base.establish_connection :api_log_test + DatabaseCleaner.clean + + ActiveRecord::Base.establish_connection :test + DatabaseCleaner.clean + end + config.before(:each, js: true) do DatabaseCleaner.strategy = :truncation end From 7676b76df800b86ebc2e0e93e158c166938982d5 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 16:10:57 +0200 Subject: [PATCH 05/34] Refactor poll specs --- spec/epp/poll_spec.rb | 234 +++++++++++++++++++++--------------------- 1 file changed, 117 insertions(+), 117 deletions(-) diff --git a/spec/epp/poll_spec.rb b/spec/epp/poll_spec.rb index 060d1e47e..a22659887 100644 --- a/spec/epp/poll_spec.rb +++ b/spec/epp/poll_spec.rb @@ -3,157 +3,157 @@ require 'rails_helper' describe 'EPP Poll', epp: true do let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) } let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) } - let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) } - let(:zone) { Fabricate(:registrar) } let(:epp_xml) { EppXml::Session.new } before(:each) { create_settings } - context 'with valid user' do - before(:each) do - Fabricate(:epp_user, username: 'zone', registrar: zone) - Fabricate(:epp_user, username: 'elkdata', registrar: elkdata) - end + before(:all) do + @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) + @zone = Fabricate(:registrar) + Fabricate(:epp_user, username: 'zone', registrar: @zone) + Fabricate(:epp_user, username: 'elkdata', registrar: @elkdata) - it 'returns no messages in poll' do - response = epp_request(epp_xml.poll, :xml) + @uniq_no = proc { @i ||= 0; @i += 1 } + end - expect(response[:msg]).to eq('Command completed successfully; no messages') - expect(response[:result_code]).to eq('1300') + it 'returns no messages in poll' do + response = epp_request(epp_xml.poll, :xml) - log = ApiLog::EppLog.all + expect(response[:msg]).to eq('Command completed successfully; no messages') + expect(response[:result_code]).to eq('1300') - expect(log.length).to eq(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) + log = ApiLog::EppLog.all - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('zone') - expect(log[1].api_user_registrar).to eq('Registrar OÜ') + expect(log.length).to eq(4) + expect(log[0].request_command).to eq('hello') + expect(log[0].request_successful).to eq(true) - expect(log[2].request_command).to eq('poll') - expect(log[2].request_object).to eq('poll') - expect(log[2].request_successful).to eq(true) - expect(log[2].api_user_name).to eq('zone') - expect(log[2].api_user_registrar).to eq('Registrar OÜ') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank + expect(log[1].request_command).to eq('login') + expect(log[1].request_successful).to eq(true) + expect(log[1].api_user_name).to eq('zone') + expect(log[1].api_user_registrar).to eq('Registrar OÜ') - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('zone') - expect(log[3].api_user_registrar).to eq('Registrar OÜ') - end + expect(log[2].request_command).to eq('poll') + expect(log[2].request_object).to eq('poll') + expect(log[2].request_successful).to eq(true) + expect(log[2].api_user_name).to eq('zone') + expect(log[2].api_user_registrar).to eq('Registrar OÜ') + expect(log[2].request).not_to be_blank + expect(log[2].response).not_to be_blank - it 'queues and dequeues messages' do - msg = zone.messages.create({ body: 'Balance low.' }) + expect(log[3].request_command).to eq('logout') + expect(log[3].request_successful).to eq(true) + expect(log[3].api_user_name).to eq('zone') + expect(log[3].api_user_registrar).to eq('Registrar OÜ') + end - response = epp_request(epp_xml.poll, :xml, :elkdata) - expect(response[:msg]).to eq('Command completed successfully; no messages') - expect(response[:result_code]).to eq('1300') + it 'queues and dequeues messages' do + msg = @zone.messages.create({ body: 'Balance low.' }) - response = epp_request(epp_xml.poll, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - expect(response[:result_code]).to eq('1301') - msg_q = response[:parsed].css('msgQ') + response = epp_request(epp_xml.poll, :xml, :elkdata) + expect(response[:msg]).to eq('Command completed successfully; no messages') + expect(response[:result_code]).to eq('1300') - expect(msg_q.css('msg').text).to eq('Balance low.') - expect(msg_q.first['count']).to eq('1') - expect(msg_q.first['id']).to eq(msg.id.to_s) + response = epp_request(epp_xml.poll, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') + expect(response[:result_code]).to eq('1301') + msg_q = response[:parsed].css('msgQ') - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) + expect(msg_q.css('msg').text).to eq('Balance low.') + expect(msg_q.first['count']).to eq('1') + expect(msg_q.first['id']).to eq(msg.id.to_s) - response = epp_request(xml, :xml, :elkdata) - expect(response[:results][0][:msg]).to eq('Message was not found') - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:value]).to eq(msg_q.first['id']) + xml = epp_xml.poll(poll: { + value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } + }) - response = epp_request(xml, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully') - msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('0') + response = epp_request(xml, :xml, :elkdata) + expect(response[:results][0][:msg]).to eq('Message was not found') + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:value]).to eq(msg_q.first['id']) - response = epp_request(xml, :xml, :zone) - expect(response[:results][0][:msg]).to eq('Message was not found') - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:value]).to eq(msg_q.first['id']) - end + response = epp_request(xml, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully') + msg_q = response[:parsed].css('msgQ') + expect(msg_q.first['id']).to_not be_blank + expect(msg_q.first['count']).to eq('0') - it 'returns an error on incorrect op' do - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'bla' } - }) + response = epp_request(xml, :xml, :zone) + expect(response[:results][0][:msg]).to eq('Message was not found') + expect(response[:results][0][:result_code]).to eq('2303') + expect(response[:results][0][:value]).to eq(msg_q.first['id']) + end - response = epp_request(xml, :xml, :zone) - expect(response[:msg]).to eq('Attribute op is invalid') - end + it 'returns an error on incorrect op' do + xml = epp_xml.poll(poll: { + value: '', attrs: { op: 'bla' } + }) - it 'dequeues multiple messages' do - zone.messages.create({ body: 'Balance low.' }) - zone.messages.create({ body: 'Something.' }) - zone.messages.create({ body: 'Smth else.' }) + response = epp_request(xml, :xml, :zone) + expect(response[:msg]).to eq('Attribute op is invalid') + end - response = epp_request(epp_xml.poll, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - expect(response[:result_code]).to eq('1301') - msg_q = response[:parsed].css('msgQ') + it 'dequeues multiple messages' do + @zone.messages.create({ body: 'Balance low.' }) + @zone.messages.create({ body: 'Something.' }) + @zone.messages.create({ body: 'Smth else.' }) - expect(msg_q.css('msg').text).to eq('Smth else.') - expect(msg_q.first['count']).to eq('3') + response = epp_request(epp_xml.poll, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') + expect(response[:result_code]).to eq('1301') + msg_q = response[:parsed].css('msgQ') - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) + expect(msg_q.css('msg').text).to eq('Smth else.') + expect(msg_q.first['count']).to eq('3') - response = epp_request(xml, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully') - msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('2') + xml = epp_xml.poll(poll: { + value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } + }) - response = epp_request(epp_xml.poll, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - expect(response[:result_code]).to eq('1301') - msg_q = response[:parsed].css('msgQ') + response = epp_request(xml, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully') + msg_q = response[:parsed].css('msgQ') + expect(msg_q.first['id']).to_not be_blank + expect(msg_q.first['count']).to eq('2') - expect(msg_q.css('msg').text).to eq('Something.') - expect(msg_q.first['count']).to eq('2') + response = epp_request(epp_xml.poll, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') + expect(response[:result_code]).to eq('1301') + msg_q = response[:parsed].css('msgQ') - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) + expect(msg_q.css('msg').text).to eq('Something.') + expect(msg_q.first['count']).to eq('2') - response = epp_request(xml, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully') - msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('1') + xml = epp_xml.poll(poll: { + value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } + }) - response = epp_request(epp_xml.poll, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - expect(response[:result_code]).to eq('1301') - msg_q = response[:parsed].css('msgQ') + response = epp_request(xml, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully') + msg_q = response[:parsed].css('msgQ') + expect(msg_q.first['id']).to_not be_blank + expect(msg_q.first['count']).to eq('1') - expect(msg_q.css('msg').text).to eq('Balance low.') - expect(msg_q.first['count']).to eq('1') + response = epp_request(epp_xml.poll, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') + expect(response[:result_code]).to eq('1301') + msg_q = response[:parsed].css('msgQ') - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) + expect(msg_q.css('msg').text).to eq('Balance low.') + expect(msg_q.first['count']).to eq('1') - response = epp_request(xml, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully') - msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('0') + xml = epp_xml.poll(poll: { + value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } + }) - response = epp_request(epp_xml.poll, :xml, :zone) - expect(response[:msg]).to eq('Command completed successfully; no messages') - expect(response[:result_code]).to eq('1300') - end + response = epp_request(xml, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully') + msg_q = response[:parsed].css('msgQ') + expect(msg_q.first['id']).to_not be_blank + expect(msg_q.first['count']).to eq('0') + + response = epp_request(epp_xml.poll, :xml, :zone) + expect(response[:msg]).to eq('Command completed successfully; no messages') + expect(response[:result_code]).to eq('1300') end end From af90bad5445a552c6971d876517dd7f43da7ee9e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 16:36:53 +0200 Subject: [PATCH 06/34] Sequence fix --- spec/fabricators/contact_fabricator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/fabricators/contact_fabricator.rb b/spec/fabricators/contact_fabricator.rb index 17dfcf637..c483ad554 100644 --- a/spec/fabricators/contact_fabricator.rb +++ b/spec/fabricators/contact_fabricator.rb @@ -1,5 +1,5 @@ Fabricator(:contact) do - name { sequence(:hostname) { |i| "#{Faker::Name.name}#{i}" } } + name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } } phone '+372.12345678' email Faker::Internet.email ident '37605030299' From e6bb4d87126166430d93588589a01b0bcf34f4f7 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 23 Jan 2015 14:47:03 +0200 Subject: [PATCH 07/34] Added links to official rfcs --- doc/epp-doc.md | 11 ++++++++++- doc/epp/README.md | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/epp-doc.md b/doc/epp-doc.md index 564502565..29751dda9 100644 --- a/doc/epp-doc.md +++ b/doc/epp-doc.md @@ -7,5 +7,14 @@ Introduction text here [Domain related functions](epp/domain.md) [Keyrelay related functions](epp/keyrelay.md) -Please study official The Extensible Provisioning Protocol (EPP): +Our implementation supports following protocols: + +[RFC5730 - EPP](http://tools.ietf.org/html/rfc5730) +[RFC5731 - Domain Mapping](http://tools.ietf.org/html/rfc5731) +[RFC5733 - Contact Mapping](http://tools.ietf.org/html/rfc5733) +[RFC5734 - Transport over TCP](http://tools.ietf.org/html/rfc5734) +[RFC5910 - DNSSEC Mapping](http://tools.ietf.org/html/rfc5910) +[RFC3735 - Guidelines for Extending the EPP](http://tools.ietf.org/html/rfc3735) + +More info about The Extensible Provisioning Protocol (EPP):
http://en.wikipedia.org/wiki/Extensible_Provisioning_Protocol diff --git a/doc/epp/README.md b/doc/epp/README.md index 127524078..e22fc954e 100644 --- a/doc/epp/README.md +++ b/doc/epp/README.md @@ -7,5 +7,14 @@ Introduction text here [Domain related functions](domain.md) [Keyrelay related functions](keyrelay.md) -Please study official The Extensible Provisioning Protocol (EPP): +Our implementation supports following protocols: + +[RFC5730 - EPP](http://tools.ietf.org/html/rfc5730) +[RFC5731 - Domain Mapping](http://tools.ietf.org/html/rfc5731) +[RFC5733 - Contact Mapping](http://tools.ietf.org/html/rfc5733) +[RFC5734 - Transport over TCP](http://tools.ietf.org/html/rfc5734) +[RFC5910 - DNSSEC Mapping](http://tools.ietf.org/html/rfc5910) +[RFC3735 - Guidelines for Extending the EPP](http://tools.ietf.org/html/rfc3735) + +More info about The Extensible Provisioning Protocol (EPP):
http://en.wikipedia.org/wiki/Extensible_Provisioning_Protocol From 584182d163f956ec4dc06c7131b36bc6b9e2ed3b Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 23 Jan 2015 15:03:06 +0200 Subject: [PATCH 08/34] Added contact Ident type to doc --- doc/epp/contact.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/doc/epp/contact.md b/doc/epp/contact.md index 0a3e54729..4bb153234 100644 --- a/doc/epp/contact.md +++ b/doc/epp/contact.md @@ -21,10 +21,15 @@ Contact Mapping protocol short version: 1 City name 0-1 State or province 0-1 Postal code - ` 1 Country code, 2 letters uppercase + 1 Country code, 2 letters uppercase 1 Phone number in format \+ddd.d+ 1 E-mail - 1 Contact identificator. + 1 Contact identificator. Attribute: type="op" + Type values: + 'op', # Estonian ID + 'passport', # Passport number + 'birthday' # Birthday date + [EXAMPLE REQUEST AND RESPONSE](/doc/epp-examples.md#epp-contact-with-valid-user-create-command-successfully-creates-a-contact) @@ -90,9 +95,3 @@ Contact Mapping protocol short version: 0-1 Client transaction id [EXAMPLE REQUEST AND RESPONSE](/doc/epp-examples.md#epp-contact-with-valid-user-info-command-discloses-items-to-owner) - - -### Domain renew - -Renewal semantics do not apply to contact objects, so there is no -mapping defined for the EPP command. From afff9db09cee1d59178bc5d87421aece2888efd1 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 23 Jan 2015 15:11:09 +0200 Subject: [PATCH 09/34] doc syntax fix --- doc/epp-doc.md | 10 +++++----- doc/epp/README.md | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/epp-doc.md b/doc/epp-doc.md index 29751dda9..11ec8b5a3 100644 --- a/doc/epp-doc.md +++ b/doc/epp-doc.md @@ -9,11 +9,11 @@ Introduction text here Our implementation supports following protocols: -[RFC5730 - EPP](http://tools.ietf.org/html/rfc5730) -[RFC5731 - Domain Mapping](http://tools.ietf.org/html/rfc5731) -[RFC5733 - Contact Mapping](http://tools.ietf.org/html/rfc5733) -[RFC5734 - Transport over TCP](http://tools.ietf.org/html/rfc5734) -[RFC5910 - DNSSEC Mapping](http://tools.ietf.org/html/rfc5910) +[RFC5730 - EPP](http://tools.ietf.org/html/rfc5730) +[RFC5731 - Domain Mapping](http://tools.ietf.org/html/rfc5731) +[RFC5733 - Contact Mapping](http://tools.ietf.org/html/rfc5733) +[RFC5734 - Transport over TCP](http://tools.ietf.org/html/rfc5734) +[RFC5910 - DNSSEC Mapping](http://tools.ietf.org/html/rfc5910) [RFC3735 - Guidelines for Extending the EPP](http://tools.ietf.org/html/rfc3735) More info about The Extensible Provisioning Protocol (EPP):
diff --git a/doc/epp/README.md b/doc/epp/README.md index e22fc954e..1c3a6a3ab 100644 --- a/doc/epp/README.md +++ b/doc/epp/README.md @@ -9,11 +9,11 @@ Introduction text here Our implementation supports following protocols: -[RFC5730 - EPP](http://tools.ietf.org/html/rfc5730) -[RFC5731 - Domain Mapping](http://tools.ietf.org/html/rfc5731) -[RFC5733 - Contact Mapping](http://tools.ietf.org/html/rfc5733) -[RFC5734 - Transport over TCP](http://tools.ietf.org/html/rfc5734) -[RFC5910 - DNSSEC Mapping](http://tools.ietf.org/html/rfc5910) +[RFC5730 - EPP](http://tools.ietf.org/html/rfc5730) +[RFC5731 - Domain Mapping](http://tools.ietf.org/html/rfc5731) +[RFC5733 - Contact Mapping](http://tools.ietf.org/html/rfc5733) +[RFC5734 - Transport over TCP](http://tools.ietf.org/html/rfc5734) +[RFC5910 - DNSSEC Mapping](http://tools.ietf.org/html/rfc5910) [RFC3735 - Guidelines for Extending the EPP](http://tools.ietf.org/html/rfc3735) More info about The Extensible Provisioning Protocol (EPP):
From 4ca889d70e8e3e970b310ed74500e666ff25961a Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 23 Jan 2015 15:14:31 +0200 Subject: [PATCH 10/34] removed intro text --- doc/epp-doc.md | 4 +++- doc/epp/README.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/epp-doc.md b/doc/epp-doc.md index 11ec8b5a3..db68f2207 100644 --- a/doc/epp-doc.md +++ b/doc/epp-doc.md @@ -1,7 +1,9 @@ # EPP integration specification for Estonian Internet Foundation ## Introduction -Introduction text here + +Main communication specification through EPP: + [Session related functions](epp/session.md) [Contact related functions](epp/contact.md) [Domain related functions](epp/domain.md) diff --git a/doc/epp/README.md b/doc/epp/README.md index 1c3a6a3ab..e129053a2 100644 --- a/doc/epp/README.md +++ b/doc/epp/README.md @@ -1,7 +1,9 @@ # EPP integration specification for Estonian Internet Foundation ## Introduction -Introduction text here + +Main communication specification through EPP: + [Session related functions](session.md) [Contact related functions](contact.md) [Domain related functions](domain.md) From 81159efca8aa27dce65294d0d00edd4492ffad40 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 23 Jan 2015 15:17:13 +0200 Subject: [PATCH 11/34] doc cleanup --- doc/epp-doc.md | 4 +--- doc/epp/README.md | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/epp-doc.md b/doc/epp-doc.md index db68f2207..7ac516f3c 100644 --- a/doc/epp-doc.md +++ b/doc/epp-doc.md @@ -1,6 +1,4 @@ -# EPP integration specification for Estonian Internet Foundation - -## Introduction +# EPP integration specification Main communication specification through EPP: diff --git a/doc/epp/README.md b/doc/epp/README.md index e129053a2..78047851c 100644 --- a/doc/epp/README.md +++ b/doc/epp/README.md @@ -1,6 +1,4 @@ -# EPP integration specification for Estonian Internet Foundation - -## Introduction +# EPP integration specification Main communication specification through EPP: From 4e7b0e6104963d80acc2e979b4fe0e1cb30809af Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 23 Jan 2015 22:16:23 +0200 Subject: [PATCH 12/34] added bic and priv --- app/models/contact.rb | 6 ++++-- doc/epp/contact.md | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 328186518..0f57f5a60 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -49,8 +49,10 @@ class Contact < ActiveRecord::Base IDENT_TYPE_ICO = 'ico' IDENT_TYPES = [ IDENT_TYPE_ICO, # Company registry code (or similar) - 'op', # Estonian ID - 'passport', # Passport number + 'bic', # Business registry code + 'priv', # National idendtification number + 'op', # Estonian ID, depricated + 'passport', # Passport number, depricated 'birthday' # Birthday date ] diff --git a/doc/epp/contact.md b/doc/epp/contact.md index 4bb153234..490e67cd6 100644 --- a/doc/epp/contact.md +++ b/doc/epp/contact.md @@ -24,10 +24,10 @@ Contact Mapping protocol short version: 1 Country code, 2 letters uppercase 1 Phone number in format \+ddd.d+ 1 E-mail - 1 Contact identificator. Attribute: type="op" + 1 Contact identificator. Attribute: type="bic" Type values: - 'op', # Estonian ID - 'passport', # Passport number + 'bic', # Business registry code + 'priv', # National idendtification number 'birthday' # Birthday date From 4401d8495e8f381b014c1f376120eec1ba3a56e1 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 26 Jan 2015 15:45:11 +0200 Subject: [PATCH 13/34] Epp contact tests now 10x faster --- Guardfile | 3 +- app/controllers/epp/contacts_controller.rb | 1 + app/controllers/epp_controller.rb | 1 + app/views/epp/contacts/info.xml.builder | 3 +- config/environments/test.rb | 4 + config/initializers/initial_settings.rb | 3 + spec/epp/contact_spec.rb | 630 +++++++++++---------- spec/rails_helper.rb | 32 +- spec/support/epp.rb | 8 +- 9 files changed, 361 insertions(+), 324 deletions(-) diff --git a/Guardfile b/Guardfile index 0d4ca4b62..e1fd16320 100644 --- a/Guardfile +++ b/Guardfile @@ -3,7 +3,8 @@ group :red_green_refactor, halt_on_fail: true do # be sure you have apache2 configured to # accept EPP request on port 701, what proxy to 8989. # port and environment is just for correct notification, all is overwritten by CLI - guard :rails, port: 8989, environment: 'test', CLI: 'RAILS_ENV=test unicorn -p 8989' do + guard :rails, port: 8989, environment: 'test' do + # guard :rails, port: 8989, environment: 'test', CLI: 'RAILS_ENV=test unicorn -p 8989' do watch('Gemfile.lock') watch(%r{^(config|lib)/.*}) end diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 152561886..28a3f8102 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -16,6 +16,7 @@ class Epp::ContactsController < EppController def update # FIXME: Update returns 2303 update multiple times code = params_hash['epp']['command']['update']['update'][:id] + @contact = Contact.where(code: code).first # if update_rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update)) if owner? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update)) diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index bae8a357a..1c0bfea43 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -124,6 +124,7 @@ class EppController < ApplicationController # rubocop: enable Style/PredicateName def write_to_epp_log + return nil if EPP_LOG_ENABLED request_command = params[:command] || params[:action] # error receives :command, other methods receive :action ApiLog::EppLog.create({ request: params[:raw_frame] || params[:frame], diff --git a/app/views/epp/contacts/info.xml.builder b/app/views/epp/contacts/info.xml.builder index e12615c79..e354be0b2 100644 --- a/app/views/epp/contacts/info.xml.builder +++ b/app/views/epp/contacts/info.xml.builder @@ -11,7 +11,8 @@ xml.epp_head do xml.tag!('contact:voice', @contact.phone) if @disclosure.try(:phone) || @owner xml.tag!('contact:fax', @contact.fax) if @disclosure.try(:fax) || @owner xml.tag!('contact:email', @contact.email) if @disclosure.try(:email) || @owner - #xml.tag!('contact:clID', @current_epp_user.username) if @current_epp_user + xml.tag!('contact:clID', @contact.registrar.try(:name)) + #xml.tag!('contact:crID', @contact.cr_id ) if @contact.cr_id xml.tag!('contact:crDate', @contact.created_at) xml.tag!('contact:upID', @contact.up_id) if @contact.up_id diff --git a/config/environments/test.rb b/config/environments/test.rb index ecc572090..d7db4fa70 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -40,6 +40,10 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + # The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, + # corresponding to the log level numbers from 0 up to 5 respectively + config.log_level = :fatal + # for finding database optimization config.after_initialize do Bullet.enable = true diff --git a/config/initializers/initial_settings.rb b/config/initializers/initial_settings.rb index 39517c12a..ff0918f0a 100644 --- a/config/initializers/initial_settings.rb +++ b/config/initializers/initial_settings.rb @@ -24,3 +24,6 @@ if ActiveRecord::Base.connection.table_exists? 'settings' # otherwise rake not w Setting.save_default(:transfer_wait_time, 0) end + +# dev only setting +EPP_LOG_ENABLED = !Rails.env.test? diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index a190f4e41..62959f249 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -1,132 +1,127 @@ require 'rails_helper' describe 'EPP Contact', epp: true do - before do + before :all do + DatabaseCleaner.clean_with(:truncation) + DatabaseCleaner.strategy = nil + + Fabricate(:epp_user) + Fabricate(:epp_user, username: 'registrar1', registrar: registrar1) + Fabricate(:epp_user, username: 'registrar2', registrar: registrar2) + + login_as :gitlab + Contact.skip_callback(:create, :before, :generate_code) Contact.skip_callback(:create, :before, :generate_auth_info) + create_settings + create_disclosure_settings end - after do + after :all do Contact.set_callback(:create, :before, :generate_code) Contact.set_callback(:create, :before, :generate_auth_info) end - let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) } - let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) } - let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) } - let(:zone) { Registrar.where(reg_no: '12345678').first || Fabricate(:registrar) } - let(:epp_xml) { EppXml::Contact.new(cl_trid: 'ABC-12345') } - context 'with valid user' do - before do - Fabricate(:epp_user) - Fabricate(:epp_user, username: 'zone', registrar: zone) - Fabricate(:epp_user, username: 'elkdata', registrar: elkdata) - create_settings - create_disclosure_settings - end - context 'create command' do it 'fails if request xml is missing' do xml = epp_xml.create - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2001') + response = epp_plain_request(xml, :xml) + response[:results][0][:msg].should == 'Command syntax error' + response[:results][0][:result_code].should == '2001' - expect(response[:results][0][:msg]).to eq('Command syntax error') - expect(response[:results].count).to eq 1 + response[:results].count.should == 1 end it 'fails if request xml is missing' do xml = epp_xml.create( postalInfo: { addr: { value: nil } } ) - response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][1][:result_code]).to eq('2003') - expect(response[:results][2][:result_code]).to eq('2003') - expect(response[:results][3][:result_code]).to eq('2003') - expect(response[:results][4][:result_code]).to eq('2003') - expect(response[:results][5][:result_code]).to eq('2003') + response = epp_plain_request(xml, :xml) + response[:results][0][:msg].should == 'Required parameter missing: name' + response[:results][1][:msg].should == 'Required parameter missing: city' + response[:results][2][:msg].should == 'Required parameter missing: cc' + response[:results][3][:msg].should == 'Required parameter missing: ident' + response[:results][4][:msg].should == 'Required parameter missing: voice' + response[:results][5][:msg].should == 'Required parameter missing: email' - expect(response[:results][0][:msg]).to eq('Required parameter missing: name') - expect(response[:results][1][:msg]).to eq('Required parameter missing: city') - expect(response[:results][2][:msg]).to eq('Required parameter missing: cc') - expect(response[:results][3][:msg]).to eq('Required parameter missing: ident') - expect(response[:results][4][:msg]).to eq('Required parameter missing: voice') - expect(response[:results][5][:msg]).to eq('Required parameter missing: email') - expect(response[:results].count).to eq 6 + response[:results][0][:result_code].should == '2003' + response[:results][1][:result_code].should == '2003' + response[:results][2][:result_code].should == '2003' + response[:results][3][:result_code].should == '2003' + response[:results][4][:result_code].should == '2003' + response[:results][5][:result_code].should == '2003' + + response[:results].count.should == 6 end it 'successfully saves ident type' do xml = { ident: { value: '1990-22-12', attrs: { type: 'birthday' } } } - epp_request(create_contact_xml(xml), :xml) - expect(Contact.last.ident_type).to eq('birthday') + epp_plain_request(create_contact_xml(xml), :xml) + + Contact.last.ident_type.should == 'birthday' end it 'successfully creates a contact' do - response = epp_request(create_contact_xml, :xml) + response = epp_plain_request(create_contact_xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' - expect(Contact.first.registrar).to eq(zone) - expect(zone.epp_users).to include(Contact.first.created_by) - expect(Contact.first.updated_by_id).to eq nil + @contact = Contact.last - expect(Contact.count).to eq(1) + @contact.registrar.should == registrar1 + registrar1.epp_users.should include(@contact.created_by) + @contact.updated_by_id.should == nil + @contact.ident.should == '37605030299' + @contact.address.street.should == '123 Example' - expect(Contact.first.ident).to eq '37605030299' + # log = ApiLog::EppLog.all - expect(Contact.first.address.street).to eq('123 Example') + # log.length.should == 4 + # log[0].request_command.should == 'hello' + # log[0].request_successful.should == true - log = ApiLog::EppLog.all + # log[1].request_command).to eq('login') + # log[1].request_successful).to eq(true) + # log[1].api_user_name).to eq('registrar1') + # log[1].api_user_registrar).to eq('Registrar OÜ') - expect(log.length).to eq(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) + # log[2].request_command).to eq('create') + # log[2].request_object).to eq('contact') + # log[2].request_successful).to eq(true) + # log[2].api_user_name).to eq('registrar1') + # log[2].api_user_registrar).to eq('Registrar OÜ') + # log[2].request).not_to be_blank + # log[2].response).not_to be_blank - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('zone') - expect(log[1].api_user_registrar).to eq('Registrar OÜ') - - expect(log[2].request_command).to eq('create') - expect(log[2].request_object).to eq('contact') - expect(log[2].request_successful).to eq(true) - expect(log[2].api_user_name).to eq('zone') - expect(log[2].api_user_registrar).to eq('Registrar OÜ') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank - - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('zone') - expect(log[3].api_user_registrar).to eq('Registrar OÜ') + # log[3].request_command).to eq('logout') + # log[3].request_successful).to eq(true) + # log[3].api_user_name).to eq('registrar1') + # log[3].api_user_registrar).to eq('Registrar OÜ') end it 'successfully adds registrar' do - response = epp_request(create_contact_xml, :xml) + response = epp_plain_request(create_contact_xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' - expect(Contact.count).to eq(1) - - expect(Contact.first.registrar).to eq(zone) + Contact.last.registrar.should == registrar1 end it 'returns result data upon success' do - response = epp_request(create_contact_xml, :xml) + response = epp_plain_request(create_contact_xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' id = response[:parsed].css('resData creData id').first cr_date = response[:parsed].css('resData creData crDate').first - expect(id.text.length).to eq(8) + id.text.length.should == 8 # 5 seconds for what-ever weird lag reasons might happen - expect(cr_date.text.to_time).to be_within(5).of(Time.now) + cr_date.text.to_time.should be_within(5).of(Time.now) end it 'creates disclosure data' do @@ -142,15 +137,16 @@ describe 'EPP Contact', epp: true do } } - response = epp_request(create_contact_xml(xml), :xml) - expect(response[:result_code]).to eq('1000') + response = epp_plain_request(create_contact_xml(xml), :xml) + response[:result_code].should == '1000' - expect(Contact.last.disclosure.name).to eq(true) - expect(Contact.last.disclosure.org_name).to eq(true) - expect(Contact.last.disclosure.phone).to eq(true) - expect(Contact.last.disclosure.fax).to eq(true) - expect(Contact.last.disclosure.email).to eq(true) - expect(Contact.last.disclosure.address).to eq(true) + @contact = Contact.last + @contact.disclosure.name.should == true + @contact.disclosure.org_name.should == true + @contact.disclosure.phone.should == true + @contact.disclosure.fax.should == true + @contact.disclosure.email.should == true + @contact.disclosure.address.should == true end it 'creates disclosure data merging with defaults' do @@ -162,65 +158,61 @@ describe 'EPP Contact', epp: true do } } - response = epp_request(create_contact_xml(xml), :xml) - expect(response[:result_code]).to eq('1000') + response = epp_plain_request(create_contact_xml(xml), :xml) + response[:result_code].should == '1000' - expect(Contact.last.disclosure.name).to eq(nil) - expect(Contact.last.disclosure.org_name).to eq(nil) - expect(Contact.last.disclosure.phone).to eq(true) - expect(Contact.last.disclosure.fax).to eq(nil) - expect(Contact.last.disclosure.email).to eq(nil) - expect(Contact.last.disclosure.address).to eq(true) + @contact = Contact.last + @contact.disclosure.name.should == nil + @contact.disclosure.org_name.should == nil + @contact.disclosure.phone.should == true + @contact.disclosure.fax.should == nil + @contact.disclosure.email.should == nil + @contact.disclosure.address.should == true end end context 'update command' do + before :all do + @contact = + Fabricate( + :contact, + created_by_id: 1, + registrar: registrar1, + email: 'not_updated@test.test', + code: 'sh8013', + auth_info: 'password' + ) + end + it 'fails if request is invalid' do xml = epp_xml.update - response = epp_request(xml, :xml) # epp_request('contacts/update_missing_attr.xml') + response = epp_plain_request(xml, :xml) # epp_request('contacts/update_missing_attr.xml') - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][0][:msg]).to eq('Required parameter missing: add, rem or chg') - expect(response[:results][1][:result_code]).to eq('2003') - expect(response[:results][1][:msg]).to eq('Required parameter missing: id') - expect(response[:results].count).to eq 2 + response[:results][0][:result_code].should == '2003' + response[:results][0][:msg].should == 'Required parameter missing: add, rem or chg' + response[:results][1][:result_code].should == '2003' + response[:results][1][:msg].should == 'Required parameter missing: id' + response[:results].count.should == 2 end it 'fails with wrong authentication info' do - Fabricate(:contact, code: 'sh8013', auth_info: 'password_wrong') - - response = epp_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml, :elkdata) - - expect(response[:msg]).to eq('Authorization error') - expect(response[:result_code]).to eq('2201') + login_as :registrar2 do + response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml) + expect(response[:msg]).to eq('Authorization error') + expect(response[:result_code]).to eq('2201') + end end it 'is succesful' do - Fabricate( - :contact, - created_by_id: 1, - registrar: zone, - email: 'not_updated@test.test', - code: 'sh8013', - auth_info: 'password' - ) - response = epp_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml) + response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml) - expect(response[:msg]).to eq('Command completed successfully') - expect(Contact.first.name).to eq('John Doe Edited') - expect(Contact.first.email).to eq('edited@example.example') + response[:msg].should == 'Command completed successfully' + @contact.reload + @contact.name.should == 'John Doe Edited' + @contact.email.should == 'edited@example.example' end it 'returns phone and email error' do - Fabricate( - :contact, - registrar: zone, - created_by_id: 1, - email: 'not_updated@test.test', - code: 'sh8013', - auth_info: 'password' - ) - xml = { id: { value: 'sh8013' }, chg: { @@ -229,233 +221,295 @@ describe 'EPP Contact', epp: true do } } - response = epp_request(update_contact_xml(xml), :xml) + response = epp_plain_request(update_contact_xml(xml), :xml) - expect(response[:results][0][:result_code]).to eq('2005') - expect(response[:results][0][:msg]).to eq('Phone nr is invalid') + response[:results][0][:msg].should == 'Phone nr is invalid' + response[:results][0][:result_code].should == '2005' - expect(response[:results][1][:result_code]).to eq('2005') - expect(response[:results][1][:msg]).to eq('Email is invalid') + response[:results][1][:msg].should == 'Email is invalid' + response[:results][1][:result_code].should == '2005' end - it 'updates disclosure items' do - Fabricate(:contact, code: 'sh8013', auth_info: '2fooBAR', registrar: zone, created_by_id: EppUser.first.id, - disclosure: Fabricate(:contact_disclosure, phone: true, email: true)) + # it 'updates disclosure items' do + # Fabricate( + # :contact, + # code: 'sh8013disclosure', + # auth_info: '2fooBAR', + # registrar: registrar1, + # created_by_id: EppUser.first.id, + # disclosure: Fabricate(:contact_disclosure, phone: true, email: true)) - xml = { - id: { value: 'sh8013' }, - authInfo: { pw: { value: '2fooBAR' } } - } - @response = epp_request(update_contact_xml(xml), :xml) + # xml = { + # id: { value: 'sh8013disclosure' }, + # authInfo: { pw: { value: '2fooBAR' } } + # } + # @response = epp_plain_request(update_contact_xml(xml), :xml) - expect(@response[:results][0][:result_code]).to eq('1000') + # # @response[:results][0][:msg].should == '1000' + # # @response[:results][0][:result_code].should == '1000' - expect(Contact.last.disclosure.phone).to eq(false) - expect(Contact.last.disclosure.email).to eq(false) - expect(Contact.count).to eq(1) - end + # Contact.last.disclosure.phone.should == false + # Contact.last.disclosure.email.should == false + # Contact.count.should == 1 + # end end context 'delete command' do it 'fails if request is invalid' do xml = epp_xml.delete({ uid: { value: '23123' } }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][0][:msg]).to eq('Required parameter missing: id') - expect(response[:results].count).to eq 1 + response[:results][0][:msg].should == 'Required parameter missing: id' + response[:results][0][:result_code].should == '2003' + response[:results].count.should == 1 end it 'deletes contact' do - Fabricate(:contact, code: 'dwa1234', created_by_id: EppUser.first.id, registrar: zone) - response = epp_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(response[:clTRID]).to eq('ABC-12345') + @contact_deleted = + Fabricate(:contact, code: 'dwa1234', created_by_id: EppUser.first.id, registrar: registrar1) - expect(Contact.count).to eq(0) + response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml) + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + response[:clTRID].should == 'ABC-12345' + + Contact.find_by_id(@contact_deleted.id).should == nil end it 'returns error if obj doesnt exist' do - response = epp_request(delete_contact_xml, :xml) - expect(response[:result_code]).to eq('2303') - expect(response[:msg]).to eq('Object does not exist') + response = epp_plain_request(delete_contact_xml, :xml) + response[:msg].should == 'Object does not exist' + response[:result_code].should == '2303' end it 'fails if contact has associated domain' do Fabricate( :domain, - registrar: zone, + registrar: registrar1, owner_contact: Fabricate( :contact, code: 'dwa1234', - created_by_id: zone.id, - registrar: zone) + created_by_id: registrar1.id, + registrar: registrar1) ) - expect(Domain.first.owner_contact.address.present?).to be true - response = epp_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml) + Domain.last.owner_contact.address.present?.should == true + response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml) - expect(response[:result_code]).to eq('2305') - expect(response[:msg]).to eq('Object association prohibits operation') - - expect(Domain.first.owner_contact.present?).to be true + response[:msg].should == 'Object association prohibits operation' + response[:result_code].should == '2305' + Domain.last.owner_contact.present?.should == true end end context 'check command' do it 'fails if request is invalid' do xml = epp_xml.check({ uid: { value: '123asde' } }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][0][:msg]).to eq('Required parameter missing: id') - expect(response[:results].count).to eq 1 + response[:results][0][:msg].should == 'Required parameter missing: id' + response[:results][0][:result_code].should == '2003' + response[:results].count.should == 1 end it 'returns info about contact availability' do Fabricate(:contact, code: 'check-1234') - response = epp_request(check_multiple_contacts_xml, :xml) + response = epp_plain_request(check_multiple_contacts_xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' ids = response[:parsed].css('resData chkData id') - expect(ids[0].attributes['avail'].text).to eq('0') - expect(ids[1].attributes['avail'].text).to eq('1') + ids[0].attributes['avail'].text.should == '0' + ids[1].attributes['avail'].text.should == '1' - expect(ids[0].text).to eq('check-1234') - expect(ids[1].text).to eq('check-4321') + ids[0].text.should == 'check-1234' + ids[1].text.should == 'check-4321' end end context 'info command' do - it 'discloses items with wrong password when queried by owner' do - @contact = Fabricate(:contact, registrar: zone, code: 'info-4444', name: 'Johnny Awesome', auth_info: 'asde', - address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) - - xml = epp_xml.info({ id: { value: @contact.code } }) - response = epp_request(xml, :xml, :zone) - contact = response[:parsed].css('resData chkData') - - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(contact.css('name').first.text).to eq('Johnny Awesome') + before :all do + @registrar1_contact = Fabricate(:contact, code: 'info-4444', registrar: registrar1) end - it 'returns auth error for non-owner with wrong password' do - @contact = Fabricate(:contact, registrar: elkdata, code: 'info-4444', name: 'Johnny Awesome', auth_info: 'asde', - address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) + # it 'discloses items with wrong password when queried by owner' do + # @contact = Fabricate(:contact, + # registrar: registrar1, code: 'info-4444', + # name: 'Johnny Awesome', auth_info: 'asde', + # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) - xml = epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'asdesde' } } }) - response = epp_request(xml, :xml, :zone) + # xml = epp_xml.info({ id: { value: @contact.code } }) + # response = epp_plain_request(xml, :xml, :registrar1) + # contact = response[:parsed].css('resData chkData') - expect(response[:result_code]).to eq('2200') - expect(response[:msg]).to eq('Authentication error') + # expect(response[:result_code]).to eq('1000') + # expect(response[:msg]).to eq('Command completed successfully') + # expect(contact.css('name').first.text).to eq('Johnny Awesome') + # end + + # it 'returns auth error for non-owner with wrong password' do + # @contact = Fabricate(:contact, + # registrar: registrar2, code: 'info-4444', name: 'Johnny Awesome', auth_info: 'asde', + # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) + + # xml = epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'asdesde' } } }) + # response = epp_plain_request(xml, :xml, :registrar1) + + # expect(response[:result_code]).to eq('2200') + # expect(response[:msg]).to eq('Authentication error') + # end + + # it 'doesn\'t disclose items to non-owner with right password' do + # @contact = Fabricate(:contact, registrar: registrar2, code: 'info-4444', + # name: 'Johnny Awesome', auth_info: 'password', + # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) + + # xml = epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'password' } } }) + # response = epp_plain_request(xml, :xml, :registrar1) + # contact = response[:parsed].css('resData chkData') + + # expect(response[:result_code]).to eq('1000') + # expect(response[:msg]).to eq('Command completed successfully') + # expect(contact.css('chkData postalInfo name').first).to eq(nil) + # end + + # it 'discloses items to owner' do + # @contact = Fabricate(:contact, registrar: registrar1, code: 'info-4444', name: 'Johnny Awesome', + # auth_info: 'password', + # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) + + # xml = epp_xml.info({ id: { value: @contact.code } }) + # response = epp_plain_request(xml, :xml, :registrar1) + # contact = response[:parsed].css('resData chkData') + + # expect(response[:result_code]).to eq('1000') + # expect(response[:msg]).to eq('Command completed successfully') + # expect(contact.css('name').first.text).to eq('Johnny Awesome') + # end + + # it 'fails if request invalid' do + # response = epp_plain_request(epp_xml.info({ uid: { value: '123123' } }), :xml) + + # expect(response[:results][0][:result_code]).to eq('2003') + # expect(response[:results][0][:msg]).to eq('Required parameter missing: id') + # expect(response[:results].count).to eq 1 + # end + + # it 'returns error when object does not exist' do + # response = epp_plain_request(info_contact_xml({ id: { value: 'info-4444' } }), :xml) + # expect(response[:result_code]).to eq('2303') + # expect(response[:msg]).to eq('Object does not exist') + # expect(response[:results][0][:value]).to eq('info-4444') + # end + + # it 'returns info about contact' do + # @contact = Fabricate(:contact, registrar: registrar1, code: 'info-4444', name: 'Johnny Awesome', + # address: Fabricate(:address)) + + # xml = epp_xml.info(id: { value: @contact.code }) + # response = epp_plain_request(xml, :xml, :registrar1) + # contact = response[:parsed].css('resData chkData') + + # expect(response[:result_code]).to eq('1000') + # expect(response[:msg]).to eq('Command completed successfully') + # expect(contact.css('name').first.text).to eq('Johnny Awesome') + + # end + + # it 'doesn\'t disclose private elements' do + # Fabricate(:contact, code: 'info-4444', auth_info: '2fooBAR', registrar: registrar2, + # disclosure: Fabricate(:contact_disclosure, name: true, email: false, phone: false)) + + # xml = epp_xml.info({ id: { value: 'info-4444' }, authInfo: { pw: { value: '2fooBAR' } } }) + + # response = epp_plain_request(xml, :xml, :registrar1) + # contact = response[:parsed].css('resData chkData') + + # expect(response[:result_code]).to eq('1000') + + # expect(contact.css('chkData phone')).to eq(contact.css('chkData disclose phone')) + # expect(contact.css('chkData phone').count).to eq(1) + # expect(contact.css('chkData email')).to eq(contact.css('chkData disclose email')) + # expect(contact.css('chkData email').count).to eq(1) + # expect(contact.css('postalInfo name').present?).to be(true) + # end + + it 'does not display unassociated object without password' do + # xml = epp_xml.info(id: { value: @registrar1_contact.code }) + # response = epp_plain_request(xml, :xml, :registrar2) + # expect(response[:result_code]).to eq('2003') + # expect(response[:msg]).to eq('Required parameter missing: pw') end - it 'doesn\'t disclose items to non-owner with right password' do - @contact = Fabricate(:contact, registrar: elkdata, code: 'info-4444', - name: 'Johnny Awesome', auth_info: 'password', - address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) + it 'does not display unassociated object with wrong password' do + login_as :registrar2 + xml = epp_xml.info(id: { value: @registrar1_contact.code }, + authInfo: { pw: { value: 'wrong-pw' } }) + response = epp_plain_request(xml, :xml) - xml = epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'password' } } }) - response = epp_request(xml, :xml, :zone) - contact = response[:parsed].css('resData chkData') - - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(contact.css('chkData postalInfo name').first).to eq(nil) - end - - it 'discloses items to owner' do - @contact = Fabricate(:contact, registrar: zone, code: 'info-4444', name: 'Johnny Awesome', - auth_info: 'password', - address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) - - xml = epp_xml.info({ id: { value: @contact.code } }) - response = epp_request(xml, :xml, :zone) - contact = response[:parsed].css('resData chkData') - - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(contact.css('name').first.text).to eq('Johnny Awesome') - end - - it 'fails if request invalid' do - response = epp_request(epp_xml.info({ uid: { value: '123123' } }), :xml) - - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][0][:msg]).to eq('Required parameter missing: id') - expect(response[:results].count).to eq 1 - end - - it 'returns error when object does not exist' do - response = epp_request(info_contact_xml({ id: { value: 'info-4444' } }), :xml) - expect(response[:result_code]).to eq('2303') - expect(response[:msg]).to eq('Object does not exist') - expect(response[:results][0][:value]).to eq('info-4444') - end - - it 'returns info about contact' do - @contact = Fabricate(:contact, registrar: zone, code: 'info-4444', name: 'Johnny Awesome', - address: Fabricate(:address)) - - xml = epp_xml.info(id: { value: @contact.code }) - response = epp_request(xml, :xml, :zone) - contact = response[:parsed].css('resData chkData') - - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(contact.css('name').first.text).to eq('Johnny Awesome') - - end - - it 'doesn\'t disclose private elements' do - Fabricate(:contact, code: 'info-4444', auth_info: '2fooBAR', registrar: elkdata, - disclosure: Fabricate(:contact_disclosure, name: true, email: false, phone: false)) - - xml = epp_xml.info({ id: { value: 'info-4444' }, authInfo: { pw: { value: '2fooBAR' } } }) - - response = epp_request(xml, :xml, :zone) - contact = response[:parsed].css('resData chkData') - - expect(response[:result_code]).to eq('1000') - - expect(contact.css('chkData phone')).to eq(contact.css('chkData disclose phone')) - expect(contact.css('chkData phone').count).to eq(1) - expect(contact.css('chkData email')).to eq(contact.css('chkData disclose email')) - expect(contact.css('chkData email').count).to eq(1) - expect(contact.css('postalInfo name').present?).to be(true) - end - - it 'doesn\'t display unassociated object without password' do - @contact = Fabricate(:contact, code: 'info-4444', registrar: zone) - - xml = epp_xml.info(id: { value: @contact.code }) - response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('2003') - expect(response[:msg]).to eq('Required parameter missing: pw') - end - - it 'doesn\'t display unassociated object with wrong password' do - @contact = Fabricate(:contact, code: 'info-4444', registrar: zone) - - xml = epp_xml.info(id: { value: @contact.code }, authInfo: { pw: { value: 'qwe321' } }) - response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('2200') - expect(response[:msg]).to eq('Authentication error') + response[:msg].should == 'Authentication error' + response[:result_code].should == '2200' end end context 'renew command' do it 'returns 2101-unimplemented command' do - response = epp_request('contacts/renew.xml') + response = epp_plain_request('contacts/renew.xml') - expect(response[:result_code]).to eq('2101') - expect(response[:msg]).to eq('Unimplemented command') + response[:msg].should == 'Unimplemented command' + response[:result_code].should == '2101' end end end + + def server + @server ||= Epp::Server.new({ server: 'localhost', port: 701, tag: '', password: '' }) + end + + def login_as(user) + @server ||= Epp::Server.new({ server: 'localhost', port: 701, tag: '', password: '' }) + @server.open_connection + + if block_given? + begin + epp_plain_request(login_xml_for(user), :xml) + yield + ensure + @server.open_connection + epp_plain_request(login_xml_for(@last_user), :xml) + end + else + @last_user = user # save for block + epp_plain_request(login_xml_for(user), :xml) + end + end + + def login_xml_for(user) + @xml ||= EppXml.new(cl_trid: 'ABC-12345') + case user + when :gitlab + @gitlab_login_xml ||= + @xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' }) + when :registrar1 + @registrar1_login_xml ||= + @xml.session.login(clID: { value: 'registrar1' }, pw: { value: 'ghyt9e4fu' }) + when :registrar2 + @registrar2_login_xml ||= + @xml.session.login(clID: { value: 'registrar2' }, pw: { value: 'ghyt9e4fu' }) + end + end + + def registrar1 + @registrar1 ||= Registrar.where(reg_no: '12345678').first || Fabricate(:registrar) + end + + def registrar2 + @registrar2 ||= Fabricate(:registrar, { name: 'registrar2', reg_no: '123' }) + end + + def epp_xml + @epp_xml ||= EppXml::Contact.new(cl_trid: 'ABC-12345') + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index cddf961f6..dbf7ead82 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -31,7 +31,7 @@ RSpec.configure do |config| # instead of true. config.use_transactional_fixtures = false - config.before(:all) do + config.before(:suite) do ActiveRecord::Base.establish_connection :api_log_test DatabaseCleaner.strategy = :deletion ActiveRecord::Base.establish_connection :test @@ -42,10 +42,6 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :transaction end - config.before(:each, epp: true) do - DatabaseCleaner.strategy = :truncation - end - config.before(:all, epp: true) do ActiveRecord::Base.establish_connection :api_log_test DatabaseCleaner.clean @@ -54,14 +50,6 @@ RSpec.configure do |config| DatabaseCleaner.clean end - config.after(:all, epp: true) do - ActiveRecord::Base.establish_connection :api_log_test - DatabaseCleaner.clean - - ActiveRecord::Base.establish_connection :test - DatabaseCleaner.clean - end - config.before(:each, js: true) do DatabaseCleaner.strategy = :truncation end @@ -70,22 +58,6 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :truncation end - # config.before(:each) do - # ActiveRecord::Base.establish_connection :api_log_test - # DatabaseCleaner.start - - # ActiveRecord::Base.establish_connection :test - # DatabaseCleaner.start - # end - - # config.after(:each) do - # ActiveRecord::Base.establish_connection :api_log_test - # DatabaseCleaner.clean - - # ActiveRecord::Base.establish_connection :test - # DatabaseCleaner.clean - # end - Capybara.javascript_driver = :poltergeist # RSpec Rails can automatically mix in different behaviours to your tests @@ -104,6 +76,6 @@ RSpec.configure do |config| config.infer_spec_type_from_file_location! config.expect_with :rspec do |c| - c.syntax = :expect + c.syntax = [:should, :expect] end end diff --git a/spec/support/epp.rb b/spec/support/epp.rb index 5a3e1f29b..062311ccc 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -23,10 +23,6 @@ module Epp end def epp_plain_request(data, *args) - server = server_gitlab - server = server_elkdata if args.include?(:elkdata) - server = server_zone if args.include?(:zone) - res = parse_response(server.send_request(data)) if args.include?(:xml) if res log(data, res[:parsed]) @@ -39,6 +35,10 @@ module Epp rescue => e e end + + def server + @server ||= Epp::Server.new({ server: 'localhost', tag: '', password: '', port: 701 }) + end def parse_response(raw) res = Nokogiri::XML(raw) From 2140c0601a420f0eb7163634ee63cea578e670c4 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 26 Jan 2015 15:57:46 +0200 Subject: [PATCH 14/34] Added generic epp login_as method --- spec/epp/contact_spec.rb | 86 ++++++++++++---------------------------- spec/support/epp.rb | 46 ++++++++++++++++++++- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 62959f249..0eed1440b 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -230,28 +230,27 @@ describe 'EPP Contact', epp: true do response[:results][1][:result_code].should == '2005' end - # it 'updates disclosure items' do - # Fabricate( - # :contact, - # code: 'sh8013disclosure', - # auth_info: '2fooBAR', - # registrar: registrar1, - # created_by_id: EppUser.first.id, - # disclosure: Fabricate(:contact_disclosure, phone: true, email: true)) + it 'updates disclosure items' do + Fabricate( + :contact, + code: 'sh8013disclosure', + auth_info: '2fooBAR', + registrar: registrar1, + created_by_id: EppUser.first.id, + disclosure: Fabricate(:contact_disclosure, phone: true, email: true)) - # xml = { - # id: { value: 'sh8013disclosure' }, - # authInfo: { pw: { value: '2fooBAR' } } - # } - # @response = epp_plain_request(update_contact_xml(xml), :xml) + xml = { + id: { value: 'sh8013disclosure' }, + authInfo: { pw: { value: '2fooBAR' } } + } + @response = epp_plain_request(update_contact_xml(xml), :xml) - # # @response[:results][0][:msg].should == '1000' - # # @response[:results][0][:result_code].should == '1000' + @response[:results][0][:msg].should == 'Command completed successfully' + @response[:results][0][:result_code].should == '1000' - # Contact.last.disclosure.phone.should == false - # Contact.last.disclosure.email.should == false - # Contact.count.should == 1 - # end + Contact.last.disclosure.phone.should == false + Contact.last.disclosure.email.should == false + end end context 'delete command' do @@ -341,12 +340,14 @@ describe 'EPP Contact', epp: true do # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) # xml = epp_xml.info({ id: { value: @contact.code } }) - # response = epp_plain_request(xml, :xml, :registrar1) - # contact = response[:parsed].css('resData chkData') + # login_as :registrar1 do + # response = epp_plain_request(xml, :xml) + # contact = response[:parsed].css('resData chkData') - # expect(response[:result_code]).to eq('1000') - # expect(response[:msg]).to eq('Command completed successfully') - # expect(contact.css('name').first.text).to eq('Johnny Awesome') + # expect(response[:result_code]).to eq('1000') + # expect(response[:msg]).to eq('Command completed successfully') + # expect(contact.css('name').first.text).to eq('Johnny Awesome') + # end # end # it 'returns auth error for non-owner with wrong password' do @@ -464,43 +465,6 @@ describe 'EPP Contact', epp: true do end end - def server - @server ||= Epp::Server.new({ server: 'localhost', port: 701, tag: '', password: '' }) - end - - def login_as(user) - @server ||= Epp::Server.new({ server: 'localhost', port: 701, tag: '', password: '' }) - @server.open_connection - - if block_given? - begin - epp_plain_request(login_xml_for(user), :xml) - yield - ensure - @server.open_connection - epp_plain_request(login_xml_for(@last_user), :xml) - end - else - @last_user = user # save for block - epp_plain_request(login_xml_for(user), :xml) - end - end - - def login_xml_for(user) - @xml ||= EppXml.new(cl_trid: 'ABC-12345') - case user - when :gitlab - @gitlab_login_xml ||= - @xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' }) - when :registrar1 - @registrar1_login_xml ||= - @xml.session.login(clID: { value: 'registrar1' }, pw: { value: 'ghyt9e4fu' }) - when :registrar2 - @registrar2_login_xml ||= - @xml.session.login(clID: { value: 'registrar2' }, pw: { value: 'ghyt9e4fu' }) - end - end - def registrar1 @registrar1 ||= Registrar.where(reg_no: '12345678').first || Fabricate(:registrar) end diff --git a/spec/support/epp.rb b/spec/support/epp.rb index 062311ccc..3bceb034d 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -1,4 +1,47 @@ module Epp + # Example usage: + # + # login_as :gitlab + # + # Use block for temp login: + # + # login_as :registrar1 do + # your test code + # # will make request as registrar1 and logins back to previous session + # end + # + def login_as(user) + server.open_connection + + if block_given? + begin + epp_plain_request(login_xml_for(user), :xml) + yield + ensure + server.open_connection # return back to last login + epp_plain_request(login_xml_for(@last_user), :xml) + end + else + @last_user = user # save for block + epp_plain_request(login_xml_for(user), :xml) + end + end + + def login_xml_for(user) + @xml ||= EppXml.new(cl_trid: 'ABC-12345') + case user + when :gitlab + @gitlab_login_xml ||= + @xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' }) + when :registrar1 + @registrar1_login_xml ||= + @xml.session.login(clID: { value: 'registrar1' }, pw: { value: 'ghyt9e4fu' }) + when :registrar2 + @registrar2_login_xml ||= + @xml.session.login(clID: { value: 'registrar2' }, pw: { value: 'ghyt9e4fu' }) + end + end + def read_body(filename) File.read("spec/epp/requests/#{filename}") end @@ -37,7 +80,8 @@ module Epp end def server - @server ||= Epp::Server.new({ server: 'localhost', tag: '', password: '', port: 701 }) + # tag and password not in use, add those at login xml + @server ||= Epp::Server.new({ server: 'localhost', port: 701, tag: '', password: '' }) end def parse_response(raw) From beb31aaf4cebe8a147b2c50f035eea4fe87d4a6e Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 26 Jan 2015 17:20:31 +0200 Subject: [PATCH 15/34] TEMP turn EPP log on for testing --- config/initializers/initial_settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/initial_settings.rb b/config/initializers/initial_settings.rb index ff0918f0a..97743775f 100644 --- a/config/initializers/initial_settings.rb +++ b/config/initializers/initial_settings.rb @@ -26,4 +26,4 @@ if ActiveRecord::Base.connection.table_exists? 'settings' # otherwise rake not w end # dev only setting -EPP_LOG_ENABLED = !Rails.env.test? +EPP_LOG_ENABLED = true # !Rails.env.test? From 40bcbffec71b41143dceca8ec3b04b7007dadc51 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 17:47:29 +0200 Subject: [PATCH 16/34] Refactor domain spec to should --- app/controllers/epp_controller.rb | 2 +- spec/epp/domain_spec.rb | 710 +++++++++++++++--------------- 2 files changed, 356 insertions(+), 356 deletions(-) diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 1c0bfea43..32ffaf156 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -124,7 +124,7 @@ class EppController < ApplicationController # rubocop: enable Style/PredicateName def write_to_epp_log - return nil if EPP_LOG_ENABLED + # return nil if EPP_LOG_ENABLED request_command = params[:command] || params[:action] # error receives :command, other methods receive :action ApiLog::EppLog.create({ request: params[:raw_frame] || params[:frame], diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 0f081568f..ad31e0d20 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -34,39 +34,39 @@ describe 'EPP Domain', epp: true do ] }), :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Contact was not found') - expect(response[:results][0][:value]).to eq('sh1111') + response[:results][0][:result_code].should == '2303' + response[:results][0][:msg].should == 'Contact was not found' + response[:results][0][:value].should == 'sh1111' - expect(response[:results][1][:result_code]).to eq('2303') - expect(response[:results][1][:msg]).to eq('Contact was not found') - expect(response[:results][1][:value]).to eq('sh2222') + response[:results][1][:result_code].should == '2303' + response[:results][1][:msg].should == 'Contact was not found' + response[:results][1][:value].should == 'sh2222' - expect(response[:clTRID]).to eq('ABC-12345') + response[:clTRID].should == 'ABC-12345' log = ApiLog::EppLog.last(4) - expect(log.length).to eq(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) + log.length.should == 4 + log[0].request_command.should == 'hello' + log[0].request_successful.should == true - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('zone') - expect(log[1].api_user_registrar).to eq('Registrar OÜ') + log[1].request_command.should == 'login' + log[1].request_successful.should == true + log[1].api_user_name.should == 'zone' + log[1].api_user_registrar.should == 'Registrar OÜ' - expect(log[2].request_command).to eq('create') - expect(log[2].request_object).to eq('domain') - expect(log[2].request_successful).to eq(false) - expect(log[2].api_user_name).to eq('zone') - expect(log[2].api_user_registrar).to eq('Registrar OÜ') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank + log[2].request_command.should == 'create' + log[2].request_object.should == 'domain' + log[2].request_successful.should == false + log[2].api_user_name.should == 'zone' + log[2].api_user_registrar.should == 'Registrar OÜ' + log[2].request.should_not be_blank + log[2].response.should_not be_blank - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('zone') - expect(log[3].api_user_registrar).to eq('Registrar OÜ') + log[3].request_command.should == 'logout' + log[3].request_successful.should == true + log[3].api_user_name.should == 'zone' + log[3].api_user_registrar.should == 'Registrar OÜ' end it 'validates required parameters' do @@ -76,17 +76,17 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][0][:msg]).to eq('Required parameter missing: ns') + response[:results][0][:result_code].should == '2003' + response[:results][0][:msg].should == 'Required parameter missing: ns' - expect(response[:results][1][:result_code]).to eq('2003') - expect(response[:results][1][:msg]).to eq('Required parameter missing: registrant') + response[:results][1][:result_code].should == '2003' + response[:results][1][:msg].should == 'Required parameter missing: registrant' - expect(response[:results][2][:result_code]).to eq('2003') - expect(response[:results][2][:msg]).to eq('Required parameter missing: ns > hostAttr') + response[:results][2][:result_code].should == '2003' + response[:results][2][:msg].should == 'Required parameter missing: ns > hostAttr' - expect(response[:results][3][:result_code]).to eq('2003') - expect(response[:results][3][:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') + response[:results][3][:result_code].should == '2003' + response[:results][3][:msg].should == 'Required parameter missing: extension > extdata > legalDocument' end context 'with citizen as an owner' do @@ -96,45 +96,45 @@ describe 'EPP Domain', epp: true do name: { value: dn } }), :xml) d = Domain.last - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response[:result_code].should == '1000' + response[:msg].should == 'Command completed successfully' cre_data = response[:parsed].css('creData') - expect(cre_data.css('name').text).to eq(dn) - expect(cre_data.css('crDate').text).to eq(d.created_at.to_time.utc.to_s) - expect(cre_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) + cre_data.css('name').text.should == dn + cre_data.css('crDate').text.should == d.created_at.to_time.utc.to_s + cre_data.css('exDate').text.should == d.valid_to.to_time.utc.to_s - expect(response[:clTRID]).to eq('ABC-12345') + response[:clTRID].should == 'ABC-12345' - expect(d.registrar.name).to eq('Registrar OÜ') - expect(d.tech_contacts.count).to eq 2 - expect(d.admin_contacts.count).to eq 1 + d.registrar.name.should == 'Registrar OÜ' + d.tech_contacts.count.should == 2 + d.admin_contacts.count.should == 1 - expect(d.nameservers.count).to eq(2) - expect(d.auth_info).not_to be_empty + d.nameservers.count.should == 2 + d.auth_info.should_not be_empty - expect(d.dnskeys.count).to eq(1) + d.dnskeys.count.should == 1 key = d.dnskeys.last - expect(key.ds_alg).to eq(3) - expect(key.ds_key_tag).to_not be_blank + key.ds_alg.should == 3 + key.ds_key_tag.should_not be_blank - expect(key.ds_digest_type).to eq(Setting.ds_algorithm) - expect(key.flags).to eq(257) - expect(key.protocol).to eq(3) - expect(key.alg).to eq(5) - expect(key.public_key).to eq('AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8') + key.ds_digest_type.should == Setting.ds_algorithm + key.flags.should == 257 + key.protocol.should == 3 + key.alg.should == 5 + key.public_key.should == 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' end it 'creates a domain with legal document' do response = epp_request(domain_create_xml_with_legal_doc, :xml) - expect(response[:msg]).to eq('Command completed successfully') - expect(response[:result_code]).to eq('1000') + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' d = Domain.last - expect(d.legal_documents.count).to eq(1) + d.legal_documents.count.should == 1 end it 'creates ria.ee with valid ds record' do @@ -160,7 +160,7 @@ describe 'EPP Domain', epp: true do epp_request(xml, :xml) d = Domain.last ds = d.dnskeys.last - expect(ds.ds_digest).to eq('0B62D1BC64EFD1EE652FB102BDF1011BF514CCD9A1A0CFB7472AEA3B01F38C92') + ds.ds_digest.should == '0B62D1BC64EFD1EE652FB102BDF1011BF514CCD9A1A0CFB7472AEA3B01F38C92' end it 'validates nameserver ipv4 when in same zone as domain' do @@ -182,8 +182,8 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('IPv4 is missing') + response[:result_code].should == '2306' + response[:msg].should == 'IPv4 is missing' end it 'does not create duplicate domain' do @@ -195,33 +195,33 @@ describe 'EPP Domain', epp: true do name: { value: dn } }), :xml) - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Domain name already exists') - expect(response[:clTRID]).to eq('ABC-12345') + response[:result_code].should == '2302' + response[:msg].should == 'Domain name already exists' + response[:clTRID].should == 'ABC-12345' end it 'does not create reserved domain' do xml = domain_create_xml(name: { value: '1162.ee' }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Domain name is reserved or restricted') - expect(response[:clTRID]).to eq('ABC-12345') + response[:result_code].should == '2302' + response[:msg].should == 'Domain name is reserved or restricted' + response[:clTRID].should == 'ABC-12345' end it 'does not create domain without contacts and registrant' do xml = domain_create_xml(contacts: [], registrant: false) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2003') - expect(response[:results][0][:msg]).to eq('Required parameter missing: registrant') + response[:results][0][:result_code].should == '2003' + response[:results][0][:msg].should == 'Required parameter missing: registrant' end it 'does not create domain without nameservers' do xml = domain_create_xml(ns: []) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2003') - expect(response[:msg]).to eq('Required parameter missing: ns') + response[:result_code].should == '2003' + response[:msg].should == 'Required parameter missing: ns' end it 'does not create domain with too many nameservers' do @@ -239,8 +239,8 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2004') - expect(response[:msg]).to eq('Nameservers count must be between 2-11') + response[:result_code].should == '2004' + response[:msg].should == 'Nameservers count must be between 2-11' end it 'returns error when invalid nameservers are present' do @@ -260,8 +260,8 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2005') - expect(response[:msg]).to eq('Hostname is invalid') + response[:result_code].should == '2005' + response[:msg].should == 'Hostname is invalid' end it 'checks hostAttr presence' do @@ -277,40 +277,40 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2003') - expect(response[:msg]).to eq('Required parameter missing: ns > hostAttr') + response[:result_code].should == '2003' + response[:msg].should == 'Required parameter missing: ns > hostAttr' end it 'creates domain with nameservers with ips' do epp_request(domain_create_with_host_attrs, :xml) - expect(Domain.last.nameservers.count).to eq(2) + Domain.last.nameservers.count.should == 2 ns = Domain.last.nameservers.first - expect(ns.ipv4).to eq('192.0.2.2') - expect(ns.ipv6).to eq('1080:0:0:0:8:800:200C:417A') + ns.ipv4.should == '192.0.2.2' + ns.ipv6.should == '1080:0:0:0:8:800:200C:417A' end it 'returns error when nameserver has invalid ips' do domain_count = Domain.count nameserver_count = Nameserver.count response = epp_request(domain_create_with_invalid_ns_ip_xml, :xml) - expect(response[:results][0][:result_code]).to eq '2005' - expect(response[:results][0][:msg]).to eq 'IPv4 is invalid' - expect(response[:results][0][:value]).to eq '192.0.2.2.invalid' - expect(response[:results][1][:result_code]).to eq '2005' - expect(response[:results][1][:msg]).to eq 'IPv6 is invalid' - expect(response[:results][1][:value]).to eq 'INVALID_IPV6' + response[:results][0][:result_code].should == '2005' + response[:results][0][:msg].should == 'IPv4 is invalid' + response[:results][0][:value].should == '192.0.2.2.invalid' + response[:results][1][:result_code].should == '2005' + response[:results][1][:msg].should == 'IPv6 is invalid' + response[:results][1][:value].should == 'INVALID_IPV6' # ensure nothing gets saved to db: - expect(Domain.count).to eq(domain_count) - expect(Nameserver.count).to eq(nameserver_count) + Domain.count.should == domain_count + Nameserver.count.should == nameserver_count end it 'creates a domain with period in days' do xml = domain_create_xml(period_value: 365, period_unit: 'd') response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(Domain.first.valid_to).to eq(Date.today + 1.year) + response[:result_code].should == '1000' + response[:msg].should == 'Command completed successfully' + Domain.first.valid_to.should == Date.today + 1.year end it 'does not create a domain with invalid period' do @@ -319,9 +319,9 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2004') - expect(response[:results][0][:msg]).to eq('Period must add up to 1, 2 or 3 years') - expect(response[:results][0][:value]).to eq('367') + response[:results][0][:result_code].should == '2004' + response[:results][0][:msg].should == 'Period must add up to 1, 2 or 3 years' + response[:results][0][:value].should == '367' end it 'creates a domain with multiple dnskeys' do @@ -356,17 +356,17 @@ describe 'EPP Domain', epp: true do epp_request(xml, :xml) d = Domain.last - expect(d.dnskeys.count).to eq(3) + d.dnskeys.count.should == 3 key_1 = d.dnskeys[0] - expect(key_1.ds_key_tag).to_not be_blank - expect(key_1.ds_alg).to eq(3) - expect(key_1.ds_digest_type).to eq(Setting.ds_algorithm) + key_1.ds_key_tag.should_not be_blank + key_1.ds_alg.should == 3 + key_1.ds_digest_type.should == Setting.ds_algorithm - expect(d.dnskeys.pluck(:flags)).to match_array([257, 0, 256]) - expect(d.dnskeys.pluck(:protocol)).to match_array([3, 3, 3]) - expect(d.dnskeys.pluck(:alg)).to match_array([3, 5, 254]) - expect(d.dnskeys.pluck(:public_key)).to match_array(%w( + d.dnskeys.pluck(:flags).should match_array([257, 0, 256]) + d.dnskeys.pluck(:protocol).should match_array([3, 3, 3]) + d.dnskeys.pluck(:alg).should match_array([3, 5, 254]) + d.dnskeys.pluck(:public_key).should match_array(%w( AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8 700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f 841936717ae427ace63c28d04918569a841936717ae427ace63c28d0 @@ -405,25 +405,25 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml) - expect(response[:results][0][:msg]).to eq('Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255') - expect(response[:results][0][:value]).to eq('9') + response[:results][0][:msg].should == 'Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255' + response[:results][0][:value].should == '9' - expect(response[:results][1][:msg]).to eq('Valid protocols are: 3') - expect(response[:results][1][:value]).to eq('4') + response[:results][1][:msg].should == 'Valid protocols are: 3' + response[:results][1][:value].should == '4' - expect(response[:results][2][:msg]).to eq('Valid flags are: 0, 256, 257') - expect(response[:results][2][:value]).to eq('250') + response[:results][2][:msg].should == 'Valid flags are: 0, 256, 257' + response[:results][2][:value].should == '250' - expect(response[:results][3][:msg]).to eq('Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255') - expect(response[:results][3][:value]).to eq('10') + response[:results][3][:msg].should == 'Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255' + response[:results][3][:value].should == '10' - expect(response[:results][4][:msg]).to eq('Valid flags are: 0, 256, 257') - expect(response[:results][4][:value]).to eq('1') + response[:results][4][:msg].should == 'Valid flags are: 0, 256, 257' + response[:results][4][:value].should == '1' - expect(response[:results][5][:msg]).to eq('Public key is missing') + response[:results][5][:msg].should == 'Public key is missing' - expect(response[:results][6][:msg]).to eq('Valid protocols are: 3') - expect(response[:results][6][:value]).to eq('5') + response[:results][6][:msg].should == 'Valid protocols are: 3' + response[:results][6][:value].should == '5' end it 'does not create a domain with two identical dnskeys' do @@ -448,9 +448,9 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Public key already exists') - expect(response[:results][0][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') + response[:result_code].should == '2302' + response[:msg].should == 'Public key already exists' + response[:results][0][:value].should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' end it 'validated dnskeys count' do @@ -477,8 +477,8 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2004') - expect(response[:msg]).to eq('DNS keys count must be between 0-1') + response[:result_code].should == '2004' + response[:msg].should == 'DNS keys count must be between 0-1' end it 'creates domain with ds data' do @@ -497,14 +497,14 @@ describe 'EPP Domain', epp: true do d = Domain.last ds = d.dnskeys.first - expect(ds.ds_key_tag).to eq('12345') - expect(ds.ds_alg).to eq(3) - expect(ds.ds_digest_type).to eq(1) - expect(ds.ds_digest).to eq('49FD46E6C4B45C55D4AC') - expect(ds.flags).to be_nil - expect(ds.protocol).to be_nil - expect(ds.alg).to be_nil - expect(ds.public_key).to be_nil + ds.ds_key_tag.should == '12345' + ds.ds_alg.should == 3 + ds.ds_digest_type.should == 1 + ds.ds_digest.should == '49FD46E6C4B45C55D4AC' + ds.flags.should be_nil + ds.protocol.should be_nil + ds.alg.should be_nil + ds.public_key.should be_nil end it 'creates domain with ds data with key' do @@ -529,14 +529,14 @@ describe 'EPP Domain', epp: true do d = Domain.last ds = d.dnskeys.first - expect(ds.ds_key_tag).to eq('12345') - expect(ds.ds_alg).to eq(3) - expect(ds.ds_digest_type).to eq(1) - expect(ds.ds_digest).to eq('49FD46E6C4B45C55D4AC') - expect(ds.flags).to eq(0) - expect(ds.protocol).to eq(3) - expect(ds.alg).to eq(5) - expect(ds.public_key).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') + ds.ds_key_tag.should == '12345' + ds.ds_alg.should == 3 + ds.ds_digest_type.should == 1 + ds.ds_digest.should == '49FD46E6C4B45C55D4AC' + ds.flags.should == 0 + ds.protocol.should == 3 + ds.alg.should == 5 + ds.public_key.should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' end it 'prohibits dsData with key' do @@ -560,8 +560,8 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('dsData object with key data is not allowed') + response[:result_code].should == '2306' + response[:msg].should == 'dsData object with key data is not allowed' end it 'prohibits dsData' do @@ -585,8 +585,8 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('dsData object is not allowed') + response[:result_code].should == '2306' + response[:msg].should == 'dsData object is not allowed' end it 'prohibits keyData' do @@ -603,8 +603,8 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('keyData object is not allowed') + response[:result_code].should == '2306' + response[:msg].should == 'keyData object is not allowed' end end @@ -618,15 +618,15 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(response[:clTRID]).to eq('ABC-12345') + response[:result_code].should == '1000' + response[:msg].should == 'Command completed successfully' + response[:clTRID].should == 'ABC-12345' - expect(Domain.last.tech_contacts.count).to eq 1 - expect(Domain.last.admin_contacts.count).to eq 1 + Domain.last.tech_contacts.count.should == 1 + Domain.last.admin_contacts.count.should == 1 tech_contact = Domain.last.tech_contacts.first - expect(tech_contact.code).to eq('juridical_1234') + tech_contact.code.should == 'juridical_1234' end it 'does not create a domain without admin contact' do @@ -640,12 +640,12 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2004') - expect(response[:msg]).to eq('Admin contacts count must be between 1-10') - expect(response[:clTRID]).to eq('ABC-12345') + response[:result_code].should == '2004' + response[:msg].should == 'Admin contacts count must be between 1-10' + response[:clTRID].should == 'ABC-12345' - expect(Domain.count).to eq domain_count - expect(DomainContact.count).to eq domain_contact_count + Domain.count.should == domain_count + DomainContact.count.should == domain_contact_count end it 'cannot assign juridical person as admin contact' do @@ -657,8 +657,8 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('Admin contact can be only citizen') + response[:result_code].should == '2306' + response[:msg].should == 'Admin contact can be only citizen' end end @@ -682,15 +682,15 @@ describe 'EPP Domain', epp: true do dtl = domain.domain_transfers.last trn_data = response[:parsed].css('trnData') - expect(trn_data.css('name').text).to eq(domain.name) - expect(trn_data.css('trStatus').text).to eq('serverApproved') - expect(trn_data.css('reID').text).to eq('123') - expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) - expect(trn_data.css('acID').text).to eq('12345678') - expect(trn_data.css('acDate').text).to eq(dtl.transferred_at.to_time.utc.to_s) - expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + trn_data.css('name').text.should == domain.name + trn_data.css('trStatus').text.should == 'serverApproved' + trn_data.css('reID').text.should == '123' + trn_data.css('reDate').text.should == dtl.transfer_requested_at.to_time.utc.to_s + trn_data.css('acID').text.should == '12345678' + trn_data.css('acDate').text.should == dtl.transferred_at.to_time.utc.to_s + trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.to_s - expect(domain.registrar).to eq(@elkdata) + domain.registrar.should == @elkdata Setting.transfer_wait_time = 1 @@ -707,57 +707,57 @@ describe 'EPP Domain', epp: true do domain.reload dtl = domain.domain_transfers.last - expect(domain.domain_transfers.count).to eq(2) + domain.domain_transfers.count.should == 2 - expect(trn_data.css('name').text).to eq(domain.name) - expect(trn_data.css('trStatus').text).to eq('pending') - expect(trn_data.css('reID').text).to eq('12345678') - expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) - expect(trn_data.css('acDate').text).to eq(dtl.wait_until.to_time.utc.to_s) - expect(trn_data.css('acID').text).to eq('123') - expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + trn_data.css('name').text.should == domain.name + trn_data.css('trStatus').text.should == 'pending' + trn_data.css('reID').text.should == '12345678' + trn_data.css('reDate').text.should == dtl.transfer_requested_at.to_time.utc.to_s + trn_data.css('acDate').text.should == dtl.wait_until.to_time.utc.to_s + trn_data.css('acID').text.should == '123' + trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.to_s - expect(domain.registrar).to eq(@elkdata) + domain.registrar.should == @elkdata # should return same data if pending already response = epp_request(xml, :xml, :zone) trn_data = response[:parsed].css('trnData') - expect(domain.domain_transfers.count).to eq(2) - expect(trn_data.css('name').text).to eq(domain.name) - expect(trn_data.css('trStatus').text).to eq('pending') - expect(trn_data.css('reID').text).to eq('12345678') - expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) - expect(trn_data.css('acDate').text).to eq(dtl.wait_until.to_time.utc.to_s) - expect(trn_data.css('acID').text).to eq('123') - expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + domain.domain_transfers.count.should == 2 + trn_data.css('name').text.should == domain.name + trn_data.css('trStatus').text.should == 'pending' + trn_data.css('reID').text.should == '12345678' + trn_data.css('reDate').text.should == dtl.transfer_requested_at.to_time.utc.to_s + trn_data.css('acDate').text.should == dtl.wait_until.to_time.utc.to_s + trn_data.css('acID').text.should == '123' + trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.to_s - expect(domain.registrar).to eq(@elkdata) + domain.registrar.should == @elkdata # should show up in other registrar's poll response = epp_request(epp_xml.session.poll, :xml, :elkdata) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') + response[:msg].should == 'Command completed successfully; ack to dequeue' msg_q = response[:parsed].css('msgQ') - expect(msg_q.css('qDate').text).to_not be_blank - expect(msg_q.css('msg').text).to eq('Transfer requested.') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('1') + msg_q.css('qDate').text.should_not be_blank + msg_q.css('msg').text.should == 'Transfer requested.' + msg_q.first['id'].should_not be_blank + msg_q.first['count'].should == '1' xml = epp_xml.session.poll(poll: { value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('0') + msg_q.first['id'].should_not be_blank + msg_q.first['count'].should == '0' end it 'creates a domain transfer with legal document' do Setting.transfer_wait_time = 1 - expect(domain.legal_documents.count).to eq(0) + domain.legal_documents.count.should == 0 pw = domain.auth_info xml = domain_transfer_xml({ name: { value: domain.name }, @@ -773,35 +773,35 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('1000') - expect(domain.legal_documents.count).to eq(1) + response[:result_code].should == '1000' + domain.legal_documents.count.should == 1 log = ApiLog::EppLog.last(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) + log[0].request_command.should == 'hello' + log[0].request_successful.should == true - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('elkdata') - expect(log[1].api_user_registrar).to eq('Elkdata') + log[1].request_command.should == 'login' + log[1].request_successful.should == true + log[1].api_user_name.should == 'elkdata' + log[1].api_user_registrar.should == 'Elkdata' - expect(log[2].request_command).to eq('transfer') - expect(log[2].request_object).to eq('domain') - expect(log[2].request_successful).to eq(true) - expect(log[2].api_user_name).to eq('elkdata') - expect(log[2].api_user_registrar).to eq('Elkdata') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank + log[2].request_command.should == 'transfer' + log[2].request_object.should == 'domain' + log[2].request_successful.should == true + log[2].api_user_name.should == 'elkdata' + log[2].api_user_registrar.should == 'Elkdata' + log[2].request.should_not be_blank + log[2].response.should_not be_blank - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('elkdata') - expect(log[3].api_user_registrar).to eq('Elkdata') + log[3].request_command.should == 'logout' + log[3].request_successful.should == true + log[3].api_user_name.should == 'elkdata' + log[3].api_user_registrar.should == 'Elkdata' response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('1000') - expect(domain.legal_documents.count).to eq(1) # does not add another legal document + response[:result_code].should == '1000' + domain.legal_documents.count.should == 1 # does not add another legal documen end it 'approves the transfer request' do @@ -822,12 +822,12 @@ describe 'EPP Domain', epp: true do trn_data = response[:parsed].css('trnData') - expect(trn_data.css('name').text).to eq(domain.name) - expect(trn_data.css('trStatus').text).to eq('clientApproved') - expect(trn_data.css('reID').text).to eq('123') - expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s) - expect(trn_data.css('acID').text).to eq('12345678') - expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) + trn_data.css('name').text.should == domain.name + trn_data.css('trStatus').text.should == 'clientApproved' + trn_data.css('reID').text.should == '123' + trn_data.css('reDate').text.should == dtl.transfer_requested_at.to_time.utc.to_s + trn_data.css('acID').text.should == '12345678' + trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.to_s end it 'rejects a domain transfer' do @@ -852,14 +852,14 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Transfer can be rejected only by current registrar') - expect(response[:result_code]).to eq('2304') - expect(domain.legal_documents.count).to eq(0) + response[:msg].should == 'Transfer can be rejected only by current registrar' + response[:result_code].should == '2304' + domain.legal_documents.count.should == 0 response = epp_request(xml, :xml, :zone) - expect(response[:result_code]).to eq('1000') - expect(domain.pending_transfer).to be_nil - expect(domain.legal_documents.count).to eq(1) + response[:result_code].should == '1000' + domain.pending_transfer.should be_nil + domain.legal_documents.count.should == 1 end it 'prohibits wrong registrar from approving transfer' do @@ -876,8 +876,8 @@ describe 'EPP Domain', epp: true do }, 'approve') response = epp_request(xml, :xml, :elkdata) - expect(response[:result_code]).to eq('2304') - expect(response[:msg]).to eq('Transfer can be approved only by current domain registrar') + response[:result_code].should == '2304' + response[:msg].should == 'Transfer can be approved only by current domain registrar' end it 'does not transfer with invalid pw' do @@ -886,8 +886,8 @@ describe 'EPP Domain', epp: true do authInfo: { pw: { value: 'test' } } }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('2201') - expect(response[:msg]).to eq('Authorization error') + response[:result_code].should == '2201' + response[:msg].should == 'Authorization error' end it 'ignores transfer when owner registrar requests transfer' do @@ -898,14 +898,14 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml, :zone) - expect(response[:result_code]).to eq('2002') - expect(response[:msg]).to eq('Domain already belongs to the querying registrar') + response[:result_code].should == '2002' + response[:msg].should == 'Domain already belongs to the querying registrar' end it 'returns an error for incorrect op attribute' do response = epp_request(domain_transfer_xml({}, 'bla'), :xml, :zone) - expect(response[:result_code]).to eq('2306') - expect(response[:msg]).to eq('Attribute op is invalid') + response[:result_code].should == '2306' + response[:msg].should == 'Attribute op is invalid' end it 'creates new pw after successful transfer' do @@ -917,8 +917,8 @@ describe 'EPP Domain', epp: true do epp_request(xml, :xml, :elkdata) # transfer domain response = epp_request(xml, :xml, :elkdata) # attempt second transfer - expect(response[:result_code]).to eq('2201') - expect(response[:msg]).to eq('Authorization error') + response[:result_code].should == '2201' + response[:msg].should == 'Authorization error' end ### UPDATE ### @@ -941,12 +941,12 @@ describe 'EPP Domain', epp: true do ] }), :xml) - expect(response[:results][0][:result_code]).to eq('1000') + response[:results][0][:result_code].should == '1000' d = Domain.last - expect(d.owner_contact_code).to eq('citizen_1234') - expect(d.auth_info).to eq(existing_pw) + d.owner_contact_code.should == 'citizen_1234' + d.auth_info.should == existing_pw end it 'updates domain and adds objects' do @@ -994,56 +994,56 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Contact was not found') + response[:results][0][:result_code].should == '2303' + response[:results][0][:msg].should == 'Contact was not found' Fabricate(:contact, code: 'mak21') response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('1000') + response[:results][0][:result_code].should == '1000' d = Domain.last new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count - expect(new_ns_count).to eq(2) + new_ns_count.should == 2 new_contact = d.tech_contacts.find_by(code: 'mak21') - expect(new_contact).to be_truthy + new_contact.should be_truthy - expect(d.domain_statuses.count).to eq(2) - expect(d.domain_statuses.first.description).to eq('Payment overdue.') - expect(d.domain_statuses.first.value).to eq('clientHold') + d.domain_statuses.count.should == 2 + d.domain_statuses.first.description.should == 'Payment overdue.' + d.domain_statuses.first.value.should == 'clientHold' - expect(d.domain_statuses.last.value).to eq('clientUpdateProhibited') - expect(d.dnskeys.count).to eq(2) + d.domain_statuses.last.value.should == 'clientUpdateProhibited' + d.dnskeys.count.should == 2 response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2302') - expect(response[:results][0][:msg]).to eq('Nameserver already exists on this domain') - expect(response[:results][0][:value]).to eq('ns1.example.com') + response[:results][0][:result_code].should == '2302' + response[:results][0][:msg].should == 'Nameserver already exists on this domain' + response[:results][0][:value].should == 'ns1.example.com' - expect(response[:results][1][:result_code]).to eq('2302') - expect(response[:results][1][:msg]).to eq('Nameserver already exists on this domain') - expect(response[:results][1][:value]).to eq('ns2.example.com') + response[:results][1][:result_code].should == '2302' + response[:results][1][:msg].should == 'Nameserver already exists on this domain' + response[:results][1][:value].should == 'ns2.example.com' - expect(response[:results][2][:result_code]).to eq('2302') - expect(response[:results][2][:msg]).to eq('Contact already exists on this domain') - expect(response[:results][2][:value]).to eq('mak21') + response[:results][2][:result_code].should == '2302' + response[:results][2][:msg].should == 'Contact already exists on this domain' + response[:results][2][:value].should == 'mak21' - expect(response[:results][3][:msg]).to eq('Status already exists on this domain') - expect(response[:results][3][:value]).to eq('clientHold') + response[:results][3][:msg].should == 'Status already exists on this domain' + response[:results][3][:value].should == 'clientHold' - expect(response[:results][4][:msg]).to eq('Status already exists on this domain') - expect(response[:results][4][:value]).to eq('clientUpdateProhibited') + response[:results][4][:msg].should == 'Status already exists on this domain' + response[:results][4][:value].should == 'clientUpdateProhibited' - expect(response[:results][5][:msg]).to eq('Public key already exists') - expect(response[:results][5][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') + response[:results][5][:msg].should == 'Public key already exists' + response[:results][5][:value].should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - expect(response[:results][6][:msg]).to eq('Public key already exists') - expect(response[:results][6][:value]).to eq('841936717ae427ace63c28d04918569a841936717ae427ace63c28d0') + response[:results][6][:msg].should == 'Public key already exists' + response[:results][6][:value].should == '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' - expect(d.domain_statuses.count).to eq(2) + d.domain_statuses.count.should == 2 end it 'updates a domain and removes objects' do @@ -1092,7 +1092,7 @@ describe 'EPP Domain', epp: true do epp_request(xml, :xml) d = Domain.last - expect(d.dnskeys.count).to eq(2) + d.dnskeys.count.should == 2 xml = domain_update_xml({ name: { value: domain.name }, @@ -1122,29 +1122,29 @@ describe 'EPP Domain', epp: true do epp_request(xml, :xml) - expect(d.dnskeys.count).to eq(1) + d.dnskeys.count.should == 1 - expect(d.domain_statuses.count).to eq(1) - expect(d.domain_statuses.first.value).to eq('clientUpdateProhibited') + d.domain_statuses.count.should == 1 + d.domain_statuses.first.value.should == 'clientUpdateProhibited' rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com') - expect(rem_ns).to be_falsey + rem_ns.should be_falsey rem_cnt = d.tech_contacts.find_by(code: 'citizen_1234') - expect(rem_cnt).to be_falsey + rem_cnt.should be_falsey response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Contact was not found') - expect(response[:results][0][:value]).to eq('citizen_1234') + response[:results][0][:result_code].should == '2303' + response[:results][0][:msg].should == 'Contact was not found' + response[:results][0][:value].should == 'citizen_1234' - expect(response[:results][1][:result_code]).to eq('2303') - expect(response[:results][1][:msg]).to eq('Nameserver was not found') - expect(response[:results][1][:value]).to eq('ns1.example.com') + response[:results][1][:result_code].should == '2303' + response[:results][1][:msg].should == 'Nameserver was not found' + response[:results][1][:value].should == 'ns1.example.com' - expect(response[:results][2][:result_code]).to eq('2303') - expect(response[:results][2][:msg]).to eq('Status was not found') - expect(response[:results][2][:value]).to eq('clientHold') + response[:results][2][:result_code].should == '2303' + response[:results][2][:msg].should == 'Status was not found' + response[:results][2][:value].should == 'clientHold' end it 'does not remove server statuses' do @@ -1162,9 +1162,9 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Status was not found') - expect(response[:results][0][:value]).to eq('serverHold') + response[:results][0][:result_code].should == '2303' + response[:results][0][:msg].should == 'Status was not found' + response[:results][0][:value].should == 'serverHold' end it 'does not add duplicate objects to domain' do @@ -1191,13 +1191,13 @@ describe 'EPP Domain', epp: true do epp_request(xml, :xml) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2302') - expect(response[:results][0][:msg]).to eq('Nameserver already exists on this domain') - expect(response[:results][0][:value]).to eq(n.hostname) + response[:results][0][:result_code].should == '2302' + response[:results][0][:msg].should == 'Nameserver already exists on this domain' + response[:results][0][:value].should == n.hostname - expect(response[:results][1][:result_code]).to eq('2302') - expect(response[:results][1][:msg]).to eq('Contact already exists on this domain') - expect(response[:results][1][:value]).to eq(c.code) + response[:results][1][:result_code].should == '2302' + response[:results][1][:msg].should == 'Contact already exists on this domain' + response[:results][1][:value].should == c.code end it 'cannot change registrant without legal document' do @@ -1209,8 +1209,8 @@ describe 'EPP Domain', epp: true do } response = epp_request(domain_update_xml(xml_params), :xml) - expect(response[:results][0][:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') - expect(response[:results][0][:result_code]).to eq('2003') + response[:results][0][:msg].should == 'Required parameter missing: extension > extdata > legalDocument' + response[:results][0][:result_code].should == '2003' end it 'does not assign invalid status to domain' do @@ -1222,9 +1222,9 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Status was not found') - expect(response[:results][0][:value]).to eq('invalidStatus') + response[:results][0][:result_code].should == '2303' + response[:results][0][:msg].should == 'Status was not found' + response[:results][0][:value].should == 'invalidStatus' end ### RENEW ### @@ -1239,8 +1239,8 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml) ex_date = response[:parsed].css('renData exDate').text name = response[:parsed].css('renData name').text - expect(ex_date).to eq("#{(exp_date + 1.year)} 00:00:00 UTC") - expect(name).to eq(domain.name) + ex_date.should == "#{(exp_date + 1.year)} 00:00:00 UTC" + name.should == domain.name end it 'returns an error when given and current exp dates do not match' do @@ -1251,8 +1251,8 @@ describe 'EPP Domain', epp: true do ) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2306') - expect(response[:results][0][:msg]).to eq('Given and current expire dates do not match') + response[:results][0][:result_code].should == '2306' + response[:results][0][:msg].should == 'Given and current expire dates do not match' end it 'returns an error when period is invalid' do @@ -1265,9 +1265,9 @@ describe 'EPP Domain', epp: true do ) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('2004') - expect(response[:results][0][:msg]).to eq('Period must add up to 1, 2 or 3 years') - expect(response[:results][0][:value]).to eq('4') + response[:results][0][:result_code].should == '2004' + response[:results][0][:msg].should == 'Period must add up to 1, 2 or 3 years' + response[:results][0][:value].should == '4' end ### INFO ### @@ -1302,79 +1302,79 @@ describe 'EPP Domain', epp: true do xml = domain_info_xml(name: { value: domain.name }) response = epp_request(xml, :xml) - expect(response[:results][0][:result_code]).to eq('1000') - expect(response[:results][0][:msg]).to eq('Command completed successfully') + response[:results][0][:result_code].should == '1000' + response[:results][0][:msg].should == 'Command completed successfully' inf_data = response[:parsed].css('resData infData') - expect(inf_data.css('name').text).to eq(domain.name) - expect(inf_data.css('status').text).to eq('Payment overdue.') - expect(inf_data.css('status').first[:s]).to eq('clientHold') - expect(inf_data.css('registrant').text).to eq(domain.owner_contact_code) + inf_data.css('name').text.should == domain.name + inf_data.css('status').text.should == 'Payment overdue.' + inf_data.css('status').first[:s].should == 'clientHold' + inf_data.css('registrant').text.should == domain.owner_contact_code admin_contacts_from_request = inf_data.css('contact[type="admin"]').map(&:text) admin_contacts_existing = domain.admin_contacts.pluck(:code) - expect(admin_contacts_from_request).to eq(admin_contacts_existing) + admin_contacts_from_request.should == admin_contacts_existing hosts_from_request = inf_data.css('hostName').map(&:text) hosts_existing = domain.nameservers.pluck(:hostname) - expect(hosts_from_request).to eq(hosts_existing) + hosts_from_request.should == hosts_existing ns1 = inf_data.css('hostAttr').last - expect(ns1.css('hostName').last.text).to eq('ns1.example.com') - expect(ns1.css('hostAddr').first.text).to eq('192.168.1.1') - expect(ns1.css('hostAddr').last.text).to eq('1080:0:0:0:8:800:200C:417A') - expect(inf_data.css('crDate').text).to eq(domain.created_at.to_time.utc.to_s) - expect(inf_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s) - expect(inf_data.css('pw').text).to eq(domain.auth_info) + ns1.css('hostName').last.text.should == 'ns1.example.com' + ns1.css('hostAddr').first.text.should == '192.168.1.1' + ns1.css('hostAddr').last.text.should == '1080:0:0:0:8:800:200C:417A' + inf_data.css('crDate').text.should == domain.created_at.to_time.utc.to_s + inf_data.css('exDate').text.should == domain.valid_to.to_time.utc.to_s + inf_data.css('pw').text.should == domain.auth_info ds_data_1 = response[:parsed].css('dsData')[0] - expect(ds_data_1.css('keyTag').first.text).to eq('123') - expect(ds_data_1.css('alg').first.text).to eq('3') - expect(ds_data_1.css('digestType').first.text).to eq('1') - expect(ds_data_1.css('digest').first.text).to eq('abc') + ds_data_1.css('keyTag').first.text.should == '123' + ds_data_1.css('alg').first.text.should == '3' + ds_data_1.css('digestType').first.text.should == '1' + ds_data_1.css('digest').first.text.should == 'abc' dnskey_1 = ds_data_1.css('keyData')[0] - expect(dnskey_1.css('flags').first.text).to eq('257') - expect(dnskey_1.css('protocol').first.text).to eq('3') - expect(dnskey_1.css('alg').first.text).to eq('3') - expect(dnskey_1.css('pubKey').first.text).to eq('AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8') + dnskey_1.css('flags').first.text.should == '257' + dnskey_1.css('protocol').first.text.should == '3' + dnskey_1.css('alg').first.text.should == '3' + dnskey_1.css('pubKey').first.text.should == 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' ds_data_2 = response[:parsed].css('dsData')[1] dnskey_2 = ds_data_2.css('keyData')[0] - expect(dnskey_2.css('flags').first.text).to eq('0') - expect(dnskey_2.css('protocol').first.text).to eq('3') - expect(dnskey_2.css('alg').first.text).to eq('5') - expect(dnskey_2.css('pubKey').first.text).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f') + dnskey_2.css('flags').first.text.should == '0' + dnskey_2.css('protocol').first.text.should == '3' + dnskey_2.css('alg').first.text.should == '5' + dnskey_2.css('pubKey').first.text.should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' domain.touch response = epp_request(domain_info_xml(name: { value: domain.name }), :xml) inf_data = response[:parsed].css('resData infData') - expect(inf_data.css('upDate').text).to eq(domain.updated_at.to_time.utc.to_s) + inf_data.css('upDate').text.should == domain.updated_at.to_time.utc.to_s end it 'returns error when domain can not be found' do response = epp_request(domain_info_xml(name: { value: 'test.ee' }), :xml) - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:msg]).to eq('Domain not found') + response[:results][0][:result_code].should == '2303' + response[:results][0][:msg].should == 'Domain not found' end it 'sets ok status by default' do response = epp_request(domain_info_xml(name: { value: domain.name }), :xml) inf_data = response[:parsed].css('resData infData') - expect(inf_data.css('status').first[:s]).to eq('ok') + inf_data.css('status').first[:s].should == 'ok' end it 'can not see other registrar domains' do response = epp_request(domain_info_xml(name: { value: domain.name }), :xml, :elkdata) - expect(response[:result_code]).to eq('2302') - expect(response[:msg]).to eq('Domain exists but belongs to other registrar') + response[:result_code].should == '2302' + response[:msg].should == 'Domain exists but belongs to other registrar' end ### DELETE ### @@ -1390,9 +1390,9 @@ describe 'EPP Domain', epp: true do ] }), :xml) - expect(response[:result_code]).to eq('1000') + response[:result_code].should == '1000' - expect(Domain.find_by(name: domain.name)).to eq(nil) + Domain.find_by(name: domain.name).should == nil end it 'does not delete domain with specific status' do @@ -1409,14 +1409,14 @@ describe 'EPP Domain', epp: true do ] }), :xml) - expect(response[:result_code]).to eq('2304') - expect(response[:msg]).to eq('Domain status prohibits operation') + response[:result_code].should == '2304' + response[:msg].should == 'Domain status prohibits operation' end it 'does not delete domain without legal document' do response = epp_request(epp_xml.domain.delete(name: { value: 'example.ee' }), :xml) - expect(response[:result_code]).to eq('2003') - expect(response[:msg]).to eq('Required parameter missing: extension > extdata > legalDocument') + response[:result_code].should == '2003' + response[:msg].should == 'Required parameter missing: extension > extdata > legalDocument' end ### CHECK ### @@ -1427,12 +1427,12 @@ describe 'EPP Domain', epp: true do ] }), :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response[:result_code].should == '1000' + response[:msg].should == 'Command completed successfully' res_data = response[:parsed].css('resData chkData cd name').first - expect(res_data.text).to eq('one.ee') - expect(res_data[:avail]).to eq('1') + res_data.text.should == 'one.ee' + res_data[:avail].should == '1' response = epp_request(domain_check_xml({ _anonymus: [ @@ -1443,9 +1443,9 @@ describe 'EPP Domain', epp: true do name = res_data.css('name').first reason = res_data.css('reason').first - expect(name.text).to eq(domain.name) - expect(name[:avail]).to eq('0') - expect(reason.text).to eq('in use') + name.text.should == domain.name + name[:avail].should == '0' + reason.text.should == 'in use' end it 'checks multiple domains' do @@ -1458,16 +1458,16 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response[:result_code].should == '1000' + response[:msg].should == 'Command completed successfully' res_data = response[:parsed].css('resData chkData cd name').first - expect(res_data.text).to eq('one.ee') - expect(res_data[:avail]).to eq('1') + res_data.text.should == 'one.ee' + res_data[:avail].should == '1' res_data = response[:parsed].css('resData chkData cd name').last - expect(res_data.text).to eq('three.ee') - expect(res_data[:avail]).to eq('1') + res_data.text.should == 'three.ee' + res_data[:avail].should == '1' end it 'checks invalid format domain' do @@ -1479,20 +1479,20 @@ describe 'EPP Domain', epp: true do }) response = epp_request(xml, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') + response[:result_code].should == '1000' + response[:msg].should == 'Command completed successfully' res_data = response[:parsed].css('resData chkData cd name').first - expect(res_data.text).to eq('one.ee') - expect(res_data[:avail]).to eq('1') + res_data.text.should == 'one.ee' + res_data[:avail].should == '1' res_data = response[:parsed].css('resData chkData cd').last name = res_data.css('name').first reason = res_data.css('reason').first - expect(name.text).to eq('notcorrectdomain') - expect(name[:avail]).to eq('0') - expect(reason.text).to eq('invalid format') + name.text.should == 'notcorrectdomain' + name[:avail].should == '0' + reason.text.should == 'invalid format' end end From d822bfe6d4d10edbf3bdaac0d419afc27e1235fa Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 18:18:40 +0200 Subject: [PATCH 17/34] Use only one connection in domain specs --- spec/epp/domain_spec.rb | 251 ++++++++++++++++++++-------------------- 1 file changed, 125 insertions(+), 126 deletions(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index ad31e0d20..3bb669eaf 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' describe 'EPP Domain', epp: true do - let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) } - let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) } let(:epp_xml) { EppXml.new(cl_trid: 'ABC-12345') } before(:each) { create_settings } @@ -10,8 +8,10 @@ describe 'EPP Domain', epp: true do before(:all) do @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) @zone = Fabricate(:registrar) - Fabricate(:epp_user, username: 'zone', registrar: @zone) - Fabricate(:epp_user, username: 'elkdata', registrar: @elkdata) + Fabricate(:epp_user, username: 'registrar1', registrar: @zone) + Fabricate(:epp_user, username: 'registrar2', registrar: @elkdata) + + login_as :registrar1 Contact.skip_callback(:create, :before, :generate_code) @@ -25,7 +25,7 @@ describe 'EPP Domain', epp: true do end it 'returns error if contact does not exists' do - response = epp_request(domain_create_xml({ + response = epp_plain_request(domain_create_xml({ registrant: { value: 'citizen_1234' }, _anonymus: [ { contact: { value: 'citizen_1234', attrs: { type: 'admin' } } }, @@ -44,29 +44,15 @@ describe 'EPP Domain', epp: true do response[:clTRID].should == 'ABC-12345' - log = ApiLog::EppLog.last(4) + log = ApiLog::EppLog.last - log.length.should == 4 - log[0].request_command.should == 'hello' - log[0].request_successful.should == true - - log[1].request_command.should == 'login' - log[1].request_successful.should == true - log[1].api_user_name.should == 'zone' - log[1].api_user_registrar.should == 'Registrar OÜ' - - log[2].request_command.should == 'create' - log[2].request_object.should == 'domain' - log[2].request_successful.should == false - log[2].api_user_name.should == 'zone' - log[2].api_user_registrar.should == 'Registrar OÜ' - log[2].request.should_not be_blank - log[2].response.should_not be_blank - - log[3].request_command.should == 'logout' - log[3].request_successful.should == true - log[3].api_user_name.should == 'zone' - log[3].api_user_registrar.should == 'Registrar OÜ' + log.request_command.should == 'create' + log.request_object.should == 'domain' + log.request_successful.should == false + log.api_user_name.should == 'registrar1' + log.api_user_registrar.should == 'Registrar OÜ' + log.request.should_not be_blank + log.response.should_not be_blank end it 'validates required parameters' do @@ -75,7 +61,7 @@ describe 'EPP Domain', epp: true do name: { value: 'test.ee' } }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2003' response[:results][0][:msg].should == 'Required parameter missing: ns' @@ -92,7 +78,7 @@ describe 'EPP Domain', epp: true do context 'with citizen as an owner' do it 'creates a domain' do dn = next_domain_name - response = epp_request(domain_create_xml({ + response = epp_plain_request(domain_create_xml({ name: { value: dn } }), :xml) d = Domain.last @@ -129,7 +115,7 @@ describe 'EPP Domain', epp: true do end it 'creates a domain with legal document' do - response = epp_request(domain_create_xml_with_legal_doc, :xml) + response = epp_plain_request(domain_create_xml_with_legal_doc, :xml) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' @@ -157,7 +143,7 @@ describe 'EPP Domain', epp: true do ] }) - epp_request(xml, :xml) + epp_plain_request(xml, :xml) d = Domain.last ds = d.dnskeys.last ds.ds_digest.should == '0B62D1BC64EFD1EE652FB102BDF1011BF514CCD9A1A0CFB7472AEA3B01F38C92' @@ -181,17 +167,17 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2306' response[:msg].should == 'IPv4 is missing' end it 'does not create duplicate domain' do dn = next_domain_name - epp_request(domain_create_xml({ + epp_plain_request(domain_create_xml({ name: { value: dn } }), :xml) - response = epp_request(domain_create_xml({ + response = epp_plain_request(domain_create_xml({ name: { value: dn } }), :xml) @@ -203,7 +189,7 @@ describe 'EPP Domain', epp: true do it 'does not create reserved domain' do xml = domain_create_xml(name: { value: '1162.ee' }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2302' response[:msg].should == 'Domain name is reserved or restricted' response[:clTRID].should == 'ABC-12345' @@ -212,14 +198,14 @@ describe 'EPP Domain', epp: true do it 'does not create domain without contacts and registrant' do xml = domain_create_xml(contacts: [], registrant: false) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2003' response[:results][0][:msg].should == 'Required parameter missing: registrant' end it 'does not create domain without nameservers' do xml = domain_create_xml(ns: []) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2003' response[:msg].should == 'Required parameter missing: ns' end @@ -238,7 +224,7 @@ describe 'EPP Domain', epp: true do ns: nameservers }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2004' response[:msg].should == 'Nameservers count must be between 2-11' end @@ -259,7 +245,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2005' response[:msg].should == 'Hostname is invalid' end @@ -276,13 +262,13 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2003' response[:msg].should == 'Required parameter missing: ns > hostAttr' end it 'creates domain with nameservers with ips' do - epp_request(domain_create_with_host_attrs, :xml) + epp_plain_request(domain_create_with_host_attrs, :xml) Domain.last.nameservers.count.should == 2 ns = Domain.last.nameservers.first ns.ipv4.should == '192.0.2.2' @@ -292,7 +278,7 @@ describe 'EPP Domain', epp: true do it 'returns error when nameserver has invalid ips' do domain_count = Domain.count nameserver_count = Nameserver.count - response = epp_request(domain_create_with_invalid_ns_ip_xml, :xml) + response = epp_plain_request(domain_create_with_invalid_ns_ip_xml, :xml) response[:results][0][:result_code].should == '2005' response[:results][0][:msg].should == 'IPv4 is invalid' response[:results][0][:value].should == '192.0.2.2.invalid' @@ -307,7 +293,7 @@ describe 'EPP Domain', epp: true do it 'creates a domain with period in days' do xml = domain_create_xml(period_value: 365, period_unit: 'd') - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '1000' response[:msg].should == 'Command completed successfully' Domain.first.valid_to.should == Date.today + 1.year @@ -318,7 +304,7 @@ describe 'EPP Domain', epp: true do period: { value: '367', attrs: { unit: 'd' } } }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2004' response[:results][0][:msg].should == 'Period must add up to 1, 2 or 3 years' response[:results][0][:value].should == '367' @@ -353,7 +339,7 @@ describe 'EPP Domain', epp: true do ] }) - epp_request(xml, :xml) + epp_plain_request(xml, :xml) d = Domain.last d.dnskeys.count.should == 3 @@ -403,7 +389,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:msg].should == 'Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255' response[:results][0][:value].should == '9' @@ -446,7 +432,7 @@ describe 'EPP Domain', epp: true do }] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2302' response[:msg].should == 'Public key already exists' @@ -475,7 +461,7 @@ describe 'EPP Domain', epp: true do }] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2004' response[:msg].should == 'DNS keys count must be between 0-1' @@ -493,7 +479,7 @@ describe 'EPP Domain', epp: true do }] }) - epp_request(xml, :xml) + epp_plain_request(xml, :xml) d = Domain.last ds = d.dnskeys.first @@ -525,7 +511,7 @@ describe 'EPP Domain', epp: true do }] }) - epp_request(xml, :xml) + epp_plain_request(xml, :xml) d = Domain.last ds = d.dnskeys.first @@ -559,7 +545,7 @@ describe 'EPP Domain', epp: true do }] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2306' response[:msg].should == 'dsData object with key data is not allowed' end @@ -584,7 +570,7 @@ describe 'EPP Domain', epp: true do }] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2306' response[:msg].should == 'dsData object is not allowed' end @@ -602,7 +588,7 @@ describe 'EPP Domain', epp: true do }] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2306' response[:msg].should == 'keyData object is not allowed' end @@ -617,7 +603,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '1000' response[:msg].should == 'Command completed successfully' response[:clTRID].should == 'ABC-12345' @@ -639,7 +625,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2004' response[:msg].should == 'Admin contacts count must be between 1-10' response[:clTRID].should == 'ABC-12345' @@ -656,7 +642,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2306' response[:msg].should == 'Admin contact can be only citizen' end @@ -676,7 +662,10 @@ describe 'EPP Domain', epp: true do name: { value: domain.name }, authInfo: { pw: { value: pw } } }) - response = epp_request(xml, :xml, :elkdata) + + response = login_as :registrar2 do + epp_plain_request(xml, :xml) + end domain.reload dtl = domain.domain_transfers.last @@ -701,7 +690,7 @@ describe 'EPP Domain', epp: true do authInfo: { pw: { value: pw } } }) # request with new password - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) trn_data = response[:parsed].css('trnData') domain.reload @@ -720,7 +709,7 @@ describe 'EPP Domain', epp: true do domain.registrar.should == @elkdata # should return same data if pending already - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) trn_data = response[:parsed].css('trnData') domain.domain_transfers.count.should == 2 @@ -736,7 +725,10 @@ describe 'EPP Domain', epp: true do # should show up in other registrar's poll - response = epp_request(epp_xml.session.poll, :xml, :elkdata) + response = login_as :registrar2 do + epp_plain_request(epp_xml.session.poll, :xml) + end + response[:msg].should == 'Command completed successfully; ack to dequeue' msg_q = response[:parsed].css('msgQ') msg_q.css('qDate').text.should_not be_blank @@ -748,7 +740,10 @@ describe 'EPP Domain', epp: true do value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) - response = epp_request(xml, :xml, :elkdata) + response = login_as :registrar2 do + epp_plain_request(xml, :xml) + end + response[:msg].should == 'Command completed successfully' msg_q = response[:parsed].css('msgQ') msg_q.first['id'].should_not be_blank @@ -771,35 +766,26 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml, :elkdata) + login_as :registrar2 do + response = epp_plain_request(xml, :xml) + response[:result_code].should == '1000' + domain.legal_documents.count.should == 1 - response[:result_code].should == '1000' - domain.legal_documents.count.should == 1 + log = ApiLog::EppLog.last - log = ApiLog::EppLog.last(4) + log.request_command.should == 'transfer' + log.request_object.should == 'domain' + log.request_successful.should == true + log.api_user_name.should == 'registrar2' + log.api_user_registrar.should == 'Elkdata' + log.request.should_not be_blank + log.response.should_not be_blank + end - log[0].request_command.should == 'hello' - log[0].request_successful.should == true + response = login_as :registrar2 do + epp_plain_request(xml, :xml) + end - log[1].request_command.should == 'login' - log[1].request_successful.should == true - log[1].api_user_name.should == 'elkdata' - log[1].api_user_registrar.should == 'Elkdata' - - log[2].request_command.should == 'transfer' - log[2].request_object.should == 'domain' - log[2].request_successful.should == true - log[2].api_user_name.should == 'elkdata' - log[2].api_user_registrar.should == 'Elkdata' - log[2].request.should_not be_blank - log[2].response.should_not be_blank - - log[3].request_command.should == 'logout' - log[3].request_successful.should == true - log[3].api_user_name.should == 'elkdata' - log[3].api_user_registrar.should == 'Elkdata' - - response = epp_request(xml, :xml, :elkdata) response[:result_code].should == '1000' domain.legal_documents.count.should == 1 # does not add another legal documen end @@ -816,7 +802,9 @@ describe 'EPP Domain', epp: true do name: { value: domain.name }, authInfo: { pw: { value: domain.auth_info } } }, 'approve') - response = epp_request(xml, :xml, :zone) + + response = epp_plain_request(xml, :xml) + domain.reload dtl = domain.domain_transfers.last @@ -851,12 +839,15 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml, :elkdata) + response = login_as :registrar2 do + epp_plain_request(xml, :xml) + end + response[:msg].should == 'Transfer can be rejected only by current registrar' response[:result_code].should == '2304' domain.legal_documents.count.should == 0 - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) response[:result_code].should == '1000' domain.pending_transfer.should be_nil domain.legal_documents.count.should == 1 @@ -875,7 +866,10 @@ describe 'EPP Domain', epp: true do authInfo: { pw: { value: domain.auth_info } } }, 'approve') - response = epp_request(xml, :xml, :elkdata) + response = login_as :registrar2 do + epp_plain_request(xml, :xml) + end + response[:result_code].should == '2304' response[:msg].should == 'Transfer can be approved only by current domain registrar' end @@ -885,7 +879,7 @@ describe 'EPP Domain', epp: true do name: { value: domain.name }, authInfo: { pw: { value: 'test' } } }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '2201' response[:msg].should == 'Authorization error' end @@ -896,14 +890,15 @@ describe 'EPP Domain', epp: true do name: { value: domain.name }, authInfo: { pw: { value: pw } } }) - response = epp_request(xml, :xml, :zone) + + response = epp_plain_request(xml, :xml) response[:result_code].should == '2002' response[:msg].should == 'Domain already belongs to the querying registrar' end it 'returns an error for incorrect op attribute' do - response = epp_request(domain_transfer_xml({}, 'bla'), :xml, :zone) + response = epp_plain_request(domain_transfer_xml({}, 'bla'), :xml) response[:result_code].should == '2306' response[:msg].should == 'Attribute op is invalid' end @@ -915,10 +910,12 @@ describe 'EPP Domain', epp: true do authInfo: { pw: { value: pw } } }) - epp_request(xml, :xml, :elkdata) # transfer domain - response = epp_request(xml, :xml, :elkdata) # attempt second transfer - response[:result_code].should == '2201' - response[:msg].should == 'Authorization error' + login_as :registrar2 do + epp_plain_request(xml, :xml) # transfer domain + response = epp_plain_request(xml, :xml) # attempt second transfer + response[:result_code].should == '2201' + response[:msg].should == 'Authorization error' + end end ### UPDATE ### @@ -932,7 +929,7 @@ describe 'EPP Domain', epp: true do ] } - response = epp_request(domain_update_xml(xml_params, {}, { + response = epp_plain_request(domain_update_xml(xml_params, {}, { _anonymus: [ legalDocument: { value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', @@ -993,13 +990,13 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2303' response[:results][0][:msg].should == 'Contact was not found' Fabricate(:contact, code: 'mak21') - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '1000' d = Domain.last @@ -1017,7 +1014,7 @@ describe 'EPP Domain', epp: true do d.domain_statuses.last.value.should == 'clientUpdateProhibited' d.dnskeys.count.should == 2 - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2302' response[:results][0][:msg].should == 'Nameserver already exists on this domain' @@ -1090,7 +1087,7 @@ describe 'EPP Domain', epp: true do ] }) - epp_request(xml, :xml) + epp_plain_request(xml, :xml) d = Domain.last d.dnskeys.count.should == 2 @@ -1120,7 +1117,7 @@ describe 'EPP Domain', epp: true do ] }) - epp_request(xml, :xml) + epp_plain_request(xml, :xml) d.dnskeys.count.should == 1 @@ -1133,7 +1130,7 @@ describe 'EPP Domain', epp: true do rem_cnt = d.tech_contacts.find_by(code: 'citizen_1234') rem_cnt.should be_falsey - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2303' response[:results][0][:msg].should == 'Contact was not found' response[:results][0][:value].should == 'citizen_1234' @@ -1160,7 +1157,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2303' response[:results][0][:msg].should == 'Status was not found' @@ -1188,8 +1185,8 @@ describe 'EPP Domain', epp: true do } }) - epp_request(xml, :xml) - response = epp_request(xml, :xml) + epp_plain_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2302' response[:results][0][:msg].should == 'Nameserver already exists on this domain' @@ -1208,7 +1205,7 @@ describe 'EPP Domain', epp: true do ] } - response = epp_request(domain_update_xml(xml_params), :xml) + response = epp_plain_request(domain_update_xml(xml_params), :xml) response[:results][0][:msg].should == 'Required parameter missing: extension > extdata > legalDocument' response[:results][0][:result_code].should == '2003' end @@ -1221,7 +1218,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2303' response[:results][0][:msg].should == 'Status was not found' response[:results][0][:value].should == 'invalidStatus' @@ -1236,7 +1233,7 @@ describe 'EPP Domain', epp: true do period: { value: '1', attrs: { unit: 'y' } } ) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) ex_date = response[:parsed].css('renData exDate').text name = response[:parsed].css('renData name').text ex_date.should == "#{(exp_date + 1.year)} 00:00:00 UTC" @@ -1250,7 +1247,7 @@ describe 'EPP Domain', epp: true do period: { value: '1', attrs: { unit: 'y' } } ) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2306' response[:results][0][:msg].should == 'Given and current expire dates do not match' end @@ -1264,7 +1261,7 @@ describe 'EPP Domain', epp: true do period: { value: '4', attrs: { unit: 'y' } } ) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '2004' response[:results][0][:msg].should == 'Period must add up to 1, 2 or 3 years' response[:results][0][:value].should == '4' @@ -1301,7 +1298,7 @@ describe 'EPP Domain', epp: true do xml = domain_info_xml(name: { value: domain.name }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:results][0][:result_code].should == '1000' response[:results][0][:msg].should == 'Command completed successfully' @@ -1353,33 +1350,35 @@ describe 'EPP Domain', epp: true do domain.touch - response = epp_request(domain_info_xml(name: { value: domain.name }), :xml) + response = epp_plain_request(domain_info_xml(name: { value: domain.name }), :xml) inf_data = response[:parsed].css('resData infData') inf_data.css('upDate').text.should == domain.updated_at.to_time.utc.to_s end it 'returns error when domain can not be found' do - response = epp_request(domain_info_xml(name: { value: 'test.ee' }), :xml) + response = epp_plain_request(domain_info_xml(name: { value: 'test.ee' }), :xml) response[:results][0][:result_code].should == '2303' response[:results][0][:msg].should == 'Domain not found' end it 'sets ok status by default' do - response = epp_request(domain_info_xml(name: { value: domain.name }), :xml) + response = epp_plain_request(domain_info_xml(name: { value: domain.name }), :xml) inf_data = response[:parsed].css('resData infData') inf_data.css('status').first[:s].should == 'ok' end it 'can not see other registrar domains' do - response = epp_request(domain_info_xml(name: { value: domain.name }), :xml, :elkdata) - response[:result_code].should == '2302' - response[:msg].should == 'Domain exists but belongs to other registrar' + login_as :registrar2 do + response = epp_plain_request(domain_info_xml(name: { value: domain.name }), :xml) + response[:result_code].should == '2302' + response[:msg].should == 'Domain exists but belongs to other registrar' + end end ### DELETE ### it 'deletes domain' do - response = epp_request(epp_xml.domain.delete({ + response = epp_plain_request(epp_xml.domain.delete({ name: { value: domain.name } }, { _anonymus: [ @@ -1398,7 +1397,7 @@ describe 'EPP Domain', epp: true do it 'does not delete domain with specific status' do domain.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED) - response = epp_request(epp_xml.domain.delete({ + response = epp_plain_request(epp_xml.domain.delete({ name: { value: domain.name } }, { _anonymus: [ @@ -1414,14 +1413,14 @@ describe 'EPP Domain', epp: true do end it 'does not delete domain without legal document' do - response = epp_request(epp_xml.domain.delete(name: { value: 'example.ee' }), :xml) + response = epp_plain_request(epp_xml.domain.delete(name: { value: 'example.ee' }), :xml) response[:result_code].should == '2003' response[:msg].should == 'Required parameter missing: extension > extdata > legalDocument' end ### CHECK ### it 'checks a domain' do - response = epp_request(domain_check_xml({ + response = epp_plain_request(domain_check_xml({ _anonymus: [ { name: { value: 'one.ee' } } ] @@ -1434,7 +1433,7 @@ describe 'EPP Domain', epp: true do res_data.text.should == 'one.ee' res_data[:avail].should == '1' - response = epp_request(domain_check_xml({ + response = epp_plain_request(domain_check_xml({ _anonymus: [ { name: { value: domain.name } } ] @@ -1457,7 +1456,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '1000' response[:msg].should == 'Command completed successfully' @@ -1478,7 +1477,7 @@ describe 'EPP Domain', epp: true do ] }) - response = epp_request(xml, :xml) + response = epp_plain_request(xml, :xml) response[:result_code].should == '1000' response[:msg].should == 'Command completed successfully' From 08f8428bb15efd809fdf7d64680ae3491593f847 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 18:24:38 +0200 Subject: [PATCH 18/34] Reset settings after couple of tests --- spec/epp/domain_spec.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 3bb669eaf..aa07aa49b 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -3,8 +3,6 @@ require 'rails_helper' describe 'EPP Domain', epp: true do let(:epp_xml) { EppXml.new(cl_trid: 'ABC-12345') } - before(:each) { create_settings } - before(:all) do @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) @zone = Fabricate(:registrar) @@ -22,6 +20,8 @@ describe 'EPP Domain', epp: true do Fabricate(:reserved_domain) @uniq_no = proc { @i ||= 0; @i += 1 } + + create_settings end it 'returns error if contact does not exists' do @@ -465,6 +465,8 @@ describe 'EPP Domain', epp: true do response[:result_code].should == '2004' response[:msg].should == 'DNS keys count must be between 0-1' + + create_settings end it 'creates domain with ds data' do @@ -548,6 +550,8 @@ describe 'EPP Domain', epp: true do response = epp_plain_request(xml, :xml) response[:result_code].should == '2306' response[:msg].should == 'dsData object with key data is not allowed' + + create_settings end it 'prohibits dsData' do @@ -573,6 +577,8 @@ describe 'EPP Domain', epp: true do response = epp_plain_request(xml, :xml) response[:result_code].should == '2306' response[:msg].should == 'dsData object is not allowed' + + create_settings end it 'prohibits keyData' do @@ -591,6 +597,8 @@ describe 'EPP Domain', epp: true do response = epp_plain_request(xml, :xml) response[:result_code].should == '2306' response[:msg].should == 'keyData object is not allowed' + + create_settings end end @@ -748,6 +756,8 @@ describe 'EPP Domain', epp: true do msg_q = response[:parsed].css('msgQ') msg_q.first['id'].should_not be_blank msg_q.first['count'].should == '0' + + create_settings end it 'creates a domain transfer with legal document' do @@ -788,6 +798,8 @@ describe 'EPP Domain', epp: true do response[:result_code].should == '1000' domain.legal_documents.count.should == 1 # does not add another legal documen + + create_settings end it 'approves the transfer request' do From 06d9cbe2f0ddbe2266dfaaf1af990b0b96f819e5 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 26 Jan 2015 18:32:37 +0200 Subject: [PATCH 19/34] Refactor instance variables to methods --- spec/epp/domain_spec.rb | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index aa07aa49b..8aa44f1ba 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -3,11 +3,17 @@ require 'rails_helper' describe 'EPP Domain', epp: true do let(:epp_xml) { EppXml.new(cl_trid: 'ABC-12345') } + def registrar1 + @registrar1 ||= Registrar.where(reg_no: '12345678').first || Fabricate(:registrar) + end + + def registrar2 + @registrar2 ||= Fabricate(:registrar, { name: 'registrar2', reg_no: '123' }) + end + before(:all) do - @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) - @zone = Fabricate(:registrar) - Fabricate(:epp_user, username: 'registrar1', registrar: @zone) - Fabricate(:epp_user, username: 'registrar2', registrar: @elkdata) + Fabricate(:epp_user, username: 'registrar1', registrar: registrar1) + Fabricate(:epp_user, username: 'registrar2', registrar: registrar2) login_as :registrar1 @@ -657,12 +663,12 @@ describe 'EPP Domain', epp: true do end context 'with valid domain' do - before(:each) { Fabricate(:domain, name: next_domain_name, registrar: @zone, dnskeys: []) } + before(:each) { Fabricate(:domain, name: next_domain_name, registrar: registrar1, dnskeys: []) } let(:domain) { Domain.last } ### TRANSFER ### it 'transfers a domain' do - domain.registrar = @zone + domain.registrar = registrar1 domain.save pw = domain.auth_info @@ -687,7 +693,7 @@ describe 'EPP Domain', epp: true do trn_data.css('acDate').text.should == dtl.transferred_at.to_time.utc.to_s trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.to_s - domain.registrar.should == @elkdata + domain.registrar.should == registrar2 Setting.transfer_wait_time = 1 @@ -714,7 +720,7 @@ describe 'EPP Domain', epp: true do trn_data.css('acID').text.should == '123' trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.to_s - domain.registrar.should == @elkdata + domain.registrar.should == registrar2 # should return same data if pending already response = epp_plain_request(xml, :xml) @@ -729,7 +735,7 @@ describe 'EPP Domain', epp: true do trn_data.css('acID').text.should == '123' trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.to_s - domain.registrar.should == @elkdata + domain.registrar.should == registrar2 # should show up in other registrar's poll @@ -787,7 +793,7 @@ describe 'EPP Domain', epp: true do log.request_object.should == 'domain' log.request_successful.should == true log.api_user_name.should == 'registrar2' - log.api_user_registrar.should == 'Elkdata' + log.api_user_registrar.should == 'registrar2' log.request.should_not be_blank log.response.should_not be_blank end @@ -806,8 +812,8 @@ describe 'EPP Domain', epp: true do domain.domain_transfers.create({ status: DomainTransfer::PENDING, transfer_requested_at: Time.zone.now, - transfer_to: @elkdata, - transfer_from: @zone + transfer_to: registrar2, + transfer_from: registrar1 }) xml = domain_transfer_xml({ @@ -834,8 +840,8 @@ describe 'EPP Domain', epp: true do domain.domain_transfers.create({ status: DomainTransfer::PENDING, transfer_requested_at: Time.zone.now, - transfer_to: @elkdata, - transfer_from: @zone + transfer_to: registrar2, + transfer_from: registrar1 }) pw = domain.auth_info @@ -869,8 +875,8 @@ describe 'EPP Domain', epp: true do domain.domain_transfers.create({ status: DomainTransfer::PENDING, transfer_requested_at: Time.zone.now, - transfer_to: @elkdata, - transfer_from: @zone + transfer_to: registrar2, + transfer_from: registrar1 }) xml = domain_transfer_xml({ From 221c62c84674fe49bb3c3381b7e4ae91fc89dbbb Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 26 Jan 2015 17:55:27 +0200 Subject: [PATCH 20/34] Added manual database cleaning + Api log spec updates --- spec/epp/contact_spec.rb | 32 ++++++++++---------------------- spec/epp/keyrelay_spec.rb | 5 +++++ spec/rails_helper.rb | 30 +++++++++++++++--------------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 0eed1440b..8395fb3ef 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -63,6 +63,7 @@ describe 'EPP Contact', epp: true do end it 'successfully creates a contact' do + ApiLog::EppLog.delete_all response = epp_plain_request(create_contact_xml, :xml) response[:msg].should == 'Command completed successfully' @@ -76,29 +77,16 @@ describe 'EPP Contact', epp: true do @contact.ident.should == '37605030299' @contact.address.street.should == '123 Example' - # log = ApiLog::EppLog.all + log = ApiLog::EppLog.all - # log.length.should == 4 - # log[0].request_command.should == 'hello' - # log[0].request_successful.should == true - - # log[1].request_command).to eq('login') - # log[1].request_successful).to eq(true) - # log[1].api_user_name).to eq('registrar1') - # log[1].api_user_registrar).to eq('Registrar OÜ') - - # log[2].request_command).to eq('create') - # log[2].request_object).to eq('contact') - # log[2].request_successful).to eq(true) - # log[2].api_user_name).to eq('registrar1') - # log[2].api_user_registrar).to eq('Registrar OÜ') - # log[2].request).not_to be_blank - # log[2].response).not_to be_blank - - # log[3].request_command).to eq('logout') - # log[3].request_successful).to eq(true) - # log[3].api_user_name).to eq('registrar1') - # log[3].api_user_registrar).to eq('Registrar OÜ') + log.length.should == 1 + log[0].request_command.should == 'create' + log[0].request_object.should == 'contact' + log[0].request_successful.should == 'true' + log[0].api_user_name.should == 'registrar1' + log[0].api_user_registrar.should == 'Registrar OÜ' + log[0].request.should be_blank + log[0].response.should be_blank end it 'successfully adds registrar' do diff --git a/spec/epp/keyrelay_spec.rb b/spec/epp/keyrelay_spec.rb index 7e23faa66..c9e730585 100644 --- a/spec/epp/keyrelay_spec.rb +++ b/spec/epp/keyrelay_spec.rb @@ -1,5 +1,6 @@ require 'rails_helper' + describe 'EPP Keyrelay', epp: true do let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) } let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) } @@ -8,6 +9,8 @@ describe 'EPP Keyrelay', epp: true do before(:each) { create_settings } before(:all) do + DatabaseCleaner.clean_with(:truncation) + DatabaseCleaner.strategy = nil @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) @zone = Fabricate(:registrar) Fabricate(:epp_user, username: 'zone', registrar: @zone) @@ -20,6 +23,8 @@ describe 'EPP Keyrelay', epp: true do let(:domain) { Domain.last } it 'makes a keyrelay request' do + ApiLog::EppLog.delete_all + xml = epp_xml.keyrelay({ name: { value: domain.name }, keyData: { diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index dbf7ead82..ab4ef939b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -38,25 +38,25 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :truncation end - config.before(:each) do - DatabaseCleaner.strategy = :transaction - end + # config.before(:each) do + # DatabaseCleaner.strategy = :transaction + # end - config.before(:all, epp: true) do - ActiveRecord::Base.establish_connection :api_log_test - DatabaseCleaner.clean + # config.before(:all, epp: true) do + # ActiveRecord::Base.establish_connection :api_log_test + # DatabaseCleaner.clean - ActiveRecord::Base.establish_connection :test - DatabaseCleaner.clean - end + # ActiveRecord::Base.establish_connection :test + # DatabaseCleaner.clean + # end - config.before(:each, js: true) do - DatabaseCleaner.strategy = :truncation - end + # config.before(:each, js: true) do + # DatabaseCleaner.strategy = :truncation + # end - config.before(:each, type: :request) do - DatabaseCleaner.strategy = :truncation - end + # config.before(:each, type: :request) do + # DatabaseCleaner.strategy = :truncation + # end Capybara.javascript_driver = :poltergeist From 155cb812d93c50d82f9fe6b8e8f0f4faaa355062 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 27 Jan 2015 11:26:21 +0200 Subject: [PATCH 21/34] Updated spec and rails helper --- spec/epp/contact_spec.rb | 9 ++------ spec/epp/keyrelay_spec.rb | 3 --- spec/epp/poll_spec.rb | 1 + spec/models/contact_spec.rb | 5 +++++ spec/rails_helper.rb | 42 +++++++++++++++++++++---------------- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 8395fb3ef..a2a5f9cdb 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -2,9 +2,6 @@ require 'rails_helper' describe 'EPP Contact', epp: true do before :all do - DatabaseCleaner.clean_with(:truncation) - DatabaseCleaner.strategy = nil - Fabricate(:epp_user) Fabricate(:epp_user, username: 'registrar1', registrar: registrar1) Fabricate(:epp_user, username: 'registrar2', registrar: registrar2) @@ -82,11 +79,9 @@ describe 'EPP Contact', epp: true do log.length.should == 1 log[0].request_command.should == 'create' log[0].request_object.should == 'contact' - log[0].request_successful.should == 'true' - log[0].api_user_name.should == 'registrar1' + log[0].request_successful.should == true + log[0].api_user_name.should == 'gitlab' log[0].api_user_registrar.should == 'Registrar OÜ' - log[0].request.should be_blank - log[0].response.should be_blank end it 'successfully adds registrar' do diff --git a/spec/epp/keyrelay_spec.rb b/spec/epp/keyrelay_spec.rb index c9e730585..ab3f1693c 100644 --- a/spec/epp/keyrelay_spec.rb +++ b/spec/epp/keyrelay_spec.rb @@ -1,6 +1,5 @@ require 'rails_helper' - describe 'EPP Keyrelay', epp: true do let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) } let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) } @@ -9,8 +8,6 @@ describe 'EPP Keyrelay', epp: true do before(:each) { create_settings } before(:all) do - DatabaseCleaner.clean_with(:truncation) - DatabaseCleaner.strategy = nil @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) @zone = Fabricate(:registrar) Fabricate(:epp_user, username: 'zone', registrar: @zone) diff --git a/spec/epp/poll_spec.rb b/spec/epp/poll_spec.rb index a22659887..82186f17e 100644 --- a/spec/epp/poll_spec.rb +++ b/spec/epp/poll_spec.rb @@ -17,6 +17,7 @@ describe 'EPP Poll', epp: true do end it 'returns no messages in poll' do + ApiLog::EppLog.delete_all response = epp_request(epp_xml.poll, :xml) expect(response[:msg]).to eq('Command completed successfully; no messages') diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index d06b23525..daa6c4963 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -1,6 +1,11 @@ require 'rails_helper' describe Contact do + before :all do + # DatabaseCleaner.clean_with(:truncation) + # DatabaseCleaner.strategy = :transaction + end + before { create_disclosure_settings } it { should have_one(:address) } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ab4ef939b..403680d20 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -33,30 +33,36 @@ RSpec.configure do |config| config.before(:suite) do ActiveRecord::Base.establish_connection :api_log_test - DatabaseCleaner.strategy = :deletion + DatabaseCleaner.clean_with(:truncation) + DatabaseCleaner.strategy = nil + ActiveRecord::Base.establish_connection :test + end + + config.before(:all) do + DatabaseCleaner.clean_with(:truncation) + end + + config.before(:all, epp: true) do + DatabaseCleaner.strategy = nil + end + + config.before(:each, js: true) do DatabaseCleaner.strategy = :truncation end - # config.before(:each) do - # DatabaseCleaner.strategy = :transaction - # end + config.before(:each, type: :request) do + DatabaseCleaner.strategy = :truncation + end - # config.before(:all, epp: true) do - # ActiveRecord::Base.establish_connection :api_log_test - # DatabaseCleaner.clean + config.before(:each, type: :model) do + DatabaseCleaner.strategy = :transaction + DatabaseCleaner.start + end - # ActiveRecord::Base.establish_connection :test - # DatabaseCleaner.clean - # end - - # config.before(:each, js: true) do - # DatabaseCleaner.strategy = :truncation - # end - - # config.before(:each, type: :request) do - # DatabaseCleaner.strategy = :truncation - # end + config.after(:each, type: :model) do + DatabaseCleaner.clean + end Capybara.javascript_driver = :poltergeist From 9fde619d348387f7d79e6860a7708e775cedcabc Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 27 Jan 2015 11:29:37 +0200 Subject: [PATCH 22/34] Updated contact spec --- spec/epp/contact_spec.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index a2a5f9cdb..dd094e126 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -60,7 +60,6 @@ describe 'EPP Contact', epp: true do end it 'successfully creates a contact' do - ApiLog::EppLog.delete_all response = epp_plain_request(create_contact_xml, :xml) response[:msg].should == 'Command completed successfully' @@ -74,14 +73,12 @@ describe 'EPP Contact', epp: true do @contact.ident.should == '37605030299' @contact.address.street.should == '123 Example' - log = ApiLog::EppLog.all - - log.length.should == 1 - log[0].request_command.should == 'create' - log[0].request_object.should == 'contact' - log[0].request_successful.should == true - log[0].api_user_name.should == 'gitlab' - log[0].api_user_registrar.should == 'Registrar OÜ' + log = ApiLog::EppLog.last + log.request_command.should == 'create' + log.request_object.should == 'contact' + log.request_successful.should == true + log.api_user_name.should == 'gitlab' + log.api_user_registrar.should == 'Registrar OÜ' end it 'successfully adds registrar' do From 47334c8aae86d1a04543dbb4b5ad0109cb7603d7 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 27 Jan 2015 11:41:19 +0200 Subject: [PATCH 23/34] Fix epp helper spec --- spec/epp/epp_helper_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/epp/epp_helper_spec.rb b/spec/epp/epp_helper_spec.rb index 0a0ccc80e..0927d7e38 100644 --- a/spec/epp/epp_helper_spec.rb +++ b/spec/epp/epp_helper_spec.rb @@ -2,16 +2,19 @@ require 'rails_helper' describe 'EPP Helper', epp: true do context 'in context of Domain' do + before(:all) { @uniq_no = proc { @i ||= 0; @i += 1 } } + it 'generates valid transfer xml' do + dn = next_domain_name expected = Nokogiri::XML(' - example.ee + ' + dn + ' - 98oiewslkfkd + 98oiewslkfkd @@ -20,7 +23,7 @@ describe 'EPP Helper', epp: true do ').to_s.squish - generated = Nokogiri::XML(domain_transfer_xml).to_s.squish + generated = Nokogiri::XML(domain_transfer_xml(name: { value: dn })).to_s.squish expect(generated).to eq(expected) expected = Nokogiri::XML(' From f92d3088fba739e3f1c60ba50930fee9ddddade6 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 27 Jan 2015 11:46:39 +0200 Subject: [PATCH 24/34] Refactor poll to hold session --- spec/epp/poll_spec.rb | 92 +++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/spec/epp/poll_spec.rb b/spec/epp/poll_spec.rb index 82186f17e..ff74785a4 100644 --- a/spec/epp/poll_spec.rb +++ b/spec/epp/poll_spec.rb @@ -1,61 +1,56 @@ require 'rails_helper' describe 'EPP Poll', epp: true do - let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) } - let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) } let(:epp_xml) { EppXml::Session.new } - before(:each) { create_settings } + def registrar1 + @registrar1 ||= Registrar.where(reg_no: '12345678').first || Fabricate(:registrar) + end + + def registrar2 + @registrar2 ||= Fabricate(:registrar, { name: 'registrar2', reg_no: '123' }) + end before(:all) do - @elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) - @zone = Fabricate(:registrar) - Fabricate(:epp_user, username: 'zone', registrar: @zone) - Fabricate(:epp_user, username: 'elkdata', registrar: @elkdata) + Fabricate(:epp_user, username: 'registrar1', registrar: registrar1) + Fabricate(:epp_user, username: 'registrar2', registrar: registrar2) + + login_as :registrar1 @uniq_no = proc { @i ||= 0; @i += 1 } + + create_settings end it 'returns no messages in poll' do ApiLog::EppLog.delete_all - response = epp_request(epp_xml.poll, :xml) + response = epp_plain_request(epp_xml.poll, :xml) expect(response[:msg]).to eq('Command completed successfully; no messages') expect(response[:result_code]).to eq('1300') - log = ApiLog::EppLog.all + log = ApiLog::EppLog.last - expect(log.length).to eq(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) - - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('zone') - expect(log[1].api_user_registrar).to eq('Registrar OÜ') - - expect(log[2].request_command).to eq('poll') - expect(log[2].request_object).to eq('poll') - expect(log[2].request_successful).to eq(true) - expect(log[2].api_user_name).to eq('zone') - expect(log[2].api_user_registrar).to eq('Registrar OÜ') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank - - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('zone') - expect(log[3].api_user_registrar).to eq('Registrar OÜ') + expect(log.request_command).to eq('poll') + expect(log.request_object).to eq('poll') + expect(log.request_successful).to eq(true) + expect(log.api_user_name).to eq('registrar1') + expect(log.api_user_registrar).to eq('Registrar OÜ') + expect(log.request).not_to be_blank + expect(log.response).not_to be_blank end it 'queues and dequeues messages' do - msg = @zone.messages.create({ body: 'Balance low.' }) + msg = registrar1.messages.create({ body: 'Balance low.' }) + + response = login_as :registrar2 do + epp_plain_request(epp_xml.poll, :xml) + end - response = epp_request(epp_xml.poll, :xml, :elkdata) expect(response[:msg]).to eq('Command completed successfully; no messages') expect(response[:result_code]).to eq('1300') - response = epp_request(epp_xml.poll, :xml, :zone) + response = epp_plain_request(epp_xml.poll, :xml) expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') expect(response[:result_code]).to eq('1301') msg_q = response[:parsed].css('msgQ') @@ -68,18 +63,21 @@ describe 'EPP Poll', epp: true do value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) - response = epp_request(xml, :xml, :elkdata) + response = login_as :registrar2 do + epp_plain_request(xml, :xml) + end + expect(response[:results][0][:msg]).to eq('Message was not found') expect(response[:results][0][:result_code]).to eq('2303') expect(response[:results][0][:value]).to eq(msg_q.first['id']) - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) expect(response[:msg]).to eq('Command completed successfully') msg_q = response[:parsed].css('msgQ') expect(msg_q.first['id']).to_not be_blank expect(msg_q.first['count']).to eq('0') - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) expect(response[:results][0][:msg]).to eq('Message was not found') expect(response[:results][0][:result_code]).to eq('2303') expect(response[:results][0][:value]).to eq(msg_q.first['id']) @@ -90,16 +88,16 @@ describe 'EPP Poll', epp: true do value: '', attrs: { op: 'bla' } }) - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) expect(response[:msg]).to eq('Attribute op is invalid') end it 'dequeues multiple messages' do - @zone.messages.create({ body: 'Balance low.' }) - @zone.messages.create({ body: 'Something.' }) - @zone.messages.create({ body: 'Smth else.' }) + registrar1.messages.create({ body: 'Balance low.' }) + registrar1.messages.create({ body: 'Something.' }) + registrar1.messages.create({ body: 'Smth else.' }) - response = epp_request(epp_xml.poll, :xml, :zone) + response = epp_plain_request(epp_xml.poll, :xml) expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') expect(response[:result_code]).to eq('1301') msg_q = response[:parsed].css('msgQ') @@ -111,13 +109,13 @@ describe 'EPP Poll', epp: true do value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) expect(response[:msg]).to eq('Command completed successfully') msg_q = response[:parsed].css('msgQ') expect(msg_q.first['id']).to_not be_blank expect(msg_q.first['count']).to eq('2') - response = epp_request(epp_xml.poll, :xml, :zone) + response = epp_plain_request(epp_xml.poll, :xml) expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') expect(response[:result_code]).to eq('1301') msg_q = response[:parsed].css('msgQ') @@ -129,13 +127,13 @@ describe 'EPP Poll', epp: true do value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) expect(response[:msg]).to eq('Command completed successfully') msg_q = response[:parsed].css('msgQ') expect(msg_q.first['id']).to_not be_blank expect(msg_q.first['count']).to eq('1') - response = epp_request(epp_xml.poll, :xml, :zone) + response = epp_plain_request(epp_xml.poll, :xml) expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') expect(response[:result_code]).to eq('1301') msg_q = response[:parsed].css('msgQ') @@ -147,13 +145,13 @@ describe 'EPP Poll', epp: true do value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) - response = epp_request(xml, :xml, :zone) + response = epp_plain_request(xml, :xml) expect(response[:msg]).to eq('Command completed successfully') msg_q = response[:parsed].css('msgQ') expect(msg_q.first['id']).to_not be_blank expect(msg_q.first['count']).to eq('0') - response = epp_request(epp_xml.poll, :xml, :zone) + response = epp_plain_request(epp_xml.poll, :xml) expect(response[:msg]).to eq('Command completed successfully; no messages') expect(response[:result_code]).to eq('1300') end From 290fe0629d12bbc517b84adc20ea757c1cd48926 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 27 Jan 2015 11:50:07 +0200 Subject: [PATCH 25/34] Fix request spec log --- spec/requests/domain_v1_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/domain_v1_spec.rb b/spec/requests/domain_v1_spec.rb index 0e362179a..a622b6828 100644 --- a/spec/requests/domain_v1_spec.rb +++ b/spec/requests/domain_v1_spec.rb @@ -18,7 +18,7 @@ describe Repp::DomainV1 do # TODO: Maybe there is a way not to convert from and to json again expect(body['domains'].to_json).to eq(epp_user.registrar.domains.to_json) - log = ApiLog::ReppLog.first + log = ApiLog::ReppLog.last expect(log[:request_path]).to eq('/repp/v1/domains') expect(log[:request_method]).to eq('GET') expect(log[:request_params]).to eq('{}') From bfed783106ee47099001e5647e9edd238812bfbf Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 27 Jan 2015 12:19:34 +0200 Subject: [PATCH 26/34] Updated epp session spec --- spec/epp/session_spec.rb | 131 ++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 64 deletions(-) diff --git a/spec/epp/session_spec.rb b/spec/epp/session_spec.rb index f7c728385..91929715d 100644 --- a/spec/epp/session_spec.rb +++ b/spec/epp/session_spec.rb @@ -1,86 +1,89 @@ require 'rails_helper' describe 'EPP Session', epp: true do - let(:server_gitlab) { Epp::Server.new({ server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701 }) } - let(:epp_xml) { EppXml.new(cl_trid: 'ABC-12345') } - let(:login_xml_cache) { epp_xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' }) } + before :all do + @epp_user = Fabricate(:epp_user) + @epp_xml = EppXml.new(cl_trid: 'ABC-12345') + @login_xml_cache = @epp_xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' }) + + end context 'when not connected' do it 'greets client upon connection' do - response = Nokogiri::XML(server_gitlab.open_connection) - expect(response.css('epp svID').text).to eq('EPP server (EIS)') - server_gitlab.close_connection - + response = Nokogiri::XML(server.open_connection) + response.css('epp svID').text.should == 'EPP server (EIS)' puts "RESPONSE:\n\n```xml\n#{response}```\n\n" if ENV['EPP_DOC'] end end context 'when connected' do - before(:each) { server_gitlab.open_connection } - after(:each) { server_gitlab.close_connection } - - context 'with valid user' do - before(:each) { Fabricate(:epp_user) } - - it 'logs in epp user' do - response = epp_plain_request(login_xml_cache, :xml) - expect(response[:result_code]).to eq('1000') - expect(response[:msg]).to eq('Command completed successfully') - expect(response[:clTRID]).to eq('ABC-12345') - end - - it 'logs out epp user' do - epp_plain_request(login_xml_cache, :xml) - - expect(EppSession.first[:epp_user_id]).to eq(1) - response = epp_plain_request(epp_xml.session.logout, :xml) - expect(response[:result_code]).to eq('1500') - expect(response[:msg]).to eq('Command completed successfully; ending session') - - expect(EppSession.first[:epp_user_id]).to eq(nil) - end - - it 'does not log in twice' do - epp_plain_request(login_xml_cache, :xml) - - response = epp_plain_request(login_xml_cache, :xml) - expect(response[:result_code]).to eq('2002') - expect(response[:msg]).to match(/Already logged in. Use/) - - log = ApiLog::EppLog.all - expect(log.length).to eq(3) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) - - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('gitlab') - expect(log[1].api_user_registrar).to eq('Registrar OÜ') - - expect(log[2].request_command).to eq('login') - expect(log[2].request_successful).to eq(false) - expect(log[2].api_user_name).to eq('gitlab') - expect(log[2].api_user_registrar).to eq('Registrar OÜ') - end + before do + server.open_connection end it 'does not log in with invalid user' do - response = epp_plain_request(login_xml_cache, :xml) - expect(response[:result_code]).to eq('2501') - expect(response[:msg]).to eq('Authentication error; server closing connection') - expect(response[:clTRID]).to eq('ABC-12345') + wrong_user = @epp_xml.session.login(clID: { value: 'wrong-user' }, pw: { value: 'ghyt9e4fu' }) + response = epp_plain_request(wrong_user, :xml) + response[:msg].should == 'Authentication error; server closing connection' + response[:result_code].should == '2501' + response[:clTRID].should == 'ABC-12345' + end - Fabricate(:epp_user, active: false) + it 'does not log in with inactive user' do + @registrar = Fabricate(:registrar, { name: 'registrar1', reg_no: '123' }) + Fabricate(:epp_user, username: 'inactive-user', active: false, registrar: @registrar) - response = epp_plain_request(login_xml_cache, :xml) - expect(response[:result_code]).to eq('2501') + inactive = @epp_xml.session.login(clID: { value: 'inactive-user' }, pw: { value: 'ghyt9e4fu' }) + response = epp_plain_request(inactive, :xml) + response[:result_code].should == '2501' end it 'prohibits further actions unless logged in' do - response = epp_plain_request(epp_xml.domain.create, :xml) - expect(response[:result_code]).to eq('2002') - expect(response[:msg]).to eq('You need to login first.') - expect(response[:clTRID]).to eq('ABC-12345') + response = epp_plain_request(@epp_xml.domain.create, :xml) + response[:msg].should == 'You need to login first.' + response[:result_code].should == '2002' + response[:clTRID].should == 'ABC-12345' + end + + context 'with valid user' do + it 'logs in epp user' do + response = epp_plain_request(@login_xml_cache, :xml) + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + response[:clTRID].should == 'ABC-12345' + end + + it 'does not log in twice' do + ApiLog::EppLog.delete_all + epp_plain_request(@login_xml_cache, :xml) + response = epp_plain_request(@login_xml_cache, :xml) + response[:msg].should match(/Already logged in. Use/) + response[:result_code].should == '2002' + + log = ApiLog::EppLog.all + log.length.should == 2 + + log[0].request_command.should == 'login' + log[0].request_successful.should == true + log[0].api_user_name.should == 'gitlab' + log[0].api_user_registrar.should == 'Registrar OÜ' + + log[1].request_command.should == 'login' + log[1].request_successful.should == false + log[1].api_user_name.should == 'gitlab' + log[1].api_user_registrar.should == 'Registrar OÜ' + end + + it 'logs out epp user' do + epp_plain_request(@login_xml_cache, :xml) + + EppSession.first[:epp_user_id].should == 1 + response = epp_plain_request(@epp_xml.session.logout, :xml) + response[:msg].should == 'Command completed successfully; ending session' + response[:result_code].should == '1500' + + EppSession.first[:epp_user_id].should == nil + end end end end From 425e26cff3bdb1ce6787814380048bf1afe38598 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 27 Jan 2015 12:22:08 +0200 Subject: [PATCH 27/34] Fixed session spec --- spec/epp/session_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/epp/session_spec.rb b/spec/epp/session_spec.rb index 91929715d..55fab7391 100644 --- a/spec/epp/session_spec.rb +++ b/spec/epp/session_spec.rb @@ -77,12 +77,12 @@ describe 'EPP Session', epp: true do it 'logs out epp user' do epp_plain_request(@login_xml_cache, :xml) - EppSession.first[:epp_user_id].should == 1 + EppSession.last[:epp_user_id].should == 1 response = epp_plain_request(@epp_xml.session.logout, :xml) response[:msg].should == 'Command completed successfully; ending session' response[:result_code].should == '1500' - EppSession.first[:epp_user_id].should == nil + EppSession.last[:epp_user_id].should == nil end end end From 96dfbbba50292b46a8058f129bfd2e7a99c81d15 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 27 Jan 2015 12:26:37 +0200 Subject: [PATCH 28/34] Fixed contact spec --- spec/models/contact_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index daa6c4963..1bb2af44d 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -81,6 +81,11 @@ describe Contact do end context 'with callbacks' do + before :all do + Contact.set_callback(:create, :before, :generate_code) + Contact.set_callback(:create, :before, :generate_auth_info) + end + before(:each) { @contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321') } context 'after create' do From 07026030b268a125d61d1236ce32dc7909fe9f21 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 27 Jan 2015 12:39:33 +0200 Subject: [PATCH 29/34] Spec now clean --- spec/epp/session_spec.rb | 24 ++++++------- spec/models/domain_spec.rb | 70 +++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/spec/epp/session_spec.rb b/spec/epp/session_spec.rb index 55fab7391..c11f7c5f9 100644 --- a/spec/epp/session_spec.rb +++ b/spec/epp/session_spec.rb @@ -54,24 +54,20 @@ describe 'EPP Session', epp: true do end it 'does not log in twice' do - ApiLog::EppLog.delete_all - epp_plain_request(@login_xml_cache, :xml) + response = epp_plain_request(@login_xml_cache, :xml) + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + response[:clTRID].should == 'ABC-12345' + response = epp_plain_request(@login_xml_cache, :xml) response[:msg].should match(/Already logged in. Use/) response[:result_code].should == '2002' - log = ApiLog::EppLog.all - log.length.should == 2 - - log[0].request_command.should == 'login' - log[0].request_successful.should == true - log[0].api_user_name.should == 'gitlab' - log[0].api_user_registrar.should == 'Registrar OÜ' - - log[1].request_command.should == 'login' - log[1].request_successful.should == false - log[1].api_user_name.should == 'gitlab' - log[1].api_user_registrar.should == 'Registrar OÜ' + log = ApiLog::EppLog.last + log.request_command.should == 'login' + log.request_successful.should == false + log.api_user_name.should == 'gitlab' + log.api_user_registrar.should == 'Registrar OÜ' end it 'logs out epp user' do diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index b61c2aa19..733ce22f6 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -15,52 +15,52 @@ describe Domain do create_settings end - it 'validates domain name', skip: true do - d = Fabricate(:domain) - expect(d.name).to_not be_nil + # it 'validates domain name', skip: true do + # d = Fabricate(:domain) + # expect(d.name).to_not be_nil - invalid = ['a.ee', "#{'a' * 64}.ee", 'ab.eu', 'test.ab.ee', '-test.ee', '-test-.ee', 'test-.ee', 'te--st.ee', - 'õ.pri.ee', 'test.com', 'www.ab.ee', 'test.eu', ' .ee', 'a b.ee', 'Ž .ee', 'test.edu.ee'] + # invalid = ['a.ee', "#{'a' * 64}.ee", 'ab.eu', 'test.ab.ee', '-test.ee', '-test-.ee', 'test-.ee', 'te--st.ee', + # 'õ.pri.ee', 'test.com', 'www.ab.ee', 'test.eu', ' .ee', 'a b.ee', 'Ž .ee', 'test.edu.ee'] - invalid.each do |x| - expect(Fabricate.build(:domain, name: x).valid?).to be false - end + # invalid.each do |x| + # expect(Fabricate.build(:domain, name: x).valid?).to be false + # end - valid = ['ab.ee', "#{'a' * 63}.ee", 'te-s-t.ee', 'jäääär.ee', 'päike.pri.ee', - 'õigus.com.ee', 'õäöü.fie.ee', 'test.med.ee', 'žä.ee', ' ŽŠ.ee '] + # valid = ['ab.ee', "#{'a' * 63}.ee", 'te-s-t.ee', 'jäääär.ee', 'päike.pri.ee', + # 'õigus.com.ee', 'õäöü.fie.ee', 'test.med.ee', 'žä.ee', ' ŽŠ.ee '] - valid.each do |x| - expect(Fabricate.build(:domain, name: x).valid?).to be true - end + # valid.each do |x| + # expect(Fabricate.build(:domain, name: x).valid?).to be true + # end - invalid_punycode = ['xn--geaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-4we.pri.ee'] + # invalid_punycode = ['xn--geaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-4we.pri.ee'] - invalid_punycode.each do |x| - expect(Fabricate.build(:domain, name: x).valid?).to be false - end + # invalid_punycode.each do |x| + # expect(Fabricate.build(:domain, name: x).valid?).to be false + # end - valid_punycode = ['xn--ge-uia.pri.ee', 'xn--geaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-9te.pri.ee'] + # valid_punycode = ['xn--ge-uia.pri.ee', 'xn--geaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-9te.pri.ee'] - valid_punycode.each do |x| - expect(Fabricate.build(:domain, name: x).valid?).to be true - end + # valid_punycode.each do |x| + # expect(Fabricate.build(:domain, name: x).valid?).to be true + # end - d = Domain.new - expect(d.valid?).to be false - expect(d.errors.messages).to match_array({ - owner_contact: ['Registrant is missing'], - admin_contacts: ['Admin contacts count must be between 1 - infinity'], - nameservers: ['Nameservers count must be between 2-11'], - registrar: ['Registrar is missing'], - period: ['Period is not a number'] - }) + # d = Domain.new + # expect(d.valid?).to be false + # expect(d.errors.messages).to match_array({ + # owner_contact: ['Registrant is missing'], + # admin_contacts: ['Admin contacts count must be between 1 - infinity'], + # nameservers: ['Nameservers count must be between 2-11'], + # registrar: ['Registrar is missing'], + # period: ['Period is not a number'] + # }) - Setting.ns_min_count = 2 - Setting.ns_max_count = 7 + # Setting.ns_min_count = 2 + # Setting.ns_max_count = 7 - expect(d.valid?).to be false - expect(d.errors.messages[:nameservers]).to eq(['Nameservers count must be between 2-7']) - end + # expect(d.valid?).to be false + # expect(d.errors.messages[:nameservers]).to eq(['Nameservers count must be between 2-7']) + # end it 'downcases domain' do d = Domain.new(name: 'TesT.Ee') From 62eb65793bba52d563edc648cc8dcff0c6716b0a Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 27 Jan 2015 13:08:27 +0200 Subject: [PATCH 30/34] Add mutually_exclusive helper --- app/controllers/epp/domains_controller.rb | 7 +++--- app/controllers/epp_controller.rb | 18 +++++++++++++++- config/locales/en.yml | 2 +- spec/epp/domain_spec.rb | 26 +++++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 84ad12d85..c47e0d69f 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -126,13 +126,12 @@ class Epp::DomainsController < EppController end def validate_create - if params[:parsed_frame].css('dsData').count > 0 && params[:parsed_frame].css('create > keyData').count > 0 - epp_errors << { code: '2306', msg: I18n.t('ds_data_and_key_data_must_not_exists_together') } - end - @prefix = 'create > create >' requires('name', 'ns', 'registrant', 'ns > hostAttr') + @prefix = 'extension > create >' + mutually_exclusive 'keyData', 'dsData' + @prefix = nil requires('extension > extdata > legalDocument') end diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 32ffaf156..6d38a5225 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -75,6 +75,22 @@ class EppController < ApplicationController epp_errors.empty? end + def mutually_exclusive(*selectors) + present_count = 0 + selectors.each do |selector| + full_selector = [@prefix, selector].join(' ') + el = params[:parsed_frame].css(full_selector).first + present_count += 1 if el && el.text.present? + end + + return if present_count <= 1 + + epp_errors << { + code: '2306', + msg: I18n.t(:are_mutally_exclusive, params: selectors.join(', ')) + } + end + # let's follow grape's validations: https://github.com/intridea/grape/#parameter-validation-and-coercion def exactly_one_of(*selectors) present_count = 0 @@ -87,7 +103,7 @@ class EppController < ApplicationController return if present_count == 1 epp_errors << { - code: '2003', + code: '2306', msg: I18n.t(:exactly_one_parameter_required, params: selectors.join(' or ')) } end diff --git a/config/locales/en.yml b/config/locales/en.yml index 677c8de96..15236335a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -433,7 +433,6 @@ en: failed_to_delete_record: 'Failed to delete record' authentication_error: 'Authentication error' - ds_data_and_key_data_must_not_exists_together: 'dsData and keyData objects must not exists together' setting: 'Setting' @@ -501,3 +500,4 @@ en: could_not_determine_object_type_check_xml_format_and_namespaces: 'Could not determine object type. Check XML format and namespaces.' unknown_expiry_relative_pattern: 'Expiry relative must be compatible to ISO 8601' unknown_expiry_absolute_pattern: 'Expiry absolute must be compatible to ISO 8601' + are_mutally_exclusive: '%{params} are mutually exclusive' diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 8aa44f1ba..e810585ba 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -606,6 +606,32 @@ describe 'EPP Domain', epp: true do create_settings end + + it 'prohibits dsData and keyData when they exists together' do + xml = domain_create_xml({}, { + _anonymus: [ + { + dsData: { + keyTag: { value: '12345' }, + alg: { value: '3' }, + digestType: { value: '1' }, + digest: { value: '49FD46E6C4B45C55D4AC' } + } + }, + { + keyData: { + flags: { value: '0' }, + protocol: { value: '3' }, + alg: { value: '5' }, + pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } + } + }] + }) + + response = epp_plain_request(xml, :xml) + response[:msg].should == 'keyData, dsData are mutually exclusive' + response[:result_code].should == '2306' + end end context 'with juridical persion as an owner' do From 0f3378152715e690ca72bc45d0bb02cee5b511aa Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 27 Jan 2015 13:11:41 +0200 Subject: [PATCH 31/34] Refactor poll to use should --- spec/epp/poll_spec.rb | 98 +++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/spec/epp/poll_spec.rb b/spec/epp/poll_spec.rb index ff74785a4..befa5d2ca 100644 --- a/spec/epp/poll_spec.rb +++ b/spec/epp/poll_spec.rb @@ -26,18 +26,18 @@ describe 'EPP Poll', epp: true do ApiLog::EppLog.delete_all response = epp_plain_request(epp_xml.poll, :xml) - expect(response[:msg]).to eq('Command completed successfully; no messages') - expect(response[:result_code]).to eq('1300') + response[:msg].should == 'Command completed successfully; no messages' + response[:result_code].should == '1300' log = ApiLog::EppLog.last - expect(log.request_command).to eq('poll') - expect(log.request_object).to eq('poll') - expect(log.request_successful).to eq(true) - expect(log.api_user_name).to eq('registrar1') - expect(log.api_user_registrar).to eq('Registrar OÜ') - expect(log.request).not_to be_blank - expect(log.response).not_to be_blank + log.request_command.should == 'poll' + log.request_object.should == 'poll' + log.request_successful.should == true + log.api_user_name.should == 'registrar1' + log.api_user_registrar.should == 'Registrar OÜ' + log.request.should_not be_blank + log.response.should_not be_blank end it 'queues and dequeues messages' do @@ -47,17 +47,17 @@ describe 'EPP Poll', epp: true do epp_plain_request(epp_xml.poll, :xml) end - expect(response[:msg]).to eq('Command completed successfully; no messages') - expect(response[:result_code]).to eq('1300') + response[:msg].should == 'Command completed successfully; no messages' + response[:result_code].should == '1300' response = epp_plain_request(epp_xml.poll, :xml) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - expect(response[:result_code]).to eq('1301') + response[:msg].should == 'Command completed successfully; ack to dequeue' + response[:result_code].should == '1301' msg_q = response[:parsed].css('msgQ') - expect(msg_q.css('msg').text).to eq('Balance low.') - expect(msg_q.first['count']).to eq('1') - expect(msg_q.first['id']).to eq(msg.id.to_s) + msg_q.css('msg').text.should == 'Balance low.' + msg_q.first['count'].should == '1' + msg_q.first['id'].should == msg.id.to_s xml = epp_xml.poll(poll: { value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } @@ -67,20 +67,20 @@ describe 'EPP Poll', epp: true do epp_plain_request(xml, :xml) end - expect(response[:results][0][:msg]).to eq('Message was not found') - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:value]).to eq(msg_q.first['id']) + response[:results][0][:msg].should == 'Message was not found' + response[:results][0][:result_code].should == '2303' + response[:results][0][:value].should == msg_q.first['id'] response = epp_plain_request(xml, :xml) - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('0') + msg_q.first['id'].should_not be_blank + msg_q.first['count'].should == '0' response = epp_plain_request(xml, :xml) - expect(response[:results][0][:msg]).to eq('Message was not found') - expect(response[:results][0][:result_code]).to eq('2303') - expect(response[:results][0][:value]).to eq(msg_q.first['id']) + response[:results][0][:msg].should == 'Message was not found' + response[:results][0][:result_code].should == '2303' + response[:results][0][:value].should == msg_q.first['id'] end it 'returns an error on incorrect op' do @@ -89,7 +89,7 @@ describe 'EPP Poll', epp: true do }) response = epp_plain_request(xml, :xml) - expect(response[:msg]).to eq('Attribute op is invalid') + response[:msg].should == 'Attribute op is invalid' end it 'dequeues multiple messages' do @@ -98,61 +98,61 @@ describe 'EPP Poll', epp: true do registrar1.messages.create({ body: 'Smth else.' }) response = epp_plain_request(epp_xml.poll, :xml) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - expect(response[:result_code]).to eq('1301') + response[:msg].should == 'Command completed successfully; ack to dequeue' + response[:result_code].should == '1301' msg_q = response[:parsed].css('msgQ') - expect(msg_q.css('msg').text).to eq('Smth else.') - expect(msg_q.first['count']).to eq('3') + msg_q.css('msg').text.should == 'Smth else.' + msg_q.first['count'].should == '3' xml = epp_xml.poll(poll: { value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) response = epp_plain_request(xml, :xml) - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('2') + msg_q.first['id'].should_not be_blank + msg_q.first['count'].should == '2' response = epp_plain_request(epp_xml.poll, :xml) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - expect(response[:result_code]).to eq('1301') + response[:msg].should == 'Command completed successfully; ack to dequeue' + response[:result_code].should == '1301' msg_q = response[:parsed].css('msgQ') - expect(msg_q.css('msg').text).to eq('Something.') - expect(msg_q.first['count']).to eq('2') + msg_q.css('msg').text.should == 'Something.' + msg_q.first['count'].should == '2' xml = epp_xml.poll(poll: { value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) response = epp_plain_request(xml, :xml) - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('1') + msg_q.first['id'].should_not be_blank + msg_q.first['count'].should == '1' response = epp_plain_request(epp_xml.poll, :xml) - expect(response[:msg]).to eq('Command completed successfully; ack to dequeue') - expect(response[:result_code]).to eq('1301') + response[:msg].should == 'Command completed successfully; ack to dequeue' + response[:result_code].should == '1301' msg_q = response[:parsed].css('msgQ') - expect(msg_q.css('msg').text).to eq('Balance low.') - expect(msg_q.first['count']).to eq('1') + msg_q.css('msg').text.should == 'Balance low.' + msg_q.first['count'].should == '1' xml = epp_xml.poll(poll: { value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } }) response = epp_plain_request(xml, :xml) - expect(response[:msg]).to eq('Command completed successfully') + response[:msg].should == 'Command completed successfully' msg_q = response[:parsed].css('msgQ') - expect(msg_q.first['id']).to_not be_blank - expect(msg_q.first['count']).to eq('0') + msg_q.first['id'].should_not be_blank + msg_q.first['count'].should == '0' response = epp_plain_request(epp_xml.poll, :xml) - expect(response[:msg]).to eq('Command completed successfully; no messages') - expect(response[:result_code]).to eq('1300') + response[:msg].should == 'Command completed successfully; no messages' + response[:result_code].should == '1300' end end From 6691c790c2de21badf93d0de6df4f983c3ea484e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 27 Jan 2015 13:13:05 +0200 Subject: [PATCH 32/34] Refactor keyrelay spec to use should --- spec/epp/keyrelay_spec.rb | 62 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/spec/epp/keyrelay_spec.rb b/spec/epp/keyrelay_spec.rb index ab3f1693c..0d6dc2418 100644 --- a/spec/epp/keyrelay_spec.rb +++ b/spec/epp/keyrelay_spec.rb @@ -40,34 +40,34 @@ describe 'EPP Keyrelay', epp: true do response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Command completed successfully') - expect(response[:result_code]).to eq('1000') + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' - expect(@zone.messages.queued.count).to eq(1) + @zone.messages.queued.count.should == 1 log = ApiLog::EppLog.all - expect(log.length).to eq(4) - expect(log[0].request_command).to eq('hello') - expect(log[0].request_successful).to eq(true) + log.length.should == 4 + log[0].request_command.should == 'hello' + log[0].request_successful.should == true - expect(log[1].request_command).to eq('login') - expect(log[1].request_successful).to eq(true) - expect(log[1].api_user_name).to eq('elkdata') - expect(log[1].api_user_registrar).to eq('Elkdata') + log[1].request_command.should == 'login' + log[1].request_successful.should == true + log[1].api_user_name.should == 'elkdata' + log[1].api_user_registrar.should == 'Elkdata' - expect(log[2].request_command).to eq('keyrelay') - expect(log[2].request_object).to eq('keyrelay') - expect(log[2].request_successful).to eq(true) - expect(log[2].api_user_name).to eq('elkdata') - expect(log[2].api_user_registrar).to eq('Elkdata') - expect(log[2].request).not_to be_blank - expect(log[2].response).not_to be_blank + log[2].request_command.should == 'keyrelay' + log[2].request_object.should == 'keyrelay' + log[2].request_successful.should == true + log[2].api_user_name.should == 'elkdata' + log[2].api_user_registrar.should == 'Elkdata' + log[2].request.should_not be_blank + log[2].response.should_not be_blank - expect(log[3].request_command).to eq('logout') - expect(log[3].request_successful).to eq(true) - expect(log[3].api_user_name).to eq('elkdata') - expect(log[3].api_user_registrar).to eq('Elkdata') + log[3].request_command.should == 'logout' + log[3].request_successful.should == true + log[3].api_user_name.should == 'elkdata' + log[3].api_user_registrar.should == 'Elkdata' end it 'returns an error when parameters are missing' do @@ -89,9 +89,9 @@ describe 'EPP Keyrelay', epp: true do }) response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Required parameter missing: flags') + response[:msg].should == 'Required parameter missing: flags' - expect(@zone.messages.queued.count).to eq(msg_count) + @zone.messages.queued.count.should == msg_count end it 'returns an error on invalid relative expiry' do @@ -113,10 +113,10 @@ describe 'EPP Keyrelay', epp: true do }) response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Expiry relative must be compatible to ISO 8601') - expect(response[:results][0][:value]).to eq('Invalid Expiry') + response[:msg].should == 'Expiry relative must be compatible to ISO 8601' + response[:results][0][:value].should == 'Invalid Expiry' - expect(@zone.messages.queued.count).to eq(msg_count) + @zone.messages.queued.count.should == msg_count end it 'returns an error on invalid absolute expiry' do @@ -138,10 +138,10 @@ describe 'EPP Keyrelay', epp: true do }) response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Expiry absolute must be compatible to ISO 8601') - expect(response[:results][0][:value]).to eq('Invalid Absolute') + response[:msg].should == 'Expiry absolute must be compatible to ISO 8601' + response[:results][0][:value].should == 'Invalid Absolute' - expect(@zone.messages.queued.count).to eq(msg_count) + @zone.messages.queued.count.should == msg_count end it 'does not allow both relative and absolute' do @@ -164,8 +164,8 @@ describe 'EPP Keyrelay', epp: true do }) response = epp_request(xml, :xml, :elkdata) - expect(response[:msg]).to eq('Exactly one parameter required: expiry > relative or expiry > absolute') + response[:msg].should == 'Exactly one parameter required: expiry > relative or expiry > absolute' - expect(@zone.messages.queued.count).to eq(msg_count) + @zone.messages.queued.count.should == msg_count end end From cad6d68bfa61029f03f557ebf1b2bae408796e47 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 27 Jan 2015 13:13:52 +0200 Subject: [PATCH 33/34] Refactor epp helper spec to use should --- spec/epp/epp_helper_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/epp/epp_helper_spec.rb b/spec/epp/epp_helper_spec.rb index 0927d7e38..676925826 100644 --- a/spec/epp/epp_helper_spec.rb +++ b/spec/epp/epp_helper_spec.rb @@ -24,7 +24,7 @@ describe 'EPP Helper', epp: true do ').to_s.squish generated = Nokogiri::XML(domain_transfer_xml(name: { value: dn })).to_s.squish - expect(generated).to eq(expected) + generated.should == expected expected = Nokogiri::XML(' @@ -51,7 +51,7 @@ describe 'EPP Helper', epp: true do }, 'approve') generated = Nokogiri::XML(xml).to_s.squish - expect(generated).to eq(expected) + generated.should == expected end end end From ebfa9971243987520aa75938fbcd41932f2b7ffd Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 27 Jan 2015 13:42:02 +0200 Subject: [PATCH 34/34] Make request validation shorter on domain create --- app/controllers/epp/domains_controller.rb | 2 +- app/controllers/epp_controller.rb | 43 ++++++++++------------- config/locales/en.yml | 2 +- spec/epp/domain_spec.rb | 2 +- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index c47e0d69f..82eae2105 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -142,7 +142,7 @@ class Epp::DomainsController < EppController end def validate_update - if params[:parsed_frame].css('chg registrant').present? && params[:parsed_frame].css('legalDocument').blank? + if element_count('update > chg > registrant') > 0 requires('extension > extdata > legalDocument') end diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 6d38a5225..8981dcd8f 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -75,32 +75,9 @@ class EppController < ApplicationController epp_errors.empty? end - def mutually_exclusive(*selectors) - present_count = 0 - selectors.each do |selector| - full_selector = [@prefix, selector].join(' ') - el = params[:parsed_frame].css(full_selector).first - present_count += 1 if el && el.text.present? - end - - return if present_count <= 1 - - epp_errors << { - code: '2306', - msg: I18n.t(:are_mutally_exclusive, params: selectors.join(', ')) - } - end - # let's follow grape's validations: https://github.com/intridea/grape/#parameter-validation-and-coercion def exactly_one_of(*selectors) - present_count = 0 - selectors.each do |selector| - full_selector = [@prefix, selector].join(' ') - el = params[:parsed_frame].css(full_selector).first - present_count += 1 if el && el.text.present? - end - - return if present_count == 1 + return if element_count(*selectors) == 1 epp_errors << { code: '2306', @@ -108,6 +85,14 @@ class EppController < ApplicationController } end + def mutually_exclusive(*selectors) + return if element_count(*selectors) <= 1 + epp_errors << { + code: '2306', + msg: I18n.t(:mutally_exclusive_params, params: selectors.join(', ')) + } + end + def optional(selector, *validations) full_selector = [@prefix, selector].join(' ') el = params[:parsed_frame].css(full_selector).first @@ -121,6 +106,16 @@ class EppController < ApplicationController end end + def element_count(*selectors) + present_count = 0 + selectors.each do |selector| + full_selector = [@prefix, selector].join(' ') + el = params[:parsed_frame].css(full_selector).first + present_count += 1 if el && el.text.present? + end + present_count + end + def xml_attrs_present?(ph, attributes) # TODO: THIS IS DEPRECATED AND WILL BE REMOVED IN FUTURE attributes.each do |x| epp_errors << { diff --git a/config/locales/en.yml b/config/locales/en.yml index 15236335a..b14579991 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -500,4 +500,4 @@ en: could_not_determine_object_type_check_xml_format_and_namespaces: 'Could not determine object type. Check XML format and namespaces.' unknown_expiry_relative_pattern: 'Expiry relative must be compatible to ISO 8601' unknown_expiry_absolute_pattern: 'Expiry absolute must be compatible to ISO 8601' - are_mutally_exclusive: '%{params} are mutually exclusive' + mutally_exclusive_params: 'Mutually exclusive parameters: %{params}' diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index e810585ba..355c06f09 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -629,7 +629,7 @@ describe 'EPP Domain', epp: true do }) response = epp_plain_request(xml, :xml) - response[:msg].should == 'keyData, dsData are mutually exclusive' + response[:msg].should == 'Mutually exclusive parameters: keyData, dsData' response[:result_code].should == '2306' end end