mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Merge branch 'master' of github.com:internetee/registry
Conflicts: db/schema.rb
This commit is contained in:
commit
7840e6314e
23 changed files with 361 additions and 168 deletions
|
@ -1,6 +1,9 @@
|
||||||
AllCops:
|
AllCops:
|
||||||
RunRailsCops: true
|
RunRailsCops: true
|
||||||
|
|
||||||
|
Exclude:
|
||||||
|
- 'db/schema.rb'
|
||||||
|
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Max: 120
|
Max: 120
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ Usual Rails 4 app installation, rvm and bundler are your friends.
|
||||||
rvm install ruby-2.1.2
|
rvm install ruby-2.1.2
|
||||||
bundle
|
bundle
|
||||||
rake db:setup
|
rake db:setup
|
||||||
|
mv config/secrets-example.yml config/secrets.yml # generate your own keys
|
||||||
|
|
||||||
|
|
||||||
### Apache with patched mod_epp (Debian 7/Ubuntu 14.04 LTS)
|
### Apache with patched mod_epp (Debian 7/Ubuntu 14.04 LTS)
|
||||||
|
|
||||||
|
@ -39,7 +41,8 @@ Enable ssl:
|
||||||
sudo a2enmod proxy_http
|
sudo a2enmod proxy_http
|
||||||
sudo mkdir /etc/apache2/ssl
|
sudo mkdir /etc/apache2/ssl
|
||||||
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
|
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
|
||||||
sudo nano /etc/apache2/sites-available/epp_ssl.conf
|
sudo a2enmod ssl
|
||||||
|
sudo nano /etc/apache2/sites-enabled/epp_ssl.conf
|
||||||
|
|
||||||
For development configuration, add:
|
For development configuration, add:
|
||||||
```apache
|
```apache
|
||||||
|
@ -120,7 +123,7 @@ Wait for the greeting message on the STD, then send EPP/TCP frame:
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
---
|
---
|
||||||
* Before running tests for the first time: `rake db:seed`
|
* Before running tests for the first time: `RAILS_ENV=test rake db:seed`
|
||||||
* Run tests: `rake`
|
* Run tests: `rake`
|
||||||
* Run EPP tests: `rake test:epp`
|
* Run EPP tests: `rake test:epp`
|
||||||
* Run all but EPP tests: `rake test:other`
|
* Run all but EPP tests: `rake test:other`
|
||||||
|
|
|
@ -60,6 +60,15 @@ module Epp::Common
|
||||||
epp_errors.empty?
|
epp_errors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def xml_nested_attrs_present?(array_ph, attributes )
|
||||||
|
[array_ph].flatten.each do |ph|
|
||||||
|
attributes.each do |x|
|
||||||
|
epp_errors << {code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: x.last)} unless has_attribute(ph, x)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
epp_errors.empty?
|
||||||
|
end
|
||||||
|
|
||||||
def has_attribute(ph, path)
|
def has_attribute(ph, path)
|
||||||
path.reduce(ph) do |location, key|
|
path.reduce(ph) do |location, key|
|
||||||
location.respond_to?(:keys) ? location[key] : nil
|
location.respond_to?(:keys) ? location[key] : nil
|
||||||
|
|
|
@ -1,124 +1,140 @@
|
||||||
module Epp::ContactsHelper
|
module Epp
|
||||||
def create_contact
|
module ContactsHelper
|
||||||
@contact = Contact.new(contact_and_address_attributes)
|
def create_contact
|
||||||
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
|
@contact = Contact.new(contact_and_address_attributes)
|
||||||
|
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
|
||||||
|
|
||||||
handle_errors(@contact)
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_contact
|
|
||||||
code = params_hash['epp']['command']['update']['update'][:id]
|
|
||||||
@contact = Contact.where(code: code).first
|
|
||||||
if has_rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
|
||||||
render 'epp/contacts/update'
|
|
||||||
else
|
|
||||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: code } } if @contact == []
|
|
||||||
handle_errors(@contact)
|
handle_errors(@contact)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def delete_contact
|
def update_contact
|
||||||
Contact.transaction do
|
code = params_hash['epp']['command']['update']['update'][:id]
|
||||||
|
@contact = Contact.where(code: code).first
|
||||||
|
if rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||||
|
render 'epp/contacts/update'
|
||||||
|
else
|
||||||
|
contact_exists?
|
||||||
|
handle_errors(@contact)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_contact
|
||||||
|
Contact.transaction do
|
||||||
|
@contact = find_contact
|
||||||
|
handle_errors(@contact) and return unless @contact
|
||||||
|
handle_errors(@contact) and return unless @contact.destroy_and_clean
|
||||||
|
|
||||||
|
render '/epp/contacts/delete'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_contact
|
||||||
|
ph = params_hash['epp']['command']['check']['check']
|
||||||
|
@contacts = Contact.check_availability(ph[:id])
|
||||||
|
render '/epp/contacts/check'
|
||||||
|
end
|
||||||
|
|
||||||
|
def info_contact
|
||||||
|
handle_errors and return unless rights?
|
||||||
@contact = find_contact
|
@contact = find_contact
|
||||||
handle_errors(@contact) and return unless @contact
|
handle_errors(@contact) and return unless @contact
|
||||||
handle_errors(@contact) and return unless @contact.destroy_and_clean
|
render 'epp/contacts/info'
|
||||||
|
|
||||||
render '/epp/contacts/delete'
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def check_contact
|
## HELPER METHODS
|
||||||
ph = params_hash['epp']['command']['check']['check']
|
|
||||||
@contacts = Contact.check_availability(ph[:id])
|
|
||||||
render '/epp/contacts/check'
|
|
||||||
end
|
|
||||||
|
|
||||||
def info_contact
|
private
|
||||||
handle_errors and return unless has_rights?
|
|
||||||
@contact = find_contact
|
|
||||||
handle_errors(@contact) and return unless @contact
|
|
||||||
render 'epp/contacts/info'
|
|
||||||
end
|
|
||||||
|
|
||||||
## HELPER METHODS
|
## CREATE
|
||||||
|
def validate_contact_create_request
|
||||||
|
@ph = params_hash['epp']['command']['create']['create']
|
||||||
|
xml_attrs_present?(@ph, [%w(id),
|
||||||
|
%w(authInfo pw),
|
||||||
|
%w(postalInfo)])
|
||||||
|
return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)
|
||||||
|
|
||||||
private
|
xml_nested_attrs_present?(@ph['postalInfo'], [%w(name),
|
||||||
|
%w(addr city),
|
||||||
## CREATE
|
%w(addr cc)])
|
||||||
def validate_contact_create_request
|
|
||||||
@ph = params_hash['epp']['command']['create']['create']
|
|
||||||
xml_attrs_present?(@ph, [['id'],
|
|
||||||
%w(authInfo pw),
|
|
||||||
%w(postalInfo name),
|
|
||||||
%w(postalInfo addr city),
|
|
||||||
%w(postalInfo addr cc)])
|
|
||||||
end
|
|
||||||
|
|
||||||
## UPDATE
|
|
||||||
def validate_contact_update_request
|
|
||||||
@ph = params_hash['epp']['command']['update']['update']
|
|
||||||
xml_attrs_present?(@ph, [['id']])
|
|
||||||
end
|
|
||||||
|
|
||||||
## DELETE
|
|
||||||
def validate_contact_delete_request
|
|
||||||
@ph = params_hash['epp']['command']['delete']['delete']
|
|
||||||
xml_attrs_present?(@ph, [['id']])
|
|
||||||
end
|
|
||||||
|
|
||||||
## CHECK
|
|
||||||
def validate_contact_check_request
|
|
||||||
@ph = params_hash['epp']['command']['check']['check']
|
|
||||||
xml_attrs_present?(@ph, [['id']])
|
|
||||||
end
|
|
||||||
|
|
||||||
## INFO
|
|
||||||
def validate_contact_info_request
|
|
||||||
@ph = params_hash['epp']['command']['info']['info']
|
|
||||||
xml_attrs_present?(@ph, [['id']])
|
|
||||||
end
|
|
||||||
|
|
||||||
## SHARED
|
|
||||||
|
|
||||||
def find_contact
|
|
||||||
contact = Contact.find_by(code: @ph[:id])
|
|
||||||
unless contact
|
|
||||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: @ph[:id] } }
|
|
||||||
end
|
end
|
||||||
contact
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_rights?
|
## UPDATE
|
||||||
pw = @ph.try(:[], :authInfo).try(:[], :pw) || @ph.try(:[], :chg).try(:[], :authInfo).try(:[], :pw) || []
|
def validate_contact_update_request
|
||||||
id = @ph[:id]
|
@ph = params_hash['epp']['command']['update']['update']
|
||||||
|
xml_attrs_present?(@ph, [['id']])
|
||||||
return true if !find_contact.nil? && find_contact.auth_info_matches(pw)
|
|
||||||
|
|
||||||
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } }
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def contact_and_address_attributes(type = :create)
|
|
||||||
case type
|
|
||||||
when :update
|
|
||||||
contact_hash = Contact.extract_attributes(@ph[:chg], type)
|
|
||||||
contact_hash[:address_attributes] =
|
|
||||||
Address.extract_attributes(( @ph.try(:[], :chg).try(:[], :postalInfo).try(:[], :addr) || []), type)
|
|
||||||
else
|
|
||||||
contact_hash = Contact.extract_attributes(@ph, type)
|
|
||||||
contact_hash[:address_attributes] =
|
|
||||||
Address.extract_attributes(( @ph.try(:[], :postalInfo).try(:[], :addr) || []), type)
|
|
||||||
end
|
end
|
||||||
contact_hash[:ident_type] = ident_type unless ident_type.nil?
|
|
||||||
contact_hash
|
|
||||||
end
|
|
||||||
|
|
||||||
def ident_type
|
def contact_exists?
|
||||||
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
|
return true if @contact.is_a?(Contact)
|
||||||
|
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'),
|
||||||
|
value: { obj: 'id', val: code } }
|
||||||
|
end
|
||||||
|
|
||||||
return nil unless result
|
## DELETE
|
||||||
|
def validate_contact_delete_request
|
||||||
|
@ph = params_hash['epp']['command']['delete']['delete']
|
||||||
|
xml_attrs_present?(@ph, [['id']])
|
||||||
|
end
|
||||||
|
|
||||||
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
|
## CHECK
|
||||||
nil
|
def validate_contact_check_request
|
||||||
|
@ph = params_hash['epp']['command']['check']['check']
|
||||||
|
xml_attrs_present?(@ph, [['id']])
|
||||||
|
end
|
||||||
|
|
||||||
|
## INFO
|
||||||
|
def validate_contact_info_request
|
||||||
|
@ph = params_hash['epp']['command']['info']['info']
|
||||||
|
xml_attrs_present?(@ph, [['id']])
|
||||||
|
end
|
||||||
|
|
||||||
|
## SHARED
|
||||||
|
|
||||||
|
def find_contact
|
||||||
|
contact = Contact.find_by(code: @ph[:id])
|
||||||
|
unless contact
|
||||||
|
epp_errors << { code: '2303',
|
||||||
|
msg: t('errors.messages.epp_obj_does_not_exist'),
|
||||||
|
value: { obj: 'id', val: @ph[:id] } }
|
||||||
|
end
|
||||||
|
contact
|
||||||
|
end
|
||||||
|
|
||||||
|
def rights?
|
||||||
|
pw = @ph.try(:[], :authInfo).try(:[], :pw) || @ph.try(:[], :chg).try(:[], :authInfo).try(:[], :pw) || []
|
||||||
|
|
||||||
|
return true if !find_contact.nil? && find_contact.auth_info_matches(pw)
|
||||||
|
|
||||||
|
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } }
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def contact_and_address_attributes(type = :create)
|
||||||
|
case type
|
||||||
|
when :update
|
||||||
|
contact_hash = merge_attribute_hash(@ph[:chg], type)
|
||||||
|
else
|
||||||
|
contact_hash = merge_attribute_hash(@ph, type)
|
||||||
|
end
|
||||||
|
contact_hash[:ident_type] = ident_type unless ident_type.nil?
|
||||||
|
contact_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def merge_attribute_hash(prms, type)
|
||||||
|
contact_hash = Contact.extract_attributes(prms, type)
|
||||||
|
contact_hash = contact_hash.merge(
|
||||||
|
Address.extract_attributes((prms.try(:[], :postalInfo) || []))
|
||||||
|
)
|
||||||
|
contact_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def ident_type
|
||||||
|
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
|
||||||
|
|
||||||
|
return nil unless result
|
||||||
|
|
||||||
|
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,46 @@
|
||||||
class Address < ActiveRecord::Base
|
class Address < ActiveRecord::Base
|
||||||
|
LOCAL_TYPE_SHORT = 'loc'
|
||||||
|
INTERNATIONAL_TYPE_SHORT = 'int'
|
||||||
|
LOCAL_TYPE = 'LocalAddress'
|
||||||
|
TYPES = [
|
||||||
|
LOCAL_TYPE_SHORT,
|
||||||
|
INTERNATIONAL_TYPE_SHORT
|
||||||
|
]
|
||||||
|
|
||||||
belongs_to :contact
|
belongs_to :contact
|
||||||
belongs_to :country
|
belongs_to :country
|
||||||
|
|
||||||
class << self
|
#validates_inclusion_of :type, in: TYPES
|
||||||
def extract_attributes(ah, _type = :create)
|
|
||||||
address_hash = {}
|
|
||||||
address_hash = ({
|
|
||||||
country_id: Country.find_by(iso: ah[:cc]).try(:id),
|
|
||||||
city: ah[:city],
|
|
||||||
street: ah[:street][0],
|
|
||||||
street2: ah[:street][1],
|
|
||||||
street3: ah[:street][2],
|
|
||||||
zip: ah[:pc]
|
|
||||||
}) if ah.is_a?(Hash)
|
|
||||||
|
|
||||||
address_hash.delete_if { |_k, v| v.nil? }
|
class << self
|
||||||
|
def extract_attributes(ah)
|
||||||
|
address_hash = {}
|
||||||
|
[ah].flatten.each do |pi|
|
||||||
|
address_hash[local?(pi)] = addr_hash_from_params(pi)
|
||||||
|
end
|
||||||
|
|
||||||
|
address_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def local?(postal_info)
|
||||||
|
return :local_address_attributes if postal_info[:type] == LOCAL_TYPE_SHORT
|
||||||
|
:international_address_attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
def addr_hash_from_params(addr)
|
||||||
|
return {} unless addr[:addr].is_a?(Hash)
|
||||||
|
{
|
||||||
|
name: addr[:name],
|
||||||
|
org_name: addr[:org],
|
||||||
|
country_id: Country.find_by(iso: addr[:addr][:cc]).try(:id),
|
||||||
|
city: addr[:addr][:city],
|
||||||
|
street: addr[:addr][:street][0],
|
||||||
|
street2: addr[:addr][:street][1],
|
||||||
|
street3: addr[:addr][:street][2],
|
||||||
|
zip: addr[:addr][:pc]
|
||||||
|
}.delete_if { |k, v| v.nil? }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,16 +6,18 @@ class Contact < ActiveRecord::Base
|
||||||
|
|
||||||
EPP_ATTR_MAP = {}
|
EPP_ATTR_MAP = {}
|
||||||
|
|
||||||
has_one :address
|
has_one :local_address#, class_name: 'Address'#, foreign_key: 'local_address_id'
|
||||||
|
has_one :international_address
|
||||||
|
|
||||||
has_many :domain_contacts
|
has_many :domain_contacts
|
||||||
has_many :domains, through: :domain_contacts
|
has_many :domains, through: :domain_contacts
|
||||||
|
|
||||||
belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id
|
belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id
|
||||||
belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
|
belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
|
||||||
|
|
||||||
accepts_nested_attributes_for :address
|
accepts_nested_attributes_for :local_address, :international_address
|
||||||
|
|
||||||
validates_presence_of :code, :name, :phone, :email, :ident
|
validates_presence_of :code, :phone, :email, :ident
|
||||||
|
|
||||||
validate :ident_must_be_valid
|
validate :ident_must_be_valid
|
||||||
|
|
||||||
|
@ -32,6 +34,20 @@ class Contact < ActiveRecord::Base
|
||||||
'birthday' # Birthday date
|
'birthday' # Birthday date
|
||||||
]
|
]
|
||||||
|
|
||||||
|
CONTACT_TYPE_TECH = 'tech'
|
||||||
|
CONTACT_TYPE_ADMIN = 'admin'
|
||||||
|
CONTACT_TYPES = [CONTACT_TYPE_TECH, CONTACT_TYPE_ADMIN]
|
||||||
|
|
||||||
|
#TEMP METHODS for transaction to STI
|
||||||
|
def name
|
||||||
|
international_address.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def address
|
||||||
|
international_address
|
||||||
|
end
|
||||||
|
##
|
||||||
|
|
||||||
def ident_must_be_valid
|
def ident_must_be_valid
|
||||||
# TODO Ident can also be passport number or company registry code.
|
# TODO Ident can also be passport number or company registry code.
|
||||||
# so have to make changes to validations (and doc/schema) accordingly
|
# so have to make changes to validations (and doc/schema) accordingly
|
||||||
|
@ -107,11 +123,6 @@ class Contact < ActiveRecord::Base
|
||||||
email: ph[:email]
|
email: ph[:email]
|
||||||
}
|
}
|
||||||
|
|
||||||
contact_hash = contact_hash.merge({
|
|
||||||
name: ph[:postalInfo][:name],
|
|
||||||
org_name: ph[:postalInfo][:org]
|
|
||||||
}) if ph[:postalInfo].is_a? Hash
|
|
||||||
|
|
||||||
contact_hash[:code] = ph[:id] if type == :create
|
contact_hash[:code] = ph[:id] if type == :create
|
||||||
|
|
||||||
contact_hash.delete_if { |_k, v| v.nil? }
|
contact_hash.delete_if { |_k, v| v.nil? }
|
||||||
|
|
3
app/models/international_address.rb
Normal file
3
app/models/international_address.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class InternationalAddress < Address
|
||||||
|
|
||||||
|
end
|
3
app/models/local_address.rb
Normal file
3
app/models/local_address.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class LocalAddress < Address
|
||||||
|
|
||||||
|
end
|
27
app/views/epp/contacts/_postal_info.xml.builder
Normal file
27
app/views/epp/contacts/_postal_info.xml.builder
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
if @contact.international_address
|
||||||
|
address = @contact.international_address
|
||||||
|
xml.tag!('contact:postalInfo', type: 'int') do # TODO instance method of defining type
|
||||||
|
xml.tag!('contact:name', address.name)
|
||||||
|
xml.tag!('contact:org', address.org_name)
|
||||||
|
xml.tag!('contact:addr') do
|
||||||
|
xml.tag!('contact:street', address.street) if address.street
|
||||||
|
xml.tag!('contact:street', address.street2) if address.street2
|
||||||
|
xml.tag!('contact:street', address.street3) if address.street3
|
||||||
|
xml.tag!('contact:cc', address.try(:country).try(:iso)) unless address.try(:country).nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if @contact.local_address
|
||||||
|
address = @contact.local_address
|
||||||
|
xml.tag!('contact:postalInfo', type: 'loc') do
|
||||||
|
xml.tag!('contact:name', address.name)
|
||||||
|
xml.tag!('contact:org', address.org_name)
|
||||||
|
xml.tag!('contact:addr') do
|
||||||
|
xml.tag!('contact:street', address.street) if address.street
|
||||||
|
xml.tag!('contact:street', address.street2) if address.street2
|
||||||
|
xml.tag!('contact:street', address.street3) if address.street3
|
||||||
|
xml.tag!('contact:cc', address.try(:country).try(:iso)) unless address.try(:country).nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -6,15 +6,7 @@ xml.epp_head do
|
||||||
|
|
||||||
xml.resData do
|
xml.resData do
|
||||||
xml.tag!('contact:chkData', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
xml.tag!('contact:chkData', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
||||||
xml.tag!('contact:name', @contact.name)
|
xml << render('/epp/contacts/postal_info')
|
||||||
xml.tag!('contact:org', @contact.org_name)
|
|
||||||
xml.tag!('contact:addr') do
|
|
||||||
address = @contact.address
|
|
||||||
xml.tag!('contact:street', address.street) if address.street
|
|
||||||
xml.tag!('contact:street', address.street2) if address.street2
|
|
||||||
xml.tag!('contact:street', address.street3) if address.street3
|
|
||||||
xml.tag!('contact:cc', address.try(:country).try(:iso)) unless address.try(:country).nil?
|
|
||||||
end
|
|
||||||
xml.tag!('contact:voice', @contact.phone)
|
xml.tag!('contact:voice', @contact.phone)
|
||||||
xml.tag!('contact:fax', @contact.fax)
|
xml.tag!('contact:fax', @contact.fax)
|
||||||
xml.tag!('contact:email', @contact.email)
|
xml.tag!('contact:email', @contact.email)
|
||||||
|
|
8
config/secrets-example.yml
Normal file
8
config/secrets-example.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
development:
|
||||||
|
secret_key_base: generate-your-secret-key-by-rake-secret
|
||||||
|
|
||||||
|
test:
|
||||||
|
secret_key_base: generate-your-secret-key-by-rake-secret
|
||||||
|
|
||||||
|
production:
|
||||||
|
secret_key_base:
|
10
db/migrate/20140822122938_add_postal_info_to_address.rb
Normal file
10
db/migrate/20140822122938_add_postal_info_to_address.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class AddPostalInfoToAddress < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :addresses, :name, :string
|
||||||
|
add_column :addresses, :org_name, :string
|
||||||
|
add_column :addresses, :type, :string
|
||||||
|
|
||||||
|
remove_column :contacts, :name, :string
|
||||||
|
remove_column :contacts, :org_name, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -26,11 +26,13 @@ ActiveRecord::Schema.define(version: 20140826103454) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "street2"
|
t.string "street2"
|
||||||
t.string "street3"
|
t.string "street3"
|
||||||
|
t.string "name"
|
||||||
|
t.string "org_name"
|
||||||
|
t.string "type"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "contacts", force: true do |t|
|
create_table "contacts", force: true do |t|
|
||||||
t.string "code"
|
t.string "code"
|
||||||
t.string "name"
|
|
||||||
t.string "type"
|
t.string "type"
|
||||||
t.string "reg_no"
|
t.string "reg_no"
|
||||||
t.string "phone"
|
t.string "phone"
|
||||||
|
@ -40,7 +42,6 @@ ActiveRecord::Schema.define(version: 20140826103454) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "ident"
|
t.string "ident"
|
||||||
t.string "ident_type"
|
t.string "ident_type"
|
||||||
t.string "org_name"
|
|
||||||
t.integer "created_by_id"
|
t.integer "created_by_id"
|
||||||
t.integer "updated_by_id"
|
t.integer "updated_by_id"
|
||||||
t.string "auth_info"
|
t.string "auth_info"
|
||||||
|
|
|
@ -135,3 +135,18 @@
|
||||||
<clTRID>ABC-12345</clTRID>
|
<clTRID>ABC-12345</clTRID>
|
||||||
</command>
|
</command>
|
||||||
</epp>
|
</epp>
|
||||||
|
|
||||||
|
<!-- CHECK CONTACT -->
|
||||||
|
<?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="urn:ietf:params:xml:ns:contact-1.0">
|
||||||
|
<contact:id>check-1234</contact:id>
|
||||||
|
<contact:id>check-4321</contact:id>
|
||||||
|
</contact:check>
|
||||||
|
</check>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
|
|
@ -16,6 +16,11 @@ RSpec::Core::RakeTask.new('test:other') do |t|
|
||||||
t.rspec_opts = '--tag ~epp'
|
t.rspec_opts = '--tag ~epp'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Run all but EPP specs'
|
||||||
|
RSpec::Core::RakeTask.new('test:all_but_features') do |t|
|
||||||
|
t.rspec_opts = '--tag ~feature'
|
||||||
|
end
|
||||||
|
|
||||||
Rake::Task[:default].prerequisites.clear
|
Rake::Task[:default].prerequisites.clear
|
||||||
task default: :test
|
task default: :test
|
||||||
|
|
||||||
|
|
|
@ -29,17 +29,30 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(response[:result_code]).to eq('1000')
|
expect(response[:result_code]).to eq('1000')
|
||||||
expect(response[:msg]).to eq('Command completed successfully')
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
expect(response[:clTRID]).to eq('ABC-12345')
|
expect(response[:clTRID]).to eq('ABC-12345')
|
||||||
expect(Contact.first.created_by_id).to be 1
|
expect(Contact.first.created_by_id).to eq 1
|
||||||
expect(Contact.first.updated_by_id).to be nil
|
expect(Contact.first.updated_by_id).to eq nil
|
||||||
|
|
||||||
expect(Contact.count).to eq(1)
|
expect(Contact.count).to eq(1)
|
||||||
expect(Contact.first.org_name).to eq('Example Inc.')
|
|
||||||
|
|
||||||
|
expect(Contact.first.international_address.org_name).to eq('Example Inc.')
|
||||||
expect(Contact.first.ident).to eq '37605030299'
|
expect(Contact.first.ident).to eq '37605030299'
|
||||||
expect(Contact.first.ident_type).to eq 'op'
|
expect(Contact.first.ident_type).to eq 'op'
|
||||||
|
|
||||||
expect(Contact.first.address.street).to eq('123 Example Dr.')
|
expect(Contact.first.international_address.street).to eq('123 Example Dr.')
|
||||||
expect(Contact.first.address.street2).to eq('Suite 100')
|
expect(Contact.first.international_address.street2).to eq('Suite 100')
|
||||||
expect(Contact.first.address.street3).to eq nil
|
expect(Contact.first.international_address.street3).to eq nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'successfully creates contact with 2 addresses' do
|
||||||
|
response = epp_request('contacts/create_with_two_addresses.xml')
|
||||||
|
|
||||||
|
expect(response[:result_code]).to eq('1000')
|
||||||
|
|
||||||
|
expect(Contact.count).to eq(1)
|
||||||
|
expect(Contact.first.address).to_not eq Contact.first.local_address
|
||||||
|
expect(Address.count).to eq(2)
|
||||||
|
expect(LocalAddress.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns result data upon success' do
|
it 'returns result data upon success' do
|
||||||
|
@ -62,6 +75,7 @@ describe 'EPP Contact', epp: true do
|
||||||
|
|
||||||
response = epp_request(contact_create_xml, :xml)
|
response = epp_request(contact_create_xml, :xml)
|
||||||
|
|
||||||
|
|
||||||
expect(response[:result_code]).to eq('2302')
|
expect(response[:result_code]).to eq('2302')
|
||||||
expect(response[:msg]).to eq('Contact id already exists')
|
expect(response[:msg]).to eq('Contact id already exists')
|
||||||
|
|
||||||
|
@ -204,8 +218,8 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns info about contact' do
|
it 'returns info about contact' do
|
||||||
Fabricate(:contact, name: 'Johnny Awesome', created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR')
|
Fabricate(:contact, created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR',
|
||||||
Fabricate(:address)
|
international_address: Fabricate(:international_address, name: 'Johnny Awesome'))
|
||||||
|
|
||||||
response = epp_request('contacts/info.xml')
|
response = epp_request('contacts/info.xml')
|
||||||
contact = response[:parsed].css('resData chkData')
|
contact = response[:parsed].css('resData chkData')
|
||||||
|
@ -217,7 +231,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'doesn\'t display unassociated object' do
|
it 'doesn\'t display unassociated object' do
|
||||||
Fabricate(:contact, name: 'Johnny Awesome', code: 'info-4444')
|
Fabricate(:contact, code: 'info-4444')
|
||||||
|
|
||||||
response = epp_request('contacts/info.xml')
|
response = epp_request('contacts/info.xml')
|
||||||
expect(response[:result_code]).to eq('2201')
|
expect(response[:result_code]).to eq('2201')
|
||||||
|
|
45
spec/epp/requests/contacts/create_with_two_addresses.xml
Normal file
45
spec/epp/requests/contacts/create_with_two_addresses.xml
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?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="urn:ietf:params:xml:ns:contact-1.0">
|
||||||
|
<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>
|
|
@ -1,6 +0,0 @@
|
||||||
Fabricator(:address) do
|
|
||||||
city Faker::Address.city
|
|
||||||
street Faker::Address.street_name
|
|
||||||
street2 Faker::Address.street_name
|
|
||||||
zip Faker::Address.zip
|
|
||||||
end
|
|
|
@ -1,10 +1,9 @@
|
||||||
Fabricator(:contact) do
|
Fabricator(:contact) do
|
||||||
name Faker::Name.name
|
|
||||||
phone '+372.12345678'
|
phone '+372.12345678'
|
||||||
email Faker::Internet.email
|
email Faker::Internet.email
|
||||||
ident '37605030299'
|
ident '37605030299'
|
||||||
code { "sh#{Faker::Number.number(4)}" }
|
code { "sh#{Faker::Number.number(4)}" }
|
||||||
ident_type 'op'
|
ident_type 'op'
|
||||||
auth_info 'ccds4324pok'
|
auth_info 'ccds4324pok'
|
||||||
address
|
international_address
|
||||||
end
|
end
|
||||||
|
|
7
spec/fabricators/international_address_fabricator.rb
Normal file
7
spec/fabricators/international_address_fabricator.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Fabricator(:international_address) do
|
||||||
|
name Faker::Name.name
|
||||||
|
city Faker::Address.city
|
||||||
|
street Faker::Address.street_name
|
||||||
|
street2 Faker::Address.street_name
|
||||||
|
zip Faker::Address.zip
|
||||||
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
feature 'Setting management' do
|
feature 'Setting management', type: :feature do
|
||||||
background { Fabricate(:domain_validation_setting_group) }
|
background { Fabricate(:domain_validation_setting_group) }
|
||||||
|
|
||||||
scenario 'User changes a setting', js: true do
|
scenario 'User changes a setting', js: true do
|
||||||
|
|
|
@ -7,13 +7,16 @@ end
|
||||||
|
|
||||||
describe Address, '.extract_params' do
|
describe Address, '.extract_params' do
|
||||||
it 'returns params hash'do
|
it 'returns params hash'do
|
||||||
Fabricate(:country, iso: 'EE')
|
Fabricate(:country, iso:'EE')
|
||||||
ph = { postalInfo: { name: 'fred', addr: { cc: 'EE', city: 'Village', street: %w(street1 street2) } } }
|
ph = { postalInfo: { name: "fred", addr: { cc: 'EE', city: 'Village', street: [ 'street1', 'street2' ] } } }
|
||||||
expect(Address.extract_attributes(ph[:postalInfo][:addr])).to eq({
|
expect(Address.extract_attributes(ph[:postalInfo])).to eq( {
|
||||||
city: 'Village',
|
international_address_attributes: {
|
||||||
country_id: 1,
|
name: 'fred',
|
||||||
street: 'street1',
|
city: 'Village',
|
||||||
street2: 'street2'
|
country_id: 1,
|
||||||
|
street: 'street1',
|
||||||
|
street2: 'street2',
|
||||||
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Contact do
|
describe Contact do
|
||||||
it { should have_one(:address) }
|
it { should have_one(:local_address) }
|
||||||
|
it { should have_one(:international_address) }
|
||||||
|
|
||||||
context 'with invalid attribute' do
|
context 'with invalid attribute' do
|
||||||
before(:each) { @contact = Fabricate(:contact) }
|
before(:each) { @contact = Fabricate(:contact) }
|
||||||
|
@ -22,7 +23,6 @@ describe Contact do
|
||||||
|
|
||||||
expect(@contact.errors.messages).to match_array({
|
expect(@contact.errors.messages).to match_array({
|
||||||
code: ['Required parameter missing - code'],
|
code: ['Required parameter missing - code'],
|
||||||
name: ['Required parameter missing - name'],
|
|
||||||
phone: ['Required parameter missing - phone', 'Phone nr is invalid'],
|
phone: ['Required parameter missing - phone', 'Phone nr is invalid'],
|
||||||
email: ['Required parameter missing - email', 'Email is invalid'],
|
email: ['Required parameter missing - email', 'Email is invalid'],
|
||||||
ident: ['Required parameter missing - ident']
|
ident: ['Required parameter missing - ident']
|
||||||
|
@ -88,9 +88,8 @@ describe Contact, '.extract_params' do
|
||||||
ph = { id: '123123', email: 'jdoe@example.com', postalInfo: { name: 'fred', addr: { cc: 'EE' } } }
|
ph = { id: '123123', email: 'jdoe@example.com', postalInfo: { name: 'fred', addr: { cc: 'EE' } } }
|
||||||
expect(Contact.extract_attributes(ph)).to eq({
|
expect(Contact.extract_attributes(ph)).to eq({
|
||||||
code: '123123',
|
code: '123123',
|
||||||
email: 'jdoe@example.com',
|
email: 'jdoe@example.com'
|
||||||
name: 'fred'
|
} )
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue