mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Merge branch 'master' of github.com:internetee/registry
Conflicts: spec/epp/contact_spec.rb
This commit is contained in:
commit
2a8d091bfc
8 changed files with 61 additions and 32 deletions
|
@ -1,18 +1,15 @@
|
||||||
module Epp::ContactsHelper
|
module Epp::ContactsHelper
|
||||||
def create_contact
|
def create_contact
|
||||||
@contact = Contact.new( contact_and_address_attributes )
|
@contact = Contact.new( contact_and_address_attributes )
|
||||||
stamp @contact
|
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
|
||||||
if @contact.save
|
|
||||||
render '/epp/contacts/create'
|
|
||||||
else
|
|
||||||
handle_errors(@contact)
|
handle_errors(@contact)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def update_contact
|
def update_contact
|
||||||
code = params_hash['epp']['command']['update']['update'][:id]
|
code = params_hash['epp']['command']['update']['update'][:id]
|
||||||
@contact = Contact.where(code: code).first
|
@contact = Contact.where(code: code).first
|
||||||
if stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
if has_rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||||
render 'epp/contacts/update'
|
render 'epp/contacts/update'
|
||||||
else
|
else
|
||||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: code } } if @contact == []
|
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: code } } if @contact == []
|
||||||
|
@ -22,6 +19,7 @@ module Epp::ContactsHelper
|
||||||
|
|
||||||
def delete_contact
|
def delete_contact
|
||||||
#no deleting, implement PaperTrail or something similar.
|
#no deleting, implement PaperTrail or something similar.
|
||||||
|
#TODO check for relation before 'destroying'
|
||||||
@contact = find_contact
|
@contact = find_contact
|
||||||
handle_errors(@contact) and return unless @contact
|
handle_errors(@contact) and return unless @contact
|
||||||
@contact.destroy
|
@contact.destroy
|
||||||
|
@ -35,6 +33,7 @@ module Epp::ContactsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def info_contact
|
def info_contact
|
||||||
|
handle_errors and return unless has_rights?
|
||||||
@contact = find_contact
|
@contact = find_contact
|
||||||
handle_errors(@contact) and return unless @contact
|
handle_errors(@contact) and return unless @contact
|
||||||
render 'epp/contacts/info'
|
render 'epp/contacts/info'
|
||||||
|
@ -47,12 +46,10 @@ module Epp::ContactsHelper
|
||||||
def validate_contact_create_request
|
def validate_contact_create_request
|
||||||
@ph = params_hash['epp']['command']['create']['create']
|
@ph = params_hash['epp']['command']['create']['create']
|
||||||
xml_attrs_present?(@ph, [['id'],
|
xml_attrs_present?(@ph, [['id'],
|
||||||
['postalInfo'],
|
['authInfo', 'pw'],
|
||||||
['postalInfo', 'name'],
|
['postalInfo', 'name'],
|
||||||
['postalInfo', 'addr'],
|
|
||||||
['postalInfo', 'addr', 'city'],
|
['postalInfo', 'addr', 'city'],
|
||||||
['postalInfo', 'addr', 'cc'],
|
['postalInfo', 'addr', 'cc']])
|
||||||
['authInfo']])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
## UPDATE
|
## UPDATE
|
||||||
|
@ -89,6 +86,15 @@ module Epp::ContactsHelper
|
||||||
contact
|
contact
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_rights?
|
||||||
|
pw = @ph.try(:[], :authInfo).try(:[], :pw) || @ph.try(:[], :chg).try(:[], :authInfo).try(:[], :pw) || []
|
||||||
|
id = @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 } }
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
def contact_and_address_attributes( type=:create )
|
def contact_and_address_attributes( type=:create )
|
||||||
case type
|
case type
|
||||||
|
@ -105,13 +111,6 @@ module Epp::ContactsHelper
|
||||||
contact_hash
|
contact_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_rights
|
|
||||||
if @contact.created_by.registrar == current_epp_user.registrar
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
def ident_type
|
def ident_type
|
||||||
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
|
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,11 @@ class Contact < ActiveRecord::Base
|
||||||
updated_by ? updated_by.username : nil
|
updated_by ? updated_by.username : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def auth_info_matches pw
|
||||||
|
return true if auth_info == pw
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def extract_attributes ph, type=:create
|
def extract_attributes ph, type=:create
|
||||||
|
|
5
db/migrate/20140815114000_add_auth_info_to_contact.rb
Normal file
5
db/migrate/20140815114000_add_auth_info_to_contact.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddAuthInfoToContact < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :contacts, :auth_info, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20140815110028) do
|
ActiveRecord::Schema.define(version: 20140815114000) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -43,6 +43,7 @@ ActiveRecord::Schema.define(version: 20140815110028) do
|
||||||
t.string "org_name"
|
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"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "countries", force: true do |t|
|
create_table "countries", force: true do |t|
|
||||||
|
|
|
@ -7,6 +7,7 @@ describe 'EPP Contact', epp: true do
|
||||||
before(:each) { Fabricate(:epp_user) }
|
before(:each) { Fabricate(:epp_user) }
|
||||||
|
|
||||||
context 'create command' do
|
context 'create command' do
|
||||||
|
|
||||||
it "fails if request is invalid" do
|
it "fails if request is invalid" do
|
||||||
response = epp_request(contact_create_xml( { authInfo: [false], addr: { cc: false, city: false } } ), :xml)
|
response = epp_request(contact_create_xml( { authInfo: [false], addr: { cc: false, city: false } } ), :xml)
|
||||||
|
|
||||||
|
@ -14,9 +15,9 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(response[:results][1][:result_code]).to eq('2003')
|
expect(response[:results][1][:result_code]).to eq('2003')
|
||||||
expect(response[:results][2][:result_code]).to eq('2003')
|
expect(response[:results][2][:result_code]).to eq('2003')
|
||||||
|
|
||||||
expect(response[:results][0][:msg]).to eq('Required parameter missing: city')
|
expect(response[:results][0][:msg]).to eq('Required parameter missing: pw')
|
||||||
expect(response[:results][1][:msg]).to eq('Required parameter missing: cc')
|
expect(response[:results][1][:msg]).to eq('Required parameter missing: city')
|
||||||
expect(response[:results][2][:msg]).to eq('Required parameter missing: authInfo')
|
expect(response[:results][2][:msg]).to eq('Required parameter missing: cc')
|
||||||
expect(response[:results].count).to eq 3
|
expect(response[:results].count).to eq 3
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +38,6 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(Contact.first.address.street).to eq('123 Example Dr.')
|
expect(Contact.first.address.street).to eq('123 Example Dr.')
|
||||||
expect(Contact.first.address.street2).to eq('Suite 100')
|
expect(Contact.first.address.street2).to eq('Suite 100')
|
||||||
expect(Contact.first.address.street3).to eq nil
|
expect(Contact.first.address.street3).to eq nil
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns result data upon success' do
|
it 'returns result data upon success' do
|
||||||
|
@ -78,6 +78,16 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(response[:results].count).to eq 1
|
expect(response[:results].count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
it 'fails with wrong authentication info' do
|
||||||
|
Fabricate(:contact, code: 'sh8013', auth_info: 'secure_password')
|
||||||
|
|
||||||
|
response = epp_request('contacts/update.xml')
|
||||||
|
|
||||||
|
expect(response[:msg]).to eq('Authorization error')
|
||||||
|
expect(response[:result_code]).to eq('2201')
|
||||||
|
end
|
||||||
|
|
||||||
it 'stamps updated_by succesfully' do
|
it 'stamps updated_by succesfully' do
|
||||||
Fabricate(:contact, code: 'sh8013')
|
Fabricate(:contact, code: 'sh8013')
|
||||||
|
|
||||||
|
@ -89,7 +99,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is succesful' do
|
it 'is succesful' do
|
||||||
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013')
|
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
|
||||||
#response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml)
|
#response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml)
|
||||||
response = epp_request('contacts/update.xml')
|
response = epp_request('contacts/update.xml')
|
||||||
|
|
||||||
|
@ -101,7 +111,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns phone and email error' do
|
it 'returns phone and email error' do
|
||||||
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013')
|
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
|
||||||
#response = epp_request(contact_update_xml( { chg: { email: "qwe", phone: "123qweasd" } }), :xml)
|
#response = epp_request(contact_update_xml( { chg: { email: "qwe", phone: "123qweasd" } }), :xml)
|
||||||
response = epp_request('contacts/update_with_errors.xml')
|
response = epp_request('contacts/update_with_errors.xml')
|
||||||
|
|
||||||
|
@ -123,7 +133,7 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes contact' do
|
it 'deletes contact' do
|
||||||
Fabricate(:contact, code: "dwa1234")
|
Fabricate(:contact, code: "dwa1234", auth_info: '2fooBAR')
|
||||||
response = epp_request('contacts/delete.xml')
|
response = epp_request('contacts/delete.xml')
|
||||||
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')
|
||||||
|
@ -149,7 +159,7 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(response[:results].count).to eq 1
|
expect(response[:results].count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns info about contact' do
|
it 'returns info about contact availability' do
|
||||||
Fabricate(:contact, code: 'check-1234')
|
Fabricate(:contact, code: 'check-1234')
|
||||||
|
|
||||||
response = epp_request(contact_check_xml( ids: [{ id: 'check-1234'}, { id: 'check-4321' }] ), :xml)
|
response = epp_request(contact_check_xml( ids: [{ id: 'check-1234'}, { id: 'check-4321' }] ), :xml)
|
||||||
|
@ -183,7 +193,7 @@ 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')
|
Fabricate(:contact, name: "Johnny Awesome", created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR')
|
||||||
Fabricate(:address)
|
Fabricate(:address)
|
||||||
|
|
||||||
response = epp_request('contacts/info.xml')
|
response = epp_request('contacts/info.xml')
|
||||||
|
@ -195,10 +205,8 @@ describe 'EPP Contact', epp: true do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'doesn\'t display unassociated object', pending: true do
|
it 'doesn\'t display unassociated object' do
|
||||||
pending 'until new contact rights systems is implemented'
|
Fabricate(:contact, name:"Johnny Awesome", code: 'info-4444')
|
||||||
Fabricate(:contact, name:"Johnny Awesome", created_by_id: '240', code: 'info-4444')
|
|
||||||
Fabricate(:epp_user, id: 240)
|
|
||||||
|
|
||||||
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')
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
<contact:chg>
|
<contact:chg>
|
||||||
<contact:voice x="1234">123456798</contact:voice>
|
<contact:voice x="1234">123456798</contact:voice>
|
||||||
<contact:email>faulty</contact:email>
|
<contact:email>faulty</contact:email>
|
||||||
|
<contact:authInfo>
|
||||||
|
<contact:pw>2fooBAR</contact:pw>
|
||||||
|
</contact:authInfo>
|
||||||
</contact:chg>
|
</contact:chg>
|
||||||
</contact:update>
|
</contact:update>
|
||||||
</update>
|
</update>
|
||||||
|
|
|
@ -5,5 +5,6 @@ Fabricator(:contact) do
|
||||||
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'
|
||||||
address
|
address
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,6 +94,8 @@ module EppContactXmlBuilder
|
||||||
xml_params[:chg][:postalInfo] = postalInfo
|
xml_params[:chg][:postalInfo] = postalInfo
|
||||||
xml_params[:chg][:postalInfo][:addr] = addr
|
xml_params[:chg][:postalInfo][:addr] = addr
|
||||||
|
|
||||||
|
xml_params[:chg][:authInfo] = xml_params[:chg][:authInfo] || { pw: 'ccds4324pok' }
|
||||||
|
|
||||||
|
|
||||||
xml.instruct!(:xml, standalone: 'no')
|
xml.instruct!(:xml, standalone: 'no')
|
||||||
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
|
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
|
||||||
|
@ -122,6 +124,11 @@ module EppContactXmlBuilder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
unless xml_params[:chg][:authInfo] == [false]
|
||||||
|
xml.tag!('contact:authInfo') do
|
||||||
|
xml.tag!('contact:pw', xml_params[:chg][:authInfo][:pw] ) unless xml_params[:chg][:authInfo][:pw] == false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue