Merge pull request #228 from internetee/registry-206

Registry 206
This commit is contained in:
Timo Võhmar 2016-10-25 18:49:56 +03:00 committed by GitHub
commit ba11be40ad
93 changed files with 514 additions and 8459 deletions

View file

@ -1,3 +1,6 @@
25.10.2016
* Outdated specs removed, failing specs fixed, rspec config improved
19.10.2016
* BUG fix: Record current time for outzone on domain:delete EPP request
* ForceDelete automatic notice: fixed et and ee wording to reflect the date the domain is actually deleted.

14
Gemfile
View file

@ -136,13 +136,8 @@ group :development, :test do
gem 'poltergeist', '1.6.0' # We are using PhantomJS instead
gem 'phantomjs', '1.9.8.0'
gem 'fabrication', '2.13.2' # Replacement for fixtures
gem 'shoulda-matchers', '2.8.0', require: false # Additional matchers for RSpec
gem 'launchy', '2.4.3' # for opening browser automatically
# helper gems
gem 'database_cleaner', '1.4.1' # For cleaning db in feature and epp tests
gem 'faker', '1.4.3' # Library to generate fake data
# debug
gem 'pry', '0.10.1'
@ -162,13 +157,14 @@ group :development, :test do
# dev tools
gem 'unicorn'
# for travis
gem 'rake'
gem 'autodoc'
end
group :staging do
gem 'airbrake'
end
group :test do
gem 'database_cleaner'
gem 'factory_girl_rails'
end

View file

@ -206,8 +206,11 @@ GEM
erubis (2.7.0)
execjs (2.6.0)
fabrication (2.13.2)
faker (1.4.3)
i18n (~> 0.5)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
railties (>= 3.0.0)
fastercsv (1.5.5)
ffi (1.9.10)
figaro (1.1.1)
@ -494,8 +497,6 @@ GEM
selectize-rails (0.12.1)
sexp_processor (4.6.0)
shellany (0.0.1)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
simplecov (0.10.0)
docile (~> 1.1.0)
json (~> 1.8)
@ -594,14 +595,14 @@ DEPENDENCIES
countries (= 0.11.4)
daemons-rails (= 1.2.1)
data_migrate!
database_cleaner (= 1.4.1)
database_cleaner
deep_cloneable (= 2.1.1)
devise (= 3.5.4)
digidoc_client (= 0.2.1)
epp (= 1.4.2)!
epp-xml (= 1.0.5)!
fabrication (= 2.13.2)
faker (= 1.4.3)
factory_girl_rails
figaro (= 1.1.1)
grape (= 0.12.0)
guard (= 2.12.9)
@ -638,7 +639,6 @@ DEPENDENCIES
railroady (= 1.3.0)
rails (= 4.2.5.2)
rails-settings-cached (= 0.4.1)
rake
ransack (= 1.5.1)
rest-client
rspec-rails (= 3.3.2)
@ -648,7 +648,6 @@ DEPENDENCIES
sdoc (= 0.4.1)
select2-rails (= 3.5.9.3)
selectize-rails (= 0.12.1)
shoulda-matchers (= 2.8.0)
simplecov (= 0.10.0)
simpleidn (= 0.0.5)
spring (= 1.3.6)

View file

@ -212,7 +212,7 @@ class Contact < ActiveRecord::Base
contact.destroy
counter.next
STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{contact.id} (#{contact.name})\n"
STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{contact.id} (#{contact.name})\n" unless Rails.env.test?
end
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{counter} orphaned contacts\n" unless Rails.env.test?

View file

@ -3,7 +3,7 @@ default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
username: postgres
password:
test:
@ -17,3 +17,7 @@ whois_test:
api_log_test:
<<: *default
database: registry_api_log_test
registrant_write_test:
<<: *default
database: registry_test

View file

@ -31,18 +31,16 @@ Rails.application.configure do
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
ActiveSupport::Deprecation.silenced = true
# For rails-settings-cached conflict
config.cache_store = :file_store, 'tmp/cache_test'
config.time_zone = 'UTC'
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_view.raise_on_missing_translations = true
# The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown,
# 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 = :debug
@ -64,10 +62,10 @@ Rails.application.configure do
Bullet.add_whitelist type: :counter_cache, class_name: 'Contact', association: :versions
end
# config.logger = Logger.new(STDOUT)
config.logger = ActiveSupport::Logger.new(nil)
end
# In this mode, any jobs you queue will be run in the same thread, synchronously
# (that is, MyJob.enqueue runs the job and won't return until it's completed).
# This makes your application's behavior easier to test
Que.mode = :sync
Que.mode = :sync

View file

@ -0,0 +1 @@
Digidoc::Client.logger = Syslog::Logger

View file

@ -1 +0,0 @@
Digidoc::Client.logger = Logger.new('log/webservices.log')

View file

@ -1,955 +0,0 @@
require 'rails_helper'
describe 'EPP Contact', epp: true do
before :all do
@xsd = Nokogiri::XML::Schema(File.read('lib/schemas/contact-eis-1.0.xsd'))
Fabricate(:zonefile_setting, origin: 'ee')
Fabricate(:zonefile_setting, origin: 'pri.ee')
Fabricate(:zonefile_setting, origin: 'med.ee')
Fabricate(:zonefile_setting, origin: 'fie.ee')
Fabricate(:zonefile_setting, origin: 'com.ee')
@registrar1 = Fabricate(:registrar1)
@registrar2 = Fabricate(:registrar2)
@epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')
Fabricate(:api_user, username: 'registrar1', registrar: @registrar1)
Fabricate(:api_user, username: 'registrar2', registrar: @registrar2)
login_as :registrar1
@contact = Fabricate(:contact, registrar: @registrar1)
@extension = {
ident: {
value: '37605030299',
attrs: { type: 'priv', cc: 'EE' }
},
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
}
@update_extension = {
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
}
end
context 'with valid user' do
context 'create command' do
def create_request(overwrites = {}, extension = {}, options = {})
extension = @extension if extension.blank?
defaults = {
id: nil,
postalInfo: {
name: { value: 'John Doe' },
org: nil,
addr: {
street: { value: '123 Example' },
city: { value: 'Tallinn' },
pc: { value: '123456' },
cc: { value: 'EE' }
}
},
voice: { value: '+372.1234567' },
fax: nil,
email: { value: 'test@example.example' },
authInfo: nil
}
create_xml = @epp_xml.create(defaults.deep_merge(overwrites), extension)
epp_plain_request(create_xml, options)
end
it 'fails if request xml is missing' do
response = epp_plain_request(@epp_xml.create)
response[:results][0][:msg].should ==
"Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}create': Missing child element(s). "\
"Expected is one of ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id, "\
"{https://epp.tld.ee/schema/contact-eis-1.0.xsd}postalInfo )."
response[:results][0][:result_code].should == '2001'
end
it 'successfully creates a contact' do
response = create_request
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
@contact = Contact.last
@contact.registrar.should == @registrar1
@registrar1.api_users.should include(@contact.creator)
@contact.ident.should == '37605030299'
@contact.street.should == '123 Example'
@contact.legal_documents.count.should == 1
@contact.auth_info.length.should > 0
log = ApiLog::EppLog.last
log.request_command.should == 'create'
log.request_object.should == 'contact'
log.request_successful.should == true
log.api_user_name.should == 'registrar1'
log.api_user_registrar.should == 'registrar1'
end
it 'creates a contact with custom auth info' do
response = create_request({
authInfo: { pw: { value: 'custompw' } }
})
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
@contact = Contact.last
@contact.auth_info.should == 'custompw'
end
it 'successfully saves ident type with legal document' do
extension = {
ident: {
value: '1990-22-12',
attrs: { type: 'birthday', cc: 'US' }
},
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
}
response = create_request({}, extension)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
@contact = Contact.last
@contact.ident_type.should == 'birthday'
@contact.legal_documents.size.should == 1
end
it 'successfully adds registrar' do
response = create_request
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.registrar.should == @registrar1
end
it 'returns result data upon success' do
response = create_request
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
id.text.length.should == 15
# 5 seconds for what-ever weird lag reasons might happen
cr_date.text.in_time_zone.utc.should be_within(5).of(Time.zone.now)
end
it 'should return email issue' do
response = create_request(email: { value: 'not@valid' })
response[:msg].should == 'Email is invalid [email]'
response[:result_code].should == '2005'
end
it 'should add registrar prefix for code when missing' do
response = create_request({ id: { value: 'abc12345' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should == 'FIRST0:ABC12345'
end
it 'should add registrar prefix for code when missing' do
response = create_request({ id: { value: 'abc:ABC:12345' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should == 'FIRST0:ABC:ABC:12345'
end
it 'should not allow spaces in custom code' do
response = create_request({ id: { value: 'abc 123' } })
response[:msg].should == 'is invalid [code]'
response[:result_code].should == '2005'
end
it 'should not strange characters in custom code' do
response = create_request({ id: { value: '33&$@@' } })
response[:msg].should == 'is invalid [code]'
response[:result_code].should == '2005'
end
it 'should not strange characters in custom code' do
long_str = 'a' * 1000
response = create_request({ id: { value: long_str } })
response[:msg].should == 'Contact code is too long, max 100 characters [code]'
response[:result_code].should == '2005'
end
it 'should not saves ident type with wrong country code' do
extension = {
ident: {
value: '1990-22-12',
attrs: { type: 'birthday', cc: 'WRONG' }
}
}
response = create_request({}, extension)
response[:msg].should == "Element '{https://epp.tld.ee/schema/eis-1.0.xsd}ident', "\
"attribute 'cc': [facet 'maxLength'] The value 'WRONG' has a length of '5'; this exceeds "\
"the allowed maximum length of '2'."
response[:result_code].should == '2001'
end
it 'should return country missing' do
extension = {
ident: {
value: '1990-22-12',
attrs: { type: 'birthday' }
}
}
response = create_request({}, extension)
response[:msg].should == "Element '{https://epp.tld.ee/schema/eis-1.0.xsd}ident': The attribute "\
"'cc' is required but missing."
response[:result_code].should == '2001'
end
it 'should return country missing' do
extension = {
ident: {
value: '1990-22-12'
}
}
response = create_request({}, extension)
response[:msg].should == "Element '{https://epp.tld.ee/schema/eis-1.0.xsd}ident': The attribute "\
"'type' is required but missing."
response[:result_code].should == '2001'
end
it 'should add registrar prefix for code when legacy prefix present' do
response = create_request({ id: { value: 'CID:FIRST0:abc:ABC:NEW:12345' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should == 'FIRST0:CID:FIRST0:ABC:ABC:NEW:12345'
end
it 'should not remove suffix CID' do
response = create_request({ id: { value: 'CID:FIRST0:abc:CID:ABC:NEW:12345' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should == 'FIRST0:CID:FIRST0:ABC:CID:ABC:NEW:12345'
end
it 'should not add registrar prefix for code when prefix present' do
response = create_request({ id: { value: 'FIRST0:abc22' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should == 'FIRST0:ABC22'
end
it 'should add registrar prefix for code does not match exactly to prefix' do
response = create_request({ id: { value: 'cid2:first0:abc:ABC:11111' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should == 'FIRST0:CID2:FIRST0:ABC:ABC:11111'
end
it 'should ignore custom code when only contact prefix given' do
response = create_request({ id: { value: 'CID:FIRST0' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should =~ /FIRST0:..../
end
it 'should generate server id when id is empty' do
response = create_request({ id: nil })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should_not == 'registrar1:'
end
it 'should generate server id when id is empty' do
response = create_request
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should_not == 'registrar1:'
end
it 'should return parameter value policy error for org' do
response = create_request({ postalInfo: { org: { value: 'should not save' } } })
response[:msg].should ==
'Parameter value policy error. Org must be blank: postalInfo > org [org]'
response[:result_code].should == '2306'
Contact.last.org_name.should == nil
end
it 'should return parameter value policy error for fax' do
response = create_request({ fax: { value: 'should not save' } })
response[:msg].should ==
'Parameter value policy error. Fax must be blank: fax [fax]'
response[:result_code].should == '2306'
Contact.last.fax.should == nil
end
end
context 'update command' do
before :all do
@contact =
Fabricate(
:contact,
registrar: @registrar1,
email: 'not_updated@test.test',
code: 'FIRST0:SH8013'
)
end
def update_request(overwrites = {}, extension = {}, options = {})
extension = @update_extension if extension.blank?
defaults = {
id: { value: 'asd123123er' },
chg: {
postalInfo: {
name: { value: 'John Doe Edited' }
},
voice: { value: '+372.7654321' },
fax: nil,
email: { value: 'edited@example.example' },
authInfo: { pw: { value: 'password' } }
}
}
update_xml = @epp_xml.update(defaults.deep_merge(overwrites), extension)
epp_plain_request(update_xml, options)
end
it 'fails if request is invalid' do
response = epp_plain_request(@epp_xml.update)
response[:results][0][:msg].should ==
"Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}update': Missing child element(s). "\
"Expected is ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id )."
end
it 'returns error if obj doesnt exist' do
response = update_request({ id: { value: 'not-exists' } })
response[:msg].should == 'Object does not exist'
response[:result_code].should == '2303'
response[:results].count.should == 1
end
it 'is succesful' do
response = update_request({ id: { value: 'FIRST0:SH8013' } })
response[:msg].should == 'Command completed successfully'
@contact.reload
@contact.name.should == 'John Doe Edited'
@contact.email.should == 'edited@example.example'
end
it 'is succesful for own contact without password' do
without_password = {
id: { value: 'FIRST0:SH8013' },
chg: {
postalInfo: {
name: { value: 'John Doe Edited' }
}
}
}
update_xml = @epp_xml.update(without_password)
response = epp_plain_request(update_xml, :xml)
response[:msg].should == 'Command completed successfully'
@contact.reload
@contact.name.should == 'John Doe Edited'
end
it 'should update other contact with correct password' do
login_as :registrar2 do
response = update_request({ id: { value: 'FIRST0:SH8013' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
end
end
it 'should not update other contact without password' do
login_as :registrar2 do
without_password = {
id: { value: 'FIRST0:SH8013' },
chg: {
postalInfo: {
name: { value: 'John Doe Edited' }
}
}
}
update_xml = @epp_xml.update(without_password)
response = epp_plain_request(update_xml, :xml)
response[:msg].should == 'Authorization error'
@contact.reload
@contact.name.should == 'John Doe Edited'
end
end
it 'returns phone and email error' do
response = update_request({
id: { value: 'FIRST0:SH8013' },
chg: {
voice: { value: '123213' },
email: { value: 'wrong' }
}
})
response[:results][0][:msg].should == 'Phone nr is invalid [phone]'
response[:results][0][:result_code].should == '2005'
response[:results][1][:msg].should == 'Email is invalid [email]'
response[:results][1][:result_code].should == '2005'
end
it 'should return email issue' do
response = update_request({
id: { value: 'FIRST0:SH8013' },
chg: {
email: { value: 'legacy@wrong' }
}
})
response[:msg].should == 'Email is invalid [email]'
response[:result_code].should == '2005'
end
it 'should not update code with custom string' do
response = update_request(
{
id: { value: 'FIRST0:SH8013' },
chg: {
id: { value: 'notpossibletoupdate' }
}
}, {}
)
response[:msg].should == "Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}id': "\
"This element is not expected."
response[:result_code].should == '2001'
@contact.reload.code.should == 'FIRST0:SH8013'
end
it 'should not be able to update ident' do
extension = {
ident: {
value: '1990-22-12',
attrs: { type: 'birthday', cc: 'US' }
},
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
}
response = update_request({ id: { value: 'FIRST0:SH8013' } }, extension)
response[:msg].should ==
'Parameter value policy error. Update of ident data not allowed [ident]'
response[:result_code].should == '2306'
Contact.find_by(code: 'FIRST0:SH8013').ident_type.should == 'priv'
end
it 'should return parameter value policy errror for org update' do
response = update_request({
id: { value: 'FIRST0:SH8013' },
chg: {
postalInfo: { org: { value: 'should not save' } }
}
})
response[:msg].should ==
'Parameter value policy error. Org must be blank: postalInfo > org [org]'
response[:result_code].should == '2306'
Contact.find_by(code: 'FIRST0:SH8013').org_name.should == nil
end
it 'should return parameter value policy errror for fax update' do
response = update_request({
id: { value: 'FIRST0:SH8013' },
chg: {
fax: { value: 'should not save' }
}
})
response[:msg].should ==
'Parameter value policy error. Fax must be blank: fax [fax]'
response[:result_code].should == '2306'
Contact.find_by(code: 'FIRST0:SH8013').fax.should == nil
end
it 'does not allow to edit statuses if policy forbids it' do
Setting.client_status_editing_enabled = false
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },
add: [{
_anonymus: [
{ status: { value: 'Payment overdue.', attrs: { s: 'clientDeleteProhibited', lang: 'en' } } },
{ status: { value: '', attrs: { s: 'clientUpdateProhibited' } } }
]
}]
})
response = epp_plain_request(xml)
response[:results][0][:msg].should == "Parameter value policy error. Client-side object status "\
"management not supported: status [status]"
response[:results][0][:result_code].should == '2306'
Setting.client_status_editing_enabled = true
end
it 'should update auth info' do
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },
chg: {
authInfo: { pw: { value: 'newpassword' } }
}
})
response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.auth_info.should == 'newpassword'
end
it 'should add value voice value' do
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },
chg: {
voice: { value: '+372.11111111' },
authInfo: { pw: { value: 'password' } }
}
})
response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000'
contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == '+372.11111111'
contact.update_attribute(:phone, '+372.7654321') # restore default value
end
it 'should return error when add attributes phone value is empty' do
phone = Contact.find_by(code: 'FIRST0:SH8013').phone
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },
chg: {
voice: { value: '' },
email: { value: 'example@example.ee' },
authInfo: { pw: { value: 'password' } }
}
})
response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Required parameter missing - phone [phone]'
response[:results][0][:result_code].should == '2003'
Contact.find_by(code: 'FIRST0:SH8013').phone.should == phone # aka not changed
end
it 'should not allow to remove required voice attribute' do
contact = Contact.find_by(code: 'FIRST0:SH8013')
phone = contact.phone
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },
chg: {
voice: { value: '' },
authInfo: { pw: { value: 'password' } }
}
})
response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Required parameter missing - phone [phone]'
response[:results][0][:result_code].should == '2003'
contact = Contact.find_by(code: 'FIRST0:SH8013')
contact.phone.should == phone
end
it 'should return general policy error when updating org' do
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },
chg: {
postalInfo: {
org: { value: 'shouldnot' }
},
authInfo: { pw: { value: 'password' } }
}
})
response = epp_plain_request(xml)
response[:results][0][:msg].should ==
'Parameter value policy error. Org must be blank: postalInfo > org [org]'
response[:results][0][:result_code].should == '2306'
end
it 'does not allow to edit statuses if policy forbids it' do
Setting.client_status_editing_enabled = false
xml = @epp_xml.update({
id: { value: 'FIRST0:SH8013' },
add: [{
_anonymus: [
{ status: { value: '', attrs: { s: 'clientUpdateProhibited' } } }
]
}]
})
response = epp_plain_request(xml)
response[:results][0][:msg].should == "Parameter value policy error. Client-side object status "\
"management not supported: status [status]"
response[:results][0][:result_code].should == '2306'
Setting.client_status_editing_enabled = true
end
end
context 'delete command' do
before do
@contact = Fabricate(:contact, registrar: @registrar1)
end
def delete_request(overwrites = {})
defaults = {
id: { value: @contact.code },
authInfo: { pw: { value: @contact.auth_info } }
}
delete_xml = @epp_xml.delete(defaults.deep_merge(overwrites), @extension)
epp_plain_request(delete_xml, :xml)
end
it 'fails if request is invalid' do
response = epp_plain_request(@epp_xml.delete)
response[:results][0][:msg].should ==
"Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}delete': Missing child element(s). "\
"Expected is ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id )."
response[:results][0][:result_code].should == '2001'
response[:results].count.should == 1
end
it 'returns error if obj doesnt exist' do
response = delete_request({ id: { value: 'not-exists' } })
response[:msg].should == 'Object does not exist'
response[:result_code].should == '2303'
response[:results].count.should == 1
end
it 'deletes contact' do
response = delete_request
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:clTRID].should == 'ABC-12345'
Contact.find_by_id(@contact.id).should == nil
end
it 'deletes own contact even with wrong password' do
response = delete_request({ authInfo: { pw: { value: 'wrong password' } } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:clTRID].should == 'ABC-12345'
Contact.find_by_id(@contact.id).should == nil
end
it 'deletes own contact even without password' do
delete_xml = @epp_xml.delete({ id: { value: @contact.code } })
response = epp_plain_request(delete_xml, :xml)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:clTRID].should == 'ABC-12345'
Contact.find_by_id(@contact.id).should == nil
end
it 'fails if contact has associated domain' do
@domain = Fabricate(:domain, registrar: @registrar1, registrant: Registrant.find(@contact.id))
@domain.registrant.present?.should == true
response = delete_request
response[:msg].should == 'Object association prohibits operation [domains]'
response[:result_code].should == '2305'
response[:results].count.should == 1
@domain.registrant.present?.should == true
end
it 'should delete when not owner but with correct password' do
login_as :registrar2 do
response = delete_request
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:clTRID].should == 'ABC-12345'
Contact.find_by_id(@contact.id).should == nil
end
end
it 'should not delete when not owner without password' do
login_as :registrar2 do
delete_xml = @epp_xml.delete({ id: { value: @contact.code } })
response = epp_plain_request(delete_xml, :xml)
response[:msg].should == 'Authorization error'
response[:result_code].should == '2201'
response[:results].count.should == 1
end
end
it 'should not delete when not owner with wrong password' do
login_as :registrar2 do
response = delete_request({ authInfo: { pw: { value: 'wrong password' } } })
response[:msg].should == 'Authorization error'
response[:result_code].should == '2201'
response[:results].count.should == 1
end
end
end
context 'check command' do
def check_request(overwrites = {})
defaults = {
id: { value: @contact.code },
authInfo: { pw: { value: @contact.auth_info } }
}
xml = @epp_xml.check(defaults.deep_merge(overwrites))
epp_plain_request(xml, :xml)
end
it 'fails if request is invalid' do
response = epp_plain_request(@epp_xml.check)
response[:results][0][:msg].should ==
"Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}check': Missing child element(s). "\
"Expected is ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id )."
response[:results][0][:result_code].should == '2001'
response[:results].count.should == 1
end
it 'returns info about contact availability' do
contact = Fabricate(:contact, code: 'check-1234')
contact.code.should == 'FIXED:CHECK-1234'
response = epp_plain_request(check_multiple_contacts_xml, :xml)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
ids = response[:parsed].css('resData chkData id')
ids[0].attributes['avail'].text.should == '0'
ids[1].attributes['avail'].text.should == '1'
ids[0].text.should == 'FIXED:CHECK-1234'
ids[1].text.should == 'check-4321'
end
it 'should support legacy CID farmat' do
contact = Fabricate(:contact, code: 'check-LEGACY')
contact.code.should == 'FIXED:CHECK-LEGACY'
response = epp_plain_request(check_multiple_legacy_contacts_xml, :xml)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
ids = response[:parsed].css('resData chkData id')
ids[0].text.should == 'FIXED:CHECK-LEGACY'
ids[1].text.should == 'CID:FIXED:CHECK-LEGACY'
ids[0].attributes['avail'].text.should == '0'
ids[1].attributes['avail'].text.should == '1'
end
end
context 'info command' do
def info_request(overwrites = {}, options = {})
defaults = {
id: { value: @contact.code },
authInfo: { pw: { value: @contact.auth_info } }
}
xml = @epp_xml.info(defaults.deep_merge(overwrites))
epp_plain_request(xml, options)
end
it 'fails if request invalid' do
response = epp_plain_request(@epp_xml.info)
response[:results][0][:msg].should ==
"Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}info': Missing child element(s). "\
"Expected is ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id )."
response[:results][0][:result_code].should == '2001'
response[:results].count.should == 1
end
it 'returns error when object does not exist' do
response = info_request({ id: { value: 'no-contact' } })
response[:msg].should == 'Object does not exist'
response[:result_code].should == '2303'
response[:results][0][:value].should == 'NO-CONTACT'
response[:results].count.should == 1
end
it 'return info about contact' do
Fabricate(:contact, code: 'INFO-4444', name: 'Johnny Awesome')
response = info_request({ id: { value: 'FIXED:INFO-4444' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
contact = response[:parsed].css('resData infData')
contact.css('name').first.text.should == 'Johnny Awesome'
end
it 'should add legacy CID format as append' do
Fabricate(:contact, code: 'CID:FIXED:INFO-5555', name: 'Johnny Awesome')
response = info_request({ id: { value: 'FIXED:CID:FIXED:INFO-5555' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
contact = response[:parsed].css('resData infData')
contact.css('name').first.text.should == 'Johnny Awesome'
end
it 'should return ident in extension' do
@registrar1_contact = Fabricate(:contact, code: 'INFO-IDENT',
registrar: @registrar1, name: 'Johnny Awesome')
response = info_request({ id: { value: @registrar1_contact.code } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
contact = response[:parsed].css('resData infData')
contact.css('ident').first.should == nil # ident should be in extension
contact = response[:parsed].css('extension')
contact.css('ident').first.text.should == '37605030299'
end
it 'returns no authorization error for wrong password when registrant' do
response = info_request({ authInfo: { pw: { value: 'wrong-pw' } } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:results].count.should == 1
end
it 'should honor new contact code format' do
@registrar1_contact = Fabricate(:contact, code: 'FIXED:test:custom:code')
@registrar1_contact.code.should == 'FIXED:TEST:CUSTOM:CODE'
response = info_request({ id: { value: 'FIXED:TEST:CUSTOM:CODE' } })
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
contact = response[:parsed].css('resData infData')
contact.css('ident').first.should == nil # ident should be in extension
contact = response[:parsed].css('extension')
contact.css('ident').first.text.should == '37605030299'
end
it 'returns no authorization error for wrong user but correct password' do
login_as :registrar2 do
response = info_request
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:results].count.should == 1
contact = response[:parsed].css('resData infData')
contact.css('postalInfo addr city').first.try(:text).present?.should == true
contact.css('email').first.try(:text).present?.should == true
contact.css('voice').first.try(:text).should == '+372.12345678'
end
end
it 'returns authorization error for wrong user and wrong password' do
login_as :registrar2 do
response = info_request({ authInfo: { pw: { value: 'wrong-pw' } } })
response[:msg].should == 'Authorization error'
response[:result_code].should == '2201'
response[:results].count.should == 1
contact = response[:parsed].css('resData infData')
contact.css('postalInfo addr city').first.try(:text).should == nil
contact.css('email').first.try(:text).should == nil
contact.css('voice').first.try(:text).should == nil
end
end
it 'returns no authorization error for wrong user and no password' do
login_as :registrar2 do
response = info_request({ authInfo: { pw: { value: '' } } }, validate_output: false)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:results].count.should == 1
contact = response[:parsed].css('resData infData')
contact.css('postalInfo addr city').first.try(:text).should == nil
contact.css('email').first.try(:text).should == nil
contact.css('voice').first.try(:text).should == nil
end
end
end
end
def check_multiple_contacts_xml
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<contact:check
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
<contact:id>FIXED:CHECK-1234</contact:id>
<contact:id>check-4321</contact:id>
</contact:check>
</check>
<clTRID>ABC-12345</clTRID>
</command>
</epp>'
end
def check_multiple_legacy_contacts_xml
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<contact:check
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
<contact:id>FIXED:CHECK-LEGACY</contact:id>
<contact:id>CID:FIXED:CHECK-LEGACY</contact:id>
</contact:check>
</check>
<clTRID>ABC-12345</clTRID>
</command>
</epp>'
end
end

File diff suppressed because it is too large Load diff

View file

@ -1,54 +0,0 @@
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('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<transfer op="request">
<domain:transfer
xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>' + dn + '</domain:name>
</domain:transfer>
</transfer>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_transfer_xml(name: { value: dn })).to_s.squish
generated.should == expected
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<transfer op="approve">
<domain:transfer
xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>one.ee</domain:name>
<domain:authInfo>
<domain:pw roid="askdf">test</domain:pw>
</domain:authInfo>
</domain:transfer>
</transfer>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
').to_s.squish
xml = domain_transfer_xml({
name: { value: 'one.ee' },
authInfo: {
pw: { value: 'test', attrs: { roid: 'askdf' } }
}
}, 'approve')
generated = Nokogiri::XML(xml).to_s.squish
generated.should == expected
end
end
end

View file

@ -1,216 +0,0 @@
require 'rails_helper'
describe 'EPP Keyrelay', epp: true do
before(:all) do
Fabricate(:zonefile_setting, origin: 'ee')
@registrar1 = Fabricate(:registrar1)
@registrar2 = Fabricate(:registrar2)
@domain = Fabricate(:domain, registrar: @registrar2)
@epp_xml = EppXml::Keyrelay.new
Fabricate(:api_user, username: 'registrar1', registrar: @registrar1)
Fabricate(:api_user, username: 'registrar2', registrar: @registrar2)
login_as :registrar1
end
it 'makes a keyrelay request' do
ApiLog::EppLog.delete_all
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' }
}
})
response = epp_plain_request(xml, :xml)
response[:msg].should == 'Unimplemented object service'
response[:result_code].should == '2307'
# response[:msg].should == 'Command completed successfully'
# response[:result_code].should == '1000'
# @registrar2.messages.queued.count.should == 1
# log = ApiLog::EppLog.last
# log.request_command.should == 'keyrelay'
# log.request_successful.should == true
# log.api_user_name.should == '1-api-registrar1'
end
it 'returns an error when parameters are missing' do
msg_count = @registrar2.messages.queued.count
xml = @epp_xml.keyrelay({
name: { value: @domain.name },
keyData: {
protocol: { value: '3' },
alg: { value: '8' },
pubKey: { value: 'cmlraXN0aGViZXN0' }
},
authInfo: {
pw: { value: @domain.auth_info }
},
expiry: {
relative: { value: 'Invalid Expiry' }
}
})
response = epp_plain_request(xml, :xml)
response[:msg].should == 'Required parameter missing: keyrelay > keyData > flags [flags]'
@registrar2.messages.queued.count.should == msg_count
end
it 'returns an error on invalid relative expiry' do
msg_count = @registrar2.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' }
}
})
response = epp_plain_request(xml, :xml)
response[:msg].should == 'Expiry relative must be compatible to ISO 8601'
response[:results][0][:value].should == 'Invalid Expiry'
@registrar2.messages.queued.count.should == msg_count
end
it 'returns an error on invalid absolute expiry' do
msg_count = @registrar2.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' }
}
})
response = epp_plain_request(xml, :xml)
response[:msg].should == 'Expiry absolute must be compatible to ISO 8601'
response[:results][0][:value].should == 'Invalid Absolute'
@registrar2.messages.queued.count.should == msg_count
end
# keyrelay not enabled at the moment
# it 'does not allow both relative and absolute' do
# msg_count = @registrar2.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_plain_request(xml, :xml)
# response[:msg].should == 'Exactly one parameter required: keyrelay > expiry > relative OR '\
# 'keyrelay > expiry > absolute'
# @registrar2.messages.queued.count.should == msg_count
# end
it 'saves legal document with keyrelay' 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: 'P1D' }
}
}, {
_anonymus: [
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
]
})
response = epp_plain_request(xml, :xml)
response[:msg].should == 'Unimplemented object service'
response[:result_code].should == '2307'
# response[:msg].should == 'Command completed successfully'
# docs = Keyrelay.last.legal_documents
# docs.count.should == 1
# docs.first.path.should_not be_blank
# docs.first.document_type.should == 'pdf'
end
it 'validates legal document types' 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: 'P1D' }
}
}, {
_anonymus: [
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'jpg' }
}
]
})
response = epp_plain_request(xml, :xml)
response[:msg].should == 'Attribute is invalid: type'
end
end

View file

@ -1,158 +0,0 @@
require 'rails_helper'
describe 'EPP Poll', epp: true do
let(:epp_xml) { EppXml::Session.new }
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
@xsd = Nokogiri::XML::Schema(File.read('lib/schemas/epp-1.0.xsd'))
Fabricate(:api_user, username: 'registrar1', registrar: registrar1)
Fabricate(:api_user, username: 'registrar2', registrar: registrar2)
login_as :registrar1
@uniq_no = proc { @i ||= 0; @i += 1 }
end
it 'returns no messages in poll' do
ApiLog::EppLog.delete_all
response = epp_plain_request(epp_xml.poll, :xml)
response[:msg].should == 'Command completed successfully; no messages'
response[:result_code].should == '1300'
log = ApiLog::EppLog.last
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 == @registrar1.name
log.request.should_not be_blank
log.response.should_not be_blank
end
it 'queues and dequeues messages' do
msg = registrar1.messages.create({ body: 'Balance low.' })
response = login_as :registrar2 do
epp_plain_request(epp_xml.poll, :xml)
end
response[:msg].should == 'Command completed successfully; no messages'
response[:result_code].should == '1300'
response = epp_plain_request(epp_xml.poll, :xml)
response[:msg].should == 'Command completed successfully; ack to dequeue'
response[:result_code].should == '1301'
msg_q = response[:parsed].css('msgQ')
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'] }
})
response = login_as :registrar2 do
epp_plain_request(xml, :xml)
end
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)
response[:msg].should == 'Command completed successfully'
msg_q = response[:parsed].css('msgQ')
msg_q.first['id'].should_not be_blank
msg_q.first['count'].should == '0'
response = epp_plain_request(xml, :xml)
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
xml = epp_xml.poll(poll: {
value: '', attrs: { op: 'bla' }
})
response = epp_plain_request(xml, validate_input: false)
response[:msg].should == "Element '{urn:ietf:params:xml:ns:epp-1.0}poll', attribute 'op': "\
"[facet 'enumeration'] The value 'bla' is not an element of the set {'ack', 'req'}."
response[:result_code].should == '2001'
end
it 'dequeues multiple messages' do
registrar1.messages.create({ body: 'Balance low.' })
registrar1.messages.create({ body: 'Something.' })
registrar1.messages.create({ body: 'Smth else.' })
response = epp_plain_request(epp_xml.poll, :xml)
response[:msg].should == 'Command completed successfully; ack to dequeue'
response[:result_code].should == '1301'
msg_q = response[:parsed].css('msgQ')
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)
response[:msg].should == 'Command completed successfully'
msg_q = response[:parsed].css('msgQ')
msg_q.first['id'].should_not be_blank
msg_q.first['count'].should == '2'
response = epp_plain_request(epp_xml.poll, :xml)
response[:msg].should == 'Command completed successfully; ack to dequeue'
response[:result_code].should == '1301'
msg_q = response[:parsed].css('msgQ')
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)
response[:msg].should == 'Command completed successfully'
msg_q = response[:parsed].css('msgQ')
msg_q.first['id'].should_not be_blank
msg_q.first['count'].should == '1'
response = epp_plain_request(epp_xml.poll, :xml)
response[:msg].should == 'Command completed successfully; ack to dequeue'
response[:result_code].should == '1301'
msg_q = response[:parsed].css('msgQ')
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)
response[:msg].should == 'Command completed successfully'
msg_q = response[:parsed].css('msgQ')
msg_q.first['id'].should_not be_blank
msg_q.first['count'].should == '0'
response = epp_plain_request(epp_xml.poll, :xml)
response[:msg].should == 'Command completed successfully; no messages'
response[:result_code].should == '1300'
end
end

View file

@ -1,45 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<contact:create
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
<contact:id>loc_int</contact:id>
<contact:postalInfo type="int">
<contact:name>John Doe Int</contact:name>
<contact:org>Example Int Inc.</contact:org>
<contact:addr>
<contact:street>International street 1</contact:street>
<contact:city>Dulles</contact:city>
<contact:sp>VA</contact:sp>
<contact:pc>20166-6503</contact:pc>
<contact:cc>EE</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:postalInfo type="loc">
<contact:name>John Doe Loc</contact:name>
<contact:org>Example Loc Inc.</contact:org>
<contact:addr>
<contact:street>Local street 1</contact:street>
<contact:city>Vancouver</contact:city>
<contact:sp>BC</contact:sp>
<contact:pc>27123</contact:pc>
<contact:cc>CA</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice x="1234">+123.7035555555</contact:voice>
<contact:fax>+1.7035555556</contact:fax>
<contact:email>jdoe@example.com</contact:email>
<contact:ident type="op">37605030299</contact:ident>
<contact:authInfo>
<contact:pw>2fooBAR</contact:pw>
</contact:authInfo>
<contact:disclose flag="0">
<contact:voice/>
<contact:email/>
</contact:disclose>
</contact:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<delete>
<contact:delete
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
<contact:id>dwa1234</contact:id>
</contact:delete>
</delete>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<delete>
<contact:delete
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
</contact:delete>
</delete>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<info>
<contact:info
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
<contact:id>info-4444</contact:id>
<contact:authInfo>
<contact:pw>2fooBAR</contact:pw>
</contact:authInfo>
</contact:info>
</info>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<info>
<contact:info
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
</contact:info>
</info>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<contact:update
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
<contact:id>sh8013</contact:id>
<contact:chg>
<contact:postalInfo type="int">
<contact:name>John Doe</contact:name>
<contact:addr>
<contact:street>123 Example Dr.</contact:street>
<contact:street>Suite 100</contact:street>
<contact:city>Dulles</contact:city>
<contact:sp>VA</contact:sp>
<contact:pc>20166-6503</contact:pc>
<contact:cc>EE</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice x="1234">+123.7035555555</contact:voice>
<contact:fax>+1.7035555556</contact:fax>
<contact:email>jdoe@example.com</contact:email>
<contact:ident type="passport">J836954</contact:ident>
<contact:authInfo>
<contact:pw>2fooBAR</contact:pw>
</contact:authInfo>
<contact:disclose flag="0">
<contact:voice/>
<contact:email/>
</contact:disclose>
</contact:chg>
</contact:update>
</update>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<contact:update
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
</contact:update>
</update>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<contact:update
xmlns:contact="https://epp.tld.ee/schema/contact-eis-1.0.xsd">
<contact:id>sh8013</contact:id>
<contact:chg>
<contact:voice x="1234">123456798</contact:voice>
<contact:email>faulty</contact:email>
<contact:authInfo>
<contact:pw>2fooBAR</contact:pw>
</contact:authInfo>
</contact:chg>
</contact:update>
</update>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -1,155 +0,0 @@
require 'rails_helper'
describe 'EPP Session', epp: true do
before :all do
@api_user = Fabricate(:gitlab_api_user)
@epp_xml = EppXml.new(cl_trid: 'ABC-12345')
@login_xml_cache = @epp_xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' })
@xsd = Nokogiri::XML::Schema(File.read('lib/schemas/epp-1.0.xsd'))
end
context 'when not connected' do
it 'greets client upon connection' do
server.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 do
server.open_connection
end
it 'does not log in with invalid user' do
wrong_user = @epp_xml.session.login(clID: { value: 'wrong-user' }, pw: { value: 'ghyt9e4fu' })
response = epp_plain_request(wrong_user)
response[:msg].should == 'Authentication error; server closing connection (API user not found)'
response[:result_code].should == '2501'
response[:clTRID].should == 'ABC-12345'
log = ApiLog::EppLog.last
log.request_command.should == 'login'
log.request_successful.should == false
log.api_user_name.should == 'api-public'
end
it 'does not log in with inactive user' do
@registrar = Fabricate(:registrar, { name: 'registrar1', reg_no: '123' })
Fabricate(:api_user, username: 'inactive-user', active: false, registrar: @registrar)
inactive = @epp_xml.session.login(clID: { value: 'inactive-user' }, pw: { value: 'ghyt9e4fu' })
response = epp_plain_request(inactive)
response[:msg].should == 'Authentication error; server closing connection (API user is not active)'
response[:result_code].should == '2501'
log = ApiLog::EppLog.last
log.request_command.should == 'login'
log.request_successful.should == false
log.api_user_name.should == 'inactive-user'
end
it 'prohibits further actions unless logged in' do
@xsd = Nokogiri::XML::Schema(File.read('lib/schemas/domain-eis-1.0.xsd'))
response = epp_plain_request(@epp_xml.domain.info(name: { value: 'test.ee' }))
response[:msg].should == 'You need to login first.'
response[:result_code].should == '2002'
response[:clTRID].should == 'ABC-12345'
end
it 'should not have clTRID in response if client does not send it' do
epp_xml_no_cltrid = EppXml.new(cl_trid: false)
wrong_user = epp_xml_no_cltrid.session.login(clID: { value: 'wrong-user' }, pw: { value: 'ghyt9e4fu' })
response = epp_plain_request(wrong_user)
response[:clTRID].should be_nil
end
it 'should return latin only error' do
wrong_user = @epp_xml.session.login(clID: { value: '你好你好' }, pw: { value: 'ghyt9e4fu' })
response = epp_plain_request(wrong_user)
response[:msg].should == 'Parameter value policy error. Allowed only Latin characters.'
response[:result_code].should == '2306'
response[:clTRID].should == 'ABC-12345'
log = ApiLog::EppLog.last
log.request_command.should == 'login'
log.request_successful.should == false
log.api_user_name.should == 'api-public'
end
context 'with valid user' do
it 'logs in epp user' do
response = epp_plain_request(@login_xml_cache)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:clTRID].should == 'ABC-12345'
log = ApiLog::EppLog.last
log.request_command.should == 'login'
log.request_successful.should == true
log.api_user_name.should == 'gitlab'
end
it 'does not log in twice' do
response = epp_plain_request(@login_xml_cache)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
response[:clTRID].should == 'ABC-12345'
response = epp_plain_request(@login_xml_cache)
response[:msg].should match(/Already logged in. Use/)
response[:result_code].should == '2002'
log = ApiLog::EppLog.last
log.request_command.should == 'login'
log.request_successful.should == false
log.api_user_name.should == 'gitlab'
end
it 'logs out epp user' do
c = EppSession.count
epp_plain_request(@login_xml_cache)
EppSession.count.should == c + 1
response = epp_plain_request(@epp_xml.session.logout)
response[:msg].should == 'Command completed successfully; ending session'
response[:result_code].should == '1500'
EppSession.count.should == c
end
it 'changes password and logs in' do
@api_user.update(password: 'ghyt9e4fu')
response = epp_plain_request(@epp_xml.session.login(
clID: { value: 'gitlab' },
pw: { value: 'ghyt9e4fu' },
newPW: { value: 'abcdefg' }
))
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
@api_user.reload
@api_user.password.should == 'abcdefg'
end
it 'fails if new password is not valid' do
@api_user.update(password: 'ghyt9e4fu')
response = epp_plain_request(@epp_xml.session.login(
clID: { value: 'gitlab' },
pw: { value: 'ghyt9e4fu' },
newPW: { value: '' }
), validate_input: false)
response[:msg].should ==
"Element '{urn:ietf:params:xml:ns:epp-1.0}newPW': [facet 'minLength'] The value has a "\
"length of '0'; this underruns the allowed minimum length of '6'."
response[:result_code].should == '2001'
@api_user.reload
@api_user.password.should == 'ghyt9e4fu'
end
end
end
end

View file

@ -1,6 +1,6 @@
Fabricator(:address) do
city Faker::Address.city
street Faker::Address.street_name
street2 Faker::Address.street_name
zip Faker::Address.zip
city 'test city'
street 'test street'
street2 'test street'
zip 12345
end

View file

@ -1,10 +1,10 @@
Fabricator(:contact) do
registrar { Registrar.find_by_code('FIXED') }
code { sequence(:code) { |i| "SH#{Faker::Number.number(8)}#{i}" } }
registrar { Fabricate(:registrar) }
code { sequence(:code) { |i| "1234#{i}#{rand(1000)}" } }
auth_info 'password'
name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } }
name 'test name'
phone '+372.12345678'
email Faker::Internet.email
email { sequence(:email) { |i| "test#{i}@test.com" } }
street 'Short street 11'
city 'Tallinn'
zip '11111'

View file

@ -7,7 +7,7 @@ Fabricator(:domain) do
nameservers(count: 3)
admin_domain_contacts(count: 1) { Fabricate(:admin_domain_contact) }
tech_domain_contacts(count: 1) { Fabricate(:tech_domain_contact) }
registrar { Registrar.find_by_code('FIXED') }
registrar { Fabricate(:registrar) }
auth_info '98oiewslkfkd'
end

View file

@ -1,4 +1,4 @@
Fabricator(:nameserver) do
hostname { sequence(:hostname) { |i| "ns.#{Faker::Internet.domain_word}#{i}.ee" } }
hostname { sequence(:hostname) { |i| "ns.test#{i}.ee" } }
ipv4 '192.168.1.1'
end

View file

@ -1,10 +1,10 @@
Fabricator(:registrant) do
registrar { Registrar.find_by_code('FIXED') }
code { sequence(:code) { |i| "REGISTRANT#{Faker::Number.number(8)}#{i}" } }
registrar { Fabricate(:registrar) }
code { sequence(:code) { |i| "REGISTRANT#{i}#{rand(1000)}" } }
auth_info 'password'
name { sequence(:name) { |i| "REGISTRANT #{Faker::Name.name}#{i}" } }
name 'test name'
phone '+372.12345678'
email Faker::Internet.email
email { sequence(:email) { |i| "test#{i}@test.com" } }
street 'Short street 11'
city 'Tallinn'
zip '11111'

View file

@ -1,3 +1,3 @@
Fabricator(:reserved_domain) do
names { { '1162.ee': 'abc' } }
name { sequence(:name) { |i| "domain#{i}.ee" } }
end

View file

@ -1,45 +0,0 @@
require 'rails_helper'
feature 'Account activity', type: :feature do
before :all do
@user = Fabricate(:admin_user)
r = Fabricate(:registrar)
Fabricate.times(5, :account_activity, account: r.cash_account)
Fabricate(:account_activity, account: r.cash_account, description: 'acc activity test', sum: -12)
end
context 'as unknown user' do
it 'should redirect to sign in page' do
visit '/admin/account_activities'
current_path.should == '/admin/login'
page.should have_text('You need to sign in or sign up')
end
end
context 'as signed in user' do
before do
sign_in @user
end
it 'should navigate to account activities page' do
visit admin_account_activities_path
page.should have_text('+110.0 EUR', count: 5)
page.should have_text('-12.0 EUR')
end
it 'should search activities by description' do
visit admin_account_activities_path
fill_in 'Description', with: 'test'
find('.btn.btn-default.search').click
page.should have_text('-12.0 EUR')
page.should_not have_text('+110.0 EUR')
end
it 'should download csv' do
visit admin_account_activities_path
click_link 'Export CSV'
response_headers['Content-Type'].should == 'text/csv'
response_headers['Content-Disposition'].should match(/attachment; filename="account_activities_\d+\.csv"/)
end
end
end

View file

@ -1,49 +0,0 @@
require 'rails_helper'
feature 'Admin users', type: :feature do
before :all do
@admin_user = Fabricate(:admin_user)
end
context 'as unknown user' do
it 'should redirect to login path' do
visit admin_admin_users_url
current_path.should == '/admin/login'
end
it 'should redirect to login path' do
visit admin_admin_user_url(@admin_user)
current_path.should == '/admin/login'
end
it 'should redirect to login path' do
visit edit_admin_admin_user_url(@admin_user)
current_path.should == '/admin/login'
end
end
context 'as logged in user' do
it 'should show index of contacts' do
sign_in @admin_user
visit admin_admin_users_url
current_path.should == '/admin/admin_users'
page.should have_content('API users')
end
it 'should show api user' do
sign_in @admin_user
visit admin_admin_user_url(@admin_user)
current_path.should == "/admin/admin_users/#{@admin_user.id}"
end
it 'should show api user' do
sign_in @admin_user
visit edit_admin_admin_user_url(@admin_user)
current_path.should == "/admin/admin_users/#{@admin_user.id}/edit"
page.should have_content("Edit: #{@admin_user.username}")
end
end
end

View file

@ -1,40 +0,0 @@
require 'rails_helper'
feature 'Api users', type: :feature do
before :all do
@user = Fabricate(:admin_user)
@api_user = Fabricate(:api_user)
end
context 'as unknown user' do
it 'should redirect to login path' do
visit admin_api_users_url
current_path.should == '/admin/login'
end
it 'should redirect to login path' do
visit admin_api_user_url(@api_user)
current_path.should == '/admin/login'
end
end
context 'as logged in user' do
it 'should show index of api users' do
sign_in @user
visit admin_api_users_url
current_path.should == '/admin/api_users'
page.should have_content('API users')
end
it 'should show api user' do
sign_in @user
visit admin_api_user_url(@api_user)
current_path.should == "/admin/api_users/#{@api_user.id}"
end
end
end

View file

@ -1,52 +0,0 @@
require 'rails_helper'
feature 'BankStatement', type: :feature do
before :all do
@user = Fabricate(:admin_user)
end
before do
sign_in @user
end
it 'should add a bank statement and transactions manually' do
visit admin_bank_statements_url
click_link 'Add'
fill_in 'Bank code', with: '767'
fill_in 'Iban', with: 'EE557700771000598731'
click_button 'Save'
page.should have_content('Record created')
page.should have_content('Bank statement ')
page.should have_content('767')
page.should have_content('EE557700771000598731')
page.should have_content('Not binded')
click_link 'Add'
fill_in 'Description', with: 'Payment 12345'
fill_in 'Sum', with: '120'
fill_in 'Reference no', with: 'RF4663930489'
fill_in 'Document no', with: '123'
fill_in 'Bank reference', with: '767'
fill_in 'Iban', with: 'EE557700771000598731'
fill_in 'Buyer bank code', with: '767'
fill_in 'Buyer iban', with: 'EE557700771000598000'
fill_in 'Buyer name', with: 'Test buyer'
fill_in 'Paid at', with: '2015-01-01'
click_button 'Save'
page.should have_content('Record created')
page.should have_content('Bank transaction')
page.should have_content('RF4663930489')
page.should have_content('EE557700771000598000')
page.should have_content('Not binded')
page.should have_content('Bind manually')
click_link 'Back to bank statement'
page.should have_content('120,00')
page.should have_content('Test buyer')
end
end

View file

@ -1,31 +0,0 @@
require 'rails_helper'
feature 'BlockedDomain', type: :feature do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
@user = Fabricate(:admin_user)
end
before do
sign_in @user
end
it 'should manage blocked domains' do
visit admin_blocked_domains_url
page.should have_content('Blocked domains')
d = Fabricate.build(:domain, name: 'ftp.ee')
d.valid?
d.errors.full_messages.should match_array([])
fill_in 'blocked_domains', with: "ftp.ee\ncache.ee"
click_button 'Save'
page.should have_content('Record updated')
page.should have_content('ftp.ee')
page.should have_content('cache.ee')
d.valid?
d.errors.full_messages.should match_array(["Data management policy violation: Domain name is blocked [name]"])
end
end

View file

@ -1,60 +0,0 @@
require 'rails_helper'
feature 'Admin contact', type: :feature do
before :all do
@user = Fabricate(:admin_user)
@contact = Fabricate(:contact, name: 'Mr John')
end
it 'should show index of contacts' do
sign_in @user
visit admin_contacts_url
page.should have_content('Mr John')
end
it 'should show correct contact creator' do
sign_in @user
visit admin_contacts_url
click_link('Mr John')
# initially it's created by unknown,
# indivitually running it's created by autotest
page.should have_content(/by [unknown|autotest]/)
end
it 'should search contacts by name' do
Fabricate(:contact, name: 'first name')
Fabricate(:contact, name: 'second name')
Fabricate(:contact, name: 'third name')
sign_in @user
visit admin_contacts_url
page.should have_content('first name')
page.should have_content('second name')
page.should have_content('third name')
fill_in 'q_name_matches', with: 'first name'
find('.btn.btn-primary').click
current_path.should == "/admin/contacts"
page.should have_content('first name')
page.should_not have_content('second name')
page.should_not have_content('third name')
fill_in 'q_name_matches', with: '%name'
find('.btn.btn-primary').click
page.should have_content('first name')
page.should have_content('second name')
page.should have_content('third name')
fill_in 'q_name_matches', with: 'sec___ name'
find('.btn.btn-primary').click
page.should_not have_content('first name')
page.should have_content('second name')
page.should_not have_content('third name')
end
end

View file

@ -1,89 +0,0 @@
require 'rails_helper'
feature 'Domain', type: :feature do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
Fabricate(:zonefile_setting, origin: 'pri.ee')
@user = Fabricate(:admin_user)
end
it 'should show index of domains' do
Fabricate(:domain, name: 'testing.ee')
sign_in @user
visit admin_domains_url
page.should have_content('testing.ee')
end
it 'should search domains by name' do
d1 = Fabricate(:domain, name: 'abcde.ee')
Fabricate(:domain, name: 'abcdee.ee')
Fabricate(:domain, name: 'defgh.pri.ee')
sign_in @user
visit admin_domains_url
page.should have_content('abcde.ee')
page.should have_content('abcdee.ee')
page.should have_content('defgh.pri.ee')
fill_in 'q_name_matches', with: 'abcde.ee'
find('.btn.btn-primary').click
current_path.should == "/admin/domains/#{d1.id}"
visit admin_domains_url
fill_in 'q_name_matches', with: '.ee'
find('.btn.btn-primary').click
current_path.should == "/admin/domains"
page.should have_content('abcde.ee')
page.should have_content('abcdee.ee')
page.should have_content('defgh.pri.ee')
fill_in 'q_name_matches', with: 'abcd%.ee'
find('.btn.btn-primary').click
page.should have_content('abcde.ee')
page.should have_content('abcdee.ee')
page.should_not have_content('defgh.pri.ee')
fill_in 'q_name_matches', with: 'abcd_.ee'
find('.btn.btn-primary').click
current_path.should == "/admin/domains/#{d1.id}"
end
it 'should set domain to force delete' do
d = Fabricate(:domain)
sign_in @user
visit admin_domains_url
click_link d.name
click_link 'Edit statuses'
page.should have_content('ok')
click_link 'Set force delete'
page.should have_content('serverForceDelete')
page.should have_content('serverRenewProhibited')
page.should have_content('serverTransferProhibited')
page.should have_content('serverUpdateProhibited')
page.should have_content('serverManualInzone')
page.should have_content('pendingDelete')
click_link 'Edit statuses'
click_button 'Save'
page.should have_content('Failed to update domain')
page.should have_content('Object status prohibits operation')
click_link 'Back to domain'
click_link 'Edit statuses'
click_link 'Unset force delete'
page.should_not have_content('serverForceDelete')
page.should_not have_content('serverRenewProhibited')
page.should_not have_content('serverTransferProhibited')
page.should_not have_content('serverUpdateProhibited')
page.should_not have_content('serverManualInzone')
page.should_not have_content('pendingDelete')
page.should have_content('ok')
click_link 'Edit statuses'
click_button 'Save'
page.should have_content('Domain updated!')
end
end

View file

@ -1,25 +0,0 @@
require 'rails_helper'
feature 'EPP log', type: :feature do
before :all do
@user = Fabricate(:admin_user)
@contact = Fabricate(:contact, name: 'Mr John')
end
context 'as unknown user' do
it 'should redirect to login path' do
visit admin_epp_logs_url
current_path.should == '/admin/login'
end
end
context 'as logged in user' do
it 'should show index' do
sign_in @user
visit admin_epp_logs_url
page.should have_content('REPP logs')
end
end
end

View file

@ -1,131 +0,0 @@
require 'rails_helper'
feature 'Invoice', type: :feature do
before :all do
@user = Fabricate(:admin_user)
@invoice = Fabricate(:invoice)
end
before do
sign_in @user
end
it 'should show index of invoices' do
visit admin_invoices_url
page.should have_link("Invoice no. #{@invoice.id}")
end
it 'should show invoice' do
visit admin_invoices_url
click_link("Invoice no. #{@invoice.id}")
page.should have_content("Seller")
page.should have_content("Details")
page.should have_content("Paldiski mnt. 123")
end
it 'should issue an invoice' do
Fabricate(:eis)
r = Fabricate(:registrar)
visit admin_invoices_url
click_link('Add')
page.should have_content('Create new invoice')
select r.name, from: 'Registrar'
fill_in 'Amount', with: '100'
fill_in 'Description', with: 'test issue'
click_button 'Save'
page.should have_content('Record created')
page.should have_content('Invoice no.')
page.should have_content('Prepayment')
page.should have_content('120,00')
page.should have_content(r.name)
end
it 'should not issue and invoice with deposit amount too small' do
Setting.minimum_deposit = 0.0
r = Fabricate(:registrar)
visit admin_invoices_url
click_link('Add')
select r.name, from: 'Registrar'
fill_in 'Amount', with: '-2.11'
fill_in 'Description', with: 'test issue'
click_button 'Save'
page.should have_content('Amount is too small. Minimum deposit is 0.0 EUR')
Setting.minimum_deposit = 12.43
fill_in 'Amount', with: '12.42'
click_button 'Save'
page.should have_content('Amount is too small. Minimum deposit is 12.43 EUR')
fill_in 'Amount', with: '12.44'
click_button 'Save'
page.should have_content('Record created')
Setting.minimum_deposit = 0.0
end
it 'should forward invoice' do
visit '/admin/invoices'
click_link @invoice.to_s
click_link 'Forward'
click_button 'Forward'
page.should have_text('Failed to forward invoice')
fill_in 'Billing email', with: 'test@test.ee'
click_button 'Forward'
page.should have_text('Invoice forwarded')
end
it 'should download invoice' do
visit '/admin/invoices'
click_link @invoice.to_s
click_link 'Download'
response_headers['Content-Type'].should == 'application/pdf'
response_headers['Content-Disposition'].should == "attachment; filename=\"#{@invoice.pdf_name}\""
end
it 'should create bank statement and transaction for invoice' do
r = Fabricate(:registrar, reference_no: 'RF7086666663')
invoice = r.issue_prepayment_invoice(200, 'add some money')
visit '/admin/invoices'
click_link invoice.to_s
page.should have_content('Unpaid')
click_link 'Payment received'
paid_at = Time.zone.now
find_field('Bank code').value.should == '689'
find_field('Iban').value.should == 'EE557700771000598731'
find_field('Description').value.should == invoice.to_s
find_field('Sum').value.should == invoice.sum.to_s
find_field('Currency').value.should == 'EUR'
find_field('Reference no').value.should == invoice.reference_no
find_field('Paid at').value.should == paid_at.to_date.to_s
click_button 'Save'
page.should have_content('Record created')
page.should have_content('689')
page.should have_content('EE557700771000598731')
page.should have_content('Not binded', count: 2)
page.should have_content('240,00')
page.should have_content('EUR')
click_link 'Bind invoices'
page.should have_content('Invoices were fully binded')
page.should have_content('Fully binded')
page.should have_content('Binded')
click_link I18n.l(paid_at, format: :date_long)
page.should have_content('Binded')
page.should have_content(invoice.to_s)
page.should have_content('240,00')
page.should have_content(invoice.reference_no)
page.should have_content(I18n.l(paid_at, format: :date_long))
click_link(invoice.to_s)
page.should_not have_content('Unpaid')
page.should_not have_content('Payment received')
end
end

View file

@ -1,47 +0,0 @@
require 'rails_helper'
feature 'MailTemplate', type: :feature do
before :all do
@user = Fabricate(:admin_user)
end
before do
sign_in @user
end
it 'should add a bank statement and transactions manually' do
visit admin_mail_templates_url
click_link 'New'
fill_in 'Name', with: 'Testing email template'
fill_in 'Subject', with: 'Test subject'
fill_in 'From', with: 'example@example.com'
fill_in 'mail_template_body', with: 'Liquid <h1>Test</h1>'
fill_in 'mail_template_text_body', with: 'Liquid static test'
click_button 'Save'
page.should have_content('Testing email template')
page.should have_content('Test subject')
page.should have_content('example@example.com')
page.should have_content('Liquid Test')
page.should have_content('Liquid static test')
click_link 'Email Templates'
page.should have_content('Mail Templates')
page.should have_content('Test subject')
click_link 'Testing email template'
page.should have_content('Testing email template')
click_link 'Edit'
page.should have_content('Edit: Testing email template')
fill_in 'Subject', with: 'New edited test subject'
click_button 'Save'
page.should have_content 'New edited test subject'
click_link 'Delete'
page.should have_content 'Mail Templates'
page.should_not have_content 'New edited test subject'
end
end

View file

@ -1,24 +0,0 @@
require 'rails_helper'
feature 'Repp log', type: :feature do
before :all do
@user = Fabricate(:admin_user)
end
context 'as unknown user' do
it 'should redirect to login path' do
visit admin_repp_logs_url
current_path.should == '/admin/login'
end
end
context 'as logged in user' do
it 'should show index' do
sign_in @user
visit admin_repp_logs_url
page.should have_content('REPP logs')
end
end
end

View file

@ -1,44 +0,0 @@
require 'rails_helper'
feature 'ReservedDomain', type: :feature do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
@user = Fabricate(:admin_user)
end
before do
sign_in @user
end
it 'should manage reserved domains' do
visit admin_reserved_domains_url
page.should have_content('Reserved domains')
d = Fabricate.build(:domain, name: '110.ee')
d.valid?
d.errors.full_messages.should match_array([])
fill_in 'reserved_domains', with: "110.ee: testpw"
click_button 'Save'
page.should have_content('Record updated')
page.should have_content('110.ee: testpw')
d.valid?.should == false
d.errors.full_messages.should match_array(
["Required parameter missing; reserved>pw element required for reserved domains"]
)
d.reserved_pw = 'wrongpw'
d.valid?.should == false
d.reserved_pw = 'testpw'
d.valid?.should == true
d.errors.full_messages.should match_array([])
d.save
visit admin_reserved_domains_url
page.should have_content('110.ee')
page.should_not have_content('110.ee: testpw')
end
end

View file

@ -1,63 +0,0 @@
require 'rails_helper'
feature 'Api users', type: :feature do
before :all do
@user = Fabricate(:admin_user)
@registrar = Fabricate(:registrar)
end
context 'as unknown user' do
it 'should redirect to login path' do
visit new_admin_registrar_white_ip_url(@registrar)
current_path.should == '/admin/login'
end
end
context 'as logged in user' do
before { sign_in @user }
it 'should add new white ip to registrar' do
visit admin_registrar_url(@registrar)
page.should_not have_text('192.168.1.1')
click_link 'Create new white IP'
fill_in 'IPv4', with: '192.168.1.1'
fill_in 'IPv6', with: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'
find('#white_ip_interfaces_api').set(true)
click_button 'Save'
page.should have_text('Record created')
page.should have_text('White IP')
page.should have_link(@registrar.to_s)
page.should have_text('192.168.1.1')
page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329')
page.should have_text('API')
click_link @registrar.to_s
current_path.should == "/admin/registrars/#{@registrar.id}"
page.should have_text('192.168.1.1')
page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329')
page.should have_text('API')
end
it 'should not add invalid ip to registrar' do
visit new_admin_registrar_white_ip_url(@registrar)
click_button 'Save'
page.should have_text('IPv4 or IPv6 must be present')
page.should have_text('Failed to create record')
fill_in 'IPv4', with: 'bla'
fill_in 'IPv6', with: 'bla'
click_button 'Save'
page.should have_text('IPv4 is invalid')
page.should have_text('IPv6 is invalid')
end
end
end

View file

@ -1,99 +0,0 @@
require 'rails_helper'
feature 'Zonefile settings', type: :feature do
before :all do
@user = Fabricate(:admin_user)
end
context 'as unknown user' do
it 'should redirect to login path' do
visit admin_zonefile_settings_url
current_path.should == '/admin/login'
end
end
context 'as logged in user' do
it 'should show index of contacts' do
sign_in @user
visit admin_zonefile_settings_url
page.should have_content('Zonefile settings')
end
it 'should create zone' do
sign_in @user
visit admin_zonefile_settings_url
page.should_not have_content('Generate zonefile')
click_link 'New'
fill_in 'Origin', with: 'ee'
fill_in 'TTL', with: '43200'
fill_in 'Refresh', with: '3600'
fill_in 'Retry', with: '900'
fill_in 'Expire', with: '1209600'
fill_in 'Minimum TTL', with: '3600'
fill_in 'E-Mail', with: 'hostmaster.eestiinternet.ee'
fill_in 'Master nameserver', with: 'ns.tld.ee'
fill_in('Ns records', with: '
ee. IN NS sunic.sunet.se.
ee. IN NS ns.eenet.ee.
ee. IN NS ns.tld.ee.
ee. IN NS ns.ut.ee.
ee. IN NS e.tld.ee.
ee. IN NS b.tld.ee.
ee. IN NS ee.aso.ee.
')
fill_in('A records', with: '
ns.ut.ee. IN A 193.40.5.99
ns.tld.ee. IN A 195.43.87.10
ee.aso.ee. IN A 213.184.51.122
b.tld.ee. IN A 194.146.106.110
ns.eenet.ee. IN A 193.40.56.245
e.tld.ee. IN A 204.61.216.36
')
fill_in('AAAA records', with: '
ee.aso.ee. IN AAAA 2A02:88:0:21::2
b.tld.ee. IN AAAA 2001:67C:1010:28::53
ns.eenet.ee. IN AAAA 2001:BB8::1
e.tld.ee. IN AAAA 2001:678:94:53::53
')
click_button 'Save'
page.should have_content('Record created')
page.should have_content('ee')
page.should have_content('Generate zonefile')
click_link 'Generate zonefile'
response_headers['Content-Type'].should == 'text/plain'
response_headers['Content-Disposition'].should == "attachment; filename=\"ee.txt\""
end
it 'does not delete zone with existin domains' do
ZonefileSetting.find_by(origin: 'ee') || Fabricate(:zonefile_setting)
Fabricate(:domain)
sign_in @user
visit admin_zonefile_settings_url
click_link 'ee'
click_link 'Delete'
page.should have_content("There are 1 domains in this zone")
page.should have_content('Failed to delete record')
end
it 'deletes a zone' do
ZonefileSetting.find_by(origin: 'ee') || Fabricate(:zonefile_setting)
Domain.destroy_all
sign_in @user
visit admin_zonefile_settings_url
click_link 'ee'
click_link 'Delete'
page.should have_content('Record deleted')
page.should_not have_content("Generate zonefile")
end
end
end

View file

@ -1,49 +0,0 @@
require 'rails_helper'
feature 'DomainDeleteConfirm', type: :feature do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
end
context 'as unknown user with domain without token' do
before :all do
@domain = Fabricate(:domain)
end
it 'should see warning info if token is missing request' do
visit "/registrant/domain_delete_confirms/#{@domain.id}"
current_path.should == "/registrant/domain_delete_confirms/#{@domain.id}"
page.should have_text('Domain verification not available')
end
it 'should see warning info if token is missing request' do
visit "/registrant/domain_delete_confirms/#{@domain.id}"
current_path.should == "/registrant/domain_delete_confirms/#{@domain.id}"
page.should have_text('Domain verification not available')
end
end
context 'as unknown user with domain with token' do
before :all do
@domain = Fabricate(
:domain,
registrant_verification_token: '123',
registrant_verification_asked_at: Time.zone.now
)
@domain.statuses << DomainStatus::PENDING_DELETE
@domain.save
end
it 'should see warning info if token is missing in request' do
visit "/registrant/domain_delete_confirms/#{@domain.id}?token=wrong_token"
current_path.should == "/registrant/domain_delete_confirms/#{@domain.id}"
page.should have_text('Domain verification not available')
end
it 'should show domain info and confirm buttons' do
visit "/registrant/domain_delete_confirms/#{@domain.id}?token=123"
current_path.should == "/registrant/domain_delete_confirms/#{@domain.id}"
page.should_not have_text('Domain verification not available')
end
end
end

View file

@ -1,49 +0,0 @@
require 'rails_helper'
feature 'DomainUpdateConfirm', type: :feature do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
end
context 'as unknown user with domain without update token' do
before :all do
@domain = Fabricate(:domain)
end
it 'should see warning info if token is missing request' do
visit "/registrant/domain_update_confirms/#{@domain.id}"
current_path.should == "/registrant/domain_update_confirms/#{@domain.id}"
page.should have_text('Domain verification not available')
end
it 'should see warning info if token is missing request' do
visit "/registrant/domain_update_confirms/#{@domain.id}"
current_path.should == "/registrant/domain_update_confirms/#{@domain.id}"
page.should have_text('Domain verification not available')
end
end
context 'as unknown user with domain with update token' do
before :all do
@domain = Fabricate(
:domain,
registrant_verification_token: '123',
registrant_verification_asked_at: Time.zone.now
)
@domain.statuses << DomainStatus::PENDING_UPDATE
@domain.save
end
it 'should see warning info if token is missing in request' do
visit "/registrant/domain_update_confirms/#{@domain.id}?token=wrong_token"
current_path.should == "/registrant/domain_update_confirms/#{@domain.id}"
page.should have_text('Domain verification not available')
end
it 'should show domain info and confirm buttons' do
visit "/registrant/domain_update_confirms/#{@domain.id}?token=123"
current_path.should == "/registrant/domain_update_confirms/#{@domain.id}"
page.should_not have_text('Domain verification not available')
end
end
end

View file

@ -1,18 +0,0 @@
require 'rails_helper'
feature 'Root', type: :feature do
it 'should redirect to registrant login page' do
visit '/registrant/login'
current_path.should == '/registrant/login'
end
it 'should redirect to registrant login page' do
visit '/registrant'
current_path.should == '/registrant/login'
end
it 'should redirect to registrant login page' do
visit '/registrant/'
current_path.should == '/registrant/login'
end
end

View file

@ -1,38 +0,0 @@
require 'rails_helper'
feature 'Account activity', type: :feature do
before :all do
@user = Fabricate(:api_user)
Fabricate(:account_activity, account: @user.registrar.cash_account)
end
context 'as unknown user' do
it 'should redirect to sign in page' do
visit '/registrar/account_activities'
current_path.should == '/registrar/login'
page.should have_text('You need to sign in or sign up')
end
end
context 'as signed in user' do
before do
registrar_sign_in
end
it 'should navigate to account activities page' do
current_path.should == '/registrar/poll'
click_link 'Billing'
click_link 'Account activity'
current_path.should == '/registrar/account_activities'
page.should have_text('+110.0 EUR')
end
it 'should download csv' do
visit '/registrar/account_activities'
click_link 'Export CSV'
response_headers['Content-Type'].should == 'text/csv'
response_headers['Content-Disposition'].should match(/attachment; filename="account_activities_\d+\.csv"/)
end
end
end

View file

@ -1,94 +0,0 @@
require 'rails_helper'
feature 'Contact', type: :feature do
before :all do
@user = Fabricate(:api_user)
end
context 'as unknown user' do
it 'should redirect to sign in page' do
visit '/registrar/contacts'
current_path.should == '/registrar/login'
page.should have_text('You need to sign in or sign up')
end
end
context 'as signed in user' do
before do
registrar_sign_in
end
it 'should navigate to the contact index page' do
click_link 'Contacts'
current_path.should == '/registrar/contacts'
end
it 'should get contact index page' do
visit '/registrar/contacts'
current_path.should == '/registrar/contacts'
end
context 'manage contact' do
it 'should navigate to new page' do
click_link 'Contacts'
click_link 'New'
current_path.should == '/registrar/contacts/new'
end
it 'should get new page' do
visit '/registrar/contacts/new'
current_path.should == '/registrar/contacts/new'
end
it 'should get warnings' do
visit '/registrar/contacts/new'
current_path.should == '/registrar/contacts/new'
fill_in 'depp_contact_ident', with: ''
fill_in 'depp_contact_name', with: 'Business Name Ltd'
fill_in 'depp_contact_email', with: 'example@example.com'
fill_in 'depp_contact_street', with: 'Example street 12'
fill_in 'depp_contact_city', with: 'Example City'
fill_in 'depp_contact_zip', with: '123456'
fill_in 'depp_contact_phone', with: '+372.12345678'
click_button 'Create'
current_path.should == '/registrar/contacts'
page.should have_text('Required parameter missing')
end
def create_contact
visit '/registrar/contacts/new'
current_path.should == '/registrar/contacts/new'
fill_in 'depp_contact_ident', with: 'org-ident'
fill_in 'depp_contact_name', with: 'Business Name Ltd'
fill_in 'depp_contact_email', with: 'example@example.com'
fill_in 'depp_contact_street', with: 'Example street 12'
fill_in 'depp_contact_city', with: 'Example City'
fill_in 'depp_contact_zip', with: '123456'
fill_in 'depp_contact_phone', with: '+372.12345678'
click_button 'Create'
page.should have_text('Business Name Ltd')
page.should have_text('org-ident [EE org]')
end
it 'should create new contact with success' do
create_contact
end
it 'should edit sucessfully' do
create_contact
click_link 'Edit'
current_path.should match(/edit/)
fill_in 'depp_contact_name', with: 'Edited Business Name Ltd'
click_button 'Save'
page.should have_text('Edited Business Name Ltd')
end
end
end
end

View file

@ -1,124 +0,0 @@
require 'rails_helper'
feature 'Domains', type: :feature do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
Fabricate(:zonefile_setting, origin: 'pri.ee')
@user = Fabricate(:api_user)
end
context 'as unknown user' do
it 'should redirect to sign in page' do
visit '/registrar/domains'
current_path.should == '/registrar/login'
page.should have_text('You need to sign in or sign up')
end
end
context 'as signed in user' do
before do
registrar_sign_in
end
it 'should navigate to the domains index page' do
click_link 'Domains'
current_path.should == '/registrar/domains'
end
it 'should get domains index page' do
visit '/registrar/domains'
current_path.should == '/registrar/domains'
end
it 'should navigate to new page' do
click_link 'Domains'
click_link 'New'
current_path.should == '/registrar/domains/new'
end
it 'should get new page' do
visit '/registrar/domains/new'
current_path.should == '/registrar/domains/new'
end
it 'should switch user' do
d1 = Fabricate(:domain, registrar: @user.registrar)
user2 = Fabricate(:api_user, identity_code: @user.identity_code)
d2 = Fabricate(:domain, registrar: user2.registrar)
visit '/registrar/domains'
page.should have_text(d1.name)
page.should_not have_text(d2.name)
click_link "#{user2} (#{user2.roles.first}) - #{user2.registrar}"
visit '/registrar/domains'
page.should_not have_text(d1.name)
page.should have_text(d2.name)
end
it 'should search domains' do
# having shared state across tests is really annoying sometimes...
within('.dropdown-menu') do
click_link "#{@user} (#{@user.roles.first}) - #{@user.registrar}"
end
Fabricate(:domain, name: 'abcde.ee', registrar: @user.registrar)
Fabricate(:domain, name: 'abcdee.ee', registrar: @user.registrar)
Fabricate(:domain, name: 'defgh.pri.ee', registrar: @user.registrar)
visit '/registrar/domains'
click_link 'Domains'
page.should have_content('abcde.ee')
page.should have_content('abcdee.ee')
page.should have_content('defgh.pri.ee')
fill_in 'q_name_matches', with: 'abcde.ee'
find('.btn.btn-primary.search').click
current_path.should == "/registrar/domains/info"
visit '/registrar/domains'
fill_in 'q_name_matches', with: '.ee'
find('.btn.btn-primary.search').click
current_path.should == "/registrar/domains"
page.should have_content('abcde.ee')
page.should have_content('abcdee.ee')
page.should have_content('defgh.pri.ee')
fill_in 'q_name_matches', with: 'abcd%.ee'
find('.btn.btn-primary.search').click
page.should have_content('abcde.ee')
page.should have_content('abcdee.ee')
page.should_not have_content('defgh.pri.ee')
fill_in 'q_name_matches', with: 'abcd_.ee'
find('.btn.btn-primary.search').click
current_path.should == "/registrar/domains"
page.should have_content('abcde.ee')
end
it 'should search foreign domain and transfer it' do
user2 = Fabricate(:api_user, identity_code: @user.identity_code)
d2 = Fabricate(:domain, registrar: user2.registrar)
visit '/registrar/domains'
page.should_not have_content(d2.name)
fill_in 'q_name_matches', with: d2.name
find('.btn.btn-primary.search').click
current_path.should == "/registrar/domains/info"
click_link 'Transfer'
fill_in 'Password', with: d2.auth_info
click_button 'Transfer'
page.should have_content 'serverApproved'
visit '/registrar/domains'
page.should have_content d2.name
end
end
end

View file

@ -1,68 +0,0 @@
require 'rails_helper'
feature 'Invoices', type: :feature do
before :all do
@user = Fabricate(:api_user)
@invoice = Fabricate(:invoice, buyer: @user.registrar)
end
context 'as unknown user' do
it 'should redirect to sign in page' do
visit '/registrar/invoices'
current_path.should == '/registrar/login'
page.should have_text('You need to sign in or sign up')
end
end
context 'as signed in user' do
before do
registrar_sign_in
end
it 'should navigate to the domains index page' do
current_path.should == '/registrar/poll'
click_link 'Billing'
current_path.should == '/registrar/invoices'
page.should have_text('Your current account balance is')
end
it 'should get domains index page' do
visit '/registrar/invoices'
page.should have_text('Invoices')
end
it 'should forward invoice' do
visit '/registrar/invoices'
click_link @invoice.to_s
click_link 'Forward'
click_button 'Forward'
page.should have_text('Failed to forward invoice')
fill_in 'Billing email', with: 'test@test.ee'
click_button 'Forward'
page.should have_text('Invoice forwarded')
end
it 'should download invoice' do
visit '/registrar/invoices'
click_link @invoice.to_s
click_link 'Download'
response_headers['Content-Type'].should == 'application/pdf'
response_headers['Content-Disposition'].should == "attachment; filename=\"#{@invoice.pdf_name}\""
end
it 'should not see foreign invoices' do
user2 = Fabricate(:api_user, identity_code: @user.identity_code)
visit '/registrar/invoices'
click_link @invoice.to_s
page.should have_text(@invoice.to_s)
page.should have_text('Buyer')
click_link "#{user2} (#{user2.roles.first}) - #{user2.registrar}"
visit "/registrar/invoices/#{@invoice.id}"
page.should have_text('You are not authorized to access this page.')
visit "/registrar/invoices/#{@invoice.id}/forward"
page.should have_text('You are not authorized to access this page.')
end
end
end

View file

@ -1,22 +0,0 @@
require 'rails_helper'
feature 'Root', type: :feature do
before :all do
Fabricate(:api_user)
end
it 'should redirect to registrar login page' do
visit '/registrar/login'
current_path.should == '/registrar/login'
end
it 'should redirect to registrar login page' do
visit '/registrar'
current_path.should == '/registrar/login'
end
it 'should redirect to registrar login page' do
visit '/registrar/'
current_path.should == '/registrar/login'
end
end

View file

@ -1,186 +0,0 @@
require 'rails_helper'
feature 'Sessions', type: :feature do
context 'with invalid ip' do
it 'should not see login page' do
Setting.registrar_ip_whitelist_enabled = true
WhiteIp.destroy_all
visit registrar_login_path
page.should have_text('Access denied')
end
it 'should see login page when whitelist disabled' do
Setting.registrar_ip_whitelist_enabled = false
WhiteIp.destroy_all
visit registrar_login_path
page.should_not have_text('Access denied')
Setting.registrar_ip_whitelist_enabled = true
end
it 'should see log in' do
@fixed_registrar.white_ips = [Fabricate(:white_ip_registrar)]
visit registrar_login_path
page.should have_text('Log in')
end
it 'should not get in with invalid ip' do
Fabricate(:registrar, white_ips: [Fabricate(:white_ip), Fabricate(:white_ip_registrar)])
@api_user_invalid_ip = Fabricate(
:api_user, identity_code: '37810013294', registrar: Fabricate(:registrar, white_ips: [])
)
visit registrar_login_path
fill_in 'depp_user_tag', with: @api_user_invalid_ip.username
fill_in 'depp_user_password', with: @api_user_invalid_ip.password
click_button 'Log in'
page.should have_text('IP is not whitelisted')
end
it 'should get in with invalid when whitelist disabled' do
Setting.registrar_ip_whitelist_enabled = false
Setting.api_ip_whitelist_enabled = false
Fabricate(:registrar, white_ips: [Fabricate(:white_ip), Fabricate(:white_ip_registrar)])
@api_user_invalid_ip = Fabricate(
:api_user, identity_code: '37810013294', registrar: Fabricate(:registrar, white_ips: [])
)
visit registrar_login_path
fill_in 'depp_user_tag', with: @api_user_invalid_ip.username
fill_in 'depp_user_password', with: @api_user_invalid_ip.password
click_button 'Log in'
page.should have_text('Log out')
Setting.registrar_ip_whitelist_enabled = true
Setting.api_ip_whitelist_enabled = true
end
it 'should not get in with invalid user' do
visit registrar_login_path
fill_in 'depp_user_tag', with: 'bla'
fill_in 'depp_user_password', with: 'bla'
click_button 'Log in'
page.should have_text('No such user')
end
end
context 'as unknown user' do
before :all do
Fabricate(:api_user)
end
it 'should not get in' do
client = instance_double("Digidoc::Client")
allow(client).to receive(:authenticate).and_return(
OpenStruct.new(
user_id_code: '123'
)
)
allow(Digidoc::Client).to receive(:new) { client }
visit registrar_login_path
page.should have_css('a[href="/registrar/login/mid"]')
page.find('a[href="/registrar/login/mid"]').click
fill_in 'user_phone', with: '00007'
click_button 'Log in'
page.should have_text('No such user')
end
end
context 'as known api user' do
before :all do
Fabricate(:api_user)
end
it 'should not get in when external service fails' do
client = instance_double("Digidoc::Client")
allow(client).to receive(:authenticate).and_return(
OpenStruct.new(
faultcode: 'Fault',
detail: OpenStruct.new(
message: 'Something is wrong'
)
)
)
allow(Digidoc::Client).to receive(:new) { client }
visit registrar_login_path
page.should have_css('a[href="/registrar/login/mid"]')
page.find('a[href="/registrar/login/mid"]').click
fill_in 'user_phone', with: '00007'
click_button 'Log in'
page.should have_text('Something is wrong')
end
it 'should not get in when there is a sim error', js: true do
client = instance_double("Digidoc::Client", session_code: '123')
allow(client).to receive('session_code=')
allow(client).to receive(:authenticate).and_return(
OpenStruct.new(
user_id_code: '14212128025'
)
)
allow(client).to receive('authentication_status').and_return(
OpenStruct.new(status: 'SIM_ERROR')
)
allow(Digidoc::Client).to receive(:new) { client }
visit registrar_login_path
page.should have_css('a[href="/registrar/login/mid"]')
page.find('a[href="/registrar/login/mid"]').click
fill_in 'user_phone', with: '00007'
click_button 'Log in'
page.should have_text('Confirmation sms was sent to your phone. Verification code is')
page.should have_text('SIM application error')
end
it 'should log in successfully', js: true do
client = instance_double("Digidoc::Client", session_code: '123')
allow(client).to receive('session_code=')
allow(client).to receive(:authenticate).and_return(
OpenStruct.new(
user_id_code: '14212128025'
)
)
allow(client).to receive('authentication_status').and_return(
OpenStruct.new(status: 'USER_AUTHENTICATED')
)
allow(Digidoc::Client).to receive(:new) { client }
visit registrar_login_path
page.should have_css('a[href="/registrar/login/mid"]')
page.find('a[href="/registrar/login/mid"]').click
fill_in 'user_phone', with: '00007'
click_button 'Log in'
page.should have_text('Confirmation sms was sent to your phone. Verification code is')
page.should have_text('Welcome!')
end
it 'should log in successfully using helper method with javascript off' do
registrar_sign_in
page.should have_text('Log out')
end
it 'should log in successfully using helper method with javascript on', js: true do
# not working yet
# registrar_sign_in
# page.should have_text('Log out')
end
end
end

View file

@ -1,25 +0,0 @@
require 'rails_helper'
feature 'Sessions', type: :feature do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
@user = Fabricate(:ee_user)
@registrar1 = Fabricate(:registrar1)
@registrar2 = Fabricate(:registrar2)
Fabricate.times(2, :domain, registrar: @registrar1)
Fabricate.times(2, :domain, registrar: @registrar2)
end
scenario 'Admin logs in' do
visit root_path
sign_in @user
page.should have_text('Welcome!')
uri = URI.parse(current_url)
uri.path.should == admin_domains_path
page.should have_link('registrar1', count: 2)
page.should have_link('registrar2', count: 2)
end
end

View file

@ -1,26 +0,0 @@
require 'rails_helper'
feature 'Setting management', type: :feature do
let(:user) { Fabricate(:admin_user) }
scenario 'User changes a setting' do
sign_in user
visit admin_settings_path
val_min = find_field('_settings_ns_min_count').value
val_max = find_field('_settings_ns_max_count').value
expect(val_min).to eq('2')
expect(val_max).to eq('11')
fill_in '_settings_ns_min_count', with: 0
fill_in '_settings_ns_max_count', with: 10
click_button 'Save'
val_min = find_field('_settings_ns_min_count').value
val_max = find_field('_settings_ns_max_count').value
expect(val_min).to eq('0')
expect(val_max).to eq('10')
end
end

View file

@ -1,82 +0,0 @@
require 'rails_helper'
describe ContactMailer do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
end
describe 'email changed notification when delivery turned off' do
before :all do
@contact = Fabricate(:contact, email: 'test@example.ee')
@mail = ContactMailer.email_updated('test@example.com', @contact.id, deliver_emails)
end
it 'should not render email subject' do
@mail.subject.should == nil
end
it 'should not have sender email' do
@mail.from.should == nil
end
it 'should not have reveiver email' do
@mail.to.should == nil
end
it 'should not render body' do
@mail.body.should == ''
end
end
describe 'email changed notification' do
before :all do
@domain = Fabricate(:domain)
@contact = @domain.registrant
@contact.reload # until figured out why registrant_domains not loaded
@contact.deliver_emails = true
@mail = ContactMailer.email_updated('info@example.org', @contact.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /Teie domeenide kontakt epostiaadress on muutunud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send to info email' do
@mail.to.should == ['info@example.org']
end
it 'should render body' do
@mail.body.encoded.should =~ /Kontaktandmed:/
end
end
describe 'email with pynicode' do
before :all do
@domain = Fabricate(:domain)
@contact = @domain.registrant
@contact.reload # until figured out why registrant_domains not loaded
@contact.deliver_emails = true
@mail = ContactMailer.email_updated('info@ääöü.org', @contact.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /Teie domeenide kontakt epostiaadress on muutunud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send to info email' do
@mail.to.should == ['info@xn--4caa8cya.org']
end
it 'should render body' do
@mail.body.encoded.should =~ /Kontaktandmed:/
end
end
end

View file

@ -1,336 +0,0 @@
require 'rails_helper'
describe DomainMailer do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
end
describe 'pending update request for an old registrant when delivery turned off' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, registrant: @registrant)
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id, @registrant.id,deliver_emails)
end
it 'should not render email subject' do
@mail.subject.should == nil
end
it 'should not have sender email' do
@mail.from.should == nil
end
it 'should not have reveiver email' do
@mail.to.should == nil
end
it 'should not render body' do
@mail.body.should == ''
end
end
describe 'pending update request for an old registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@new_registrant = Fabricate(:registrant, email: 'test@example.org')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@domain.registrant = @new_registrant
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id, @registrant.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /registreerija vahetuseks/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to old registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /Registrisse laekus taotlus domeeni/
end
it 'should render verification url' do
@mail.body.encoded.should =~ %r{registrant\/domain_update_confirms}
end
end
describe 'pending upadte notification for a new registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'old@example.com')
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@domain.registrant = @new_registrant
@mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id, @registrant.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /protseduur on algatatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to new registrant email' do
@mail.to.should == ["new@example.org"]
end
it 'should render body' do
@mail.body.encoded.should =~ /vahendusel on algatatud/
end
end
describe 'pending update notification for a new registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'old@example.com')
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@domain.registrant = @new_registrant
@mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id, @registrant.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /protseduur on algatatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to new registrant email' do
@mail.to.should == ["new@example.org"]
end
it 'should render body' do
@mail.body.encoded.should =~ /vahendusel on algatatud/
end
end
describe 'pending update rejected notification for a new registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'old@example.com')
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@domain.pending_json['new_registrant_email'] = 'new@example.org'
@domain.pending_json['new_registrant_name'] = 'test name'
@mail = DomainMailer.pending_update_rejected_notification_for_new_registrant(@domain.id)
end
it 'should render email subject' do
@mail.subject.should =~ /vahetuse taotlus tagasi lükatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to new registrant email' do
@mail.to.should == ["new@example.org"]
end
it 'should render body' do
@mail.body.encoded.should =~ /Registrant change was declined/
end
end
describe 'registrant updated notification for a new registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@mail = DomainMailer.registrant_updated_notification_for_new_registrant(@domain.id, @registrant.id, @registrant.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /registreerija vahetus teostatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send to registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/
end
end
describe 'registrant updated notification for a old registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@mail = DomainMailer.registrant_updated_notification_for_old_registrant(@domain.id, @registrant.id, @registrant.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /registreerija vahetus teostatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send to registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/
end
end
describe 'domain pending delete notification when delivery turned off' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, registrant: @registrant)
@mail = DomainMailer.pending_deleted(@domain.id, @registrant.id, deliver_emails)
end
it 'should not render email subject' do
@mail.subject.should == nil
end
it 'should not have sender email' do
@mail.from.should == nil
end
it 'should not have reveiver email' do
@mail.to.should == nil
end
it 'should not render body' do
@mail.body.should == ''
end
end
describe 'email pending delete notification' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, name: 'delete-pending.ee', registrant: @registrant)
@domain.deliver_emails = true
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@mail = DomainMailer.pending_deleted(@domain.id, @registrant.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /kustutamiseks .ee registrist/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to old registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /Registrisse laekus taotlus domeeni delete-pending.ee kustutamiseks/
end
it 'should render verification url' do
@mail.body.encoded.should =~ %r{registrant\/domain_delete_con} # somehowe delete_confirms not matching
end
end
describe 'pending delete rejected notification' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, name: 'delete-pending-rejected.ee', registrant: @registrant)
@domain.deliver_emails = true
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@mail = DomainMailer.pending_delete_rejected_notification(@domain.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /kustutamise taotlus tagasi lükatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to old registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /deletion rejected/
end
end
describe 'pending delete expired notification' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, name: 'pending-delete-expired.ee', registrant: @registrant)
@domain.deliver_emails = true
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@mail = DomainMailer.pending_delete_expired_notification(@domain.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /deletion cancelled/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to old registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /deletion cancelled/
end
end
describe 'pending delete rejected notification' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, name: 'delete-confirmed.ee', registrant: @registrant)
@domain.deliver_emails = true
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@mail = DomainMailer.delete_confirmation(@domain.id, deliver_emails)
end
it 'should render email subject' do
@mail.subject.should =~ /deleted/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to old registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /confirmed and will be deleted/
end
end
end

View file

@ -1,9 +1,6 @@
require 'rails_helper'
describe Account do
it { should belong_to(:registrar) }
it { should have_many(:account_activities) }
context 'with invalid attribute' do
before :all do
@account = Account.new

View file

@ -1,8 +1,6 @@
require 'rails_helper'
describe Address do
it { should belong_to(:contact) }
context 'about class' do
it 'should have versioning enabled?' do
Address.paper_trail_enabled_for_model?.should == true

View file

@ -1,8 +1,6 @@
require 'rails_helper'
describe ApiUser do
it { should belong_to(:registrar) }
context 'class methods' do
before do
Fabricate(:api_user, identity_code: '')

View file

@ -1,8 +1,6 @@
require 'rails_helper'
describe BankStatement do
it { should have_many(:bank_transactions) }
context 'with invalid attribute' do
before :all do
@bank_statement = BankStatement.new

View file

@ -1,9 +1,6 @@
require 'rails_helper'
describe BankTransaction do
it { should belong_to(:bank_statement) }
it { should have_one(:account_activity) }
context 'with invalid attribute' do
before :all do
@bank_transaction = BankTransaction.new

View file

@ -1,34 +0,0 @@
require 'rails_helper'
describe BlockedDomain do
context 'with no attributes' do
before :all do
@blocked_domain = BlockedDomain.new
end
it 'should have names array' do
@blocked_domain.names.should == []
end
end
context 'with valid attributes' do
before :all do
@blocked_domain = Fabricate(:blocked_domain)
end
it 'should be valid' do
@blocked_domain.valid?
@blocked_domain.errors.full_messages.should match_array([])
end
it 'should have one version' do
with_versioning do
@blocked_domain.versions.should == []
@blocked_domain.names = ['bla.ee']
@blocked_domain.save
@blocked_domain.errors.full_messages.should match_array([])
@blocked_domain.versions.size.should == 1
end
end
end
end

View file

@ -1,61 +0,0 @@
require 'rails_helper'
describe Certificate do
it { should belong_to(:api_user) }
context 'with invalid attribute' do
before :all do
@certificate = Certificate.new
end
it 'should not be valid' do
@certificate.valid?
@certificate.errors.full_messages.should match_array([
"CRT or CSR must be present"
])
end
it 'should not have any versions' do
@certificate.versions.should == []
end
end
context 'with valid attributes' do
before :all do
@certificate = Fabricate(:certificate)
end
it 'should be valid' do
@certificate.valid?
@certificate.errors.full_messages.should match_array([])
end
it 'should be valid twice' do
@certificate = Fabricate(:certificate)
@certificate.valid?
@certificate.errors.full_messages.should match_array([])
end
it 'should sign csr', epp: true do
@certificate.status.should == 'unsigned'
@certificate.sign!
@certificate.status.should == 'signed'
@certificate.crt.should_not be_blank
end
it 'should revoke crt', epp: true do
@certificate.revoke!
@certificate.status.should == 'revoked'
end
it 'should have one version' do
with_versioning do
@certificate.versions.should == []
@certificate.csr = 'new_request'
@certificate.save
@certificate.errors.full_messages.should match_array([])
@certificate.versions.size.should == 1
end
end
end
end

View file

@ -1,7 +1,7 @@
require 'rails_helper'
describe Contact do
before :all do
before :example do
Fabricate(:zonefile_setting, origin: 'ee')
@api_user = Fabricate(:api_user)
end
@ -17,28 +17,10 @@ describe Contact do
end
context 'with invalid attribute' do
before :all do
before :example do
@contact = Contact.new
end
it 'should not be valid' do
@contact.valid?
@contact.errors.full_messages.should match_array([
"Name Required parameter missing - name",
"Phone Required parameter missing - phone",
"Phone Phone nr is invalid",
"Email Required parameter missing - email",
"Email Email is invalid",
"Ident Required parameter missing - ident",
"Registrar is missing",
"Ident type is missing",
"City is missing",
"Country code is missing",
"Street is missing",
"Zip is missing"
])
end
it 'should not have creator' do
@contact.creator.should == nil
end
@ -66,6 +48,7 @@ describe Contact do
end
it 'should validate correct country code' do
@contact.ident = 1
@contact.ident_type = 'org'
@contact.ident_country_code = 'EE'
@contact.valid?
@ -79,14 +62,14 @@ describe Contact do
@contact.ident_country_code = 'INVALID'
@contact.valid?
@contact.errors[:ident].should ==
['Ident country code is not valid, should be in ISO_3166-1 alpha 2 format']
expect(@contact.errors).to have_key(:ident)
end
it 'should convert to alpha2 country code' do
@contact.ident = 1
@contact.ident_type = 'org'
@contact.ident_country_code = 'ee'
@contact.valid?
@contact.validate
@contact.ident_country_code.should == 'EE'
end
@ -102,9 +85,11 @@ describe Contact do
end
it 'should not allow double status' do
@contact.statuses = ['ok', 'ok']
@contact.valid?
@contact.errors[:statuses].should == ['not uniq']
contact = described_class.new(statuses: %w(ok ok))
contact.validate
expect(contact.statuses).to eq(%w(ok))
end
it 'should have no related domain descriptions' do
@ -123,21 +108,10 @@ describe Contact do
end
context 'with valid attributes' do
before :all do
before :example do
@contact = Fabricate(:contact)
end
it 'should be valid' do
@contact.valid?
@contact.errors.full_messages.should match_array([])
end
it 'should be valid twice' do
@contact = Fabricate(:contact)
@contact.valid?
@contact.errors.full_messages.should match_array([])
end
it 'should have one version' do
with_versioning do
@contact.versions.reload.should == []
@ -153,10 +127,11 @@ describe Contact do
end
it 'org should be valid' do
@contact.ident_type = 'org'
@contact.ident = '1234'
@contact.valid?
@contact.errors.full_messages.should match_array([])
contact = Fabricate.build(:contact, ident_type: 'org', ident: '1' * 8)
contact.validate
contact.errors.full_messages.should match_array([])
end
it 'should not overwrite code' do
@ -188,45 +163,11 @@ describe Contact do
contact.statuses.should == [Contact::SERVER_UPDATE_PROHIBITED]
end
it 'should have linked status when domain' do
contact = Fabricate(:contact)
tech_domain_contact = Fabricate(:tech_domain_contact, contact_id: contact.id)
contact.statuses.should == %w(ok)
domain = Fabricate(:domain, tech_domain_contacts: [tech_domain_contact])
contact = domain.contacts.first
contact.save
contact.statuses.sort.should == %w(linked ok)
contact = domain.contacts.second
contact.save
contact.statuses.sort.should == %w(linked ok)
end
it 'should not have linked status when no domain' do
@admin_domain_contact = Fabricate(:admin_domain_contact, contact_id: @contact.id)
@domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact])
contact = @domain.contacts.first
contact.save
contact.statuses.sort.should == %w(linked ok)
contact.domains.first.destroy
contact.reload
contact.statuses.should == %w(ok)
end
it 'should have code' do
@contact.code.should =~ /FIXED:..../
end
registrar = Fabricate.create(:registrar, code: 'registrarcode')
contact = Fabricate.create(:contact, registrar: registrar, code: 'contactcode')
it 'should have linked status when domain is created' do
# @admin_domain_contact = Fabricate(:admin_domain_contact)
# @domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact])
# puts @domain.contacts.size
# contact = @domain.contacts.first
# contact.statuses.map(&:value).should == %w(ok linked)
expect(contact.code).to eq('REGISTRARCODE:CONTACTCODE')
end
it 'should save status notes' do
@ -258,17 +199,17 @@ describe Contact do
it 'should have related domain descriptions hash' do
contact = @domain.registrant
contact.reload # somehow it registrant_domains are empty?
contact.related_domain_descriptions.should == { "#{@domain.name}" => [:registrant] }
contact.related_domain_descriptions.should == {"#{@domain.name}" => [:registrant]}
end
it 'should have related domain descriptions hash when find directly' do
contact = @domain.registrant
Contact.find(contact.id).related_domain_descriptions.should == { "#{@domain.name}" => [:registrant] }
Contact.find(contact.id).related_domain_descriptions.should == {"#{@domain.name}" => [:registrant]}
end
it 'should have related domain descriptions hash' do
contact = @domain.contacts.first
contact.related_domain_descriptions.should == { "#{@domain.name}" => [:admin] }
contact.related_domain_descriptions.should == {"#{@domain.name}" => [:admin]}
end
it 'should fully validate email syntax for old records' do
@ -281,7 +222,7 @@ describe Contact do
end
context 'as birthday' do
before :all do
before :example do
@contact.ident_type = 'birthday'
end
@ -300,13 +241,13 @@ describe Contact do
@contact.ident = date
@contact.valid?
@contact.errors.full_messages.should ==
["Ident Ident not in valid birthady format, should be YYYY-MM-DD"]
["Ident Ident not in valid birthady format, should be YYYY-MM-DD"]
end
end
end
context 'with callbacks' do
before :all do
before :example do
# Ensure callbacks are not taken out from other specs
Contact.set_callback(:create, :before, :generate_auth_info)
end
@ -314,6 +255,7 @@ describe Contact do
context 'after create' do
it 'should not generate a new code when code is present' do
@contact = Fabricate.build(:contact,
registrar: Fabricate(:registrar, code: 'FIXED'),
code: 'FIXED:new-code',
auth_info: 'qwe321')
@contact.code.should == 'FIXED:new-code' # still new record
@ -321,20 +263,21 @@ describe Contact do
@contact.code.should == 'FIXED:NEW-CODE'
end
it 'should not allaw to use same code' do
@contact = Fabricate.build(:contact,
code: 'FIXED:new-code',
auth_info: 'qwe321')
@contact.code.should == 'FIXED:new-code' # still new record
@contact.save.should == true
@contact.code.should == 'FIXED:NEW-CODE'
it 'should not allow to use same code' do
registrar = Fabricate.create(:registrar, code: 'FIXED')
Fabricate.create(:contact,
registrar: registrar,
code: 'FIXED:new-code',
auth_info: 'qwe321')
@contact = Fabricate.build(:contact,
registrar: registrar,
code: 'FIXED:new-code',
auth_info: 'qwe321')
@contact.code.should == 'FIXED:new-code' # still new record
@contact.valid?
@contact.errors.full_messages.should == ["Code Contact id already exists"]
@contact.validate
expect(@contact.errors).to have_key(:code)
end
it 'should generate a new password' do
@ -344,20 +287,14 @@ describe Contact do
@contact.auth_info.should_not be_nil
end
it 'should not allow same code' do
@double_contact = Fabricate.build(:contact, code: @contact.code)
@double_contact.valid?
@double_contact.errors.full_messages.should == ["Code Contact id already exists"]
end
it 'should allow supported code format' do
@contact = Fabricate.build(:contact, code: 'CID:REG1:12345')
@contact = Fabricate.build(:contact, code: 'CID:REG1:12345', registrar: Fabricate(:registrar, code: 'FIXED'))
@contact.valid?
@contact.errors.full_messages.should == []
end
it 'should not allow unsupported characters in code' do
@contact = Fabricate.build(:contact, code: 'unsupported!ÄÖÜ~?')
@contact = Fabricate.build(:contact, code: 'unsupported!ÄÖÜ~?', registrar: Fabricate(:registrar, code: 'FIXED'))
@contact.valid?
@contact.errors.full_messages.should == ['Code is invalid']
end
@ -368,15 +305,16 @@ describe Contact do
end
it 'should not ignore empty spaces as code and generate new one' do
@contact = Fabricate.build(:contact, code: ' ')
@contact = Fabricate.build(:contact, code: ' ', registrar: Fabricate(:registrar, code: 'FIXED'))
@contact.valid?.should == true
@contact.code.should =~ /FIXED:..../
end
end
context 'after update' do
before :all do
before :example do
@contact = Fabricate.build(:contact,
registrar: Fabricate(:registrar, code: 'FIXED'),
code: '123asd',
auth_info: 'qwe321')
@contact.save

View file

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Directo, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View file

@ -1,14 +1,12 @@
require 'rails_helper'
describe Dnskey do
before :all do
before :example do
Fabricate(:zonefile_setting, origin: 'ee')
end
it { should belong_to(:domain) }
context 'with invalid attribute' do
before :all do
before :example do
@dnskey = Dnskey.new
end
@ -24,7 +22,7 @@ describe Dnskey do
end
context 'with valid attributes' do
before :all do
before :example do
@dnskey = Fabricate(:dnskey)
end

View file

@ -1,7 +1,7 @@
require 'rails_helper'
describe Domain do
before :all do
RSpec.describe Domain do
before :example do
Fabricate(:zonefile_setting, origin: 'ee')
Fabricate(:zonefile_setting, origin: 'pri.ee')
Fabricate(:zonefile_setting, origin: 'med.ee')
@ -9,17 +9,8 @@ describe Domain do
Fabricate(:zonefile_setting, origin: 'com.ee')
end
it { should belong_to(:registrar) }
it { should have_many(:nameservers) }
it { should belong_to(:registrant) }
it { should have_many(:tech_contacts) }
it { should have_many(:admin_contacts) }
it { should have_many(:domain_transfers) }
it { should have_many(:dnskeys) }
it { should have_many(:legal_documents) }
context 'with invalid attribute' do
before :all do
before :example do
@domain = Domain.new
end
@ -68,11 +59,6 @@ describe Domain do
@domain = Fabricate(:domain)
end
after do
@domain.delete
@domain = nil
end
it 'should be valid' do
@domain.valid?
@domain.errors.full_messages.should match_array([])
@ -85,8 +71,6 @@ describe Domain do
end
it 'should have correct validity dates' do
valid_to = Time.zone.now + 1.year
@domain.valid_to.should be_within(5).of(valid_to)
@domain.outzone_at.should be_nil
@domain.delete_at.should be_nil
end
@ -146,6 +130,9 @@ describe Domain do
end
it 'should expire domains' do
Setting.expire_warning_period = 1
Setting.redemption_grace_period = 1
DomainCron.start_expire_period
@domain.statuses.include?(DomainStatus::EXPIRED).should == false
@ -156,10 +143,6 @@ describe Domain do
DomainCron.start_expire_period
@domain.reload
@domain.statuses.include?(DomainStatus::EXPIRED).should == true
@domain.outzone_at.should be_within(5).of(old_valid_to + Setting.expire_warning_period.days)
@domain.delete_at.should be_within(5).of(
old_valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days
)
DomainCron.start_expire_period
@domain.reload
@ -176,10 +159,6 @@ describe Domain do
DomainCron.start_expire_period
@domain.reload
@domain.statuses.include?(DomainStatus::EXPIRED).should == true
@domain.outzone_at.should be_within(5).of(old_valid_to + Setting.expire_warning_period.days)
@domain.delete_at.should be_within(5).of(
old_valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days
)
end
it 'should start redemption grace period' do
@ -203,43 +182,6 @@ describe Domain do
@domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true
end
it 'should start delete period' do
DomainCron.start_delete_period
@domain.reload
@domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == false
@domain.delete_at = Time.zone.now
@domain.statuses << DomainStatus::SERVER_DELETE_PROHIBITED # this prohibits delete_candidate
@domain.save
DomainCron.start_delete_period
@domain.reload
@domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == false
@domain.statuses = []
@domain.save
DomainCron.start_delete_period
@domain.reload
@domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == true
end
it 'should destroy delete candidates' do
d = Fabricate(:domain)
d.force_delete_at = Time.zone.now
d.save
@domain.delete_at = Time.zone.now
@domain.save
Domain.count.should == 2
DomainCron.start_delete_period
Domain.destroy_delete_candidates
Domain.count.should == 0
end
it 'should set force delete time' do
@domain.statuses = ['ok']
@domain.set_force_delete
@ -254,7 +196,6 @@ describe Domain do
])
fda = Time.zone.now + Setting.redemption_grace_period.days
@domain.force_delete_at.should be_within(20).of(fda)
@domain.registrar.messages.count.should == 1
m = @domain.registrar.messages.first
@ -263,7 +204,6 @@ describe Domain do
@domain.unset_force_delete
@domain.statuses.should == ['ok']
@domain.force_delete_at.should be_nil
@domain.statuses = [
DomainStatus::CLIENT_DELETE_PROHIBITED,
@ -311,6 +251,8 @@ describe Domain do
end
it 'should should be manual in zone and held after force delete' do
Setting.redemption_grace_period = 1
@domain.valid?
@domain.outzone_at = Time.zone.now + 1.day # before redemption grace period
# what should this be?
@ -333,7 +275,7 @@ describe Domain do
end
context 'with time period settings' do
before :all do
before :example do
@save_days_to_renew = Setting.days_to_renew_domain_before_expire
@save_warning_period = Setting.expire_warning_period
@save_grace_period = Setting.redemption_grace_period
@ -359,13 +301,14 @@ describe Domain do
end
it 'should not allow to renew after force delete' do
Setting.redemption_grace_period = 1
@domain.set_force_delete
@domain.renewable?.should be false
end
end
context 'with renew policy' do
before :all do
before :example do
@policy = 30
Setting.days_to_renew_domain_before_expire = @policy
end
@ -383,6 +326,7 @@ describe Domain do
end
it 'should not allow to renew after force delete' do
Setting.redemption_grace_period = 1
@domain.set_force_delete
@domain.renewable?.should be false
end
@ -714,34 +658,13 @@ describe Domain do
it 'should not create zone origin domain' do
d = Fabricate.build(:domain, name: 'ee')
d.save.should == false
d.errors.full_messages.should match_array([
"Data management policy violation: Domain name is blocked [name]"
])
expect(d.errors.full_messages).to include('Data management policy violation: Domain name is blocked [name]')
d = Fabricate.build(:domain, name: 'bla')
d.save.should == false
d.errors.full_messages.should match_array([
"Domain name Domain name is invalid"
])
expect(d.errors.full_messages).to include('Domain name Domain name is invalid')
end
# d = Domain.new
# expect(d.valid?).to be false
# expect(d.errors.messages).to match_array({
# registrant: ['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
# 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')
expect(d.name).to eq('test.ee')
@ -849,20 +772,13 @@ describe Domain do
d.errors.full_messages.should == []
end
it 'normalizes ns attrs' do
d = Fabricate(:domain)
d.nameservers.build(hostname: 'BLA.EXAMPLE.EE', ipv4: ' 192.168.1.1', ipv6: '1080:0:0:0:8:800:200c:417a')
d.save
ns = d.nameservers.last
expect(ns.hostname).to eq('bla.example.ee')
expect(ns.ipv4).to eq('192.168.1.1')
expect(ns.ipv6).to eq('1080:0:0:0:8:800:200C:417A')
end
it 'does not create a reserved domain' do
Fabricate(:reserved_domain)
expect(Fabricate.build(:domain, name: '1162.ee').valid?).to be false
Fabricate.create(:reserved_domain, name: 'test.ee')
domain = Fabricate.build(:domain, name: 'test.ee')
domain.validate
expect(domain.errors[:base]).to include('Required parameter missing; reserved>pw element required for reserved domains')
end
it 'validates period' do
@ -913,8 +829,6 @@ describe Domain do
context 'when saved' do
before(:each) do
# Fabricate(:domain_validation_setting_group)
# Fabricate(:dnskeys_setting_group)
Fabricate(:domain)
end

View file

@ -1,14 +1,12 @@
require 'rails_helper'
describe DomainTransfer do
before :all do
before :example do
Fabricate(:zonefile_setting, origin: 'ee')
end
it { should belong_to(:domain) }
context 'with invalid attribute' do
before :all do
before :example do
@domain_transfer = DomainTransfer.new
end
@ -24,7 +22,7 @@ describe DomainTransfer do
end
context 'with valid attributes' do
before :all do
before :example do
@domain_transfer = Fabricate(:domain_transfer)
end

View file

@ -1,10 +1,6 @@
require 'rails_helper'
describe Invoice do
it { should belong_to(:seller) }
it { should belong_to(:buyer) }
it { should have_many(:invoice_items) }
context 'with invalid attribute' do
before :all do
@invoice = Invoice.new

View file

@ -1,17 +1,12 @@
require 'rails_helper'
describe Keyrelay do
before :all do
before :example do
Fabricate(:zonefile_setting, origin: 'ee')
end
it { should belong_to(:domain) }
it { should belong_to(:requester) }
it { should belong_to(:accepter) }
it { should have_many(:legal_documents) }
context 'with invalid attribute' do
before :all do
before :example do
@keyrelay = Keyrelay.new
end
@ -34,7 +29,7 @@ describe Keyrelay do
end
context 'with valid attributes' do
before :all do
before :example do
@keyrelay = Fabricate(:keyrelay)
end

View file

@ -1,8 +1,6 @@
require 'rails_helper'
describe Message do
it { should belong_to(:registrar) }
context 'with invalid attribute' do
before :all do
@mssage = Message.new

View file

@ -1,31 +1,22 @@
require 'rails_helper'
describe Nameserver do
before :all do
before :example do
Fabricate(:zonefile_setting, origin: 'ee')
end
it { should belong_to(:domain) }
context 'with invalid attribute' do
before :all do
before :example do
@nameserver = Nameserver.new
end
it 'should not be valid' do
@nameserver.valid?
@nameserver.errors.full_messages.should match_array([
"Hostname Hostname is invalid"
])
end
it 'should not have any versions' do
@nameserver.versions.should == []
end
end
context 'with valid attributes' do
before :all do
before :example do
@nameserver = Fabricate(:nameserver)
end
@ -51,7 +42,7 @@ describe Nameserver do
end
context 'with many nameservers' do
before :all do
before :example do
@api_user = Fabricate(:api_user)
@domain_1 = Fabricate(:domain, nameservers: [
Fabricate(:nameserver, hostname: 'ns1.ns.ee'),

View file

@ -1,185 +0,0 @@
require 'rails_helper'
describe Pricelist do
before :all do
end
context 'about class' do
end
context 'with invalid attribute' do
before :all do
@pricelist = Pricelist.new
end
it 'should not be valid' do
@pricelist.valid?
@pricelist.errors.full_messages.should match_array([
"Category is missing",
"Duration is missing",
"Operation category is missing"
])
end
it 'should not have creator' do
@pricelist.creator.should == nil
end
it 'should not have updater' do
@pricelist.updator.should == nil
end
it 'should not have any versions' do
@pricelist.versions.should == []
end
it 'should not have name' do
@pricelist.name.should == ' '
end
end
context 'with valid attributes' do
before :all do
@pricelist = Fabricate(:pricelist)
end
it 'should be valid' do
@pricelist.valid?
@pricelist.errors.full_messages.should match_array([])
end
it 'should be valid twice' do
@pricelist = Fabricate(:pricelist)
@pricelist.valid?
@pricelist.errors.full_messages.should match_array([])
end
it 'should have name' do
@pricelist.name.should == 'create ee'
end
it 'should have one version' do
with_versioning do
@pricelist.versions.reload.should == []
@pricelist.price = 11
@pricelist.save
@pricelist.errors.full_messages.should match_array([])
@pricelist.versions.size.should == 1
end
end
end
it 'should return correct price' do
Pricelist.pricelist_for('ee', 'create', '1year').should == nil
Fabricate(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.50,
valid_from: Time.zone.parse('2198-01-01'),
valid_to: Time.zone.parse('2199-01-01')
})
Pricelist.pricelist_for('ee', 'create', '1year').should == nil
Fabricate(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.50,
valid_from: Time.zone.parse('2015-01-01'),
valid_to: nil
})
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.50
Fabricate(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.30,
valid_from: Time.zone.parse('2015-01-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.30
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.20,
valid_from: Time.zone.parse('2015-06-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.10,
valid_from: Time.zone.parse('2014-01-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.10,
valid_from: Time.zone.parse('2999-02-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.10,
valid_from: Time.zone.parse('2015-06-02'),
valid_to: nil
})
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 1.10,
valid_from: Time.zone.parse('2015-07-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.10
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '1year',
price: 2.10,
valid_from: Time.zone.now.to_date,
valid_to: Time.zone.now.to_date
})
Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 2.10
Fabricate.create(:pricelist, {
category: 'ee',
operation_category: 'create',
duration: '2years',
price: 1.20,
valid_from: Time.zone.parse('2015-07-01'),
valid_to: Time.zone.parse('2999-01-01')
})
Pricelist.pricelist_for('ee', 'create', '2years').price.amount.should == 1.20
end
end

View file

@ -1,11 +1,11 @@
require 'rails_helper'
describe RegistrantVerification do
before :all do
before :example do
Fabricate(:zonefile_setting, origin: 'ee')
end
context 'with invalid attribute' do
before :all do
before :example do
@registrant_verification = RegistrantVerification.new
end
@ -22,7 +22,7 @@ describe RegistrantVerification do
end
context 'with valid attributes' do
before :all do
before :example do
@registrant_verification = Fabricate(:registrant_verification)
end

View file

@ -1,11 +1,6 @@
require 'rails_helper'
describe Registrar do
it { should have_many(:domains) }
it { should have_many(:api_users) }
it { should have_many(:messages) }
it { should have_many(:white_ips) }
context 'with invalid attribute' do
before :all do
@registrar = Registrar.new
@ -62,18 +57,6 @@ describe Registrar do
@registrar.errors.full_messages.should match_array([])
end
it 'should have a cash account' do
@registrar.cash_account.should_not be_nil
end
it 'should validates uniqueness of code' do
registrar = Fabricate.build(:registrar, code: @registrar.code)
registrar.valid?
registrar.errors.full_messages.should match_array([
'Code has already been taken'
])
end
it 'should remove blank from code' do
registrar = Fabricate.build(:registrar, code: 'with blank')
registrar.valid?
@ -138,30 +121,8 @@ describe Registrar do
registrar.errors.full_messages.should == ['Code is forbidden to use']
end
it 'should have priv contacts' do
Fabricate(:contact, registrar: @registrar)
@registrar.reload.priv_contacts.size.should == 1
end
it 'should not have priv contacts' do
@registrar.priv_contacts.size.should == 0
end
it 'should credit and debit registrar cash account' do
@registrar.credit!({ sum: 13.32, description: 'Add money' })
@registrar.balance.should == BigDecimal.new('13.32')
@registrar.cash_account.account_activities.count.should == 1
a = @registrar.cash_account.account_activities.last
a.description.should == 'Add money'
a.sum.should == BigDecimal.new('13.32')
a.log_pricelist_id.should == nil
@registrar.debit!({ sum: 10.31, description: 'Remove money' })
@registrar.balance.should == BigDecimal.new('3.01')
@registrar.cash_account.account_activities.count.should == 2
a = @registrar.cash_account.account_activities.last
a.description.should == 'Remove money'
a.sum.should == -BigDecimal.new('10.31')
end
end
end

View file

@ -1,8 +1,6 @@
require 'rails_helper'
describe WhiteIp do
it { should belong_to(:registrar) }
context 'with invalid attribute' do
before :all do
@white_ip = WhiteIp.new

View file

@ -1,139 +0,0 @@
require 'rails_helper'
describe WhoisRecord do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
end
context 'with invalid attribute' do
before :all do
@whois_record = WhoisRecord.new
end
it 'should not be valid' do
@whois_record.valid?
@whois_record.errors.full_messages.should match_array([
"Body is missing",
"Domain is missing",
"Json is missing",
"Name is missing"
])
end
it 'should not support versions' do
@whois_record.respond_to?(:versions).should == false
end
it 'should not have whois body' do
@whois_record.body.should == nil
end
it 'should not have registrar' do
@whois_record.registrar.should == nil
end
end
context 'with valid attributes' do
before :all do
@whois_record = Fabricate(:domain).whois_record
end
it 'should be valid' do
@whois_record.valid?
@whois_record.errors.full_messages.should match_array([])
end
it 'should be valid twice' do
@whois_record = Fabricate(:domain).whois_record
@whois_record.valid?
@whois_record.errors.full_messages.should match_array([])
end
it 'should have registrar' do
@whois_record.registrar.present?.should == true
end
it 'should have whois body by default' do
@whois_record.body.present?.should == true
end
it 'should have whois json by default' do
@whois_record.json.present?.should == true
end
it 'should have whois record present by default' do
@domain = Fabricate(:domain, name: 'yeah.ee')
@domain.updated_at = Time.zone.parse('2020.02.02 02:00')
@domain.valid_to = Time.zone.parse('2016.04.21 0:00')
registrar = Fabricate(:registrar,
name: 'First Registrar Ltd',
created_at: Time.zone.parse('1995.01.01'),
updated_at: Time.zone.parse('1996.01.01'))
@domain.registrant = Fabricate(:registrant,
name: 'Jarren Jakubowski0',
created_at: Time.zone.parse('2005.01.01'))
@domain.admin_contacts = [Fabricate(:contact,
name: 'First Admin',
registrar: registrar,
created_at: Time.zone.parse('2016.01.01'))]
@domain.tech_contacts = [Fabricate(:contact,
name: 'First Tech',
registrar: registrar,
created_at: Time.zone.parse('2016.01.01'))]
@domain.registrar = registrar
ns1 = Fabricate(:nameserver, hostname: 'test.ee')
ns1.updated_at = Time.zone.parse('1980.01.01')
ns2 = Fabricate(:nameserver, hostname: 'test1.ee')
ns2.updated_at = Time.zone.parse('1970.01.01')
@domain.nameservers = [ns1, ns2]
@domain.save
# load some very dynamic attributes
registered = @domain.whois_record.json['registered']
changed = @domain.whois_record.json['updated_at']
@domain.whois_record.body.should == <<-EOS
Estonia .ee Top Level Domain WHOIS server
Domain:
name: yeah.ee
registrant: Jarren Jakubowski0
status: ok (paid and in zone)
registered: #{Time.zone.parse(registered)}
changed: #{Time.zone.parse(changed)}
expire: 2016-04-21 00:00:00 UTC
outzone:
delete:
Administrative contact
name: First Admin
email: Not Disclosed - Visit www.internet.ee for webbased WHOIS
registrar: First Registrar Ltd
created: 2016-01-01 00:00:00 UTC
Technical contact:
name: First Tech
email: Not Disclosed - Visit www.internet.ee for webbased WHOIS
registrar: First Registrar Ltd
created: 2016-01-01 00:00:00 UTC
Registrar:
name: First Registrar Ltd
phone:
address: Street 999, Town, County, Postal
changed: 1996-01-01 00:00:00 UTC
Name servers:
nserver: test.ee
changed: 1980-01-01 00:00:00 UTC
nserver: test1.ee
changed: 1970-01-01 00:00:00 UTC
Estonia .ee Top Level Domain WHOIS server
More information at http://internet.ee
EOS
end
end
end

View file

@ -1,112 +0,0 @@
require 'rails_helper'
describe ZonefileSetting do
it 'generates the zonefile' do
Fabricate(:zonefile_setting)
Fabricate(:zonefile_setting, origin: 'pri.ee')
d = Fabricate(:domain_with_dnskeys, name: 'testpri.ee')
d.nameservers << Nameserver.new({
hostname: "ns.#{d.name}",
ipv4: '123.123.123.123',
ipv6: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'
})
@zonefile = ActiveRecord::Base.connection.execute(
"select generate_zonefile('ee')"
)[0]['generate_zonefile']
@zonefile.should_not be_blank
# origin ns
@zonefile.scan(/ee. IN NS ns.ut.ee.\nee. IN NS ns.tld.ee./).count.should == 1
# origin a
@zonefile.scan(/ns.ut.ee. IN A 193.40.5.99\nns.tld.ee. IN A 195.43.87.10/).count.should == 1
# origin aaaa
@zonefile.scan(/ee.aso.ee. IN AAAA 2a02:88:0:21::2\nb.tld.ee. IN AAAA 2001:67c:1010:28::53/).count.should == 1
@zonefile.scan(/^#{d.name}/).count.should == 5
@zonefile.scan(/ns.#{d.name}/).count.should == 3
@zonefile.scan('123.123.123.123').count.should == 1
@zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 1
@zonefile = ActiveRecord::Base.connection.execute(
"select generate_zonefile('pri.ee')"
)[0]['generate_zonefile']
@zonefile.should_not be_blank
@zonefile.scan(/^#{d.name}/).count.should == 0
end
it 'should not place serverHold nor clientHold domains into zonefile' do
Fabricate(:zonefile_setting)
d = Fabricate(:domain_with_dnskeys,
name: 'testzone.ee',
statuses: ['serverHold', 'serverDeleteProhibited', 'clientHold'])
d.nameservers << Nameserver.new({
hostname: "ns.#{d.name}",
ipv4: '123.123.123.123',
ipv6: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'
})
@zonefile = ActiveRecord::Base.connection.execute(
"select generate_zonefile('ee')"
)[0]['generate_zonefile']
@zonefile.should_not be_blank
@zonefile.scan(/^#{d.name}/).count.should == 0
@zonefile.scan(/ns.#{d.name}/).count.should == 0
@zonefile.scan('123.123.123.123').count.should == 0
@zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 0
d.statuses = ['clientHold', 'serverDeleteProhibited']
d.save
@zonefile = ActiveRecord::Base.connection.execute(
"select generate_zonefile('ee')"
)[0]['generate_zonefile']
@zonefile.should_not be_blank
@zonefile.scan(/^#{d.name}/).count.should == 0
@zonefile.scan(/ns.#{d.name}/).count.should == 0
@zonefile.scan('123.123.123.123').count.should == 0
@zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 0
d.statuses = ['serverDeleteProhibited']
d.save
@zonefile = ActiveRecord::Base.connection.execute(
"select generate_zonefile('ee')"
)[0]['generate_zonefile']
@zonefile.should_not be_blank
@zonefile.scan(/^#{d.name}/).count.should == 5
@zonefile.scan(/ns.#{d.name}/).count.should == 3
@zonefile.scan('123.123.123.123').count.should == 1
@zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 1
end
it 'does not create duplicate zones' do
Fabricate(:zonefile_setting)
zs = Fabricate.build(:zonefile_setting)
zs.save.should == false
zs.errors.full_messages.should match_array(["Origin has already been taken"])
end
it 'does not allow deleting zone when it has existing domains' do
zs = Fabricate(:zonefile_setting)
d = Fabricate(:domain)
zs.destroy.should == false
zs.errors.full_messages.should match_array(["There are 1 domains in this zone"])
ZonefileSetting.count.should == 1
d.destroy
zs.destroy
ZonefileSetting.count.should == 0
end
end

View file

@ -1,30 +1,23 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'shoulda/matchers'
require 'capybara/poltergeist'
require 'paper_trail/frameworks/rspec'
PaperTrail.whodunnit = 'autotest'
require "money-rails/test_helpers"
require 'money-rails/test_helpers'
if ENV['ROBOT']
require 'simplecov'
SimpleCov.start 'rails'
end
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
require 'support/matchers/alias_attribute'
require 'support/matchers/active_job'
require 'support/capybara'
require 'support/database_cleaner'
require 'support/request'
require 'support/paper_trail'
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
# create general settings
@ -47,84 +40,42 @@ def create_settings
Setting.tech_contacts_max_count = 10
Setting.client_side_status_editing_enabled = true
# speedup and easier to create fabrications
@fixed_registrar =
Registrar.find_by_name('fixed registrar') ||
Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED')
end
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.include ActionView::TestCase::Behavior, type: :presenter
config.include ActiveSupport::Testing::TimeHelpers
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
config.before(:suite) do
ActiveRecord::Base.establish_connection :api_log_test
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.strategy = nil
ActiveRecord::Base.establish_connection :test
config.define_derived_metadata(file_path: %r{/spec/presenters/}) do |metadata|
metadata[:type] = :presenter
metadata[:db] = false
end
config.use_transactional_fixtures = false
config.before(:all) do
DatabaseCleaner.clean_with(:truncation)
create_settings
end
config.before(:all, epp: true) do
DatabaseCleaner.strategy = nil
create_settings
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
create_settings
end
config.before(:each, type: :request) do
DatabaseCleaner.strategy = :truncation
create_settings
end
config.before(:each, type: :model) do
create_settings
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end
config.after(:each, type: :model) do
DatabaseCleaner.clean
end
Capybara.javascript_driver = :poltergeist
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
Autodoc.configuration.path = 'doc/repp'
Autodoc.configuration.suppressed_request_header = ['Host']
Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime']
Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb')
end

View file

@ -1,20 +0,0 @@
<%# coding: UTF-8 -%>
## <%= title %>
<%= description %>
<% rid = route_info_doc %>
<% if rid %>
#### Parameters
<%= rid %>
<% end %>
#### Request
```
<%= method %> <%= request.path %><%= request_query %> <%= request_http_version %>
<%= request_header %><%= request_body_section %>
```
#### Response
```
<%= response_http_version %> <%= response.status %>
<%= response_header %><%= response_body_section %>
```

View file

@ -1,47 +0,0 @@
require 'rails_helper'
describe Repp::AccountV1 do
it 'should fail without whitelisted IP' do
ENV['webclient_ips'] = '192.188.1.1'
Setting.api_ip_whitelist_enabled = true
@registrar1 = Fabricate(:registrar, white_ips: [Fabricate(:white_ip_registrar, ipv4: '99.99.99.99')])
@api_user = Fabricate(:api_user, registrar: @registrar1)
get_with_auth '/repp/v1/accounts/balance', {}, @api_user
response.status.should == 401
body = JSON.parse(response.body)
body['error'].should == 'IP is not whitelisted'
ENV['webclient_ips'] = '127.0.0.1'
Setting.api_ip_whitelist_enabled = false
end
context 'with valid registrar' do
before :all do
@registrar1 = Fabricate(:registrar1)
@registrar1.accounts = [Fabricate(:account, { balance: '324.45', account_activities: [] })]
@registrar1.save
@api_user = Fabricate(:gitlab_api_user, registrar: @registrar1)
end
describe 'GET /repp/v1/accounts/balance' do
it 'returns account balance of the current registrar', autodoc: true, route_info_doc: true do
get_with_auth '/repp/v1/accounts/balance', {}, @api_user
response.status.should == 200
body = JSON.parse(response.body)
body['balance'].should == '324.45'
body['currency'].should == 'EUR'
log = ApiLog::ReppLog.last
log[:request_path].should == '/repp/v1/accounts/balance'
log[:request_method].should == 'GET'
log[:request_params].should == '{}'
log[:response_code].should == '200'
log[:api_user_name].should == 'gitlab'
log[:api_user_registrar].should == 'registrar1'
log[:ip].should == '127.0.0.1'
end
end
end
end

View file

@ -1,81 +0,0 @@
require 'rails_helper'
describe Repp::ContactV1 do
before :all do
@api_user = Fabricate(:gitlab_api_user)
Fabricate.times(2, :contact, registrar: @api_user.registrar)
Fabricate.times(2, :contact)
end
describe 'GET /repp/v1/contacts' do
it 'returns contacts of the current registrar', autodoc: true, route_info_doc: true do
get_with_auth '/repp/v1/contacts', { limit: 1, details: true }, @api_user
expect(response.status).to eq(200)
body = JSON.parse(response.body)
body['total_number_of_records'].should == 2
# TODO: Maybe there is a way not to convert from and to json again
expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.limit(1).to_json)
log = ApiLog::ReppLog.last
expect(log[:request_path]).to eq('/repp/v1/contacts')
expect(log[:request_method]).to eq('GET')
expect(log[:request_params]).to eq('{"limit":1,"details":"true"}')
expect(log[:response].length).to be > 20
expect(log[:response_code]).to eq('200')
expect(log[:api_user_name]).to eq('gitlab')
expect(log[:ip]).to eq('127.0.0.1')
end
it 'returns contact names with offset', autodoc: true do
get_with_auth '/repp/v1/contacts', { offset: 1 }, @api_user
expect(response.status).to eq(200)
body = JSON.parse(response.body)
body['total_number_of_records'].should == 2
# TODO: Maybe there is a way not to convert from and to json again
expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.offset(1).pluck(:code).to_json)
log = ApiLog::ReppLog.last
expect(log[:request_path]).to eq('/repp/v1/contacts')
expect(log[:request_method]).to eq('GET')
expect(log[:request_params]).to eq('{"offset":1}')
expect(log[:response].length).to be > 20
expect(log[:response_code]).to eq('200')
expect(log[:api_user_name]).to eq('gitlab')
expect(log[:ip]).to eq('127.0.0.1')
end
it 'returns contact names of the current registrar' do
get_with_auth '/repp/v1/contacts', {}, @api_user
expect(response.status).to eq(200)
body = JSON.parse(response.body)
body['total_number_of_records'].should == 2
# TODO: Maybe there is a way not to convert from and to json again
expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.pluck(:code).to_json)
log = ApiLog::ReppLog.last
expect(log[:request_path]).to eq('/repp/v1/contacts')
expect(log[:request_method]).to eq('GET')
expect(log[:request_params]).to eq('{}')
expect(log[:response].length).to be > 20
expect(log[:response_code]).to eq('200')
expect(log[:api_user_name]).to eq('gitlab')
expect(log[:ip]).to eq('127.0.0.1')
end
it 'returns an error with invalid parameters in contact index' do
get_with_auth '/repp/v1/contacts', { limit: 0 }, @api_user
expect(response.status).to eq(400)
body = JSON.parse(response.body)
body['error'].should == 'limit does not have a valid value'
# TODO: Log failed API requests too
end
end
end

View file

@ -1,91 +0,0 @@
require 'rails_helper'
describe Repp::DomainV1 do
before :all do
Fabricate(:zonefile_setting, origin: 'ee')
@registrar1 = Fabricate(:registrar1)
@api_user = Fabricate(:gitlab_api_user, registrar: @registrar1)
Fabricate.times(2, :domain, registrar: @api_user.registrar)
end
describe 'GET /repp/v1/domains' do
it 'returns domains of the current registrar', autodoc: true, route_info_doc: true do
get_with_auth '/repp/v1/domains', { limit: 1, details: true }, @api_user
response.status.should == 200
body = JSON.parse(response.body)
body['total_number_of_records'].should == 2
# TODO: Maybe there is a way not to convert from and to json again
body['domains'].to_json.should == @api_user.reload.registrar.domains.limit(1).to_json
log = ApiLog::ReppLog.last
log[:request_path].should == '/repp/v1/domains'
log[:request_method].should == 'GET'
log[:request_params].should == '{"limit":1,"details":"true"}'
log[:response_code].should == '200'
log[:api_user_name].should == 'gitlab'
log[:api_user_registrar].should == 'registrar1'
log[:ip].should == '127.0.0.1'
end
it 'returns domain names with offset', autodoc: true do
get_with_auth '/repp/v1/domains', { offset: 1 }, @api_user
response.status.should == 200
body = JSON.parse(response.body)
body['total_number_of_records'].should == 2
# TODO: Maybe there is a way not to convert from and to json again
body['domains'].to_json.should == @api_user.reload.registrar.domains.offset(1).pluck(:name).to_json
log = ApiLog::ReppLog.last
log[:request_path].should == '/repp/v1/domains'
log[:request_method].should == 'GET'
log[:request_params].should == '{"offset":1}'
log[:response_code].should == '200'
log[:api_user_name].should == 'gitlab'
log[:api_user_registrar].should == 'registrar1'
log[:ip].should == '127.0.0.1'
end
it 'returns domain names of the current registrar' do
get_with_auth '/repp/v1/domains', {}, @api_user
response.status.should == 200
body = JSON.parse(response.body)
body['total_number_of_records'].should == 2
# TODO: Maybe there is a way not to convert from and to json again
body['domains'].to_json.should == @api_user.reload.registrar.domains.pluck(:name).to_json
log = ApiLog::ReppLog.last
log[:request_path].should == '/repp/v1/domains'
log[:request_method].should == 'GET'
log[:request_params].should == '{}'
log[:response_code].should == '200'
log[:api_user_name].should == 'gitlab'
log[:api_user_registrar].should == 'registrar1'
log[:ip].should == '127.0.0.1'
end
it 'returns an error with invalid parameters in domain index' do
get_with_auth '/repp/v1/domains', { limit: 0 }, @api_user
response.status.should == 400
body = JSON.parse(response.body)
body['error'].should == 'limit does not have a valid value'
# TODO: Log failed API requests too
end
it 'returns an error with invalid credentials' do
invalid_user = OpenStruct.new(username: 'bla', password: 'blabala')
get_with_auth '/repp/v1/domains', {}, invalid_user
response.status.should == 401
body = JSON.parse(response.body)
body['error'].should == 'API user not found'
end
end
end

View file

@ -1,76 +1,77 @@
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
# file to always be loaded, without a need to explicitly require it in any files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, make a
# separate helper file that requires this one and then use it only in the specs
# that actually need it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |_config|
RSpec.configure do |config|
# https://github.com/rspec/rspec-rails/issues/1076
config.around :each, type: :view do |example|
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = false
example.run
mocks.verify_partial_doubles = true
end
end
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# # These two settings work together to allow you to limit a spec run
# # to individual examples or groups you care about by tagging them with
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
# # get run.
# config.filter_run :focus
# config.run_all_when_everything_filtered = true
#
# # Many RSpec users commonly either run the entire suite or an individual
# # file, and it's useful to allow more verbose output when running an
# # individual spec file.
# if config.files_to_run.one?
# # Use the documentation formatter for detailed output,
# # unless a formatter has already been configured
# # (e.g. via a command-line flag).
# config.default_formatter = 'doc'
# end
#
# # Print the 10 slowest examples and example groups at the
# # end of the spec run, to help surface which specs are running
# # particularly slow.
# config.profile_examples = 10
#
# # Run specs in random order to surface order dependencies. If you find an
# # order dependency and want to debug it, you can fix the order by providing
# # the seed, which is printed after each run.
# # --seed 1234
# config.order = :random
#
# # Seed global randomization in this process using the `--seed` CLI option.
# # Setting this allows you to use `--seed` to deterministically reproduce
# # test failures related to randomization by passing the same `--seed` value
# # as the one that triggered the failure.
# Kernel.srand config.seed
#
# # rspec-expectations config goes here. You can use an alternate
# # assertion/expectation library such as wrong or the stdlib/minitest
# # assertions if you prefer.
# config.expect_with :rspec do |expectations|
# # Enable only the newer, non-monkey-patching expect syntax.
# # For more details, see:
# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# expectations.syntax = :expect
# end
#
# # rspec-mocks config goes here. You can use an alternate test double
# # library (such as bogus or mocha) by changing the `mock_with` option here.
# config.mock_with :rspec do |mocks|
# # Enable only the newer, non-monkey-patching expect syntax.
# # For more details, see:
# # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# mocks.syntax = :expect
#
# # Prevents you from mocking or stubbing a method that does not exist on
# # a real object. This is generally recommended.
# mocks.verify_partial_doubles = true
# end
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Limits the available syntax to the non-monkey patched syntax that is recommended.
# For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
config.disable_monkey_patching!
# This setting enables warnings. It's recommended, but in some cases may
# be too noisy due to issues in dependencies.
config.warnings = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
end

8
spec/support/capybara.rb Normal file
View file

@ -0,0 +1,8 @@
require_relative 'macros/capybara'
RSpec.configure do |config|
config.include CapybaraViewMacros, type: :view
config.include CapybaraViewMacros, type: :presenter
end
Capybara.javascript_driver = :poltergeist

View file

@ -0,0 +1,30 @@
RSpec.configure do |config|
db_connection_names = %i(test whois_test api_log_test registrant_write_test)
config.before :suite do
DatabaseCleaner.strategy = :truncation
db_connection_names.each do |connection_name|
ActiveRecord::Base.establish_connection(connection_name)
DatabaseCleaner[:active_record, connection: connection_name].strategy = :truncation
end
end
config.before :example do |example|
if example.metadata[:db] || (%i(model).include?(example.metadata[:type]) && example.metadata[:db].nil?)
db_connection_names.each do |connection_name|
ActiveRecord::Base.establish_connection(connection_name)
DatabaseCleaner[:active_record, connection: connection_name].start
end
end
end
config.after :example do |example|
if example.metadata[:db] || (%i(model).include?(example.metadata[:type]) && example.metadata[:db].nil?)
db_connection_names.each do |connection_name|
ActiveRecord::Base.establish_connection(connection_name)
DatabaseCleaner[:active_record, connection: connection_name].clean
end
end
end
end

View file

@ -1,375 +0,0 @@
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
# handles connection and login automatically
def epp_request(data, *args)
server = server_zone
server = server_elkdata if args.include?(:elkdata)
res = parse_response(server.request(data)) if args.include?(:xml)
if res
log(data, res[:parsed])
return res
end
res = parse_response(server.request(read_body(data)))
log(read_body(data), res[:parsed])
return res
rescue => e
e
end
def epp_plain_request(data, *args)
options = args.extract_options!
# validate_input = options[:validate_input] != false # true by default
validate_output = options[:validate_output] != false # true by default
# if validate_input && @xsd
# xml = Nokogiri::XML(data)
# @xsd.validate(xml).each do |error|
# fail Exception.new, error.to_s
# end
# end
res = parse_response(server.send_request(data))
if res
log(data, res[:raw])
if validate_output && @xsd
@xsd.validate(Nokogiri(res[:raw])).each do |error|
fail Exception.new, error.to_s
end
end
return res
end
rescue => e
e
end
def server
port = ENV['epp_port'] || 700
hostname = ENV['epp_hostname'] || 'localhost'
# tag and password not in use, add those at login xml
@server ||= Epp::Server.new({ server: hostname, port: port, tag: '', password: '' })
end
def parse_response(raw)
res = Nokogiri::XML(raw)
obj = {
results: [],
clTRID: res.css('epp trID clTRID').first.try(:text),
parsed: res.remove_namespaces!,
raw: raw
}
res.css('epp response result').each do |x|
obj[:results] << {
result_code: x[:code], msg: x.css('msg').text, value: x.css('value > *').try(:first).try(:text)
}
end
obj[:result_code] = obj[:results][0][:result_code]
obj[:msg] = obj[:results][0][:msg]
obj
end
# print output
def po(r)
puts r[:parsed].to_s
end
def next_domain_name
"example#{rand(100_000_000_000_000_000)}.ee"
end
### REQUEST TEMPLATES ###
def domain_info_xml(xml_params = {})
defaults = {
name: { value: next_domain_name, attrs: { hosts: 'all' } },
authInfo: {
pw: { value: '2fooBAR' }
}
}
xml_params = defaults.deep_merge(xml_params)
epp_xml = EppXml::Domain.new(cl_trid: false)
epp_xml.info(xml_params)
end
# rubocop: disable Metrics/MethodLength
def domain_create_xml(xml_params = {}, dnssec_params = {}, custom_params = {})
defaults = {
name: { value: next_domain_name },
period: { value: '1', attrs: { unit: 'y' } },
ns: [
{
hostAttr: [
{ hostName: { value: 'ns1.example.net' } },
{ hostAddr: { value: '192.0.2.2', attrs: { ip: 'v4' } } },
{ hostAddr: { value: '1080:0:0:0:8:800:200C:417A', attrs: { ip: 'v6' } } }
]
},
{
hostAttr: {
hostName: { value: 'ns2.example.net' }
}
}
],
registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [
{ contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } },
{ contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } },
{ contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } }
]
}
xml_params = defaults.deep_merge(xml_params)
dnssec_defaults = {
_anonymus: [
{ keyData: {
flags: { value: '257' },
protocol: { value: '3' },
alg: { value: '5' },
pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' }
}
}]
}
dnssec_params = dnssec_defaults.deep_merge(dnssec_params) if dnssec_params != false
custom_defaults = {
_anonymus: [
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
]
}
custom_params = custom_defaults.deep_merge(custom_params) if custom_params != false
epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345')
epp_xml.create(xml_params, dnssec_params, custom_params)
end
def domain_create_xml_with_legal_doc(xml_params = {})
defaults = {
name: { value: next_domain_name },
period: { value: '1', attrs: { unit: 'y' } },
ns: [
{
hostAttr: [
{ hostName: { value: 'ns1.example.net' } },
{ hostAddr: { value: '192.0.2.2', attrs: { ip: 'v4' } } },
{ hostAddr: { value: '1080:0:0:0:8:800:200C:417A', attrs: { ip: 'v6' } } }
]
},
{
hostAttr: {
hostName: { value: 'ns2.example.net' }
}
}
],
registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [
{ contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } },
{ contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } },
{ contact: { value: 'FIXED: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: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
]
})
end
def domain_create_with_invalid_ns_ip_xml
xml_params = {
name: { value: next_domain_name },
period: { value: '1', attrs: { unit: 'y' } },
ns: [
{
hostAttr: {
hostName: { value: 'ns1.example.net' },
hostAddr: { value: '192.0.2.2.invalid', attrs: { ip: 'v4' } }
}
},
{
hostAttr: {
hostName: { value: 'ns2.example.net' },
hostAddr: { value: 'invalid_ipv6', attrs: { ip: 'v6' } }
}
}
],
registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [
{ contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } },
{ contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } },
{ contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } }
],
authInfo: {
pw: {
value: '2fooBAR'
}
}
}
custom_params = {
_anonymus: [
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
]
}
epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345')
epp_xml.create(xml_params, {}, custom_params)
end
def domain_create_with_host_attrs
xml_params = {
name: { value: next_domain_name },
period: { value: '1', attrs: { unit: 'y' } },
ns: [
{
hostAttr: [
{ hostName: { value: 'ns1.example.net' } },
{ hostAddr: { value: '192.0.2.2', attrs: { ip: 'v4' } } },
{ hostAddr: { value: '1080:0:0:0:8:800:200C:417A', attrs: { ip: 'v6' } } }
]
},
{
hostAttr: {
hostName: { value: 'ns2.example.net' }
}
}
],
registrant: { value: 'FIXED:CITIZEN_1234' },
_anonymus: [
{ contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } },
{ contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } },
{ contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } }
],
authInfo: {
pw: {
value: '2fooBAR'
}
}
}
custom_params = {
_anonymus: [
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
}
]
}
epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345')
epp_xml.create(xml_params, {}, custom_params)
end
def domain_update_xml(xml_params = {}, dnssec_params = {}, custom_params = {})
defaults = {
name: { value: next_domain_name }
}
xml_params = defaults.deep_merge(xml_params)
epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345')
epp_xml.update(xml_params, dnssec_params, custom_params)
end
def domain_check_xml(xml_params = {})
defaults = {
_anonymus: [
{ name: { value: next_domain_name } }
]
}
xml_params = defaults.deep_merge(xml_params)
epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345')
epp_xml.check(xml_params)
end
def domain_transfer_xml(xml_params = {}, op = 'request', custom_params = {})
defaults = {
name: { value: next_domain_name },
period: nil,
authInfo: nil
}
xml_params = defaults.deep_merge(xml_params)
epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345')
epp_xml.transfer(xml_params, op, custom_params)
end
def log(req, res)
return unless ENV['EPP_DOC']
puts "REQUEST:\n\n```xml\n#{Nokogiri(req)}```\n\n"
puts "RESPONSE:\n\n```xml\n#{Nokogiri(res)}```\n\n"
end
end
RSpec.configure do |c|
c.include Epp, epp: true
end

View file

@ -1,18 +0,0 @@
class EppDoc
RSpec::Core::Formatters.register self, :start, :example_started
def initialize(output)
@output = output
end
def start(example_count)
@output.puts '# EPP REQUEST - RESPONSE EXAMPLES'
@output.puts "GENERATED AT: #{Time.zone.now} "
@output.puts "EXAMPLE COUNT: #{example_count.count} "
@output.puts "\n---\n\n"
end
def example_started(notification)
@output.puts "### #{notification.example.full_description} \n\n"
end
end

View file

@ -1,20 +0,0 @@
module Feature
def sign_in(user)
visit '/admin/logout'
if user.username == 'user1'
fill_in 'admin_user_username', with: 'user1'
fill_in 'admin_user_password', with: 'testtest'
end
if user.username == 'gitlab'
fill_in 'admin_user_username', with: 'gitlab'
fill_in 'admin_user_password', with: 'ghyt9e4fu'
end
click_on 'Log in'
end
end
RSpec.configure do |c|
c.include Feature, type: :feature
end

View file

@ -0,0 +1,5 @@
module CapybaraViewMacros
def page
Capybara::Node::Simple.new(rendered)
end
end

View file

@ -0,0 +1,252 @@
require "active_job/base"
require "active_job/arguments"
# This matcher is needed because it is absent it rspec-rails 3.3.2
module RSpec
module Rails
module Matchers
# Namespace for various implementations of ActiveJob features
#
# @api private
module ActiveJob
# rubocop: disable Style/ClassLength
# @private
class Base < RSpec::Matchers::BuiltIn::BaseMatcher
def initialize
@args = []
@queue = nil
@at = nil
@block = Proc.new {}
set_expected_number(:exactly, 1)
end
def with(*args, &block)
@args = args
@block = block if block.present?
self
end
def on_queue(queue)
@queue = queue
self
end
def at(date)
@at = date
self
end
def exactly(count)
set_expected_number(:exactly, count)
self
end
def at_least(count)
set_expected_number(:at_least, count)
self
end
def at_most(count)
set_expected_number(:at_most, count)
self
end
def times
self
end
def once
exactly(:once)
end
def twice
exactly(:twice)
end
def thrice
exactly(:thrice)
end
def failure_message
"expected to enqueue #{base_message}"
end
def failure_message_when_negated
"expected not to enqueue #{base_message}"
end
def message_expectation_modifier
case @expectation_type
when :exactly then "exactly"
when :at_most then "at most"
when :at_least then "at least"
end
end
def supports_block_expectations?
true
end
private
def check(jobs)
@matching_jobs_count = jobs.count do |job|
if serialized_attributes.all? { |key, value| value == job[key] }
args = ::ActiveJob::Arguments.deserialize(job[:args])
@block.call(*args)
true
else
false
end
end
case @expectation_type
when :exactly then @expected_number == @matching_jobs_count
when :at_most then @expected_number >= @matching_jobs_count
when :at_least then @expected_number <= @matching_jobs_count
end
end
def base_message
"#{message_expectation_modifier} #{@expected_number} jobs,".tap do |msg|
msg << " with #{@args}," if @args.any?
msg << " on queue #{@queue}," if @queue
msg << " at #{@at}," if @at
msg << " but enqueued #{@matching_jobs_count}"
end
end
def serialized_attributes
{}.tap do |attributes|
attributes[:args] = ::ActiveJob::Arguments.serialize(@args) if @args.any?
attributes[:at] = @at.to_f if @at
attributes[:queue] = @queue if @queue
attributes[:job] = @job if @job
end
end
def set_expected_number(relativity, count)
@expectation_type = relativity
@expected_number = case count
when :once then 1
when :twice then 2
when :thrice then 3
else Integer(count)
end
end
def queue_adapter
::ActiveJob::Base.queue_adapter
end
end
# rubocop: enable Style/ClassLength
# @private
class HaveEnqueuedJob < Base
def initialize(job)
super()
@job = job
end
def matches?(proc)
raise ArgumentError, "have_enqueued_job and enqueue_job only support block expectations" unless Proc === proc
original_enqueued_jobs_count = queue_adapter.enqueued_jobs.count
proc.call
in_block_jobs = queue_adapter.enqueued_jobs.drop(original_enqueued_jobs_count)
check(in_block_jobs)
end
end
# @private
class HaveBeenEnqueued < Base
def matches?(job)
@job = job
check(queue_adapter.enqueued_jobs)
end
end
end
# @api public
# Passes if a job has been enqueued inside block. May chain at_least, at_most or exactly to specify a number of times.
#
# @example
# expect {
# HeavyLiftingJob.perform_later
# }.to have_enqueued_job
#
# # Using alias
# expect {
# HeavyLiftingJob.perform_later
# }.to enqueue_job
#
# expect {
# HelloJob.perform_later
# HeavyLiftingJob.perform_later
# }.to have_enqueued_job(HelloJob).exactly(:once)
#
# expect {
# 3.times { HelloJob.perform_later }
# }.to have_enqueued_job(HelloJob).at_least(2).times
#
# expect {
# HelloJob.perform_later
# }.to have_enqueued_job(HelloJob).at_most(:twice)
#
# expect {
# HelloJob.perform_later
# HeavyLiftingJob.perform_later
# }.to have_enqueued_job(HelloJob).and have_enqueued_job(HeavyLiftingJob)
#
# expect {
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
# }.to have_enqueued_job.with(42).on_queue("low").at(Date.tomorrow.noon)
def have_enqueued_job(job = nil)
check_active_job_adapter
ActiveJob::HaveEnqueuedJob.new(job)
end
alias_method :enqueue_job, :have_enqueued_job
# @api public
# Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times.
#
# @example
# before { ActiveJob::Base.queue_adapter.enqueued_jobs.clear }
#
# HeavyLiftingJob.perform_later
# expect(HeavyLiftingJob).to have_been_enqueued
#
# HelloJob.perform_later
# HeavyLiftingJob.perform_later
# expect(HeavyLiftingJob).to have_been_enqueued.exactly(:once)
#
# 3.times { HelloJob.perform_later }
# expect(HelloJob).to have_been_enqueued.at_least(2).times
#
# HelloJob.perform_later
# expect(HelloJob).to enqueue_job(HelloJob).at_most(:twice)
#
# HelloJob.perform_later
# HeavyLiftingJob.perform_later
# expect(HelloJob).to have_been_enqueued
# expect(HeavyLiftingJob).to have_been_enqueued
#
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
# expect(HelloJob).to have_been_enqueued.with(42).on_queue("low").at(Date.tomorrow.noon)
def have_been_enqueued
check_active_job_adapter
ActiveJob::HaveBeenEnqueued.new
end
private
# @private
def check_active_job_adapter
return if ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter
raise StandardError, "To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`"
end
end
end
end

View file

@ -0,0 +1,9 @@
RSpec::Matchers.define :alias_attribute do |alias_name, original_name|
match do |actual|
actual.class.attribute_alias(alias_name) == original_name.to_s
end
failure_message do |actual|
"expected #{actual.class.name} to alias attribute :#{alias_name} by :#{original_name}"
end
end

View file

@ -0,0 +1 @@
PaperTrail.whodunnit = 'autotest'

View file

@ -1,18 +0,0 @@
module RegistrarHelpers
def registrar_sign_in(_user = nil)
# TODO: try to make it run with before :all and speed it up
visit registrar_login_path
page.should have_css('a[href="/registrar/login/mid"]')
page.find('a[href="/registrar/login/mid"]').click
fill_in 'user_phone', with: '123'
click_button 'Log in'
page.should have_text('Log out')
end
end
RSpec.configure do |c|
c.include RegistrarHelpers, type: :feature
end