From 65a749edc8214f995d89117d86cb42e0a10b0a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 27 Jul 2020 11:47:49 +0300 Subject: [PATCH 01/21] Reference LHV branch without keystores gem --- Gemfile | 2 +- Gemfile.lock | 6 ++---- test/fixtures/files/keystore.jks | Bin 2242 -> 0 bytes test/fixtures/files/keystore.p12 | Bin 0 -> 2579 bytes 4 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 test/fixtures/files/keystore.jks create mode 100644 test/fixtures/files/keystore.p12 diff --git a/Gemfile b/Gemfile index 99091f556..b78d2edbd 100644 --- a/Gemfile +++ b/Gemfile @@ -66,7 +66,7 @@ gem 'airbrake' gem 'company_register', github: 'internetee/company_register', branch: :master gem 'e_invoice', github: 'internetee/e_invoice', branch: :master -gem 'lhv', github: 'internetee/lhv', branch: :master +gem 'lhv', github: 'internetee/lhv', branch: 'remove-keystores-gem' gem 'domain_name' gem 'haml', '~> 5.0' gem 'wkhtmltopdf-binary', '~> 0.12.5.1' diff --git a/Gemfile.lock b/Gemfile.lock index e4ad26396..8d303b602 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,11 +45,10 @@ GIT GIT remote: https://github.com/internetee/lhv.git - revision: c53dd82393f8a81f6e9da793ae0474294ef88762 - branch: master + revision: af0d3127bed6606ac50c44696bd56b09c096ac39 + branch: remove-keystores-gem specs: lhv (0.1.0) - keystores logger nokogiri @@ -266,7 +265,6 @@ GEM activerecord kaminari-core (= 1.2.1) kaminari-core (1.2.1) - keystores (0.4.0) libxml-ruby (3.2.0) listen (3.2.1) rb-fsevent (~> 0.10, >= 0.10.3) diff --git a/test/fixtures/files/keystore.jks b/test/fixtures/files/keystore.jks deleted file mode 100644 index 7ce34f308d5df462a90842275cecdb54f6fef5ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2242 zcmchYS5VW58pZQZLP(@ZS%UNuFrY|6LRG4iD1wq0dJ}1yEU+NLg0$c!2ulf|$fAgV zFiLMqk!I*62uKqaM2Sj?2rMAg%iX#6&d&ILAI`)1J$-ZL%=r$u2V4*c1U?k-x1cw? zgKr!f>Pyl0L^j;iLMA?U*BE~Ic;{x7h$jG9xLQl zEzf4?w3~P(#%`%9y4NkX&Mmv5{cwiOwEjUOHgSO4@3);~;NGbBGcU~}j@`!hx%C;> z=RhHW5n>z~0A}&`?W}|?aOro0F8hM%aw*mO6hCGxHwe`gy-A`;+SEp=m7W^p zbwahjtHdIDE=fzybMOsN7cJ?#7Ahwg=NX{5}TD6;Lvy z7Os_>s#^6z?aT-am7w(*K1nm1EY8X0CYVp6wErEKuT@fJe+o3m`a<62c_s<7)pXwT zkLJp6Gf;gZI={L0Oe?p@Q1`E-9_TKH2G$(AQBfz(-@+B<6{&YxJ&$Ycx}>`*qSNTU zRD1%e_y+kzaA!DY#D@fC$)93*31Nd7vb4(Pa1)1L=2NSlpVj|fp{ID;48bxOEGJc# z&|w6c$g`V6u$at-0hNeeLHwB9lkr zEa~?_p9ZuGhZeY#BYuGw&}L}d*WLpPJc~IBs(Y458frZRhq6Sw`os7CzE3=$G5j_ z)lPm;YTDN0PFu`&246nEvaZ>JsYE z$-JO@&KBOSoD=3EKA%?TNiiDzBrbUEcBXt>BMviGdwQYJY9f8Fq~q7gSJX2Qjbzyv zza<}rbuyx1v3S_>Sxj`ey~#VtO;jtks30`l@TT$BL>tN7*#=row+$)ru7x_66I>

#;q z{e!G#eTxM{)FBS`iFc>N-=rDy5fFacA1p1Z$0PyjEFjVZ(!^wn@p)gTivOmQ?Ak_cA z1pWiz{ec|$f$;r6Apav6S)>3~52K6G!)jvma5$%bTPzl%^B?-U{xgolZvmkJ zLLdwcI0B{t0H`<|noSsbGSgf^RB(R3ahG2w6`Hmn|2y68+Il3ab<3>Yx)r=C*2Lc; zSJe|}4Tb<9AYTC^hmkpKh>Rdq94bbTugp$HuJtr#9gmW^IaO_Iq+jyS5Dz8RpAbE^Tlwo4qKM zVb9M-4#zpJ8Vt>jf?S#-QX|O;3$3c_Dgo&P?W>!NK4XM+j*FLhFcByWm9spjPK?JZ Q*B=|e+h($ diff --git a/test/fixtures/files/keystore.p12 b/test/fixtures/files/keystore.p12 new file mode 100644 index 0000000000000000000000000000000000000000..962ddede2ae754b1ca56a2967b800799ba2d0194 GIT binary patch literal 2579 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 Date: Mon, 27 Jul 2020 11:48:51 +0300 Subject: [PATCH 02/21] Replace LHV JKS store with P12 --- config/application.yml.sample | 6 ++---- .../create_bank_transactions.rake | 11 ++++------- lib/tasks/invoices/process_payments.rake | 11 ++++------- test/tasks/invoices/process_payments_test.rb | 6 ++++++ 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/config/application.yml.sample b/config/application.yml.sample index 691740b2a..7fd92d092 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -148,9 +148,8 @@ action_mailer_default_port: # default: no port (80) action_mailer_default_from: # no-reply@example.com action_mailer_force_delete_from: # `From` header for `DomainDeleteMailer#forced` email -lhv_keystore: +lhv_p12_keystore: lhv_keystore_password: -lhv_keystore_alias: lhv_ca_file: # Needed only in dev mode lhv_dev_mode: 'false' @@ -163,9 +162,8 @@ test: action_mailer_default_host: 'registry.test' action_mailer_default_from: 'no-reply@registry.test' action_mailer_force_delete_from: 'legal@registry.test' - lhv_keystore: 'test/fixtures/files/keystore.jks' + lhv_p12_keystore: 'test/fixtures/files/keystore.p12' lhv_keystore_password: 'testtest' - lhv_keystore_alias: 'testtest' # Airbrake // Errbit: airbrake_host: "https://your-errbit-host.ee" diff --git a/lib/tasks/dev/create_bank_transactions/create_bank_transactions.rake b/lib/tasks/dev/create_bank_transactions/create_bank_transactions.rake index 33614d049..17b7586e2 100644 --- a/lib/tasks/dev/create_bank_transactions/create_bank_transactions.rake +++ b/lib/tasks/dev/create_bank_transactions/create_bank_transactions.rake @@ -3,12 +3,9 @@ namespace :dev do remitter_iban = ENV['remitter_iban'] beneficiary_iban = Setting.registry_iban - keystore_password = ENV['lhv_keystore_password'] - keystore_alias = ENV['lhv_keystore_alias'] - keystore = Keystores::JavaKeystore.new - keystore.load(ENV['lhv_keystore'], keystore_password) - cert = keystore.get_certificate(keystore_alias) - key = keystore.get_key(keystore_alias, keystore_password) + keystore = OpenSSL::PKCS12.new(File.read(ENV['lhv_p12_keystore']), ENV['lhv_keystore_password']) + key = keystore.key + cert = keystore.certificate api_base_uri = URI.parse('https://testconnect.lhv.eu/connect-prelive') request_headers = { 'content-type' => 'application/xml' } @@ -38,4 +35,4 @@ namespace :dev do end end end -end \ No newline at end of file +end diff --git a/lib/tasks/invoices/process_payments.rake b/lib/tasks/invoices/process_payments.rake index 6e4c57213..340aba187 100644 --- a/lib/tasks/invoices/process_payments.rake +++ b/lib/tasks/invoices/process_payments.rake @@ -2,12 +2,9 @@ namespace :invoices do task process_payments: :environment do registry_bank_account_iban = Setting.registry_iban - keystore_password = ENV['lhv_keystore_password'] - keystore_alias = ENV['lhv_keystore_alias'] - keystore = Keystores::JavaKeystore.new - keystore.load(ENV['lhv_keystore'], keystore_password) - cert = keystore.get_certificate(keystore_alias) - key = keystore.get_key(keystore_alias, keystore_password) + keystore = OpenSSL::PKCS12.new(File.read(ENV['lhv_p12_keystore']), ENV['lhv_keystore_password']) + key = keystore.key + cert = keystore.certificate api = Lhv::ConnectApi.new api.cert = cert @@ -46,4 +43,4 @@ namespace :invoices do puts "Transactions processed: #{incoming_transactions.size}" end -end \ No newline at end of file +end diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index 02855e9fa..bd447be29 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -88,6 +88,12 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase end end + def test_parses_keystore_properly + assert_nothing_raised do + run_task + end + end + private def run_task From 3b53e122845c395d87a57847644068982c67d881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 10 Aug 2020 12:47:02 +0300 Subject: [PATCH 03/21] Clear contact address fields if address processing turned off --- app/models/contact.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/models/contact.rb b/app/models/contact.rb index ac64b059f..e91dab3b5 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -62,6 +62,7 @@ class Contact < ApplicationRecord mapping: [%w[ident code], %w[ident_type type], %w[ident_country_code country_code]] after_save :update_related_whois_records + before_save :clear_address_modifications, if: -> { !self.class.address_processing? } self.ignored_columns = %w[legacy_id legacy_history_id] @@ -507,6 +508,21 @@ class Contact < ApplicationRecord ]).present? end + def clear_address_modifications + return unless modifies_address? + + addr_fields = %i[city street zip state country_code] + addr_fields.each { |field| self[field] = nil } + end + + def modifies_address? + addr_fields = %i[city street zip state country_code] + modified = false + addr_fields.each { |field| modified = true if changes.key?(field) } + + modified + end + def update_related_whois_records # not doing anything if no real changes ignored_columns = %w[updated_at created_at statuses status_notes] From 1bc0ec07d38b39c86875780473775fa1f80d353e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 10 Aug 2020 13:59:50 +0300 Subject: [PATCH 04/21] Fix registrant API test --- test/integration/api/v1/registrant/contacts/update_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/api/v1/registrant/contacts/update_test.rb b/test/integration/api/v1/registrant/contacts/update_test.rb index 6e0c0eea3..e2e9abe9a 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -91,8 +91,8 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest end def test_address_is_optional_when_enabled - @contact.update!(street: 'any', zip: 'any', city: 'any', state: 'any', country_code: 'US') Setting.address_processing = true + @contact.update!(street: 'any', zip: 'any', city: 'any', state: 'any', country_code: 'US') patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'any' }, as: :json, From 55ae0dc0b785e1a3fd3c514e215dd353039ab59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 10 Aug 2020 14:05:22 +0300 Subject: [PATCH 05/21] Remove redundant functions --- app/models/contact.rb | 6 ++---- test/models/contact_test.rb | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index e91dab3b5..a2057f229 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -511,14 +511,12 @@ class Contact < ApplicationRecord def clear_address_modifications return unless modifies_address? - addr_fields = %i[city street zip state country_code] - addr_fields.each { |field| self[field] = nil } + remove_address end def modifies_address? - addr_fields = %i[city street zip state country_code] modified = false - addr_fields.each { |field| modified = true if changes.key?(field) } + self.class.address_attribute_names.each { |field| modified = true if changes.key?(field) } modified end diff --git a/test/models/contact_test.rb b/test/models/contact_test.rb index f833011c6..48b98a0d2 100644 --- a/test/models/contact_test.rb +++ b/test/models/contact_test.rb @@ -152,6 +152,8 @@ class ContactTest < ActiveSupport::TestCase end def test_address + Setting.address_processing = true + address = Contact::Address.new('new street', '83746', 'new city', 'new state', 'EE') @contact.address = address @contact.save! From 625bd459de045ae7f923acefc47b81e57a10164b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 10 Aug 2020 14:27:05 +0300 Subject: [PATCH 06/21] Explicitly set address_processing to false in tests --- test/test_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index bee6fdcf9..1b70baf49 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -47,6 +47,7 @@ class ActiveSupport::TestCase teardown do travel_back + Setting.address_processing = false end end @@ -60,9 +61,14 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest WebMock.reset! Capybara.reset_sessions! Capybara.use_default_driver + Setting.address_processing = false end end class EppTestCase < ActionDispatch::IntegrationTest include Assertions::EppAssertions + + teardown do + Setting.address_processing = false + end end From 8f8b246e493779503dd7c19e6c13d9ff51d093d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 10 Aug 2020 16:04:02 +0300 Subject: [PATCH 07/21] Query address mandatoryness via Contact.address_processing? --- app/models/actions/contact_update.rb | 2 +- app/models/contact.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/actions/contact_update.rb b/app/models/actions/contact_update.rb index 5b94cf918..f8b39ecb4 100644 --- a/app/models/actions/contact_update.rb +++ b/app/models/actions/contact_update.rb @@ -23,7 +23,7 @@ module Actions end def maybe_remove_address - return if Setting.address_processing? + return if Contact.address_processing? new_attributes.delete(:city) new_attributes.delete(:zip) diff --git a/app/models/contact.rb b/app/models/contact.rb index a2057f229..4199e6dc7 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -62,7 +62,7 @@ class Contact < ApplicationRecord mapping: [%w[ident code], %w[ident_type type], %w[ident_country_code country_code]] after_save :update_related_whois_records - before_save :clear_address_modifications, if: -> { !self.class.address_processing? } + before_validation :clear_address_modifications, if: -> { !self.class.address_processing? } self.ignored_columns = %w[legacy_id legacy_history_id] From e40353042e7d509c9b1196db1f7d9a9b75296ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 10 Aug 2020 16:04:52 +0300 Subject: [PATCH 08/21] Include tests for EPP contact create/update actions regarding to addressing --- app/models/epp/response/result/code.rb | 1 + .../epp/contact/create/base_test.rb | 111 ++++++++++++++++++ .../epp/contact/update/base_test.rb | 93 +++++++++++++++ 3 files changed, 205 insertions(+) diff --git a/app/models/epp/response/result/code.rb b/app/models/epp/response/result/code.rb index 2a65f6747..e2af0823d 100644 --- a/app/models/epp/response/result/code.rb +++ b/app/models/epp/response/result/code.rb @@ -7,6 +7,7 @@ module Epp KEY_TO_VALUE = { completed_successfully: 1000, completed_successfully_action_pending: 1001, + completed_without_address: 1100, completed_successfully_no_messages: 1300, completed_successfully_ack_to_dequeue: 1301, completed_successfully_ending_session: 1500, diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb index e9a59b8d2..262487a1e 100644 --- a/test/integration/epp/contact/create/base_test.rb +++ b/test/integration/epp/contact/create/base_test.rb @@ -140,4 +140,115 @@ class EppContactCreateBaseTest < EppTestCase end assert_epp_response :required_parameter_missing end + + def test_does_not_save_address_when_address_processing_turned_off + name = 'new' + email = 'new@registrar.test' + phone = '+1.2' + + request_xml = <<-XML + + + + + + + #{name} + + 123 Example + Tallinn + FFF + 123456 + EE + + + #{phone} + #{email} + + + + + 123 + + + + + XML + + assert_difference 'Contact.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :completed_without_address + contact = Contact.find_by(name: name) + assert_equal name, contact.name + assert_equal email, contact.email + assert_equal phone, contact.phone + assert_not_empty contact.code + assert_nil contact.city + assert_nil contact.street + assert_nil contact.zip + assert_nil contact.country_code + assert_nil contact.state + end + + def test_saves_address_when_address_processing_turned_on + Setting.address_processing = true + + name = 'new' + email = 'new@registrar.test' + phone = '+1.2' + street = '123 Example' + city = 'Tallinn' + state = 'Harjumaa' + zip = '123456' + country_code = 'EE' + + request_xml = <<-XML + + + + + + + #{name} + + #{street} + #{city} + #{state} + #{zip} + #{country_code} + + + #{phone} + #{email} + + + + + 123 + + + + + XML + + assert_difference 'Contact.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :completed_successfully + contact = Contact.find_by(name: name) + assert_equal name, contact.name + assert_equal email, contact.email + assert_equal phone, contact.phone + assert_not_empty contact.code + assert_equal city, contact.city + assert_equal street, contact.street + assert_equal zip, contact.zip + assert_equal country_code, contact.country_code + assert_equal state, contact.state + end end diff --git a/test/integration/epp/contact/update/base_test.rb b/test/integration/epp/contact/update/base_test.rb index 3d332711f..98c0e4462 100644 --- a/test/integration/epp/contact/update/base_test.rb +++ b/test/integration/epp/contact/update/base_test.rb @@ -232,6 +232,99 @@ class EppContactUpdateBaseTest < EppTestCase assert_epp_response :completed_successfully end + def test_updates_address_when_address_processing_turned_on + @contact.update_columns(code: @contact.code.upcase) + Setting.address_processing = true + + street = '123 Example' + city = 'Tallinn' + state = 'Harjumaa' + zip = '123456' + country_code = 'EE' + + request_xml = <<-XML + + + + + + #{@contact.code} + + + + #{street} + #{city} + #{state} + #{zip} + #{country_code} + + + + + + + + XML + + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_epp_response :completed_successfully + @contact.reload + + assert_equal city, @contact.city + assert_equal street, @contact.street + assert_equal zip, @contact.zip + assert_equal country_code, @contact.country_code + assert_equal state, @contact.state + end + + def test_does_not_update_address_when_address_processing_turned_off + @contact.update_columns(code: @contact.code.upcase) + + street = '123 Example' + city = 'Tallinn' + state = 'Harjumaa' + zip = '123456' + country_code = 'EE' + + request_xml = <<-XML + + + + + + #{@contact.code} + + + + #{street} + #{city} + #{state} + #{zip} + #{country_code} + + + + + + + + XML + + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_epp_response :completed_without_address + @contact.reload + + assert_nil @contact.city + assert_nil @contact.street + assert_nil @contact.zip + assert_nil @contact.country_code + assert_nil @contact.state + end + private def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact) From 414519d17fa76363b1077cdaaa8dfa65f10056a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 10 Aug 2020 16:13:35 +0300 Subject: [PATCH 09/21] Improve addressing tests --- app/models/epp/response/result/code.rb | 1 + test/models/contact_test.rb | 1 + test/models/epp/response/result/code_test.rb | 2 ++ 3 files changed, 4 insertions(+) diff --git a/app/models/epp/response/result/code.rb b/app/models/epp/response/result/code.rb index e2af0823d..1be4a3f7c 100644 --- a/app/models/epp/response/result/code.rb +++ b/app/models/epp/response/result/code.rb @@ -36,6 +36,7 @@ module Epp DEFAULT_DESCRIPTIONS = { 1000 => 'Command completed successfully', 1001 => 'Command completed successfully; action pending', + 1100 => 'Command completed successfully; Postal address data discarded', 1300 => 'Command completed successfully; no messages', 1301 => 'Command completed successfully; ack to dequeue', 1500 => 'Command completed successfully; ending session', diff --git a/test/models/contact_test.rb b/test/models/contact_test.rb index 48b98a0d2..000333d57 100644 --- a/test/models/contact_test.rb +++ b/test/models/contact_test.rb @@ -240,6 +240,7 @@ class ContactTest < ActiveSupport::TestCase end def test_normalizes_country_code + Setting.address_processing = true contact = Contact.new(country_code: 'us') contact.validate assert_equal 'US', contact.country_code diff --git a/test/models/epp/response/result/code_test.rb b/test/models/epp/response/result/code_test.rb index 3c75303f1..f16013180 100644 --- a/test/models/epp/response/result/code_test.rb +++ b/test/models/epp/response/result/code_test.rb @@ -28,6 +28,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase codes = { completed_successfully: 1000, completed_successfully_action_pending: 1001, + completed_without_address: 1100, completed_successfully_no_messages: 1300, completed_successfully_ack_to_dequeue: 1301, completed_successfully_ending_session: 1500, @@ -58,6 +59,7 @@ class EppResponseResultCodeTest < ActiveSupport::TestCase descriptions = { 1000 => 'Command completed successfully', 1001 => 'Command completed successfully; action pending', + 1100 => 'Command completed successfully; Postal address data discarded', 1300 => 'Command completed successfully; no messages', 1301 => 'Command completed successfully; ack to dequeue', 1500 => 'Command completed successfully; ending session', From 075b4900a05f75a84660a374361d6764c64ff505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 11 Aug 2020 13:37:30 +0300 Subject: [PATCH 10/21] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6a9ff66a..3ba471dc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +11.08.2020 +* FIxed postal address saving bug with disabled address processing [#1650](https://github.com/internetee/registry/issues/1650) + 07.08.2020 * Restored creator and updator strings to contacts and related object records [#1636](https://github.com/internetee/registry/issues/1636) * Security gem updates: sdoc to 1.1 and json to 2.3.1 [#1657](https://github.com/internetee/registry/pull/1657) From 7953b3f8dfcae5a3f5ef8e24d9fd82350c1005a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 13 Aug 2020 12:36:42 +0300 Subject: [PATCH 11/21] Create Whois Records for subzones --- app/jobs/update_whois_record_job.rb | 11 ++++- app/models/dns/zone.rb | 63 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/app/jobs/update_whois_record_job.rb b/app/jobs/update_whois_record_job.rb index 16f4e0e79..0cf07026d 100644 --- a/app/jobs/update_whois_record_job.rb +++ b/app/jobs/update_whois_record_job.rb @@ -8,10 +8,11 @@ class UpdateWhoisRecordJob < Que::Job when 'blocked' then BlockedDomain when 'domain' then Domain when 'disputed' then Dispute.active + when 'zone' then DNS::Zone end Array(names).each do |name| - record = klass.find_by(name: name) + record = klass == DNS::Zone ? klass.find_by(origin: name) : klass.find_by(name: name) if record send "update_#{type}", record else @@ -36,6 +37,10 @@ class UpdateWhoisRecordJob < Que::Job update_reserved(record) end + def update_zone(record) + update_reserved(record) + end + # 1. deleting own # 2. trying to regenerate reserved in order domain is still in the list def delete_domain(name) @@ -60,6 +65,10 @@ class UpdateWhoisRecordJob < Que::Job remove_status_from_whois(domain_name: name, domain_status: 'disputed') end + def delete_zone(name) + WhoisRecord.where(name: name).destroy_all + end + def remove_status_from_whois(domain_name:, domain_status:) Whois::Record.where(name: domain_name).each do |r| r.json['status'] = r.json['status'].delete_if { |status| status == domain_status } diff --git a/app/models/dns/zone.rb b/app/models/dns/zone.rb index a641c4e49..a7cbb924b 100644 --- a/app/models/dns/zone.rb +++ b/app/models/dns/zone.rb @@ -3,6 +3,8 @@ module DNS validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true } validates :origin, uniqueness: true + after_save :update_whois_record, if: :subzone? + after_destroy :update_whois_record, if: :subzone? before_destroy do throw(:abort) if used? @@ -43,5 +45,66 @@ module DNS def to_partial_path 'zone' end + + def subzone? + origin.include? '.' + end + + def update_whois_record + UpdateWhoisRecordJob.enqueue origin, 'zone' + end + + def generate_data + wr = Whois::Record.find_or_initialize_by(name: origin) + wr.json = generate_json + wr.save + end + + def generate_json + h = HashWithIndifferentAccess.new + + h[:disclaimer] = Setting.registry_whois_disclaimer if Setting.registry_whois_disclaimer + h[:name] = origin + h[:status] = ['ok (paid and in zone)'] + h[:registered] = created_at.try(:to_s, :iso8601) + h[:changed] = updated_at.try(:to_s, :iso8601) + h[:expire] = nil + h[:outzone] = nil + h[:delete] = nil + + h[:registrant] = Setting.registry_juridical_name + h[:registrant_kind] = 'org' + h[:registrant_reg_no] = Setting.registry_reg_no + h[:registrant_ident_country_code] = Setting.registry_country_code + + h[:email] = Setting.registry_email + h[:registrant_changed] = nil + h[:registrant_disclosed_attributes] = %w[name email], + + contact = { + name: Setting.registry_invoice_contact, + email: Setting.registry_email, + changed: nil, + disclosed_attributes: %w[name email], + } + + h[:admin_contacts] = [contact] + + h[:tech_contacts] = [contact] + + # update registar triggers when adding new attributes + h[:registrar] = Setting.registry_juridical_name + h[:registrar_website] = Setting.registry_url + h[:registrar_phone] = Setting.registry_phone + h[:registrar_changed] = nil + + h[:nameservers] = [master_nameserver] + h[:nameservers_changed] = nil + + h[:dnssec_keys] = [] + h[:dnssec_changed] = nil + + h + end end end From ca1f3a9a48dbf928bc7f83a5c8e7242f2e4f8448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 13 Aug 2020 13:14:03 +0300 Subject: [PATCH 12/21] Reference newer version of LHV gem --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index c20e18f26..7ad72f5fa 100644 --- a/Gemfile +++ b/Gemfile @@ -66,7 +66,7 @@ gem 'airbrake' gem 'company_register', github: 'internetee/company_register', branch: :master gem 'e_invoice', github: 'internetee/e_invoice', branch: :master -gem 'lhv', github: 'internetee/lhv', branch: 'remove-keystores-gem' +gem 'lhv', github: 'internetee/lhv', branch: 'master' gem 'domain_name' gem 'haml', '~> 5.0' gem 'wkhtmltopdf-binary', '~> 0.12.5.1' diff --git a/Gemfile.lock b/Gemfile.lock index 698d8ca1d..7b18612e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,8 +45,8 @@ GIT GIT remote: https://github.com/internetee/lhv.git - revision: af0d3127bed6606ac50c44696bd56b09c096ac39 - branch: remove-keystores-gem + revision: 1825240b3bf8b262418cc6c8ef7ed1aba386dd7d + branch: master specs: lhv (0.1.0) logger From fec622f9748ba60d14440f75fcf244ff133d83f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 13 Aug 2020 14:40:40 +0300 Subject: [PATCH 13/21] Update CHANGELOG.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ba471dc7..9bf7358d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ +13.08.2020 +* Removed keystore gem and replaced LHV JKS with PKCS12 [#1645](https://github.com/internetee/registry/issues/1645) + 11.08.2020 -* FIxed postal address saving bug with disabled address processing [#1650](https://github.com/internetee/registry/issues/1650) +* Fixed postal address saving bug with disabled address processing [#1650](https://github.com/internetee/registry/issues/1650) 07.08.2020 * Restored creator and updator strings to contacts and related object records [#1636](https://github.com/internetee/registry/issues/1636) From c9c90888bd473d37f8e69e24e326d633ac810baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 13 Aug 2020 13:10:25 +0300 Subject: [PATCH 14/21] Make code more readable --- app/jobs/update_whois_record_job.rb | 24 +++++++---- app/models/dns/zone.rb | 66 ++++++++++++----------------- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/app/jobs/update_whois_record_job.rb b/app/jobs/update_whois_record_job.rb index 0cf07026d..4d81a58cf 100644 --- a/app/jobs/update_whois_record_job.rb +++ b/app/jobs/update_whois_record_job.rb @@ -3,16 +3,10 @@ class UpdateWhoisRecordJob < Que::Job def run(names, type) ::PaperTrail.request.whodunnit = "job - #{self.class.name} - #{type}" - klass = case type - when 'reserved' then ReservedDomain - when 'blocked' then BlockedDomain - when 'domain' then Domain - when 'disputed' then Dispute.active - when 'zone' then DNS::Zone - end + klass = determine_class(type) Array(names).each do |name| - record = klass == DNS::Zone ? klass.find_by(origin: name) : klass.find_by(name: name) + record = find_record(klass, name) if record send "update_#{type}", record else @@ -21,6 +15,20 @@ class UpdateWhoisRecordJob < Que::Job end end + def find_record(klass, name) + klass == DNS::Zone ? klass.find_by(origin: name) : klass.find_by(name: name) + end + + def determine_class(type) + case type + when 'reserved' then ReservedDomain + when 'blocked' then BlockedDomain + when 'domain' then Domain + when 'disputed' then Dispute.active + when 'zone' then DNS::Zone + end + end + def update_domain(domain) domain.whois_record ? domain.whois_record.save : domain.create_whois_record end diff --git a/app/models/dns/zone.rb b/app/models/dns/zone.rb index a7cbb924b..dcaf32ab1 100644 --- a/app/models/dns/zone.rb +++ b/app/models/dns/zone.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DNS class Zone < ApplicationRecord validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true @@ -61,50 +63,36 @@ module DNS end def generate_json - h = HashWithIndifferentAccess.new + data = {}.with_indifferent_access + [domain_vars, registrar_vars, registrant_vars].each do |h| + data.merge!(h) + end - h[:disclaimer] = Setting.registry_whois_disclaimer if Setting.registry_whois_disclaimer - h[:name] = origin - h[:status] = ['ok (paid and in zone)'] - h[:registered] = created_at.try(:to_s, :iso8601) - h[:changed] = updated_at.try(:to_s, :iso8601) - h[:expire] = nil - h[:outzone] = nil - h[:delete] = nil + data + end - h[:registrant] = Setting.registry_juridical_name - h[:registrant_kind] = 'org' - h[:registrant_reg_no] = Setting.registry_reg_no - h[:registrant_ident_country_code] = Setting.registry_country_code + def domain_vars + { disclaimer: Setting.registry_whois_disclaimer, name: origin, + registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'], + changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email, + admin_contacts: [contact_vars], tech_contacts: [contact_vars], + nameservers: [master_nameserver] } + end - h[:email] = Setting.registry_email - h[:registrant_changed] = nil - h[:registrant_disclosed_attributes] = %w[name email], + def registrar_vars + { registrar: Setting.registry_juridical_name, registrar_website: Setting.registry_url, + registrar_phone: Setting.registry_phone } + end - contact = { - name: Setting.registry_invoice_contact, - email: Setting.registry_email, - changed: nil, - disclosed_attributes: %w[name email], - } + def registrant_vars + { registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no, + registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org', + registrant_disclosed_attributes: %w[name email] } + end - h[:admin_contacts] = [contact] - - h[:tech_contacts] = [contact] - - # update registar triggers when adding new attributes - h[:registrar] = Setting.registry_juridical_name - h[:registrar_website] = Setting.registry_url - h[:registrar_phone] = Setting.registry_phone - h[:registrar_changed] = nil - - h[:nameservers] = [master_nameserver] - h[:nameservers_changed] = nil - - h[:dnssec_keys] = [] - h[:dnssec_changed] = nil - - h + def contact_vars + { name: Setting.registry_invoice_contact, email: Setting.registry_email, + disclosed_attributes: %w[name email] } end end end From 7e640a376e250dfa0177de80e1428266f74d0c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 13 Aug 2020 16:04:23 +0300 Subject: [PATCH 15/21] Move DNS::Zone WHOIS info logic to concern --- app/models/concerns/zone/whois_queryable.rb | 59 +++++++++++++++++++++ app/models/dns/zone.rb | 50 +---------------- 2 files changed, 60 insertions(+), 49 deletions(-) create mode 100644 app/models/concerns/zone/whois_queryable.rb diff --git a/app/models/concerns/zone/whois_queryable.rb b/app/models/concerns/zone/whois_queryable.rb new file mode 100644 index 000000000..1a24dea54 --- /dev/null +++ b/app/models/concerns/zone/whois_queryable.rb @@ -0,0 +1,59 @@ +module Concerns + module Zone + module WhoisQueryable + extend ActiveSupport::Concern + + included do + after_save :update_whois_record, if: :subzone? + after_destroy :update_whois_record, if: :subzone? + end + + def subzone? + origin.include? '.' + end + + def update_whois_record + UpdateWhoisRecordJob.enqueue origin, 'zone' + end + + def generate_data + wr = Whois::Record.find_or_initialize_by(name: origin) + wr.json = generate_json + wr.save + end + + def generate_json + data = {}.with_indifferent_access + [domain_vars, registrar_vars, registrant_vars].each do |h| + data.merge!(h) + end + + data + end + + def domain_vars + { disclaimer: Setting.registry_whois_disclaimer, name: origin, + registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'], + changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email, + admin_contacts: [contact_vars], tech_contacts: [contact_vars], + nameservers: [master_nameserver] } + end + + def registrar_vars + { registrar: Setting.registry_juridical_name, registrar_website: Setting.registry_url, + registrar_phone: Setting.registry_phone } + end + + def registrant_vars + { registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no, + registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org', + registrant_disclosed_attributes: %w[name email] } + end + + def contact_vars + { name: Setting.registry_invoice_contact, email: Setting.registry_email, + disclosed_attributes: %w[name email] } + end + end + end +end diff --git a/app/models/dns/zone.rb b/app/models/dns/zone.rb index dcaf32ab1..31749d952 100644 --- a/app/models/dns/zone.rb +++ b/app/models/dns/zone.rb @@ -5,8 +5,7 @@ module DNS validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true } validates :origin, uniqueness: true - after_save :update_whois_record, if: :subzone? - after_destroy :update_whois_record, if: :subzone? + include Concerns::Zone::WhoisQueryable before_destroy do throw(:abort) if used? @@ -47,52 +46,5 @@ module DNS def to_partial_path 'zone' end - - def subzone? - origin.include? '.' - end - - def update_whois_record - UpdateWhoisRecordJob.enqueue origin, 'zone' - end - - def generate_data - wr = Whois::Record.find_or_initialize_by(name: origin) - wr.json = generate_json - wr.save - end - - def generate_json - data = {}.with_indifferent_access - [domain_vars, registrar_vars, registrant_vars].each do |h| - data.merge!(h) - end - - data - end - - def domain_vars - { disclaimer: Setting.registry_whois_disclaimer, name: origin, - registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'], - changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email, - admin_contacts: [contact_vars], tech_contacts: [contact_vars], - nameservers: [master_nameserver] } - end - - def registrar_vars - { registrar: Setting.registry_juridical_name, registrar_website: Setting.registry_url, - registrar_phone: Setting.registry_phone } - end - - def registrant_vars - { registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no, - registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org', - registrant_disclosed_attributes: %w[name email] } - end - - def contact_vars - { name: Setting.registry_invoice_contact, email: Setting.registry_email, - disclosed_attributes: %w[name email] } - end end end From 55de10a53de6fd8d73cf92d12c74531bbb99c6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 13 Aug 2020 16:59:35 +0300 Subject: [PATCH 16/21] Ensure that Whois record is updated/destroyed when actions performed on Zone objects --- app/jobs/update_whois_record_job.rb | 1 + app/models/concerns/zone/whois_queryable.rb | 2 +- test/fixtures/dns/zones.yml | 9 ++++++++ test/models/dns/zone_test.rb | 25 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/jobs/update_whois_record_job.rb b/app/jobs/update_whois_record_job.rb index 4d81a58cf..2973d5a6b 100644 --- a/app/jobs/update_whois_record_job.rb +++ b/app/jobs/update_whois_record_job.rb @@ -75,6 +75,7 @@ class UpdateWhoisRecordJob < Que::Job def delete_zone(name) WhoisRecord.where(name: name).destroy_all + Whois::Record.where(name: name).destroy_all end def remove_status_from_whois(domain_name:, domain_status:) diff --git a/app/models/concerns/zone/whois_queryable.rb b/app/models/concerns/zone/whois_queryable.rb index 1a24dea54..970ce87d6 100644 --- a/app/models/concerns/zone/whois_queryable.rb +++ b/app/models/concerns/zone/whois_queryable.rb @@ -5,7 +5,7 @@ module Concerns included do after_save :update_whois_record, if: :subzone? - after_destroy :update_whois_record, if: :subzone? + after_destroy :update_whois_record end def subzone? diff --git a/test/fixtures/dns/zones.yml b/test/fixtures/dns/zones.yml index 4f493a149..a1be9a74b 100644 --- a/test/fixtures/dns/zones.yml +++ b/test/fixtures/dns/zones.yml @@ -9,3 +9,12 @@ one: minimum_ttl: 1 email: admin@registry.test master_nameserver: ns.test +subzone: + origin: 'sub.zone' + ttl: 1 + refresh: 1 + retry: 1 + expire: 1 + minimum_ttl: 1 + email: admin@registry.test + master_nameserver: ns.test diff --git a/test/models/dns/zone_test.rb b/test/models/dns/zone_test.rb index c18f9592a..a6d14d3e9 100644 --- a/test/models/dns/zone_test.rb +++ b/test/models/dns/zone_test.rb @@ -124,6 +124,31 @@ class DNS::ZoneTest < ActiveSupport::TestCase assert zone.invalid? end + def test_determines_if_subzone + zone = valid_zone + zone.update(origin: 'pri.ee') + assert zone.subzone? + end + + def test_updates_whois_after_update + subzone = dns_zones(:subzone) + assert_nil Whois::Record.find_by(name: subzone.origin) + + subzone.update(expire: 42) + + whois_record = Whois::Record.find_by(name: subzone.origin) + assert whois_record.present? + end + + def test_deletes_whois_record_after_destroy + subzone = dns_zones(:subzone) + subzone.update(expire: 42) + assert Whois::Record.find_by(name: subzone.origin).present? + + subzone.destroy + assert_nil Whois::Record.find_by(name: subzone.origin) + end + private def valid_zone From 30be37f848913cc29fcfc2863a4214ec66bea898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 14 Aug 2020 11:02:33 +0300 Subject: [PATCH 17/21] Ensure correct fields are added to whois regarding to subzones --- test/models/dns/zone_test.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/models/dns/zone_test.rb b/test/models/dns/zone_test.rb index e991631b0..fab4c6355 100644 --- a/test/models/dns/zone_test.rb +++ b/test/models/dns/zone_test.rb @@ -140,6 +140,32 @@ class DNS::ZoneTest < ActiveSupport::TestCase assert whois_record.present? end + def test_has_setting_info_as_contacts_for_subzones + subzone = dns_zones(:one).dup + + subzone.origin = 'sub.zone' + subzone.save + + whois_record = Whois::Record.find_by(name: subzone.origin) + assert whois_record.present? + + assert_equal Setting.registry_whois_disclaimer, whois_record.json['disclaimer'] + assert_equal Setting.registry_email, whois_record.json['email'] + assert_equal Setting.registry_juridical_name, whois_record.json['registrar'] + assert_equal Setting.registry_url, whois_record.json['registrar_website'] + assert_equal Setting.registry_phone, whois_record.json['registrar_phone'] + + assert_equal Setting.registry_juridical_name, whois_record.json['registrant'] + assert_equal Setting.registry_reg_no, whois_record.json['registrant_reg_no'] + assert_equal Setting.registry_country_code, whois_record.json['registrant_ident_country_code'] + + contact = { name: Setting.registry_invoice_contact, email: Setting.registry_email, + disclosed_attributes: %w[name email] }.with_indifferent_access + + assert_equal contact, whois_record.json['admin_contacts'][0] + assert_equal contact, whois_record.json['tech_contacts'][0] + end + def test_deletes_whois_record_after_destroy subzone = dns_zones(:one).dup From 7a50d6ae9fe2f0e44fb4166403d4ae00816fa10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 14 Aug 2020 11:48:22 +0300 Subject: [PATCH 18/21] Add master and additional nameservers to WHOIS for subzones --- app/models/concerns/zone/whois_queryable.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/zone/whois_queryable.rb b/app/models/concerns/zone/whois_queryable.rb index 970ce87d6..22b2836ec 100644 --- a/app/models/concerns/zone/whois_queryable.rb +++ b/app/models/concerns/zone/whois_queryable.rb @@ -36,7 +36,7 @@ module Concerns registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'], changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email, admin_contacts: [contact_vars], tech_contacts: [contact_vars], - nameservers: [master_nameserver] } + nameservers: nameserver_vars } end def registrar_vars @@ -54,6 +54,16 @@ module Concerns { name: Setting.registry_invoice_contact, email: Setting.registry_email, disclosed_attributes: %w[name email] } end + + def nameserver_vars + vars = [] + vars.push(master_nameserver) + return vars unless ns_records + + ns_records.split("\r\n").each { |ns| (vars << ns) if ns.match? Nameserver::HOSTNAME_REGEXP } + + vars + end end end end From 2ed7f467aa801c861cc24c5e590f09c874842f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 14 Aug 2020 12:29:43 +0300 Subject: [PATCH 19/21] Create job for regenerating Subzone WHOIS entries --- app/jobs/regenerate_subzone_whoises_job.rb | 11 +++++++++++ .../jobs/regeneate_subzone_whoises_job_test.rb | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app/jobs/regenerate_subzone_whoises_job.rb create mode 100644 test/jobs/regeneate_subzone_whoises_job_test.rb diff --git a/app/jobs/regenerate_subzone_whoises_job.rb b/app/jobs/regenerate_subzone_whoises_job.rb new file mode 100644 index 000000000..280fa4088 --- /dev/null +++ b/app/jobs/regenerate_subzone_whoises_job.rb @@ -0,0 +1,11 @@ +class RegenerateSubzoneWhoisesJob < Que::Job + def run + subzones = DNS::Zone.all + + subzones.each do |zone| + next unless zone.subzone? + + UpdateWhoisRecordJob.enqueue zone.origin, 'zone' + end + end +end diff --git a/test/jobs/regeneate_subzone_whoises_job_test.rb b/test/jobs/regeneate_subzone_whoises_job_test.rb new file mode 100644 index 000000000..745c2392c --- /dev/null +++ b/test/jobs/regeneate_subzone_whoises_job_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class RegenerateSubzoneWhoisesJobTest < ActiveSupport::TestCase + def test_regenerates_whois_data_only_for_subzones + subzone = dns_zones(:one).dup + subzone.origin = 'subzone.test' + subzone.save + + Whois::Record.where(name: subzone.origin).destroy_all + Whois::Record.where(name: dns_zones(:one)).destroy_all + assert_nil Whois::Record.find_by(name: subzone.origin) + assert_nil Whois::Record.find_by(name: dns_zones(:one).origin) + + RegenerateSubzoneWhoisesJob.run + assert Whois::Record.find_by(name: subzone.origin) + assert_nil Whois::Record.find_by(name: dns_zones(:one).origin) + end +end From 4ed7edc47df43828455e54b72099d582baead821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 14 Aug 2020 16:34:42 +0300 Subject: [PATCH 20/21] Remove master nameserver from subzone WHOIS, fix whitespace anomaly while parsing nameservers --- app/models/concerns/zone/whois_queryable.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/zone/whois_queryable.rb b/app/models/concerns/zone/whois_queryable.rb index 22b2836ec..2c453dbef 100644 --- a/app/models/concerns/zone/whois_queryable.rb +++ b/app/models/concerns/zone/whois_queryable.rb @@ -57,10 +57,13 @@ module Concerns def nameserver_vars vars = [] - vars.push(master_nameserver) return vars unless ns_records - ns_records.split("\r\n").each { |ns| (vars << ns) if ns.match? Nameserver::HOSTNAME_REGEXP } + parsed_ns = ns_records.gsub("\r", '').gsub("\n", '') + parsed_ns.split("#{origin}. IN NS ").each do |ns| + ns.delete_suffix! '.' + vars << ns if ns.match? Nameserver::HOSTNAME_REGEXP + end vars end From 1c8f04c099c70d674c2cac6193f63af41b00daf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 14 Aug 2020 18:25:56 +0300 Subject: [PATCH 21/21] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf7358d7..e8045349b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +14.08.2020 +* Added handling of second lvl zoness managed by the registry in whois records [#1661](https://github.com/internetee/registry/issues/1661) + 13.08.2020 * Removed keystore gem and replaced LHV JKS with PKCS12 [#1645](https://github.com/internetee/registry/issues/1645)