Merge branch 'master' of github.com:internetee/registry

Conflicts:
	app/models/registrar.rb
	db/schema.rb
This commit is contained in:
Andres Keskküla 2014-10-07 16:20:47 +03:00
commit c14452e756
13 changed files with 128 additions and 25 deletions

View file

@ -32,6 +32,10 @@ class Client::DomainsController < ClientController
end
end
def show
@domain.all_dependencies_valid?
end
def edit
build_associations
end
@ -70,7 +74,7 @@ class Client::DomainsController < ClientController
nameservers_attributes: [:id, :hostname, :ipv4, :ipv6, :_destroy],
domain_contacts_attributes: [:id, :contact_type, :contact_id, :value_typeahead, :_destroy],
domain_statuses_attributes: [:id, :value, :description, :_destroy],
dnskeys_attributes: [:id, :flags, :alg, :protocol, :public_key]
dnskeys_attributes: [:id, :flags, :alg, :protocol, :public_key, :_destroy]
)
end

View file

@ -49,6 +49,7 @@ class Domain < ActiveRecord::Base
validate :validate_period
validate :validate_nameservers_count
validate :validate_admin_contacts_count
validate :validate_dnskeys_count
validate :validate_nameservers_uniqueness
validate :validate_tech_contacts_uniqueness
validate :validate_admin_contacts_uniqueness
@ -95,11 +96,19 @@ class Domain < ActiveRecord::Base
errors.add(:admin_contacts, :out_of_range) if admin_contacts_count.zero?
end
def validate_dnskeys_count
sg = SettingGroup.domain_validation
min, max = sg.setting(:dnskeys_min_count).value.to_i, sg.setting(:dnskeys_max_count).value.to_i
return if dnskeys.reject(&:marked_for_destruction?).length.between?(min, max)
errors.add(:dnskeys, :out_of_range, { min: min, max: max })
end
def validate_nameservers_uniqueness
validated = []
nameservers.reject(&:marked_for_destruction?).each do |ns|
list = nameservers.reject(&:marked_for_destruction?)
list.each do |ns|
next if ns.hostname.blank?
existing = nameservers.reject(&:marked_for_destruction?).select { |x| x.hostname == ns.hostname }
existing = list.select { |x| x.hostname == ns.hostname }
next unless existing.length > 1
validated << ns.hostname
errors.add(:nameservers, :invalid) if errors[:nameservers].blank?
@ -139,9 +148,10 @@ class Domain < ActiveRecord::Base
def validate_domain_statuses_uniqueness
validated = []
domain_statuses.reject(&:marked_for_destruction?).each do |status|
list = domain_statuses.reject(&:marked_for_destruction?)
list.each do |status|
next if status.value.blank?
existing = domain_statuses.select { |x| x.value == status.value }
existing = list.select { |x| x.value == status.value }
next unless existing.length > 1
validated << status.value
errors.add(:domain_statuses, :invalid) if errors[:domain_statuses].blank?
@ -151,9 +161,10 @@ class Domain < ActiveRecord::Base
def validate_dnskeys_uniqueness
validated = []
dnskeys.reject(&:marked_for_destruction?).each do |dnskey|
list = dnskeys.reject(&:marked_for_destruction?)
list.each do |dnskey|
next if dnskey.public_key.blank?
existing = dnskeys.select { |x| x.public_key == dnskey.public_key }
existing = list.select { |x| x.public_key == dnskey.public_key }
next unless existing.length > 1
validated << dnskey.public_key
errors.add(:dnskeys, :invalid) if errors[:dnskeys].blank?
@ -176,6 +187,7 @@ class Domain < ActiveRecord::Base
def all_dependencies_valid?
validate_nameservers_count
validate_dnskeys_count
validate_admin_contacts_count
errors.empty?

View file

@ -29,6 +29,12 @@ class Epp::EppDomain < Domain
max: domain_validation_sg.setting(:ns_max_count).value
}
],
[:dnskeys, :out_of_range,
{
min: domain_validation_sg.setting(:dnskeys_min_count).value,
max: domain_validation_sg.setting(:dnskeys_max_count).value
}
],
[:period, :out_of_range, { value: { obj: 'period', val: period } }]
],
'2200' => [

View file

@ -1,5 +0,0 @@
class NsSet < ActiveRecord::Base
belongs_to :registrar
has_many :domains
has_and_belongs_to_many :nameservers
end

View file

@ -1,10 +1,9 @@
class Registrar < ActiveRecord::Base
belongs_to :country
has_many :domains, :dependent => :restrict_with_error
has_many :ns_sets
has_many :epp_users
has_many :users
has_many :contacts
has_many :contacts, :dependent => :restrict_with_error
has_many :epp_users, :dependent => :restrict_with_error
has_many :users, :dependent => :restrict_with_error
validates :name, :reg_no, :address, :country, presence: true
validates :name, :reg_no, uniqueness: true

View file

@ -19,5 +19,5 @@
%tfoot
- @domain.errors.messages[:nameservers].each do |x|
%tr
%td{colspan: 4}= x
%td{colspan: 3}= x

View file

@ -44,3 +44,40 @@
%dt= t('shared.billing_address')
%dd= @registrar.billing_address
.row
.col-md-12
#users.panel.panel-default
.panel-heading.clearfix
= t('shared.users')
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-3'}= t('shared.username')
%th{class: 'col-xs-3'}= t('shared.email')
%th{class: 'col-xs-3'}= t('shared.identity_code')
%th{class: 'col-xs-3'}= t('shared.admin')
%tbody
- @registrar.users.each do |x|
%tr
%td= link_to(x, [:admin, x])
%td= x.email
%td= x.identity_code
%td= x.admin
.row
.col-md-12
#epp-users.panel.panel-default
.panel-heading.clearfix
= t('shared.epp_users')
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-6'}= t('shared.username')
%th{class: 'col-xs-6'}= t('shared.active')
%tbody
- @registrar.epp_users.each do |x|
%tr
%td= link_to(x, [:admin, x])
%td= x.active

View file

@ -14,7 +14,7 @@
.row
.col-md-4
.form-group
= key_fields.label :flags, t('shared.flag')
= key_fields.label :flags
= key_fields.text_field :flags, class: 'form-control'
.col-md-4
.form-group

View file

@ -2,6 +2,7 @@
#
# Build and run everything for automatic tests
#
set -o pipefail
# cd to Rails root directory
@ -11,7 +12,12 @@ git pull origin master
git reset --hard
unset GIT_DIR GIT_WORK_TREE
setuser app bundle install --deployment
# run rubocop
echo "RUBOCOP_RESULTS"
rubocop
echo "END_OF_RUBOCOP_RESULTS"
bundle install --deployment
# cp config/secrets-example.yml config/secrets.yml
# create manually config/database.yml
@ -26,11 +32,6 @@ echo "GIT_LAST_COMMITS"
git log origin/master -n 15 --pretty=oneline | sed -r '/^.{40} Merge branch/d' | sed -r 's/^.{40}/Latests: /'
echo "END_OF_GIT_LAST_COMMITS"
# run rubocop
echo "RUBOCOP_RESULTS"
rubocop
echo "END_OF_RUBOCOP_RESULTS"
# run tests
echo "TEST_RESULTS"
RAILS_ENV=test ROBOT=true bundle exec rake test

View file

@ -109,6 +109,7 @@ en:
dnskeys:
invalid: 'DNS keys are invalid'
not_found: 'Dnskey was not found'
out_of_range: 'DNS keys count must be between %{min}-%{max}'
domain:
<<: *epp_domain_ar_attributes
@ -211,6 +212,11 @@ en:
nameservers: 'Nameservers'
domain:
<<: *epp_domain_attributes
dnskey:
flags: 'Flag'
protocol: 'Protocol'
alg: 'Algorithm'
public_key: 'Public key'
errors:
@ -242,6 +248,8 @@ en:
codes:
ns_min_count: 'Nameserver minimum count'
ns_max_count: 'Nameserver maximum count'
dnskeys_min_count: 'DNS keys minimum count'
dnskeys_max_count: 'DNS keys maximum count'
shared:
code: 'Code'

View file

@ -0,0 +1,7 @@
class AddDnskeyRangeValidation < ActiveRecord::Migration
def change
sg = SettingGroup.find_by(code: 'domain_validation')
sg.settings << Setting.create(code: 'dnskeys_min_count'.underscore, value: '0')
sg.settings << Setting.create(code: 'dnskeys_max_count'.underscore, value: '9')
end
end

View file

@ -447,6 +447,38 @@ describe 'EPP Domain', epp: true do
expect(response[:msg]).to eq('Public key already exists')
expect(response[:results][0][:value]).to eq('700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f')
end
it 'validated dnskeys count' do
s = Setting.find_by(code: 'dnskeys_max_count')
s.value = 1
s.save
xml = domain_create_xml({
dnssec: [
{
dnskey: {
flags: { value: '257' },
protocol: { value: '3' },
alg: { value: '3' },
pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' }
}
},
{
dnskey: {
flags: { value: '0' },
protocol: { value: '3' },
alg: { value: '5' },
pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' }
}
}
]
})
response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2004')
expect(response[:msg]).to eq('DNS keys count must be between 0-1')
end
end
context 'with juridical persion as an owner' do

View file

@ -13,7 +13,9 @@ Fabricator(:domain_validation_setting_group, from: :setting_group) do
settings do
[
Fabricate(:setting, code: 'ns_min_count', value: 1),
Fabricate(:setting, code: 'ns_max_count', value: 13)
Fabricate(:setting, code: 'ns_max_count', value: 13),
Fabricate(:setting, code: 'dnskeys_min_count', value: 0),
Fabricate(:setting, code: 'dnskeys_max_count', value: 9)
]
end
end