Rename domain "auth_info" to "transfer_code"

#660
This commit is contained in:
Artur Beljajev 2018-01-21 19:31:16 +02:00
parent 340e61804b
commit 4b836f1476
23 changed files with 54 additions and 47 deletions

View file

@ -6,11 +6,11 @@ module Repp
post '/' do post '/' do
params['domainTransfers'].each do |domain_transfer| params['domainTransfers'].each do |domain_transfer|
domain_name = domain_transfer['domainName'] domain_name = domain_transfer['domainName']
auth_info = domain_transfer['authInfo'] transfer_code = domain_transfer['transferCode']
new_registrar = current_user.registrar new_registrar = current_user.registrar
domain = Domain.find_by(name: domain_name) domain = Domain.find_by(name: domain_name)
domain.transfer(registrar: new_registrar, auth_info: auth_info) domain.transfer(registrar: new_registrar, transfer_code: transfer_code)
end end
end end
end end

View file

@ -32,7 +32,7 @@ module Repp
domain = ident =~ /\A[0-9]+\z/ ? Domain.find_by(id: ident) : Domain.find_by_idn(ident) domain = ident =~ /\A[0-9]+\z/ ? Domain.find_by(id: ident) : Domain.find_by_idn(ident)
error! I18n.t('errors.messages.epp_domain_not_found'), 404 unless domain error! I18n.t('errors.messages.epp_domain_not_found'), 404 unless domain
error! I18n.t('errors.messages.epp_authorization_error'), 401 unless domain.auth_info.eql? request.headers['Auth-Code'] error! I18n.t('errors.messages.epp_authorization_error'), 401 unless domain.transfer_code.eql? request.headers['Auth-Code']
contact_repp_json = proc{|contact| contact_repp_json = proc{|contact|
contact.as_json.slice("code", "name", "ident", "ident_type", "ident_country_code", "phone", "email", "street", "city", "zip","country_code", "statuses") contact.as_json.slice("code", "name", "ident", "ident_type", "ident_country_code", "phone", "email", "street", "city", "zip","country_code", "statuses")

View file

@ -54,14 +54,14 @@ class Ability
# can(:create, :epp_request) # can(:create, :epp_request)
# Epp::Domain # Epp::Domain
can(:info, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || pw.blank? ? true : d.auth_info == pw } can(:info, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || pw.blank? ? true : d.transfer_code == pw }
can(:check, Epp::Domain) can(:check, Epp::Domain)
can(:create, Epp::Domain) can(:create, Epp::Domain)
can(:renew, Epp::Domain) { |d| d.registrar_id == @user.registrar_id } can(:renew, Epp::Domain) { |d| d.registrar_id == @user.registrar_id }
can(:update, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw } can(:update, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.transfer_code == pw }
can(:transfer, Epp::Domain) { |d, pw| d.auth_info == pw } can(:transfer, Epp::Domain) { |d, pw| d.transfer_code == pw }
can(:view_password, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw } can(:view_password, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.transfer_code == pw }
can(:delete, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw } can(:delete, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.transfer_code == pw }
# Epp::Contact # Epp::Contact
can(:info, Epp::Contact) { |c, pw| c.registrar_id == @user.registrar_id || pw.blank? ? true : c.auth_info == pw } can(:info, Epp::Contact) { |c, pw| c.registrar_id == @user.registrar_id || pw.blank? ? true : c.auth_info == pw }

View file

@ -2,17 +2,17 @@ module Concerns::Domain::Transferable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
after_initialize :generate_auth_info, if: :new_record? after_initialize :generate_transfer_code, if: :new_record?
end end
def transfer(new_registrar) def transfer(new_registrar)
self.registrar = new_registrar self.registrar = new_registrar
generate_auth_info generate_transfer_code
end end
private private
def generate_auth_info def generate_transfer_code
self.auth_info = SecureRandom.hex self.transfer_code = SecureRandom.hex
end end
end end

View file

@ -100,7 +100,7 @@ class Epp::Domain < Domain
[:puny_label, :too_long, { obj: 'name', val: name_puny }] [:puny_label, :too_long, { obj: 'name', val: name_puny }]
], ],
'2201' => [ # Authorisation error '2201' => [ # Authorisation error
[:auth_info, :wrong_pw] [:transfer_code, :wrong_pw]
], ],
'2202' => [ '2202' => [
[:base, :invalid_auth_information_reserved] [:base, :invalid_auth_information_reserved]
@ -182,7 +182,7 @@ class Epp::Domain < Domain
# at[:domain_statuses_attributes] = domain_statuses_attrs(frame, action) # at[:domain_statuses_attributes] = domain_statuses_attrs(frame, action)
pw = frame.css('authInfo > pw').text pw = frame.css('authInfo > pw').text
at[:auth_info] = pw if pw.present? at[:transfer_code] = pw if pw.present?
if new_record? if new_record?
dnskey_frame = frame.css('extension create') dnskey_frame = frame.css('extension create')
@ -722,7 +722,7 @@ class Epp::Domain < Domain
if dt.approved? if dt.approved?
transfer_contacts(current_user.registrar_id) transfer_contacts(current_user.registrar_id)
dt.notify_losing_registrar(old_contact_codes, old_registrant_code) dt.notify_losing_registrar(old_contact_codes, old_registrant_code)
generate_auth_info generate_transfer_code
self.registrar = current_user.registrar self.registrar = current_user.registrar
end end
@ -751,7 +751,7 @@ class Epp::Domain < Domain
) )
transfer_contacts(pt.transfer_to_id) transfer_contacts(pt.transfer_to_id)
generate_auth_info generate_transfer_code
self.registrar = pt.transfer_to self.registrar = pt.transfer_to
attach_legal_document(self.class.parse_legal_document_from_frame(frame)) attach_legal_document(self.class.parse_legal_document_from_frame(frame))
@ -872,7 +872,7 @@ class Epp::Domain < Domain
# For domain transfer # For domain transfer
def authenticate(pw) def authenticate(pw)
errors.add(:auth_info, :wrong_pw) if pw != auth_info errors.add(:transfer_code, :wrong_pw) if pw != transfer_code
errors.empty? errors.empty?
end end

View file

@ -1,5 +1,5 @@
class DomainPresenter class DomainPresenter
delegate :name, :auth_info, :registrant_name, :registrant_id, :registrant_code, to: :domain delegate :name, :transfer_code, :registrant_name, :registrant_id, :registrant_code, to: :domain
def initialize(domain:, view:) def initialize(domain:, view:)
@domain = domain @domain = domain

View file

@ -19,7 +19,7 @@ class Registrar::DomainListCSVPresenter
def header def header
columns = %w( columns = %w(
domain_name domain_name
auth_info transfer_code
registrant_name registrant_name
registrant_code registrant_code
expire_time expire_time
@ -33,7 +33,7 @@ class Registrar::DomainListCSVPresenter
def domain_to_row(domain:) def domain_to_row(domain:)
row = [] row = []
row[0] = domain.name row[0] = domain.name
row[1] = domain.auth_info row[1] = domain.transfer_code
row[2] = domain.registrant_name row[2] = domain.registrant_name
row[3] = domain.registrant_code row[3] = domain.registrant_code
row[4] = domain.expire_date row[4] = domain.expire_date

View file

@ -16,9 +16,9 @@
<dt><%= t(:registrar_name) %></dt> <dt><%= t(:registrar_name) %></dt>
<dd><%= link_to(@domain.registrar, admin_registrar_path(@domain.registrar)) %></dd> <dd><%= link_to(@domain.registrar, admin_registrar_path(@domain.registrar)) %></dd>
<dt><%= Domain.human_attribute_name :auth_info %></dt> <dt><%= Domain.human_attribute_name :transfer_code %></dt>
<dd> <dd>
<%= tag :input, type: 'text', value: @domain.auth_info, readonly: true, <%= tag :input, type: 'text', value: @domain.transfer_code, readonly: true,
class: 'form-control input-sm' %> class: 'form-control input-sm' %>
</dd> </dd>

View file

@ -55,7 +55,7 @@ xml.epp_head do
if can? :view_password, @domain, @password if can? :view_password, @domain, @password
xml.tag!('domain:authInfo') do xml.tag!('domain:authInfo') do
xml.tag!('domain:pw', @domain.auth_info) xml.tag!('domain:pw', @domain.transfer_code)
end end
end end
end end

View file

@ -16,9 +16,9 @@
<dt><%= t(:registrar_name) %></dt> <dt><%= t(:registrar_name) %></dt>
<dd><%= link_to(@domain.registrar, registrant_registrar_path(@domain.registrar)) %></dd> <dd><%= link_to(@domain.registrar, registrant_registrar_path(@domain.registrar)) %></dd>
<dt><%= Domain.human_attribute_name :auth_info %></dt> <dt><%= Domain.human_attribute_name :transfer_code %></dt>
<dd> <dd>
<%= tag :input, type: 'text', value: @domain.auth_info, readonly: true, <%= tag :input, type: 'text', value: @domain.transfer_code, readonly: true,
class: 'form-control input-sm' %> class: 'form-control input-sm' %>
</dd> </dd>

View file

@ -7,7 +7,7 @@
<div class="panel-body"> <div class="panel-body">
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt><%= Domain.human_attribute_name :auth_info %></dt> <dt><%= Domain.human_attribute_name :transfer_code %></dt>
<dd> <dd>
<% if @data.css('pw').text.present? %> <% if @data.css('pw').text.present? %>
<%= tag(:input, type: 'text', value: @data.css('pw').text, readonly: true, <%= tag(:input, type: 'text', value: @data.css('pw').text, readonly: true,

View file

@ -79,7 +79,7 @@ en:
period: period:
not_a_number: 'Period is not a number' not_a_number: 'Period is not a number'
not_an_integer: 'Period must be an integer' not_an_integer: 'Period must be an integer'
auth_info: transfer_code:
wrong_pw: 'Authorization error' wrong_pw: 'Authorization error'
domain_statuses: domain_statuses:
invalid: 'Statuses are invalid' invalid: 'Statuses are invalid'

View file

@ -7,7 +7,7 @@ en:
transfer_btn: Transfer transfer_btn: Transfer
csv: csv:
domain_name: Domain domain_name: Domain
auth_info: Auth info transfer_code: Transfer code
registrant_name: Registrant name registrant_name: Registrant name
registrant_code: Registrant code registrant_code: Registrant code
expire_time: Date of expiry expire_time: Date of expiry

View file

@ -0,0 +1,5 @@
class RenameDomainsAuthInfoToTransferCode < ActiveRecord::Migration
def change
rename_column :domains, :auth_info, :transfer_code
end
end

View file

@ -998,7 +998,7 @@ CREATE TABLE domains (
valid_from timestamp without time zone, valid_from timestamp without time zone,
valid_to timestamp without time zone, valid_to timestamp without time zone,
registrant_id integer NOT NULL, registrant_id integer NOT NULL,
auth_info character varying, transfer_code character varying,
created_at timestamp without time zone, created_at timestamp without time zone,
updated_at timestamp without time zone, updated_at timestamp without time zone,
name_dirty character varying, name_dirty character varying,
@ -5046,3 +5046,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180120182712');
INSERT INTO schema_migrations (version) VALUES ('20180120183441'); INSERT INTO schema_migrations (version) VALUES ('20180120183441');
INSERT INTO schema_migrations (version) VALUES ('20180121165304');

View file

@ -921,7 +921,7 @@
<text text-anchor="start" x="1958.5" y="-2136.3" font-family="Times,serif" font-size="14.00">valid_from :datetime</text> <text text-anchor="start" x="1958.5" y="-2136.3" font-family="Times,serif" font-size="14.00">valid_from :datetime</text>
<text text-anchor="start" x="1958.5" y="-2121.3" font-family="Times,serif" font-size="14.00">valid_to :datetime</text> <text text-anchor="start" x="1958.5" y="-2121.3" font-family="Times,serif" font-size="14.00">valid_to :datetime</text>
<text text-anchor="start" x="1958.5" y="-2106.3" font-family="Times,serif" font-size="14.00">registrant_id :integer</text> <text text-anchor="start" x="1958.5" y="-2106.3" font-family="Times,serif" font-size="14.00">registrant_id :integer</text>
<text text-anchor="start" x="1958.5" y="-2091.3" font-family="Times,serif" font-size="14.00">auth_info :string</text> <text text-anchor="start" x="1958.5" y="-2091.3" font-family="Times,serif" font-size="14.00">transfer_code :string</text>
<text text-anchor="start" x="1958.5" y="-2076.3" font-family="Times,serif" font-size="14.00">created_at :datetime</text> <text text-anchor="start" x="1958.5" y="-2076.3" font-family="Times,serif" font-size="14.00">created_at :datetime</text>
<text text-anchor="start" x="1958.5" y="-2061.3" font-family="Times,serif" font-size="14.00">updated_at :datetime</text> <text text-anchor="start" x="1958.5" y="-2061.3" font-family="Times,serif" font-size="14.00">updated_at :datetime</text>
<text text-anchor="start" x="1958.5" y="-2046.3" font-family="Times,serif" font-size="14.00">name_dirty :string</text> <text text-anchor="start" x="1958.5" y="-2046.3" font-family="Times,serif" font-size="14.00">name_dirty :string</text>

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 228 KiB

Before After
Before After

View file

@ -39,7 +39,7 @@ Content-Type: application/json
"valid_from": "2015-09-09T09:11:14.861Z", "valid_from": "2015-09-09T09:11:14.861Z",
"valid_to": "2016-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z",
"registrant_id": 1, "registrant_id": 1,
"auth_info": "98oiewslkfkd", "transfer_code": "98oiewslkfkd",
"created_at": "2015-09-09T09:11:14.861Z", "created_at": "2015-09-09T09:11:14.861Z",
"updated_at": "2015-09-09T09:11:14.860Z", "updated_at": "2015-09-09T09:11:14.860Z",
"name_dirty": "domain0.ee", "name_dirty": "domain0.ee",

View file

@ -340,7 +340,7 @@ namespace :import do
registered_at registered_at
valid_from valid_from
valid_to valid_to
auth_info transfer_code
created_at created_at
updated_at updated_at
name_dirty name_dirty

View file

@ -151,7 +151,7 @@ RSpec.describe DomainPresenter do
domain_delegatable_attributes = %i( domain_delegatable_attributes = %i(
name name
auth_info transfer_code
registrant_name registrant_name
registrant_id registrant_id
registrant_code registrant_code

View file

@ -2,7 +2,7 @@ require 'test_helper'
class Repp::DomainTransfersTest < ActionDispatch::IntegrationTest class Repp::DomainTransfersTest < ActionDispatch::IntegrationTest
def test_post_to_domain_transfers def test_post_to_domain_transfers
request_params = { format: :json, domainTransfers: [{ domainName: domains(:shop).name, authInfo: domains(:shop).auth_info }] } request_params = { format: :json, domainTransfers: [{ domainName: domains(:shop).name, transferCode: domains(:shop).transfer_code }] }
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :created assert_response :created

View file

@ -3,7 +3,7 @@ shop:
name_dirty: shop.test name_dirty: shop.test
registrar: bestnames registrar: bestnames
registrant: john registrant: john
auth_info: 65078d5 transfer_code: 65078d5
valid_to: 2010-07-05 valid_to: 2010-07-05
period: 1 period: 1
period_unit: m period_unit: m
@ -13,7 +13,7 @@ airport:
name_dirty: airport.test name_dirty: airport.test
registrar: bestnames registrar: bestnames
registrant: john registrant: john
auth_info: 55438j5 transfer_code: 55438j5
valid_to: 2010-07-05 valid_to: 2010-07-05
period: 1 period: 1
period_unit: m period_unit: m
@ -23,7 +23,7 @@ library:
name_dirty: library.test name_dirty: library.test
registrar: bestnames registrar: bestnames
registrant: acme_ltd registrant: acme_ltd
auth_info: 45118f5 transfer_code: 45118f5
valid_to: 2010-07-05 valid_to: 2010-07-05
period: 1 period: 1
period_unit: m period_unit: m

View file

@ -7,7 +7,7 @@ class RegistrarDomainsTest < ActionDispatch::IntegrationTest
def test_downloads_domain_list_as_csv def test_downloads_domain_list_as_csv
expected_csv = <<-CSV.strip_heredoc expected_csv = <<-CSV.strip_heredoc
Domain,Auth info,Registrant name,Registrant code,Date of expiry Domain,Transfer code,Registrant name,Registrant code,Date of expiry
library.test,45118f5,Acme Ltd,acme-ltd-001,2010-07-05 library.test,45118f5,Acme Ltd,acme-ltd-001,2010-07-05
shop.test,65078d5,John,john-001,2010-07-05 shop.test,65078d5,John,john-001,2010-07-05
airport.test,55438j5,John,john-001,2010-07-05 airport.test,55438j5,John,john-001,2010-07-05

View file

@ -9,28 +9,28 @@ class DomainTest < ActiveSupport::TestCase
assert @domain.valid? assert @domain.valid?
end end
def test_generates_random_auth_info_if_new def test_generates_random_transfer_code_if_new
domain = Domain.new domain = Domain.new
another_domain = Domain.new another_domain = Domain.new
refute_empty domain.auth_info refute_empty domain.transfer_code
refute_empty another_domain.auth_info refute_empty another_domain.transfer_code
refute_equal domain.auth_info, another_domain.auth_info refute_equal domain.transfer_code, another_domain.transfer_code
end end
def test_does_not_regenerate_auth_info_if_persisted def test_does_not_regenerate_transfer_code_if_persisted
original_auth_info = @domain.auth_info original_transfer_code = @domain.transfer_code
@domain.save! @domain.save!
@domain.reload @domain.reload
assert_equal original_auth_info, @domain.auth_info assert_equal original_transfer_code, @domain.transfer_code
end end
def test_transfers_domain def test_transfers_domain
old_auth_info = @domain.auth_info old_transfer_code = @domain.transfer_code
new_registrar = registrars(:goodnames) new_registrar = registrars(:goodnames)
@domain.transfer(new_registrar) @domain.transfer(new_registrar)
assert_equal new_registrar, @domain.registrar assert_equal new_registrar, @domain.registrar
refute_same @domain.auth_info, old_auth_info refute_same @domain.transfer_code, old_transfer_code
end end
end end