mirror of
https://github.com/internetee/registry.git
synced 2025-07-12 14:08:17 +02:00
Better contact validation
This commit is contained in:
parent
c78e40a65a
commit
5003a3ff20
5 changed files with 53 additions and 5 deletions
|
@ -7,7 +7,9 @@ module Epp::DomainsHelper
|
|||
render '/epp/domains/create'
|
||||
else
|
||||
handle_domain_name_errors
|
||||
handle_contact_errors
|
||||
render '/epp/error'
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -56,4 +58,10 @@ module Epp::DomainsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def handle_contact_errors
|
||||
if @domain.errors.added?(:admin_contacts, :blank)
|
||||
epp_errors << {code: '2306', msg: @domain.errors[:admin_contacts].first}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ class Domain < ActiveRecord::Base
|
|||
validates :period, numericality: { only_integer: true, greater_than: 0, less_than: 100 }
|
||||
validates :owner_contact, presence: true
|
||||
# validates :tech_contacts_count
|
||||
# validates :admin_contacts_count
|
||||
#validate :admin_contacts_count, on: :update
|
||||
|
||||
def name=(value)
|
||||
value.strip!
|
||||
|
@ -46,7 +46,9 @@ class Domain < ActiveRecord::Base
|
|||
attach_contact(Contact::CONTACT_TYPE_ADMIN, owner_contact) if admin_contacts.empty?
|
||||
end
|
||||
|
||||
true
|
||||
validate_admin_contacts_count
|
||||
|
||||
errors.empty?
|
||||
end
|
||||
|
||||
def attach_contact(type, contact)
|
||||
|
@ -56,6 +58,10 @@ class Domain < ActiveRecord::Base
|
|||
)
|
||||
end
|
||||
|
||||
def validate_admin_contacts_count
|
||||
errors.add(:admin_contacts, :blank) if admin_contacts.empty?
|
||||
end
|
||||
|
||||
class << self
|
||||
def check_availability(domains)
|
||||
domains = [domains] if domains.is_a?(String)
|
||||
|
|
|
@ -41,6 +41,8 @@ en:
|
|||
blank: 'Required parameter missing - name'
|
||||
owner_contact:
|
||||
blank: 'Required parameter missing - owner contact'
|
||||
admin_contacts:
|
||||
blank: 'Required parameter missing - admin contact'
|
||||
|
||||
|
||||
errors:
|
||||
|
|
|
@ -56,12 +56,13 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
context 'with juridical persion as an owner' do
|
||||
before(:each) { Fabricate(:contact, code: 'jd1234', ident_type: 'ico')}
|
||||
|
||||
it 'creates a domain with contacts' do
|
||||
before(:each) {
|
||||
Fabricate(:contact, code: 'sh8013')
|
||||
Fabricate(:contact, code: 'sh801333')
|
||||
Fabricate(:contact, code: 'jd1234', ident_type: 'ico')
|
||||
}
|
||||
|
||||
it 'creates a domain with contacts' do
|
||||
response = epp_request('domains/create_wo_tech_contact.xml')
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
|
@ -73,6 +74,16 @@ describe 'EPP Domain', epp: true do
|
|||
tech_contact = Domain.first.tech_contacts.first
|
||||
expect(tech_contact.code).to eq('jd1234')
|
||||
end
|
||||
|
||||
it 'does not create a domain without admin contact' do
|
||||
response = epp_request('domains/create_wo_contacts.xml')
|
||||
expect(response[:result_code]).to eq('2306')
|
||||
expect(response[:msg]).to eq('Required parameter missing - admin contact')
|
||||
expect(response[:clTRID]).to eq('ABC-12345')
|
||||
|
||||
expect(Domain.count).to eq 0
|
||||
expect(DomainContact.count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
it 'checks a domain' do
|
||||
|
|
21
spec/epp/requests/domains/create_wo_contacts.xml
Normal file
21
spec/epp/requests/domains/create_wo_contacts.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<create>
|
||||
<domain:create
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:period unit="y">1</domain:period>
|
||||
<domain:ns>
|
||||
<domain:hostObj>ns1.example.net</domain:hostObj>
|
||||
<domain:hostObj>ns2.example.net</domain:hostObj>
|
||||
</domain:ns>
|
||||
<domain:registrant>jd1234</domain:registrant>
|
||||
<domain:authInfo>
|
||||
<domain:pw>2fooBAR</domain:pw>
|
||||
</domain:authInfo>
|
||||
</domain:create>
|
||||
</create>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
Loading…
Add table
Add a link
Reference in a new issue