Db does not truncate between tests

This commit is contained in:
Martin Lensment 2015-01-23 18:44:59 +02:00
parent 79e64dc2ab
commit ea5c443ffb
3 changed files with 1404 additions and 1350 deletions

View file

@ -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,28 +20,47 @@ 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)
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)
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(:reserved_domain)
@uniq_no = Proc.new { @i ||= 0; @i += 1 }
end
it 'returns error if contact does not exists' do
Fabricate(:contact, code: 'jd1234')
response = epp_request(domain_create_xml, :xml)
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('sh8013')
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('sh801333')
expect(response[:results][1][:value]).to eq('sh2222')
expect(response[:clTRID]).to eq('ABC-12345')
log = ApiLog::EppLog.all
log = ApiLog::EppLog.last(4)
expect(log.length).to eq(4)
expect(log[0].request_command).to eq('hello')
@ -72,7 +92,6 @@ 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')
@ -87,22 +106,23 @@ describe 'EPP Domain', epp: true do
end
context 'with citizen as an owner' do
before(:each) do
Fabricate(:contact, code: 'jd1234')
Fabricate(:contact, code: 'sh8013')
Fabricate(:contact, code: 'sh801333')
end
# 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, :xml)
d = Domain.first
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('example.ee')
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)
@ -117,7 +137,7 @@ describe 'EPP Domain', epp: true do
expect(d.dnskeys.count).to eq(1)
key = d.dnskeys.first
key = d.dnskeys.last
expect(key.ds_alg).to eq(3)
expect(key.ds_key_tag).to_not be_blank
@ -132,9 +152,9 @@ describe 'EPP Domain', epp: true do
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(response[:result_code]).to eq('1000')
d = Domain.last
expect(d.legal_documents.count).to eq(1)
end
@ -159,22 +179,23 @@ describe 'EPP Domain', epp: true do
})
epp_request(xml, :xml)
d = Domain.first
ds = d.dnskeys.first
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.example.ee' } }
{ hostName: { value: 'ns1.uniq3.ee' } }
]
},
{
hostAttr: {
hostName: { value: 'ns2.example.ee' }
hostName: { value: 'ns2.uniq3.ee' }
}
}
]
@ -186,16 +207,19 @@ describe 'EPP Domain', epp: true do
end
it 'does not create duplicate domain' do
epp_request(domain_create_xml, :xml)
response = epp_request(domain_create_xml, :xml)
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
Fabricate(:reserved_domain)
xml = domain_create_xml(name: { value: '1162.ee' })
response = epp_request(xml, :xml)
@ -228,7 +252,10 @@ describe 'EPP Domain', epp: true do
}
}
end
xml = domain_create_xml(ns: nameservers)
xml = domain_create_xml({
ns: nameservers
})
response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2004')
@ -275,13 +302,15 @@ describe 'EPP Domain', epp: true do
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(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
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'
@ -289,8 +318,9 @@ describe 'EPP Domain', epp: true do
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)
# ensure nothing gets saved to db:
expect(Domain.count).to eq(domain_count)
expect(Nameserver.count).to eq(nameserver_count)
end
it 'creates a domain with period in days' do
@ -343,7 +373,7 @@ describe 'EPP Domain', epp: true do
})
epp_request(xml, :xml)
d = Domain.first
d = Domain.last
expect(d.dnskeys.count).to eq(3)
@ -484,7 +514,7 @@ describe 'EPP Domain', epp: true do
epp_request(xml, :xml)
d = Domain.first
d = Domain.last
ds = d.dnskeys.first
expect(ds.ds_key_tag).to eq('12345')
expect(ds.ds_alg).to eq(3)
@ -516,7 +546,7 @@ describe 'EPP Domain', epp: true do
epp_request(xml, :xml)
d = Domain.first
d = Domain.last
ds = d.dnskeys.first
expect(ds.ds_key_tag).to eq('12345')
expect(ds.ds_alg).to eq(3)
@ -598,14 +628,9 @@ describe 'EPP Domain', epp: true do
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 'creates a domain with contacts' do
xml = domain_create_xml({
registrant: { value: 'juridical_1234' },
_anonymus: [
{ contact: { value: 'sh8013', attrs: { type: 'admin' } } }
]
@ -616,15 +641,18 @@ describe 'EPP Domain', epp: true do
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
expect(Domain.last.tech_contacts.count).to eq 1
expect(Domain.last.admin_contacts.count).to eq 1
tech_contact = Domain.first.tech_contacts.first
expect(tech_contact.code).to eq('jd1234')
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' } } }
]
@ -635,14 +663,15 @@ describe 'EPP Domain', epp: true do
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
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: 'jd1234', attrs: { type: 'admin' } } }
{ contact: { value: 'juridical_1234', attrs: { type: 'admin' } } }
]
})
@ -653,20 +682,26 @@ describe 'EPP Domain', epp: true do
end
context 'with valid domain' do
before(:each) { Fabricate(:domain, name: 'example.ee', registrar: zone, dnskeys: []) }
let(:domain) { Domain.first }
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({ authInfo: { pw: { value: pw } } })
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('example.ee')
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)
@ -674,13 +709,16 @@ describe 'EPP Domain', epp: true do
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)
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
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')
@ -690,7 +728,7 @@ describe 'EPP Domain', epp: true do
expect(domain.domain_transfers.count).to eq(2)
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('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)
@ -698,14 +736,14 @@ describe 'EPP Domain', epp: true do
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)
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('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)
@ -713,7 +751,7 @@ describe 'EPP Domain', epp: true do
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)
expect(domain.registrar).to eq(@elkdata)
# should show up in other registrar's poll
@ -786,8 +824,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: @elkdata,
transfer_from: @zone
})
xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve')
@ -809,8 +847,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: @elkdata,
transfer_from: @zone
})
pw = domain.auth_info
@ -838,8 +876,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: @elkdata,
transfer_from: @zone
})
xml = domain_transfer_xml({ authInfo: { pw: { value: domain.auth_info } } }, 'approve')
@ -1382,17 +1420,24 @@ describe 'EPP Domain', epp: true do
### CHECK ###
it 'checks a domain' do
response = epp_request(domain_check_xml, :xml)
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('example.ee')
expect(domain.text).to eq('one.ee')
expect(domain[:avail]).to eq('1')
Fabricate(:domain, name: 'example.ee', registrar: zone)
response = epp_request(domain_check_xml, :xml)
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
@ -1450,4 +1495,3 @@ describe 'EPP Domain', epp: true do
end
end
end

View file

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

View file

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