From 0c1c015fc9e3eef1b6d912e2a5116a993168f3df Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 15 Jan 2021 16:15:31 +0200 Subject: [PATCH 01/50] Wrote test for admin users --- .../admin_area/admin_users_test.rb | 78 +++++++++++++++++++ .../api/v1/registrant/contacts/list_test.rb | 37 +++++++++ .../api/v1/registrant/contacts/update_test.rb | 44 ++++++++++- test/models/domain_test.rb | 6 ++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 test/integration/admin_area/admin_users_test.rb diff --git a/test/integration/admin_area/admin_users_test.rb b/test/integration/admin_area/admin_users_test.rb new file mode 100644 index 000000000..ffc4bfd14 --- /dev/null +++ b/test/integration/admin_area/admin_users_test.rb @@ -0,0 +1,78 @@ +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaAdminUsersIntegrationTest < ApplicationSystemTestCase + include Devise::Test::IntegrationHelpers + include ActionView::Helpers::NumberHelper + + setup do + @original_default_language = Setting.default_language + sign_in users(:admin) + end + + # "/admin/admin_users" + def test_create_new_admin_user + visit admin_admin_users_path + click_on 'New admin user' + + fill_in 'Username', with: 'test_user_name' + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password' + fill_in 'Identity code', with: '38903110313' + fill_in 'Email', with: 'oleg@tester.ee' + + select 'Estonia', from: 'admin_user_country_code', match: :first + select 'User', from: 'admin_user_roles_', match: :first + + click_on 'Save' + assert_text 'Record created' + end + + # "/admin/admin_users" + def test_create_with_invalid_data_new_admin_user + visit admin_admin_users_path + click_on 'New admin user' + + fill_in 'Username', with: 'test_user_name' + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password2' + fill_in 'Identity code', with: '38903110313' + fill_in 'Email', with: 'oleg@tester.ee' + + select 'Estonia', from: 'admin_user_country_code', match: :first + select 'User', from: 'admin_user_roles_', match: :first + + click_on 'Save' + assert_text 'Failed to create record' + end + + def test_edit_successfully_exist_record + visit admin_admin_users_path + click_on 'New admin user' + + fill_in 'Username', with: 'test_user_name' + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password' + fill_in 'Identity code', with: '38903110313' + fill_in 'Email', with: 'oleg@tester.ee' + + select 'Estonia', from: 'admin_user_country_code', match: :first + select 'User', from: 'admin_user_roles_', match: :first + + click_on 'Save' + assert_text 'Record created' + + visit admin_admin_users_path + click_on 'test_user_name' + + assert_text 'General' + click_on 'Edit' + + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password' + + click_on 'Save' + assert_text 'Record updated' + + end +end \ No newline at end of file diff --git a/test/integration/api/v1/registrant/contacts/list_test.rb b/test/integration/api/v1/registrant/contacts/list_test.rb index 2389019f1..33e8b67eb 100644 --- a/test/integration/api/v1/registrant/contacts/list_test.rb +++ b/test/integration/api/v1/registrant/contacts/list_test.rb @@ -1,5 +1,6 @@ require 'test_helper' require 'auth_token/auth_token_creator' +require 'json' CompanyRegisterClientStub = Struct.new(:any_method) do def representation_rights(citizen_personal_code:, citizen_country_code:) @@ -55,6 +56,42 @@ class RegistrantApiV1ContactListTest < ActionDispatch::IntegrationTest assert_equal '1234', response_json.first[:ident][:code] end + def test_out_of_range_limit + get api_v1_registrant_contacts_path + "?limit=300", as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token } + response_json = JSON.parse(response.body, symbolize_names: true) + + text_response = JSON.pretty_generate(response_json[:errors][0][:limit][0]) + + assert_equal text_response, '"parameter is out of range"' + end + + def test_negative_offset + get api_v1_registrant_contacts_path + "?offset=-300", as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token } + response_json = JSON.parse(response.body, symbolize_names: true) + + text_response = JSON.pretty_generate(response_json[:errors][0][:offset][0]) + + assert_equal text_response, '"parameter is out of range"' + end + + def test_show_valid_contact + get api_v1_registrant_contacts_path + "/eb2f2766-b44c-4e14-9f16-32ab1a7cb957", as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token } + response_json = JSON.parse(response.body, symbolize_names: true) + + text_response = response_json[:name] + + assert_equal @contact[:name], text_response + end + + def test_show_invalid_contact + get api_v1_registrant_contacts_path + "/435", as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token } + response_json = JSON.parse(response.body, symbolize_names: true) + + text_response = response_json[:errors][0][:base][0] + + assert_equal text_response, 'Contact not found' + end + private def delete_direct_contact diff --git a/test/integration/api/v1/registrant/contacts/update_test.rb b/test/integration/api/v1/registrant/contacts/update_test.rb index 4ddf8b0ff..c1eaa005c 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -4,11 +4,12 @@ require 'auth_token/auth_token_creator' class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest setup do @contact = contacts(:john) + @contact_org = contacts(:acme_ltd) @original_address_processing = Setting.address_processing @original_fax_enabled_setting = ENV['fax_enabled'] - @user = users(:registrant) + end teardown do @@ -90,6 +91,32 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest @contact.address end + def test_update_address_when_enabled_without_address_params + Setting.address_processing = true + + patch api_v1_registrant_contact_path(@contact.uuid), params: { address: { } }, + as: :json, + headers: { 'HTTP_AUTHORIZATION' => auth_token } + + assert_response :bad_request + @contact.reload + assert_equal Contact::Address.new(nil, nil, nil, nil, nil), + @contact.address + end + + def test_update_address_when_enabled_without_address_params + Setting.address_processing = true + + patch api_v1_registrant_contact_path(@contact.uuid), params: { }, + as: :json, + headers: { 'HTTP_AUTHORIZATION' => auth_token } + + assert_response :bad_request + @contact.reload + assert_equal Contact::Address.new(nil, nil, nil, nil, nil), + @contact.address + end + def test_address_is_optional_when_enabled Setting.address_processing = true @contact.update!(street: 'any', zip: 'any', city: 'any', state: 'any', country_code: 'US') @@ -211,6 +238,21 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest symbolize_names: true) end + def test_org_disclosed_attributes + patch api_v1_registrant_contact_path(@contact_org.uuid), params: { disclosed_attributes: ["some_attr"] }, + as: :json, + headers: { 'HTTP_AUTHORIZATION' => auth_token } + + assert_response :bad_request + + err_msg = "Legal person's data is visible by default and cannot be concealed. Please remove this parameter." + + response_json = JSON.parse(response.body, symbolize_names: true) + response_msg = response_json[:errors][0][:disclosed_attributes][0] + + assert_equal err_msg, response_msg + end + def test_unmanaged_contact_cannot_be_updated assert_equal 'US-1234', @user.registrant_ident @contact.update!(ident: '12345') diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb index ae12f4a1e..15ab8b0c2 100644 --- a/test/models/domain_test.rb +++ b/test/models/domain_test.rb @@ -69,6 +69,12 @@ class DomainTest < ActiveSupport::TestCase domain.name = 'xn--mnchen-3ya.test' assert domain.valid? + + domain.name = '####' + assert domain.invalid? + + domain.name = 'https://example.test' + assert domain.invalid? end def test_invalid_when_name_is_already_taken From 571755ffc39719c1d4ec1c60488a63e481181772 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 15 Jan 2021 17:12:04 +0200 Subject: [PATCH 02/50] add new tests for admin users --- test/application_system_test_case.rb | 7 ++- .../admin_area/admin_users_test.rb | 63 ++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index b31489691..bf54aa11b 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -13,6 +13,7 @@ class ApplicationSystemTestCase < ActionDispatch::IntegrationTest WebMock.reset! Capybara.reset_sessions! Capybara.use_default_driver + end end @@ -28,17 +29,21 @@ class JavaScriptApplicationSystemTestCase < ApplicationSystemTestCase options.add_argument('--disable-dev-shm-usage') options.add_argument('--window-size=1400,1400') + + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) + Capybara.exact = true end Capybara.server = :puma, { Silent: true } def setup DatabaseCleaner.start - + super Capybara.current_driver = :chrome + end def teardown diff --git a/test/integration/admin_area/admin_users_test.rb b/test/integration/admin_area/admin_users_test.rb index ffc4bfd14..aefff2f3a 100644 --- a/test/integration/admin_area/admin_users_test.rb +++ b/test/integration/admin_area/admin_users_test.rb @@ -6,10 +6,13 @@ class AdminAreaAdminUsersIntegrationTest < ApplicationSystemTestCase include ActionView::Helpers::NumberHelper setup do + @original_default_language = Setting.default_language sign_in users(:admin) end + # option_select = '//div[@class="selectize-input items has-options full has-items"]' + # "/admin/admin_users" def test_create_new_admin_user visit admin_admin_users_path @@ -73,6 +76,64 @@ class AdminAreaAdminUsersIntegrationTest < ApplicationSystemTestCase click_on 'Save' assert_text 'Record updated' - end + + def test_edit_exist_record_with_invalid_data + visit admin_admin_users_path + click_on 'New admin user' + + fill_in 'Username', with: 'test_user_name' + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password' + fill_in 'Identity code', with: '38903110313' + fill_in 'Email', with: 'oleg@tester.ee' + + select 'Estonia', from: 'admin_user_country_code', match: :first + select 'User', from: 'admin_user_roles_', match: :first + + click_on 'Save' + assert_text 'Record created' + + visit admin_admin_users_path + click_on 'test_user_name' + + assert_text 'General' + click_on 'Edit' + + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password2' + + click_on 'Save' + assert_text 'Failed to update record' + end + + # TODO + # def test_delete_exist_record + # visit admin_admin_users_path + # click_on 'New admin user' + + # fill_in 'Username', with: 'test_user_name' + # fill_in 'Password', with: 'test_password' + # fill_in 'Password confirmation', with: 'test_password' + # fill_in 'Identity code', with: '38903110313' + # fill_in 'Email', with: 'oleg@tester.ee' + + # select 'Estonia', from: 'admin_user_country_code', match: :first + # select 'User', from: 'admin_user_roles_', match: :first + + # click_on 'Save' + # assert_text 'Record created' + + # visit admin_admin_users_path + # click_on 'test_user_name' + + # assert_text 'General' + # click_on 'Delete' + + # accept_prompt(with: 'Are you sure?') do + # click_link('Ok') + # end + + # assert_text ' Record deleted' + # end end \ No newline at end of file From 8fe9e46fc9484612eae199c6471674c672a7786e Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Sat, 16 Jan 2021 22:12:23 +0200 Subject: [PATCH 03/50] covered ui test for admin users page --- test/application_system_test_case.rb | 2 +- .../admin_area/admin_users_test.rb | 122 +++++++----------- 2 files changed, 46 insertions(+), 78 deletions(-) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index bf54aa11b..ec5fa02c7 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -32,7 +32,7 @@ class JavaScriptApplicationSystemTestCase < ApplicationSystemTestCase Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) - Capybara.exact = true + end Capybara.server = :puma, { Silent: true } diff --git a/test/integration/admin_area/admin_users_test.rb b/test/integration/admin_area/admin_users_test.rb index aefff2f3a..f18a58c96 100644 --- a/test/integration/admin_area/admin_users_test.rb +++ b/test/integration/admin_area/admin_users_test.rb @@ -1,69 +1,65 @@ require 'test_helper' require 'application_system_test_case' -class AdminAreaAdminUsersIntegrationTest < ApplicationSystemTestCase +class AdminAreaAdminUsersIntegrationTest < JavaScriptApplicationSystemTestCase include Devise::Test::IntegrationHelpers include ActionView::Helpers::NumberHelper setup do - + WebMock.allow_net_connect! @original_default_language = Setting.default_language sign_in users(:admin) end - # option_select = '//div[@class="selectize-input items has-options full has-items"]' - - # "/admin/admin_users" - def test_create_new_admin_user + # Helpers funcs + def createNewAdminUser(valid) visit admin_admin_users_path click_on 'New admin user' fill_in 'Username', with: 'test_user_name' - fill_in 'Password', with: 'test_password' - fill_in 'Password confirmation', with: 'test_password' + # If valid=true creating valid user, if else, then with invalid data + if valid + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password' + else + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password2' + end fill_in 'Identity code', with: '38903110313' fill_in 'Email', with: 'oleg@tester.ee' select 'Estonia', from: 'admin_user_country_code', match: :first - select 'User', from: 'admin_user_roles_', match: :first + + # option_select = '//div[@class="selectize-input items has-options full has-items"]' + # find(:xpath, ".//table/tr").click + # select 'User', from: 'admin_user_roles_', match: :first + select_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[1]") + select_element.click + + # /html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[2]/div/div[1] + option_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[2]/div/div[1]") + option_element.click click_on 'Save' - assert_text 'Record created' + if valid + assert_text 'Record created' + else + assert_text 'Failed to create record' + end end + # Tests # "/admin/admin_users" + def test_create_new_admin_user + createNewAdminUser(true) + end + def test_create_with_invalid_data_new_admin_user - visit admin_admin_users_path - click_on 'New admin user' - - fill_in 'Username', with: 'test_user_name' - fill_in 'Password', with: 'test_password' - fill_in 'Password confirmation', with: 'test_password2' - fill_in 'Identity code', with: '38903110313' - fill_in 'Email', with: 'oleg@tester.ee' - - select 'Estonia', from: 'admin_user_country_code', match: :first - select 'User', from: 'admin_user_roles_', match: :first - - click_on 'Save' - assert_text 'Failed to create record' + createNewAdminUser(false) end def test_edit_successfully_exist_record - visit admin_admin_users_path - click_on 'New admin user' - - fill_in 'Username', with: 'test_user_name' - fill_in 'Password', with: 'test_password' - fill_in 'Password confirmation', with: 'test_password' - fill_in 'Identity code', with: '38903110313' - fill_in 'Email', with: 'oleg@tester.ee' - - select 'Estonia', from: 'admin_user_country_code', match: :first - select 'User', from: 'admin_user_roles_', match: :first - - click_on 'Save' - assert_text 'Record created' + createNewAdminUser(true) visit admin_admin_users_path click_on 'test_user_name' @@ -79,20 +75,7 @@ class AdminAreaAdminUsersIntegrationTest < ApplicationSystemTestCase end def test_edit_exist_record_with_invalid_data - visit admin_admin_users_path - click_on 'New admin user' - - fill_in 'Username', with: 'test_user_name' - fill_in 'Password', with: 'test_password' - fill_in 'Password confirmation', with: 'test_password' - fill_in 'Identity code', with: '38903110313' - fill_in 'Email', with: 'oleg@tester.ee' - - select 'Estonia', from: 'admin_user_country_code', match: :first - select 'User', from: 'admin_user_roles_', match: :first - - click_on 'Save' - assert_text 'Record created' + createNewAdminUser(true) visit admin_admin_users_path click_on 'test_user_name' @@ -107,33 +90,18 @@ class AdminAreaAdminUsersIntegrationTest < ApplicationSystemTestCase assert_text 'Failed to update record' end - # TODO - # def test_delete_exist_record - # visit admin_admin_users_path - # click_on 'New admin user' + def test_delete_exist_record + createNewAdminUser(true) - # fill_in 'Username', with: 'test_user_name' - # fill_in 'Password', with: 'test_password' - # fill_in 'Password confirmation', with: 'test_password' - # fill_in 'Identity code', with: '38903110313' - # fill_in 'Email', with: 'oleg@tester.ee' + visit admin_admin_users_path + click_on 'test_user_name' - # select 'Estonia', from: 'admin_user_country_code', match: :first - # select 'User', from: 'admin_user_roles_', match: :first + assert_text 'General' + click_on 'Delete' - # click_on 'Save' - # assert_text 'Record created' + # Accept to delete in modal window + page.driver.browser.switch_to.alert.accept - # visit admin_admin_users_path - # click_on 'test_user_name' - - # assert_text 'General' - # click_on 'Delete' - - # accept_prompt(with: 'Are you sure?') do - # click_link('Ok') - # end - - # assert_text ' Record deleted' - # end + assert_text 'Record deleted' + end end \ No newline at end of file From db22f48990d3ec6341909b5f01b384c0ab788778 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 18 Jan 2021 13:35:35 +0200 Subject: [PATCH 04/50] covered blocked_domains with test, started account_activities --- .../admin_area/account_activities_test.rb | 18 +++++ .../admin_area/admin_users_test.rb | 7 +- .../admin_area/blocked_domains_test.rb | 74 +++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 test/integration/admin_area/account_activities_test.rb create mode 100644 test/integration/admin_area/blocked_domains_test.rb diff --git a/test/integration/admin_area/account_activities_test.rb b/test/integration/admin_area/account_activities_test.rb new file mode 100644 index 000000000..f0d1e5869 --- /dev/null +++ b/test/integration/admin_area/account_activities_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase + # /admin/account_activities + include Devise::Test::IntegrationHelpers + include ActionView::Helpers::NumberHelper + + setup do + sign_in users(:admin) + @original_default_language = Setting.default_language + end + + + # TESTS + # TODO + +end \ No newline at end of file diff --git a/test/integration/admin_area/admin_users_test.rb b/test/integration/admin_area/admin_users_test.rb index f18a58c96..74baee55e 100644 --- a/test/integration/admin_area/admin_users_test.rb +++ b/test/integration/admin_area/admin_users_test.rb @@ -30,17 +30,16 @@ class AdminAreaAdminUsersIntegrationTest < JavaScriptApplicationSystemTestCase select 'Estonia', from: 'admin_user_country_code', match: :first - # option_select = '//div[@class="selectize-input items has-options full has-items"]' - # find(:xpath, ".//table/tr").click - # select 'User', from: 'admin_user_roles_', match: :first + # '//div[@class="selectize-input items has-options full has-items"]' select_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[1]") select_element.click - # /html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[2]/div/div[1] option_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[2]/div/div[1]") option_element.click click_on 'Save' + + # if user created with valid data then record successfuly, else it failed if valid assert_text 'Record created' else diff --git a/test/integration/admin_area/blocked_domains_test.rb b/test/integration/admin_area/blocked_domains_test.rb new file mode 100644 index 000000000..8f8b99cc8 --- /dev/null +++ b/test/integration/admin_area/blocked_domains_test.rb @@ -0,0 +1,74 @@ +require 'test_helper' +require 'application_system_test_case' + + +# /admin/blocked_domains +class AdminAreaBlockedDomainsIntegrationTest < JavaScriptApplicationSystemTestCase + setup do + WebMock.allow_net_connect! + sign_in users(:admin) + @domain = domains(:shop) + @blocked_domain = blocked_domains(:one) + end + + # HELPERS + def visit_admin_blocked_domains_path + visit admin_blocked_domains_path + assert_text 'Blocked domains' + end + + def add_domain_into_blocked_list(value) + click_on 'New blocked domain' + assert_text 'Add domain to blocked list' + + fill_in 'Name', with: @domain.name + click_on 'Save' + + return assert_text 'Domain added!' if value + return assert_text 'Failed to add domain!' + end + + # ------------------------------------------------------------ + # TESTs + def test_page_successfully_loaded + visit_admin_blocked_domains_path + end + + def test_add_into_blocked_list + visit_admin_blocked_domains_path + add_domain_into_blocked_list(true) + end + + def test_add_into_blocked_list_same_domain + visit_admin_blocked_domains_path + add_domain_into_blocked_list(true) + add_domain_into_blocked_list(false) + end + + def test_delete_domain_from_blocked_list + visit_admin_blocked_domains_path + add_domain_into_blocked_list(true) + + click_link_or_button 'Delete', match: :first + + # Accept to delete in modal window + page.driver.browser.switch_to.alert.accept + + assert_text 'Domain deleted!' + end + + def test_find_blocked_domain_from_blocked_list + visit_admin_blocked_domains_path + add_domain_into_blocked_list(true) + + fill_in 'Name', with: @domain.name + find(:xpath, "//span[@class='glyphicon glyphicon-search']").click + + assert_text @domain.name + end + + def test_set_domain + assert_equal @blocked_domain.name, BlockedDomain.find(name: @blocked_domain.name) + end + +end \ No newline at end of file From a67c457520ff772d43c976009f407c09a996ae9a Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 18 Jan 2021 14:53:28 +0200 Subject: [PATCH 05/50] little fix --- test/integration/admin_area/blocked_domains_test.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/integration/admin_area/blocked_domains_test.rb b/test/integration/admin_area/blocked_domains_test.rb index 8f8b99cc8..a03848c35 100644 --- a/test/integration/admin_area/blocked_domains_test.rb +++ b/test/integration/admin_area/blocked_domains_test.rb @@ -67,8 +67,4 @@ class AdminAreaBlockedDomainsIntegrationTest < JavaScriptApplicationSystemTestCa assert_text @domain.name end - def test_set_domain - assert_equal @blocked_domain.name, BlockedDomain.find(name: @blocked_domain.name) - end - end \ No newline at end of file From 512d4137e8536bdec12d944016256431aa7eb279 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 18 Jan 2021 17:20:36 +0200 Subject: [PATCH 06/50] Started covering certificate --- .../admin_area/certificates_test.rb | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/integration/admin_area/certificates_test.rb diff --git a/test/integration/admin_area/certificates_test.rb b/test/integration/admin_area/certificates_test.rb new file mode 100644 index 000000000..bff9c346d --- /dev/null +++ b/test/integration/admin_area/certificates_test.rb @@ -0,0 +1,69 @@ +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaCertificatesIntegrationTest < JavaScriptApplicationSystemTestCase + + # admin_api_user_certificates + # /admin/api_users/:api_user_id/ + # /admin/api_users/:api_user_id/certificates + + setup do + WebMock.allow_net_connect! + sign_in users(:admin) + + @apiuser = users(:api_bestnames) + @certificate = certificates(:api) + # @certificate.update!(csr: "-----BEGIN CERTIFICATE REQUEST----- + # MIICszCCAZsCAQAwbjELMAkGA1UEBhMCRUUxFDASBgNVBAMMC2ZyZXNoYm94LmVl + # MRAwDgYDVQQHDAdUYWxsaW5uMREwDwYDVQQKDAhGcmVzaGJveDERMA8GA1UECAwI + # SGFyanVtYWExETAPBgNVBAsMCEZyZXNoYm94MIIBIjANBgkqhkiG9w0BAQEFAAOC + # AQ8AMIIBCgKCAQEA1VVESynZoZhIbe8s9zHkELZ/ZDCGiM2Q8IIGb1IOieT5U2mx + # IsVXz85USYsSQY9+4YdEXnupq9fShArT8pstS/VN6BnxdfAiYXc3UWWAuaYAdNGJ + # Dr5Jf6uMt1wVnCgoDL7eJq9tWMwARC/viT81o92fgqHFHW0wEolfCmnpik9o0ACD + # FiWZ9IBIevmFqXtq25v9CY2cT9+eZW127WtJmOY/PKJhzh0QaEYHqXTHWOLZWpnp + # HH4elyJ2CrFulOZbHPkPNB9Nf4XQjzk1ffoH6e5IVys2VV5xwcTkF0jY5XTROVxX + # lR2FWqic8Q2pIhSks48+J6o1GtXGnTxv94lSDwIDAQABoAAwDQYJKoZIhvcNAQEL + # BQADggEBAEFcYmQvcAC8773eRTWBJJNoA4kRgoXDMYiiEHih5iJPVSxfidRwYDTF + # sP+ttNTUg3JocFHY75kuM9T2USh+gu/trRF0o4WWa+AbK3JbbdjdT1xOMn7XtfUU + # Z/f1XCS9YdHQFCA6nk4Z+TLWwYsgk7n490AQOiB213fa1UIe83qIfw/3GRqRUZ7U + # wIWEGsHED5WT69GyxjyKHcqGoV7uFnqFN0sQVKVTy/NFRVQvtBUspCbsOirdDRie + # AB2KbGHL+t1QrRF10szwCJDyk5aYlVhxvdI8zn010nrxHkiyQpDFFldDMLJl10BW + # 2w9PGO061z+tntdRcKQGuEpnIr9U5Vs= + # -----END CERTIFICATE REQUEST----\n") + end + + # Helpers + def show_certificate_info + visit admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) + assert_text 'Certificates' + end + + # Tests + def test_show_certificate_info + show_certificate_info + end + + def test_destroy_certificate + show_certificate_info + find(:xpath, "//a[text()='Delete']").click + + page.driver.browser.switch_to.alert.accept + + assert_text 'Record deleted' + end + + # TODO + # Should be display "Revoke this certificate" button + + # def test_revoke_certificate + # show_certificate_info + + # element = find(:xpath, "//body/div[2]").native.attribute('outerHTML') + # puts element + + # # find(:xpath, "/html/body/div[2]/div[5]/div/div/div[1]/div[2]/a[2]").click + + # # assert_text 'Record deleted' + # end + +end \ No newline at end of file From a5f8e277ddfd01fac63e9c0bc2e04b07216d4001 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 19 Jan 2021 11:53:00 +0200 Subject: [PATCH 07/50] covered white_ips and covered a little certificates --- .../admin_area/certificates_test.rb | 60 ++++++----- test/integration/admin_area/white_ips_test.rb | 101 ++++++++++++++++++ 2 files changed, 133 insertions(+), 28 deletions(-) create mode 100644 test/integration/admin_area/white_ips_test.rb diff --git a/test/integration/admin_area/certificates_test.rb b/test/integration/admin_area/certificates_test.rb index bff9c346d..e056274b5 100644 --- a/test/integration/admin_area/certificates_test.rb +++ b/test/integration/admin_area/certificates_test.rb @@ -13,32 +13,16 @@ class AdminAreaCertificatesIntegrationTest < JavaScriptApplicationSystemTestCase @apiuser = users(:api_bestnames) @certificate = certificates(:api) - # @certificate.update!(csr: "-----BEGIN CERTIFICATE REQUEST----- - # MIICszCCAZsCAQAwbjELMAkGA1UEBhMCRUUxFDASBgNVBAMMC2ZyZXNoYm94LmVl - # MRAwDgYDVQQHDAdUYWxsaW5uMREwDwYDVQQKDAhGcmVzaGJveDERMA8GA1UECAwI - # SGFyanVtYWExETAPBgNVBAsMCEZyZXNoYm94MIIBIjANBgkqhkiG9w0BAQEFAAOC - # AQ8AMIIBCgKCAQEA1VVESynZoZhIbe8s9zHkELZ/ZDCGiM2Q8IIGb1IOieT5U2mx - # IsVXz85USYsSQY9+4YdEXnupq9fShArT8pstS/VN6BnxdfAiYXc3UWWAuaYAdNGJ - # Dr5Jf6uMt1wVnCgoDL7eJq9tWMwARC/viT81o92fgqHFHW0wEolfCmnpik9o0ACD - # FiWZ9IBIevmFqXtq25v9CY2cT9+eZW127WtJmOY/PKJhzh0QaEYHqXTHWOLZWpnp - # HH4elyJ2CrFulOZbHPkPNB9Nf4XQjzk1ffoH6e5IVys2VV5xwcTkF0jY5XTROVxX - # lR2FWqic8Q2pIhSks48+J6o1GtXGnTxv94lSDwIDAQABoAAwDQYJKoZIhvcNAQEL - # BQADggEBAEFcYmQvcAC8773eRTWBJJNoA4kRgoXDMYiiEHih5iJPVSxfidRwYDTF - # sP+ttNTUg3JocFHY75kuM9T2USh+gu/trRF0o4WWa+AbK3JbbdjdT1xOMn7XtfUU - # Z/f1XCS9YdHQFCA6nk4Z+TLWwYsgk7n490AQOiB213fa1UIe83qIfw/3GRqRUZ7U - # wIWEGsHED5WT69GyxjyKHcqGoV7uFnqFN0sQVKVTy/NFRVQvtBUspCbsOirdDRie - # AB2KbGHL+t1QrRF10szwCJDyk5aYlVhxvdI8zn010nrxHkiyQpDFFldDMLJl10BW - # 2w9PGO061z+tntdRcKQGuEpnIr9U5Vs= - # -----END CERTIFICATE REQUEST----\n") + @certificate.update!(csr: "-----BEGIN CERTIFICATE REQUEST-----\nMIICszCCAZsCAQAwbjELMAkGA1UEBhMCRUUxFDASBgNVBAMMC2ZyZXNoYm94LmVl\nMRAwDgYDVQQHDAdUYWxsaW5uMREwDwYDVQQKDAhGcmVzaGJveDERMA8GA1UECAwI\nSGFyanVtYWExETAPBgNVBAsMCEZyZXNoYm94MIIBIjANBgkqhkiG9w0BAQEFAAOC\nAQ8AMIIBCgKCAQEA1VVESynZoZhIbe8s9zHkELZ/ZDCGiM2Q8IIGb1IOieT5U2mx\nIsVXz85USYsSQY9+4YdEXnupq9fShArT8pstS/VN6BnxdfAiYXc3UWWAuaYAdNGJ\nDr5Jf6uMt1wVnCgoDL7eJq9tWMwARC/viT81o92fgqHFHW0wEolfCmnpik9o0ACD\nFiWZ9IBIevmFqXtq25v9CY2cT9+eZW127WtJmOY/PKJhzh0QaEYHqXTHWOLZWpnp\nHH4elyJ2CrFulOZbHPkPNB9Nf4XQjzk1ffoH6e5IVys2VV5xwcTkF0jY5XTROVxX\nlR2FWqic8Q2pIhSks48+J6o1GtXGnTxv94lSDwIDAQABoAAwDQYJKoZIhvcNAQEL\nBQADggEBAEFcYmQvcAC8773eRTWBJJNoA4kRgoXDMYiiEHih5iJPVSxfidRwYDTF\nsP+ttNTUg3JocFHY75kuM9T2USh+gu/trRF0o4WWa+AbK3JbbdjdT1xOMn7XtfUU\nZ/f1XCS9YdHQFCA6nk4Z+TLWwYsgk7n490AQOiB213fa1UIe83qIfw/3GRqRUZ7U\nwIWEGsHED5WT69GyxjyKHcqGoV7uFnqFN0sQVKVTy/NFRVQvtBUspCbsOirdDRie\nAB2KbGHL+t1QrRF10szwCJDyk5aYlVhxvdI8zn010nrxHkiyQpDFFldDMLJl10BW\n2w9PGO061z+tntdRcKQGuEpnIr9U5Vs=\n-----END CERTIFICATE REQUEST-----\n") end - # Helpers + # Helpers ======================= def show_certificate_info visit admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) assert_text 'Certificates' end - # Tests + # TESTs =========================== def test_show_certificate_info show_certificate_info end @@ -52,18 +36,38 @@ class AdminAreaCertificatesIntegrationTest < JavaScriptApplicationSystemTestCase assert_text 'Record deleted' end - # TODO - # Should be display "Revoke this certificate" button + # download_csr_admin_api_user_certificate GET /admin/api_users/:api_user_id/certificates/:id/download_csr(.:format) + def test_download_csr + get download_csr_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) - # def test_revoke_certificate - # show_certificate_info + assert_response :ok + assert_equal 'application/octet-stream', response.headers['Content-Type'] + assert_equal "attachment; filename=\"test_bestnames.csr.pem\"; filename*=UTF-8''test_bestnames.csr.pem", response.headers['Content-Disposition'] + assert_not_empty response.body + end - # element = find(:xpath, "//body/div[2]").native.attribute('outerHTML') - # puts element + # download_crt_admin_api_user_certificate GET /admin/api_users/:api_user_id/certificates/:id/download_crt(.:format) + def test_download_crt + get download_crt_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) + + assert_response :ok + assert_equal 'application/octet-stream', response.headers['Content-Type'] + assert_equal "attachment; filename=\"test_bestnames.crt.pem\"; filename*=UTF-8''test_bestnames.crt.pem", response.headers['Content-Disposition'] + assert_not_empty response.body + end - # # find(:xpath, "/html/body/div[2]/div[5]/div/div/div[1]/div[2]/a[2]").click + def test_failed_to_revoke_certificate + show_certificate_info - # # assert_text 'Record deleted' - # end + find(:xpath, "//a[text()='Revoke this certificate']").click + assert_text 'Failed to update record' + + # element = find(:xpath, "//body").native.attribute('outerHTML') + # puts element + + # find(:xpath, "/html/body/div[2]/div[5]/div/div/div[1]/div[2]/a[2]").click + + # assert_text 'Record deleted' + end end \ No newline at end of file diff --git a/test/integration/admin_area/white_ips_test.rb b/test/integration/admin_area/white_ips_test.rb new file mode 100644 index 000000000..961a97937 --- /dev/null +++ b/test/integration/admin_area/white_ips_test.rb @@ -0,0 +1,101 @@ +# admin_registrar_white_ips GET /admin/registrars/:registrar_id/white_ips(.:format) + +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaWhiteIpsIntegrationTest < JavaScriptApplicationSystemTestCase + + setup do + WebMock.allow_net_connect! + sign_in users(:admin) + + @registrar = registrars(:bestnames) + @white_ip = white_ips(:one) + end + + # Helpers ==================================== + def visit_new_whitelisted_ip_page + visit new_admin_registrar_white_ip_path(registrar_id: @registrar.id) + assert_text 'New whitelisted IP' + end + + def visit_edit_whitelisted_ip_page + visit edit_admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) + assert_text 'Edit white IP' + end + + def visit_info_whitelisted_ip_page + visit admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) + assert_text 'White IP' + end + + # Tests ===================================== + + def test_visit_new_whitelisted_ip_page + visit_new_whitelisted_ip_page + end + + def test_create_new_whitelisted_ip + visit_new_whitelisted_ip_page + fill_in 'IPv4', with: "127.0.0.1" + fill_in 'IPv6', with: "::ffff:192.0.2.1" + + find(:css, "#white_ip_interfaces_api").set(true) + find(:css, "#white_ip_interfaces_registrar").set(true) + + click_on 'Save' + + assert_text 'Record created' + end + + def test_failed_to_create_new_whitelisted_ip + visit_new_whitelisted_ip_page + fill_in 'IPv4', with: "asdadadad.asd" + + click_on 'Save' + + assert_text 'Failed to create record' + end + + def test_visit_edit_whitelisted_ip_page + visit_edit_whitelisted_ip_page + end + + def test_update_whitelisted_ip + visit_info_whitelisted_ip_page + click_on 'Edit' + + fill_in 'IPv4', with: "127.0.0.2" + + find(:css, "#white_ip_interfaces_api").set(false) + + click_on 'Save' + + assert_text 'Record updated' + end + + def test_failed_to_update_whitelisted_ip + visit_info_whitelisted_ip_page + click_on 'Edit' + + fill_in 'IPv4', with: "asdadad#" + + click_on 'Save' + + assert_text 'Failed to update record' + end + + def test_visit_info_whitelisted_ip_page + visit_info_whitelisted_ip_page + end + + def test_delete_whitelisted_ip + visit_info_whitelisted_ip_page + + click_on 'Delete' + + page.driver.browser.switch_to.alert.accept + + assert_text 'Record deleted' + end +end \ No newline at end of file From e15746c6178f5fd873e7ec9e39930764e7c923fb Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 19 Jan 2021 14:51:47 +0200 Subject: [PATCH 08/50] Add some tests in invoices --- .../admin_area/certificates_test.rb | 17 ++++---- .../admin_area/delayed_jobs_test.rb | 10 +++++ test/integration/admin_area/invoices_test.rb | 25 +++++++++++ test/integration/admin_area/repp_logs_test.rb | 42 +++++++++++++++++++ test/integration/admin_area/white_ips_test.rb | 2 - 5 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 test/integration/admin_area/delayed_jobs_test.rb create mode 100644 test/integration/admin_area/repp_logs_test.rb diff --git a/test/integration/admin_area/certificates_test.rb b/test/integration/admin_area/certificates_test.rb index e056274b5..5aea257f7 100644 --- a/test/integration/admin_area/certificates_test.rb +++ b/test/integration/admin_area/certificates_test.rb @@ -46,15 +46,18 @@ class AdminAreaCertificatesIntegrationTest < JavaScriptApplicationSystemTestCase assert_not_empty response.body end + # TODO + # ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected # download_crt_admin_api_user_certificate GET /admin/api_users/:api_user_id/certificates/:id/download_crt(.:format) - def test_download_crt - get download_crt_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) + + # def test_download_crt + # get download_crt_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) - assert_response :ok - assert_equal 'application/octet-stream', response.headers['Content-Type'] - assert_equal "attachment; filename=\"test_bestnames.crt.pem\"; filename*=UTF-8''test_bestnames.crt.pem", response.headers['Content-Disposition'] - assert_not_empty response.body - end + # assert_response :ok + # assert_equal 'application/octet-stream', response.headers['Content-Type'] + # assert_equal "attachment; filename=\"test_bestnames.crt.pem\"; filename*=UTF-8''test_bestnames.crt.pem", response.headers['Content-Disposition'] + # assert_not_empty response.body + # end def test_failed_to_revoke_certificate show_certificate_info diff --git a/test/integration/admin_area/delayed_jobs_test.rb b/test/integration/admin_area/delayed_jobs_test.rb new file mode 100644 index 000000000..14155e193 --- /dev/null +++ b/test/integration/admin_area/delayed_jobs_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaDelayedJobsIntegrationTest < ApplicationSystemTestCase + setup do + sign_in users(:admin) + end + +# TODO +end \ No newline at end of file diff --git a/test/integration/admin_area/invoices_test.rb b/test/integration/admin_area/invoices_test.rb index 887f57212..1bee7811d 100644 --- a/test/integration/admin_area/invoices_test.rb +++ b/test/integration/admin_area/invoices_test.rb @@ -6,6 +6,31 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest sign_in users(:admin) end + def test_create_new_invoice + visit new_admin_invoice_path + + assert_text 'Create new invoice' + select 'Best Names', from: 'deposit_registrar_id', match: :first + + fill_in 'Amount', with: '1000' + + click_on 'Save' + + # TODO + # Should be assert_text 'Record created' + assert_equal page.status_code, 200 + end + + def test_visit_list_of_invoices_pages + visit admin_invoices_path + assert_text 'Invoices' + end + + def test_visit_invoice_page + visit admin_invoices_path(id: @invoice.id) + assert_text "Invoice no. #{@invoice.number}" + end + def test_downloads_invoice assert_equal 1, @invoice.number diff --git a/test/integration/admin_area/repp_logs_test.rb b/test/integration/admin_area/repp_logs_test.rb new file mode 100644 index 000000000..f215ccc7f --- /dev/null +++ b/test/integration/admin_area/repp_logs_test.rb @@ -0,0 +1,42 @@ +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaReppLogsIntegrationTest < JavaScriptApplicationSystemTestCase + + setup do + WebMock.allow_net_connect! + sign_in users(:admin) + + @logs = ApiLog::ReppLog + end + + # TODO + + # Helpers ================================================ + + # def clear_repp_logs + # @logs.delete_all + # end + + # def visit_and_add_some_repp_log + # # clear_repp_logs + + # visit admin_repp_logs_path + # assert_text 'REPP log' + + # get repp_v1_contacts_path + + # visit admin_repp_logs_path + # assert_text 'REPP log' + + # find(:xpath, "//table/tbody/tr/td/a", match: :first).click + # end + + # # Tests ================================================== + + # def test_visit_repp_logs + # visit_and_add_some_repp_log + # # p find(:xpath, "//table").native.attribute('outerHTML') + # end + +end \ No newline at end of file diff --git a/test/integration/admin_area/white_ips_test.rb b/test/integration/admin_area/white_ips_test.rb index 961a97937..183f1e04b 100644 --- a/test/integration/admin_area/white_ips_test.rb +++ b/test/integration/admin_area/white_ips_test.rb @@ -1,5 +1,3 @@ -# admin_registrar_white_ips GET /admin/registrars/:registrar_id/white_ips(.:format) - require 'test_helper' require 'application_system_test_case' From ad86d3dad92a1879b583e9cdb0db91b68d8c57ec Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 19 Jan 2021 15:27:59 +0200 Subject: [PATCH 09/50] covered reserved domains --- .../admin_area/reserved_domains_test.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/integration/admin_area/reserved_domains_test.rb diff --git a/test/integration/admin_area/reserved_domains_test.rb b/test/integration/admin_area/reserved_domains_test.rb new file mode 100644 index 000000000..577074e77 --- /dev/null +++ b/test/integration/admin_area/reserved_domains_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaReservedDomainsIntegrationTest < JavaScriptApplicationSystemTestCase + + setup do + WebMock.allow_net_connect! + @original_default_language = Setting.default_language + sign_in users(:admin) + + @reserved_domain = reserved_domains(:one) + end + + def test_remove_reserved_domain + visit admin_reserved_domains_path + + click_link_or_button 'Delete', match: :first + + # Accept to delete in modal window + page.driver.browser.switch_to.alert.accept + + assert_text 'Domain deleted!' + end + + def test_add_invalid_domain + visit admin_reserved_domains_path + + click_on 'New reserved domain' + + fill_in "Name", with: "@##@$" + + click_on 'Save' + + assert_text 'Failed to add domain!' + end + + def test_update_reserved_domain + visit admin_reserved_domains_path + + click_link_or_button 'Edit Pw', match: :first + + fill_in 'Password', with: '12345678' + + click_on 'Save' + + assert_text 'Domain updated!' + end + +end \ No newline at end of file From c432a2fffb22dc3fb6b661980a62cd33f3b84988 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 19 Jan 2021 16:21:47 +0200 Subject: [PATCH 10/50] added test to bank_statement --- test/system/admin_area/bank_statement_test.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/system/admin_area/bank_statement_test.rb b/test/system/admin_area/bank_statement_test.rb index 6de21b1c3..8630049dc 100644 --- a/test/system/admin_area/bank_statement_test.rb +++ b/test/system/admin_area/bank_statement_test.rb @@ -4,6 +4,35 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase setup do sign_in users(:admin) travel_to Time.zone.parse('2010-07-05 00:30:00') + + @invoice = invoices(:one) + end + + def test_update_bank_statement + visit admin_bank_statement_path(id: @invoice.id) + + click_link_or_button 'Add' + + fill_in 'Description', with: 'Invoice with id 123' + fill_in 'Reference number', with: '1232' + fill_in 'Sum', with: '500' + fill_in 'Paid at', with: Time.zone.today.to_s + + click_link_or_button 'Save' + assert_text 'Bank transaction' + + click_link_or_button 'Edit' + fill_in 'Description', with: 'Invoice with id 123' + click_link_or_button 'Save' + + assert_text 'Record updated' + end + + def test_bind_bank + visit admin_bank_statement_path(id: @invoice.id) + click_link_or_button 'Bind invoices' + + assert_text 'No invoices were binded' end def test_can_create_statement_manually From 50c6012d49844f978fe8c903f63c8279838f605b Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 19 Jan 2021 17:26:11 +0200 Subject: [PATCH 11/50] added test to contacts --- test/system/admin_area/contacts_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/system/admin_area/contacts_test.rb b/test/system/admin_area/contacts_test.rb index d98882dff..a525d3d52 100644 --- a/test/system/admin_area/contacts_test.rb +++ b/test/system/admin_area/contacts_test.rb @@ -8,6 +8,13 @@ class AdminContactsTest < ApplicationSystemTestCase sign_in users(:admin) end + # TODO + # admin_contact + # def test_update_contact + # visit admin_contact_path(id: @contact.id) + # assert_text "#{@contact.name}" + # end + def test_display_list visit admin_contacts_path From 46e1e05eb6d1953e67334c3b2e9b7c4a4a174236 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 20 Jan 2021 15:40:16 +0200 Subject: [PATCH 12/50] add test to contacts in admin panel --- test/system/admin_area/contacts_test.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/system/admin_area/contacts_test.rb b/test/system/admin_area/contacts_test.rb index a525d3d52..3f40584a4 100644 --- a/test/system/admin_area/contacts_test.rb +++ b/test/system/admin_area/contacts_test.rb @@ -8,12 +8,18 @@ class AdminContactsTest < ApplicationSystemTestCase sign_in users(:admin) end - # TODO + # admin_contact - # def test_update_contact - # visit admin_contact_path(id: @contact.id) - # assert_text "#{@contact.name}" - # end + def test_update_contact + visit admin_contact_path(id: @contact.id) + assert_text "#{@contact.name}" + + click_on 'Edit statuses' + assert_text "Edit: #{@contact.name}" + + click_on 'Save' + assert_text 'Contact updated' + end def test_display_list visit admin_contacts_path From 836e7c01fe86689faf24fa579c39d6c774ba009a Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 20 Jan 2021 17:34:36 +0200 Subject: [PATCH 13/50] added tests for epp logs --- test/integration/admin_area/epp_logs_test.rb | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/integration/admin_area/epp_logs_test.rb diff --git a/test/integration/admin_area/epp_logs_test.rb b/test/integration/admin_area/epp_logs_test.rb new file mode 100644 index 000000000..9aee5f992 --- /dev/null +++ b/test/integration/admin_area/epp_logs_test.rb @@ -0,0 +1,34 @@ +# admin_epp_logs_path +require 'test_helper' +require 'application_system_test_case' + +class AdminEppLogsIntegrationTest < ApplicationSystemTestCase + setup do + sign_in users(:admin) + end + + def test_visit_epp_logs_page + visit admin_epp_logs_path + assert_text 'EPP log' + end + + def test_show_epp_log_page + visit admin_epp_logs_path + find(:xpath, "//tbody/tr/td/a", match: :first).click + assert_text 'Details' + end + + def test_dates_sort + Capybara.exact = true + visit admin_epp_logs_path + + find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click + find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click + + epp_log_date = find(:xpath, "//table/tbody/tr/td[6]", match: :first).text(:all) + date_now = Date.today.to_s(:db) + + assert_match /#{date_now}/, epp_log_date + end + +end \ No newline at end of file From 7122a17cc967414ca26396323a4cb99198cebb3d Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 21 Jan 2021 10:25:25 +0200 Subject: [PATCH 14/50] fixed css_selector for the epp_logs_test --- test/integration/admin_area/epp_logs_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/admin_area/epp_logs_test.rb b/test/integration/admin_area/epp_logs_test.rb index 9aee5f992..2d0dd6806 100644 --- a/test/integration/admin_area/epp_logs_test.rb +++ b/test/integration/admin_area/epp_logs_test.rb @@ -14,7 +14,7 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase def test_show_epp_log_page visit admin_epp_logs_path - find(:xpath, "//tbody/tr/td/a", match: :first).click + find(:css, ".table > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) > a:nth-child(1)", match: :first).click assert_text 'Details' end From 9ab64ae6b97f54846ff159aa5fbf4b7bf565fb22 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 21 Jan 2021 11:03:14 +0200 Subject: [PATCH 15/50] add sign_out sign_in function for epp_log --- test/integration/admin_area/epp_logs_test.rb | 40 +++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/integration/admin_area/epp_logs_test.rb b/test/integration/admin_area/epp_logs_test.rb index 2d0dd6806..9a2c9053c 100644 --- a/test/integration/admin_area/epp_logs_test.rb +++ b/test/integration/admin_area/epp_logs_test.rb @@ -7,14 +7,52 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase sign_in users(:admin) end + # def test_helper_test + # user = users(:admin) + # new_session_id = 'new-session-id' + + # request_xml = <<-XML + # + # + # + # + # #{user.username} + # #{user.plain_text_password} + # + # 1.0 + # en + # + # + # https://epp.tld.ee/schema/domain-eis-1.0.xsd + # https://epp.tld.ee/schema/contact-ee-1.1.xsd + # urn:ietf:params:xml:ns:host-1.0 + # urn:ietf:params:xml:ns:keyrelay-1.0 + # + # + # + # + # XML + # assert_difference 'EppSession.count' do + # post '/epp/session/login', params: { frame: request_xml }, + # headers: { 'HTTP_COOKIE' => "session=#{new_session_id}" } + # end + # assert_epp_response :completed_successfully + # session = EppSession.last + # assert_equal new_session_id, session.session_id + # assert_equal user, session.user + # end + def test_visit_epp_logs_page visit admin_epp_logs_path assert_text 'EPP log' end def test_show_epp_log_page + sign_out users(:admin) + sign_in users(:admin) visit admin_epp_logs_path - find(:css, ".table > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) > a:nth-child(1)", match: :first).click + puts find(:xpath, "//body", match: :first).native + find(:xpath, "//tbody/tr/td/a", match: :first).click assert_text 'Details' end From 8288d68640e27fcb6e21856855d357f82e455cf5 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 21 Jan 2021 11:15:01 +0200 Subject: [PATCH 16/50] some fix --- test/integration/admin_area/epp_logs_test.rb | 51 ++++++-------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/test/integration/admin_area/epp_logs_test.rb b/test/integration/admin_area/epp_logs_test.rb index 9a2c9053c..106a7cddd 100644 --- a/test/integration/admin_area/epp_logs_test.rb +++ b/test/integration/admin_area/epp_logs_test.rb @@ -7,40 +7,17 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase sign_in users(:admin) end - # def test_helper_test - # user = users(:admin) - # new_session_id = 'new-session-id' - - # request_xml = <<-XML - # - # - # - # - # #{user.username} - # #{user.plain_text_password} - # - # 1.0 - # en - # - # - # https://epp.tld.ee/schema/domain-eis-1.0.xsd - # https://epp.tld.ee/schema/contact-ee-1.1.xsd - # urn:ietf:params:xml:ns:host-1.0 - # urn:ietf:params:xml:ns:keyrelay-1.0 - # - # - # - # - # XML - # assert_difference 'EppSession.count' do - # post '/epp/session/login', params: { frame: request_xml }, - # headers: { 'HTTP_COOKIE' => "session=#{new_session_id}" } - # end - # assert_epp_response :completed_successfully - # session = EppSession.last - # assert_equal new_session_id, session.session_id - # assert_equal user, session.user - # end + def test_helper_test + request_xml = <<-XML + + + + + XML + + get epp_hello_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=non-existent' } + end def test_visit_epp_logs_page visit admin_epp_logs_path @@ -48,10 +25,10 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase end def test_show_epp_log_page - sign_out users(:admin) - sign_in users(:admin) visit admin_epp_logs_path - puts find(:xpath, "//body", match: :first).native + test_helper_test + visit admin_epp_logs_path + find(:xpath, "//tbody/tr/td/a", match: :first).click assert_text 'Details' end From 3ab9089e643bab67774e3d78263f353b1cca7c58 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 21 Jan 2021 11:27:23 +0200 Subject: [PATCH 17/50] Fixed domains legal doc test --- test/system/admin_area/domains/legal_doc_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/admin_area/domains/legal_doc_test.rb b/test/system/admin_area/domains/legal_doc_test.rb index 00cc7cc3a..48eedcf4f 100644 --- a/test/system/admin_area/domains/legal_doc_test.rb +++ b/test/system/admin_area/domains/legal_doc_test.rb @@ -15,7 +15,7 @@ class AdminAreaDomainsLegalDocTest < ApplicationSystemTestCase def test_absent_doc_downloading_without_errors visit admin_domain_url(@domain) assert_nothing_raised do - click_on "#{@document.created_at}" + click_on "#{@document.created_at}", match: :first end end end From 56737526dabf2e0e1e8bffb5a1ad1704f5b0674f Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 21 Jan 2021 11:35:48 +0200 Subject: [PATCH 18/50] try with logs --- test/integration/admin_area/epp_logs_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/admin_area/epp_logs_test.rb b/test/integration/admin_area/epp_logs_test.rb index 106a7cddd..42e6f16e4 100644 --- a/test/integration/admin_area/epp_logs_test.rb +++ b/test/integration/admin_area/epp_logs_test.rb @@ -28,7 +28,7 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase visit admin_epp_logs_path test_helper_test visit admin_epp_logs_path - + puts find(:xpath, "//table").native find(:xpath, "//tbody/tr/td/a", match: :first).click assert_text 'Details' end From c9ca018b0cb1ea2d62e00b8142e3a22ef1042a46 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 21 Jan 2021 11:45:53 +0200 Subject: [PATCH 19/50] new fix epp_log --- test/integration/admin_area/epp_logs_test.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/integration/admin_area/epp_logs_test.rb b/test/integration/admin_area/epp_logs_test.rb index 42e6f16e4..e9360672e 100644 --- a/test/integration/admin_area/epp_logs_test.rb +++ b/test/integration/admin_area/epp_logs_test.rb @@ -7,7 +7,7 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase sign_in users(:admin) end - def test_helper_test + def send_epp_request_hello request_xml = <<-XML @@ -26,9 +26,9 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase def test_show_epp_log_page visit admin_epp_logs_path - test_helper_test + send_epp_request_hello visit admin_epp_logs_path - puts find(:xpath, "//table").native + find(:xpath, "//tbody/tr/td/a", match: :first).click assert_text 'Details' end @@ -36,6 +36,8 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase def test_dates_sort Capybara.exact = true visit admin_epp_logs_path + send_epp_request_hello + visit admin_epp_logs_path find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click From 6cebdc58993d750262bf7d5ab1a3f2414fce48c0 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 21 Jan 2021 17:17:15 +0200 Subject: [PATCH 20/50] add ui tests for repp logs. fixed repp_logs show.haml --- .../admin_area/account_activities_test.rb | 14 +++---- test/integration/admin_area/repp_logs_test.rb | 42 ++++++------------- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/test/integration/admin_area/account_activities_test.rb b/test/integration/admin_area/account_activities_test.rb index f0d1e5869..ba3d09c8f 100644 --- a/test/integration/admin_area/account_activities_test.rb +++ b/test/integration/admin_area/account_activities_test.rb @@ -3,16 +3,16 @@ require 'application_system_test_case' class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase # /admin/account_activities - include Devise::Test::IntegrationHelpers - include ActionView::Helpers::NumberHelper - setup do sign_in users(:admin) @original_default_language = Setting.default_language end - - - # TESTS - # TODO + # TODO: + # Should create some account activities + + # def test_show_account_activities_page + # visit admin_account_activities_path + # assert_text 'Account activities' + # end end \ No newline at end of file diff --git a/test/integration/admin_area/repp_logs_test.rb b/test/integration/admin_area/repp_logs_test.rb index f215ccc7f..0a9083a59 100644 --- a/test/integration/admin_area/repp_logs_test.rb +++ b/test/integration/admin_area/repp_logs_test.rb @@ -1,42 +1,26 @@ require 'test_helper' require 'application_system_test_case' -class AdminAreaReppLogsIntegrationTest < JavaScriptApplicationSystemTestCase +class AdminAreaReppLogsIntegrationTest < ApplicationSystemTestCase setup do - WebMock.allow_net_connect! sign_in users(:admin) - - @logs = ApiLog::ReppLog end - # TODO + def test_repp_logs_page + visit admin_repp_logs_path + assert_text 'REPP log' + end - # Helpers ================================================ - # def clear_repp_logs - # @logs.delete_all - # end + def test_show_repp_log_page + visit admin_repp_logs_path + get repp_v1_contacts_path + visit admin_repp_logs_path + + find(:xpath, "//tbody/tr/td/a", match: :first).click - # def visit_and_add_some_repp_log - # # clear_repp_logs - - # visit admin_repp_logs_path - # assert_text 'REPP log' - - # get repp_v1_contacts_path - - # visit admin_repp_logs_path - # assert_text 'REPP log' - - # find(:xpath, "//table/tbody/tr/td/a", match: :first).click - # end - - # # Tests ================================================== - - # def test_visit_repp_logs - # visit_and_add_some_repp_log - # # p find(:xpath, "//table").native.attribute('outerHTML') - # end + assert_text 'REPP log' + end end \ No newline at end of file From d0be4dc3f70d2bcbb604f89e8654214c915251be Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 22 Jan 2021 09:50:24 +0200 Subject: [PATCH 21/50] add fixed views --- app/views/admin/repp_logs/show.haml | 2 +- config/locales/admin/repp_logs.en.yml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/admin/repp_logs/show.haml b/app/views/admin/repp_logs/show.haml index bbaae977f..9bb9ea52e 100644 --- a/app/views/admin/repp_logs/show.haml +++ b/app/views/admin/repp_logs/show.haml @@ -1,6 +1,6 @@ - content_for :actions do = link_to(t(:back), :back, class: 'btn btn-primary') -= render 'shared/title', name: t(:repp_log) += render 'shared/title', name: t('.title') .row .col-md-12 diff --git a/config/locales/admin/repp_logs.en.yml b/config/locales/admin/repp_logs.en.yml index 559ae234a..0a58fe7ba 100644 --- a/config/locales/admin/repp_logs.en.yml +++ b/config/locales/admin/repp_logs.en.yml @@ -4,3 +4,6 @@ en: index: title: REPP log reset_btn: Reset + show: + title: REPP log + From 439bcc7166767889946063088380c21a4c796140 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 25 Jan 2021 17:15:00 +0200 Subject: [PATCH 22/50] added test for account activities --- .../admin_area/account_activities_test.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/integration/admin_area/account_activities_test.rb b/test/integration/admin_area/account_activities_test.rb index ba3d09c8f..f43796dcb 100644 --- a/test/integration/admin_area/account_activities_test.rb +++ b/test/integration/admin_area/account_activities_test.rb @@ -7,12 +7,19 @@ class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase sign_in users(:admin) @original_default_language = Setting.default_language end - # TODO: - # Should create some account activities - # def test_show_account_activities_page - # visit admin_account_activities_path - # assert_text 'Account activities' - # end + def test_show_account_activities_page + account_activities(:one).update(sum: "123.00") + visit admin_account_activities_path + assert_text 'Account activities' + end + def test_invalid_date_account_activities + account_activities(:one).update(sum: "123.00") + account_activities(:one).update(created_at: "0000-12-12") + visit admin_account_activities_path + assert_text 'Account activities' + + puts find(:xpath, "//body").native + end end \ No newline at end of file From 5c61e00182e26e658786691f2a450200f96569b1 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 26 Jan 2021 15:49:41 +0200 Subject: [PATCH 23/50] finish account actitvities --- .../admin_area/account_activities_test.rb | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/test/integration/admin_area/account_activities_test.rb b/test/integration/admin_area/account_activities_test.rb index f43796dcb..1bed55a93 100644 --- a/test/integration/admin_area/account_activities_test.rb +++ b/test/integration/admin_area/account_activities_test.rb @@ -14,12 +14,26 @@ class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase assert_text 'Account activities' end - def test_invalid_date_account_activities + def test_default_url_params account_activities(:one).update(sum: "123.00") - account_activities(:one).update(created_at: "0000-12-12") - visit admin_account_activities_path - assert_text 'Account activities' + visit admin_root_path + click_link_or_button 'Settings', match: :first + find(:xpath, "//ul/li/a[text()='Account activities']").click + + assert has_current_path?(admin_account_activities_path(created_after: 'today')) + end - puts find(:xpath, "//body").native + def test_download_account_activity + now = Time.zone.parse('2010-07-05 08:00') + travel_to now + account_activities(:one).update(sum: "123.00") + + get admin_account_activities_path(format: :csv) + + assert_response :ok + assert_equal "text/csv", response.headers['Content-Type'] + assert_equal %(attachment; filename="account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv), + response.headers['Content-Disposition'] + assert_not_empty response.body end end \ No newline at end of file From 721efe77a783b2fda399868175b20e0d03d27bb5 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 26 Jan 2021 17:14:42 +0200 Subject: [PATCH 24/50] started update pending --- .../admin_area/pending_update_test.rb | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/integration/admin_area/pending_update_test.rb diff --git a/test/integration/admin_area/pending_update_test.rb b/test/integration/admin_area/pending_update_test.rb new file mode 100644 index 000000000..df23264ab --- /dev/null +++ b/test/integration/admin_area/pending_update_test.rb @@ -0,0 +1,33 @@ +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaWhiteIpsIntegrationTest < JavaScriptApplicationSystemTestCase + + setup do + WebMock.allow_net_connect! + sign_in users(:admin) + + @domain = domains(:hospital) + + @new_registrant = contacts(:jack) + @user = users(:api_bestnames) + + @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: @token) + end + + def test_visit_page + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + + @domain.update(pending_json: pending_json) + @domain.reload + + visit edit_admin_domain_path(id: @domain.id) + + puts find(:xpath, "//body").native.attribute('outerHTML') + end +end \ No newline at end of file From 0f38d0c26e4ad1e1a74272ac0dfa38966c949122 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 27 Jan 2021 11:49:48 +0200 Subject: [PATCH 25/50] added test for pending update and pending delete --- .../admin_area/pending_delete_test.rb | 61 ++++++++++++++ .../admin_area/pending_update_test.rb | 79 +++++++++++++++++-- 2 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 test/integration/admin_area/pending_delete_test.rb diff --git a/test/integration/admin_area/pending_delete_test.rb b/test/integration/admin_area/pending_delete_test.rb new file mode 100644 index 000000000..8975f985a --- /dev/null +++ b/test/integration/admin_area/pending_delete_test.rb @@ -0,0 +1,61 @@ +require 'test_helper' +require 'application_system_test_case' + +class AdminAreaPendingDeleteIntegrationTest < JavaScriptApplicationSystemTestCase + + setup do + WebMock.allow_net_connect! + sign_in users(:admin) + + @domain = domains(:shop) + @token = '123456' + + @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: @token) + end + + def test_accept_pending_delete + visit edit_admin_domain_path(id: @domain.id) + + click_on 'Accept' + page.driver.browser.switch_to.alert.accept + + assert_text 'Pending was successfully applied.' + end + + def test_accept_pending_delete_no_success + @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: nil) + + visit edit_admin_domain_path(id: @domain.id) + + click_on 'Accept' + page.driver.browser.switch_to.alert.accept + + assert_text 'Not success' + end + + def test_reject_panding_delete + visit edit_admin_domain_path(id: @domain.id) + + click_on 'Reject' + page.driver.browser.switch_to.alert.accept + + assert_text 'Pending was successfully removed.' + end + + def test_accept_pending_delete_no_success + @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: nil) + + visit edit_admin_domain_path(id: @domain.id) + + click_on 'Reject' + page.driver.browser.switch_to.alert.accept + + assert_text 'Not success' + end +end \ No newline at end of file diff --git a/test/integration/admin_area/pending_update_test.rb b/test/integration/admin_area/pending_update_test.rb index df23264ab..42f3035ba 100644 --- a/test/integration/admin_area/pending_update_test.rb +++ b/test/integration/admin_area/pending_update_test.rb @@ -1,7 +1,7 @@ require 'test_helper' require 'application_system_test_case' -class AdminAreaWhiteIpsIntegrationTest < JavaScriptApplicationSystemTestCase +class AdminAreaPendingUpdateIntegrationTest < JavaScriptApplicationSystemTestCase setup do WebMock.allow_net_connect! @@ -11,23 +11,86 @@ class AdminAreaWhiteIpsIntegrationTest < JavaScriptApplicationSystemTestCase @new_registrant = contacts(:jack) @user = users(:api_bestnames) + @token = '123456' @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], registrant_verification_asked_at: Time.zone.now - 1.day, registrant_verification_token: @token) end - def test_visit_page + def test_accept_pending_update pending_json = { new_registrant_id: @new_registrant.id, - new_registrant_name: @new_registrant.name, - new_registrant_email: @new_registrant.email, - current_user_id: @user.id } + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } - @domain.update(pending_json: pending_json) - @domain.reload + @domain.update(pending_json: pending_json) + @domain.reload visit edit_admin_domain_path(id: @domain.id) - puts find(:xpath, "//body").native.attribute('outerHTML') + click_on 'Accept' + page.driver.browser.switch_to.alert.accept + + assert_text 'Pending was successfully applied.' + end + + def test_accept_pending_update_no_success + @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: nil) + + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id, + } + + @domain.update(pending_json: pending_json) + @domain.reload + + visit edit_admin_domain_path(id: @domain.id) + + click_on 'Accept' + page.driver.browser.switch_to.alert.accept + assert_text 'Not success' + end + + def test_reject_panding_update + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id, + } + + @domain.update(pending_json: pending_json) + @domain.reload + + visit edit_admin_domain_path(id: @domain.id) + + click_on 'Reject' + page.driver.browser.switch_to.alert.accept + assert_text 'Pending was successfully removed.' + end + + def test_accept_pending_update_no_success + @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: nil) + + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id, + } + + @domain.update(pending_json: pending_json) + @domain.reload + + visit edit_admin_domain_path(id: @domain.id) + + click_on 'Reject' + page.driver.browser.switch_to.alert.accept + assert_text 'Not success' end end \ No newline at end of file From ed3ee5ffc0c4ba884a9780f10e2cabd739d7f2ff Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 27 Jan 2021 16:53:54 +0200 Subject: [PATCH 26/50] added tests for certificate --- .../admin_area/certificates_test.rb | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/test/integration/admin_area/certificates_test.rb b/test/integration/admin_area/certificates_test.rb index 5aea257f7..d2b159854 100644 --- a/test/integration/admin_area/certificates_test.rb +++ b/test/integration/admin_area/certificates_test.rb @@ -3,10 +3,6 @@ require 'application_system_test_case' class AdminAreaCertificatesIntegrationTest < JavaScriptApplicationSystemTestCase - # admin_api_user_certificates - # /admin/api_users/:api_user_id/ - # /admin/api_users/:api_user_id/certificates - setup do WebMock.allow_net_connect! sign_in users(:admin) @@ -36,7 +32,6 @@ class AdminAreaCertificatesIntegrationTest < JavaScriptApplicationSystemTestCase assert_text 'Record deleted' end - # download_csr_admin_api_user_certificate GET /admin/api_users/:api_user_id/certificates/:id/download_csr(.:format) def test_download_csr get download_csr_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) @@ -46,31 +41,32 @@ class AdminAreaCertificatesIntegrationTest < JavaScriptApplicationSystemTestCase assert_not_empty response.body end - # TODO - # ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected - # download_crt_admin_api_user_certificate GET /admin/api_users/:api_user_id/certificates/:id/download_crt(.:format) - - # def test_download_crt - # get download_crt_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) + def test_download_crt + get download_crt_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) - # assert_response :ok - # assert_equal 'application/octet-stream', response.headers['Content-Type'] - # assert_equal "attachment; filename=\"test_bestnames.crt.pem\"; filename*=UTF-8''test_bestnames.crt.pem", response.headers['Content-Disposition'] - # assert_not_empty response.body - # end + assert_response :ok + assert_equal 'application/octet-stream', response.headers['Content-Type'] + assert_equal "attachment; filename=\"test_bestnames.crt.pem\"; filename*=UTF-8''test_bestnames.crt.pem", response.headers['Content-Disposition'] + assert_not_empty response.body + end def test_failed_to_revoke_certificate show_certificate_info find(:xpath, "//a[text()='Revoke this certificate']").click assert_text 'Failed to update record' + end - # element = find(:xpath, "//body").native.attribute('outerHTML') - # puts element + def test_new_api_user + visit new_admin_registrar_api_user_path(registrar_id: registrars(:bestnames).id) - # find(:xpath, "/html/body/div[2]/div[5]/div/div/div[1]/div[2]/a[2]").click + fill_in 'Username', with: 'testapiuser' + fill_in 'Password', with: 'secretpassword' + fill_in 'Identity code', with: '60305062718' - # assert_text 'Record deleted' + click_on 'Create API user' + + assert_text 'API user has been successfully created' end end \ No newline at end of file From 02b5c8c4b668739e4742e2684f3c9289a6b801cb Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 29 Jan 2021 11:59:07 +0200 Subject: [PATCH 27/50] refactored: extra line breaks, extra indentation, extra comments --- test/application_system_test_case.rb | 6 - .../admin_area/account_activities_test.rb | 2 +- .../admin_area/admin_users_test.rb | 4 +- .../admin_area/blocked_domains_test.rb | 38 +++-- .../admin_area/certificates_test.rb | 103 +++++++------ .../admin_area/delayed_jobs_test.rb | 10 -- test/integration/admin_area/epp_logs_test.rb | 87 +++++------ test/integration/admin_area/invoices_test.rb | 4 - .../admin_area/pending_delete_test.rb | 83 ++++++----- .../admin_area/pending_update_test.rb | 138 +++++++++--------- .../integration/admin_area/registrars_test.rb | 2 +- test/integration/admin_area/repp_logs_test.rb | 35 ++--- .../admin_area/reserved_domains_test.rb | 3 +- test/integration/admin_area/white_ips_test.rb | 135 +++++++++-------- test/system/admin_area/contacts_test.rb | 2 - test/system/admin_area/invoices_test.rb | 2 +- test/system/admin_area/protected_area_test.rb | 2 +- 17 files changed, 310 insertions(+), 346 deletions(-) delete mode 100644 test/integration/admin_area/delayed_jobs_test.rb diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index ec5fa02c7..726767390 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -13,7 +13,6 @@ class ApplicationSystemTestCase < ActionDispatch::IntegrationTest WebMock.reset! Capybara.reset_sessions! Capybara.use_default_driver - end end @@ -29,21 +28,16 @@ class JavaScriptApplicationSystemTestCase < ApplicationSystemTestCase options.add_argument('--disable-dev-shm-usage') options.add_argument('--window-size=1400,1400') - - Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) - end Capybara.server = :puma, { Silent: true } def setup DatabaseCleaner.start - super Capybara.current_driver = :chrome - end def teardown diff --git a/test/integration/admin_area/account_activities_test.rb b/test/integration/admin_area/account_activities_test.rb index 1bed55a93..085c51771 100644 --- a/test/integration/admin_area/account_activities_test.rb +++ b/test/integration/admin_area/account_activities_test.rb @@ -36,4 +36,4 @@ class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase response.headers['Content-Disposition'] assert_not_empty response.body end -end \ No newline at end of file +end diff --git a/test/integration/admin_area/admin_users_test.rb b/test/integration/admin_area/admin_users_test.rb index 74baee55e..bc9753565 100644 --- a/test/integration/admin_area/admin_users_test.rb +++ b/test/integration/admin_area/admin_users_test.rb @@ -30,7 +30,6 @@ class AdminAreaAdminUsersIntegrationTest < JavaScriptApplicationSystemTestCase select 'Estonia', from: 'admin_user_country_code', match: :first - # '//div[@class="selectize-input items has-options full has-items"]' select_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[1]") select_element.click @@ -39,7 +38,6 @@ class AdminAreaAdminUsersIntegrationTest < JavaScriptApplicationSystemTestCase click_on 'Save' - # if user created with valid data then record successfuly, else it failed if valid assert_text 'Record created' else @@ -103,4 +101,4 @@ class AdminAreaAdminUsersIntegrationTest < JavaScriptApplicationSystemTestCase assert_text 'Record deleted' end -end \ No newline at end of file +end diff --git a/test/integration/admin_area/blocked_domains_test.rb b/test/integration/admin_area/blocked_domains_test.rb index a03848c35..7df9d30e7 100644 --- a/test/integration/admin_area/blocked_domains_test.rb +++ b/test/integration/admin_area/blocked_domains_test.rb @@ -11,25 +11,6 @@ class AdminAreaBlockedDomainsIntegrationTest < JavaScriptApplicationSystemTestCa @blocked_domain = blocked_domains(:one) end - # HELPERS - def visit_admin_blocked_domains_path - visit admin_blocked_domains_path - assert_text 'Blocked domains' - end - - def add_domain_into_blocked_list(value) - click_on 'New blocked domain' - assert_text 'Add domain to blocked list' - - fill_in 'Name', with: @domain.name - click_on 'Save' - - return assert_text 'Domain added!' if value - return assert_text 'Failed to add domain!' - end - - # ------------------------------------------------------------ - # TESTs def test_page_successfully_loaded visit_admin_blocked_domains_path end @@ -67,4 +48,21 @@ class AdminAreaBlockedDomainsIntegrationTest < JavaScriptApplicationSystemTestCa assert_text @domain.name end -end \ No newline at end of file + private + + def visit_admin_blocked_domains_path + visit admin_blocked_domains_path + assert_text 'Blocked domains' + end + + def add_domain_into_blocked_list(value) + click_on 'New blocked domain' + assert_text 'Add domain to blocked list' + + fill_in 'Name', with: @domain.name + click_on 'Save' + + return assert_text 'Domain added!' if value + return assert_text 'Failed to add domain!' + end +end diff --git a/test/integration/admin_area/certificates_test.rb b/test/integration/admin_area/certificates_test.rb index d2b159854..d2eec0bc4 100644 --- a/test/integration/admin_area/certificates_test.rb +++ b/test/integration/admin_area/certificates_test.rb @@ -3,70 +3,69 @@ require 'application_system_test_case' class AdminAreaCertificatesIntegrationTest < JavaScriptApplicationSystemTestCase - setup do - WebMock.allow_net_connect! - sign_in users(:admin) + setup do + WebMock.allow_net_connect! + sign_in users(:admin) - @apiuser = users(:api_bestnames) - @certificate = certificates(:api) - @certificate.update!(csr: "-----BEGIN CERTIFICATE REQUEST-----\nMIICszCCAZsCAQAwbjELMAkGA1UEBhMCRUUxFDASBgNVBAMMC2ZyZXNoYm94LmVl\nMRAwDgYDVQQHDAdUYWxsaW5uMREwDwYDVQQKDAhGcmVzaGJveDERMA8GA1UECAwI\nSGFyanVtYWExETAPBgNVBAsMCEZyZXNoYm94MIIBIjANBgkqhkiG9w0BAQEFAAOC\nAQ8AMIIBCgKCAQEA1VVESynZoZhIbe8s9zHkELZ/ZDCGiM2Q8IIGb1IOieT5U2mx\nIsVXz85USYsSQY9+4YdEXnupq9fShArT8pstS/VN6BnxdfAiYXc3UWWAuaYAdNGJ\nDr5Jf6uMt1wVnCgoDL7eJq9tWMwARC/viT81o92fgqHFHW0wEolfCmnpik9o0ACD\nFiWZ9IBIevmFqXtq25v9CY2cT9+eZW127WtJmOY/PKJhzh0QaEYHqXTHWOLZWpnp\nHH4elyJ2CrFulOZbHPkPNB9Nf4XQjzk1ffoH6e5IVys2VV5xwcTkF0jY5XTROVxX\nlR2FWqic8Q2pIhSks48+J6o1GtXGnTxv94lSDwIDAQABoAAwDQYJKoZIhvcNAQEL\nBQADggEBAEFcYmQvcAC8773eRTWBJJNoA4kRgoXDMYiiEHih5iJPVSxfidRwYDTF\nsP+ttNTUg3JocFHY75kuM9T2USh+gu/trRF0o4WWa+AbK3JbbdjdT1xOMn7XtfUU\nZ/f1XCS9YdHQFCA6nk4Z+TLWwYsgk7n490AQOiB213fa1UIe83qIfw/3GRqRUZ7U\nwIWEGsHED5WT69GyxjyKHcqGoV7uFnqFN0sQVKVTy/NFRVQvtBUspCbsOirdDRie\nAB2KbGHL+t1QrRF10szwCJDyk5aYlVhxvdI8zn010nrxHkiyQpDFFldDMLJl10BW\n2w9PGO061z+tntdRcKQGuEpnIr9U5Vs=\n-----END CERTIFICATE REQUEST-----\n") - end + @apiuser = users(:api_bestnames) + @certificate = certificates(:api) + @certificate.update!(csr: "-----BEGIN CERTIFICATE REQUEST-----\nMIICszCCAZsCAQAwbjELMAkGA1UEBhMCRUUxFDASBgNVBAMMC2ZyZXNoYm94LmVl\nMRAwDgYDVQQHDAdUYWxsaW5uMREwDwYDVQQKDAhGcmVzaGJveDERMA8GA1UECAwI\nSGFyanVtYWExETAPBgNVBAsMCEZyZXNoYm94MIIBIjANBgkqhkiG9w0BAQEFAAOC\nAQ8AMIIBCgKCAQEA1VVESynZoZhIbe8s9zHkELZ/ZDCGiM2Q8IIGb1IOieT5U2mx\nIsVXz85USYsSQY9+4YdEXnupq9fShArT8pstS/VN6BnxdfAiYXc3UWWAuaYAdNGJ\nDr5Jf6uMt1wVnCgoDL7eJq9tWMwARC/viT81o92fgqHFHW0wEolfCmnpik9o0ACD\nFiWZ9IBIevmFqXtq25v9CY2cT9+eZW127WtJmOY/PKJhzh0QaEYHqXTHWOLZWpnp\nHH4elyJ2CrFulOZbHPkPNB9Nf4XQjzk1ffoH6e5IVys2VV5xwcTkF0jY5XTROVxX\nlR2FWqic8Q2pIhSks48+J6o1GtXGnTxv94lSDwIDAQABoAAwDQYJKoZIhvcNAQEL\nBQADggEBAEFcYmQvcAC8773eRTWBJJNoA4kRgoXDMYiiEHih5iJPVSxfidRwYDTF\nsP+ttNTUg3JocFHY75kuM9T2USh+gu/trRF0o4WWa+AbK3JbbdjdT1xOMn7XtfUU\nZ/f1XCS9YdHQFCA6nk4Z+TLWwYsgk7n490AQOiB213fa1UIe83qIfw/3GRqRUZ7U\nwIWEGsHED5WT69GyxjyKHcqGoV7uFnqFN0sQVKVTy/NFRVQvtBUspCbsOirdDRie\nAB2KbGHL+t1QrRF10szwCJDyk5aYlVhxvdI8zn010nrxHkiyQpDFFldDMLJl10BW\n2w9PGO061z+tntdRcKQGuEpnIr9U5Vs=\n-----END CERTIFICATE REQUEST-----\n") + end - # Helpers ======================= - def show_certificate_info - visit admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) - assert_text 'Certificates' - end + def test_show_certificate_info + show_certificate_info + end - # TESTs =========================== - def test_show_certificate_info - show_certificate_info - end + def test_destroy_certificate + show_certificate_info + find(:xpath, "//a[text()='Delete']").click - def test_destroy_certificate - show_certificate_info - find(:xpath, "//a[text()='Delete']").click + page.driver.browser.switch_to.alert.accept - page.driver.browser.switch_to.alert.accept + assert_text 'Record deleted' + end - assert_text 'Record deleted' - end + def test_download_csr + get download_csr_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) - def test_download_csr - get download_csr_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) - - assert_response :ok - assert_equal 'application/octet-stream', response.headers['Content-Type'] - assert_equal "attachment; filename=\"test_bestnames.csr.pem\"; filename*=UTF-8''test_bestnames.csr.pem", response.headers['Content-Disposition'] - assert_not_empty response.body - end + assert_response :ok + assert_equal 'application/octet-stream', response.headers['Content-Type'] + assert_equal "attachment; filename=\"test_bestnames.csr.pem\"; filename*=UTF-8''test_bestnames.csr.pem", response.headers['Content-Disposition'] + assert_not_empty response.body + end - def test_download_crt - get download_crt_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) - - assert_response :ok - assert_equal 'application/octet-stream', response.headers['Content-Type'] - assert_equal "attachment; filename=\"test_bestnames.crt.pem\"; filename*=UTF-8''test_bestnames.crt.pem", response.headers['Content-Disposition'] - assert_not_empty response.body - end + def test_download_crt + get download_crt_admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) - def test_failed_to_revoke_certificate - show_certificate_info + assert_response :ok + assert_equal 'application/octet-stream', response.headers['Content-Type'] + assert_equal "attachment; filename=\"test_bestnames.crt.pem\"; filename*=UTF-8''test_bestnames.crt.pem", response.headers['Content-Disposition'] + assert_not_empty response.body + end - find(:xpath, "//a[text()='Revoke this certificate']").click - assert_text 'Failed to update record' - end + def test_failed_to_revoke_certificate + show_certificate_info - def test_new_api_user - visit new_admin_registrar_api_user_path(registrar_id: registrars(:bestnames).id) + find(:xpath, "//a[text()='Revoke this certificate']").click + assert_text 'Failed to update record' + end - fill_in 'Username', with: 'testapiuser' - fill_in 'Password', with: 'secretpassword' - fill_in 'Identity code', with: '60305062718' + def test_new_api_user + visit new_admin_registrar_api_user_path(registrar_id: registrars(:bestnames).id) - click_on 'Create API user' + fill_in 'Username', with: 'testapiuser' + fill_in 'Password', with: 'secretpassword' + fill_in 'Identity code', with: '60305062718' - assert_text 'API user has been successfully created' - end + click_on 'Create API user' -end \ No newline at end of file + assert_text 'API user has been successfully created' + end + + private + + def show_certificate_info + visit admin_api_user_certificate_path(api_user_id: @apiuser.id, id: @certificate.id) + assert_text 'Certificates' + end +end diff --git a/test/integration/admin_area/delayed_jobs_test.rb b/test/integration/admin_area/delayed_jobs_test.rb deleted file mode 100644 index 14155e193..000000000 --- a/test/integration/admin_area/delayed_jobs_test.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'test_helper' -require 'application_system_test_case' - -class AdminAreaDelayedJobsIntegrationTest < ApplicationSystemTestCase - setup do - sign_in users(:admin) - end - -# TODO -end \ No newline at end of file diff --git a/test/integration/admin_area/epp_logs_test.rb b/test/integration/admin_area/epp_logs_test.rb index e9360672e..5ad514cb8 100644 --- a/test/integration/admin_area/epp_logs_test.rb +++ b/test/integration/admin_area/epp_logs_test.rb @@ -3,49 +3,50 @@ require 'test_helper' require 'application_system_test_case' class AdminEppLogsIntegrationTest < ApplicationSystemTestCase - setup do - sign_in users(:admin) - end + setup do + sign_in users(:admin) + end - def send_epp_request_hello - request_xml = <<-XML - - - - + def test_visit_epp_logs_page + visit admin_epp_logs_path + assert_text 'EPP log' + end + + def test_show_epp_log_page + visit admin_epp_logs_path + send_epp_request_hello + visit admin_epp_logs_path + + find(:xpath, "//tbody/tr/td/a", match: :first).click + assert_text 'Details' + end + + def test_dates_sort + Capybara.exact = true + visit admin_epp_logs_path + send_epp_request_hello + visit admin_epp_logs_path + + find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click + find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click + + epp_log_date = find(:xpath, "//table/tbody/tr/td[6]", match: :first).text(:all) + date_now = Date.today.to_s(:db) + + assert_match /#{date_now}/, epp_log_date + end + + private + + def send_epp_request_hello + request_xml = <<-XML + + + + XML - - get epp_hello_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=non-existent' } - end - def test_visit_epp_logs_page - visit admin_epp_logs_path - assert_text 'EPP log' - end - - def test_show_epp_log_page - visit admin_epp_logs_path - send_epp_request_hello - visit admin_epp_logs_path - - find(:xpath, "//tbody/tr/td/a", match: :first).click - assert_text 'Details' - end - - def test_dates_sort - Capybara.exact = true - visit admin_epp_logs_path - send_epp_request_hello - visit admin_epp_logs_path - - find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click - find(:xpath, "//a[contains(text(), 'Created at')]", match: :first).click - - epp_log_date = find(:xpath, "//table/tbody/tr/td[6]", match: :first).text(:all) - date_now = Date.today.to_s(:db) - - assert_match /#{date_now}/, epp_log_date - end - -end \ No newline at end of file + get epp_hello_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=non-existent' } + end +end diff --git a/test/integration/admin_area/invoices_test.rb b/test/integration/admin_area/invoices_test.rb index 1bee7811d..2aa17201d 100644 --- a/test/integration/admin_area/invoices_test.rb +++ b/test/integration/admin_area/invoices_test.rb @@ -11,13 +11,9 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest assert_text 'Create new invoice' select 'Best Names', from: 'deposit_registrar_id', match: :first - fill_in 'Amount', with: '1000' - click_on 'Save' - # TODO - # Should be assert_text 'Record created' assert_equal page.status_code, 200 end diff --git a/test/integration/admin_area/pending_delete_test.rb b/test/integration/admin_area/pending_delete_test.rb index 8975f985a..737d12480 100644 --- a/test/integration/admin_area/pending_delete_test.rb +++ b/test/integration/admin_area/pending_delete_test.rb @@ -2,60 +2,59 @@ require 'test_helper' require 'application_system_test_case' class AdminAreaPendingDeleteIntegrationTest < JavaScriptApplicationSystemTestCase + setup do + WebMock.allow_net_connect! + sign_in users(:admin) - setup do - WebMock.allow_net_connect! - sign_in users(:admin) + @domain = domains(:shop) + @token = '123456' - @domain = domains(:shop) - @token = '123456' + @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: @token) + end - @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], - registrant_verification_asked_at: Time.zone.now - 1.day, - registrant_verification_token: @token) - end + def test_accept_pending_delete + visit edit_admin_domain_path(id: @domain.id) - def test_accept_pending_delete - visit edit_admin_domain_path(id: @domain.id) + click_on 'Accept' + page.driver.browser.switch_to.alert.accept - click_on 'Accept' - page.driver.browser.switch_to.alert.accept + assert_text 'Pending was successfully applied.' + end - assert_text 'Pending was successfully applied.' - end + def test_accept_pending_delete_no_success + @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: nil) - def test_accept_pending_delete_no_success - @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], - registrant_verification_asked_at: Time.zone.now - 1.day, - registrant_verification_token: nil) + visit edit_admin_domain_path(id: @domain.id) - visit edit_admin_domain_path(id: @domain.id) + click_on 'Accept' + page.driver.browser.switch_to.alert.accept - click_on 'Accept' - page.driver.browser.switch_to.alert.accept + assert_text 'Not success' + end - assert_text 'Not success' - end + def test_reject_panding_delete + visit edit_admin_domain_path(id: @domain.id) - def test_reject_panding_delete - visit edit_admin_domain_path(id: @domain.id) + click_on 'Reject' + page.driver.browser.switch_to.alert.accept - click_on 'Reject' - page.driver.browser.switch_to.alert.accept + assert_text 'Pending was successfully removed.' + end - assert_text 'Pending was successfully removed.' - end + def test_accept_pending_delete_no_success + @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: nil) - def test_accept_pending_delete_no_success - @domain.update!(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION], - registrant_verification_asked_at: Time.zone.now - 1.day, - registrant_verification_token: nil) + visit edit_admin_domain_path(id: @domain.id) - visit edit_admin_domain_path(id: @domain.id) - - click_on 'Reject' - page.driver.browser.switch_to.alert.accept - - assert_text 'Not success' - end -end \ No newline at end of file + click_on 'Reject' + page.driver.browser.switch_to.alert.accept + + assert_text 'Not success' + end +end diff --git a/test/integration/admin_area/pending_update_test.rb b/test/integration/admin_area/pending_update_test.rb index 42f3035ba..5d08e104b 100644 --- a/test/integration/admin_area/pending_update_test.rb +++ b/test/integration/admin_area/pending_update_test.rb @@ -3,94 +3,94 @@ require 'application_system_test_case' class AdminAreaPendingUpdateIntegrationTest < JavaScriptApplicationSystemTestCase - setup do - WebMock.allow_net_connect! - sign_in users(:admin) + setup do + WebMock.allow_net_connect! + sign_in users(:admin) - @domain = domains(:hospital) + @domain = domains(:hospital) - @new_registrant = contacts(:jack) - @user = users(:api_bestnames) - @token = '123456' + @new_registrant = contacts(:jack) + @user = users(:api_bestnames) + @token = '123456' - @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], - registrant_verification_asked_at: Time.zone.now - 1.day, - registrant_verification_token: @token) - end + @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: @token) + end - def test_accept_pending_update - pending_json = { new_registrant_id: @new_registrant.id, - new_registrant_name: @new_registrant.name, - new_registrant_email: @new_registrant.email, - current_user_id: @user.id } + def test_accept_pending_update + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } - @domain.update(pending_json: pending_json) - @domain.reload + @domain.update(pending_json: pending_json) + @domain.reload - visit edit_admin_domain_path(id: @domain.id) + visit edit_admin_domain_path(id: @domain.id) - click_on 'Accept' - page.driver.browser.switch_to.alert.accept + click_on 'Accept' + page.driver.browser.switch_to.alert.accept - assert_text 'Pending was successfully applied.' - end + assert_text 'Pending was successfully applied.' + end - def test_accept_pending_update_no_success - @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], - registrant_verification_asked_at: Time.zone.now - 1.day, - registrant_verification_token: nil) + def test_accept_pending_update_no_success + @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: nil) - pending_json = { new_registrant_id: @new_registrant.id, - new_registrant_name: @new_registrant.name, - new_registrant_email: @new_registrant.email, - current_user_id: @user.id, - } + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id, + } - @domain.update(pending_json: pending_json) - @domain.reload + @domain.update(pending_json: pending_json) + @domain.reload - visit edit_admin_domain_path(id: @domain.id) + visit edit_admin_domain_path(id: @domain.id) - click_on 'Accept' - page.driver.browser.switch_to.alert.accept - assert_text 'Not success' - end + click_on 'Accept' + page.driver.browser.switch_to.alert.accept + assert_text 'Not success' + end - def test_reject_panding_update - pending_json = { new_registrant_id: @new_registrant.id, - new_registrant_name: @new_registrant.name, - new_registrant_email: @new_registrant.email, - current_user_id: @user.id, - } + def test_reject_panding_update + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id, + } - @domain.update(pending_json: pending_json) - @domain.reload + @domain.update(pending_json: pending_json) + @domain.reload - visit edit_admin_domain_path(id: @domain.id) + visit edit_admin_domain_path(id: @domain.id) - click_on 'Reject' - page.driver.browser.switch_to.alert.accept - assert_text 'Pending was successfully removed.' - end + click_on 'Reject' + page.driver.browser.switch_to.alert.accept + assert_text 'Pending was successfully removed.' + end - def test_accept_pending_update_no_success - @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], - registrant_verification_asked_at: Time.zone.now - 1.day, - registrant_verification_token: nil) + def test_accept_pending_update_no_success + @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], + registrant_verification_asked_at: Time.zone.now - 1.day, + registrant_verification_token: nil) - pending_json = { new_registrant_id: @new_registrant.id, - new_registrant_name: @new_registrant.name, - new_registrant_email: @new_registrant.email, - current_user_id: @user.id, - } + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id, + } - @domain.update(pending_json: pending_json) - @domain.reload + @domain.update(pending_json: pending_json) + @domain.reload - visit edit_admin_domain_path(id: @domain.id) + visit edit_admin_domain_path(id: @domain.id) - click_on 'Reject' - page.driver.browser.switch_to.alert.accept - assert_text 'Not success' - end -end \ No newline at end of file + click_on 'Reject' + page.driver.browser.switch_to.alert.accept + assert_text 'Not success' + end +end diff --git a/test/integration/admin_area/registrars_test.rb b/test/integration/admin_area/registrars_test.rb index d73496899..552650791 100644 --- a/test/integration/admin_area/registrars_test.rb +++ b/test/integration/admin_area/registrars_test.rb @@ -17,4 +17,4 @@ class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest assert_equal new_iban, @registrar.iban end -end \ No newline at end of file +end diff --git a/test/integration/admin_area/repp_logs_test.rb b/test/integration/admin_area/repp_logs_test.rb index 0a9083a59..6630a6d57 100644 --- a/test/integration/admin_area/repp_logs_test.rb +++ b/test/integration/admin_area/repp_logs_test.rb @@ -2,25 +2,22 @@ require 'test_helper' require 'application_system_test_case' class AdminAreaReppLogsIntegrationTest < ApplicationSystemTestCase + setup do + sign_in users(:admin) + end - setup do - sign_in users(:admin) - end + def test_repp_logs_page + visit admin_repp_logs_path + assert_text 'REPP log' + end - def test_repp_logs_page - visit admin_repp_logs_path - assert_text 'REPP log' - end + def test_show_repp_log_page + visit admin_repp_logs_path + get repp_v1_contacts_path + visit admin_repp_logs_path + + find(:xpath, "//tbody/tr/td/a", match: :first).click - - def test_show_repp_log_page - visit admin_repp_logs_path - get repp_v1_contacts_path - visit admin_repp_logs_path - - find(:xpath, "//tbody/tr/td/a", match: :first).click - - assert_text 'REPP log' - end - -end \ No newline at end of file + assert_text 'REPP log' + end +end diff --git a/test/integration/admin_area/reserved_domains_test.rb b/test/integration/admin_area/reserved_domains_test.rb index 577074e77..1020255b0 100644 --- a/test/integration/admin_area/reserved_domains_test.rb +++ b/test/integration/admin_area/reserved_domains_test.rb @@ -45,5 +45,4 @@ class AdminAreaReservedDomainsIntegrationTest < JavaScriptApplicationSystemTestC assert_text 'Domain updated!' end - -end \ No newline at end of file +end diff --git a/test/integration/admin_area/white_ips_test.rb b/test/integration/admin_area/white_ips_test.rb index 183f1e04b..b4ffda90a 100644 --- a/test/integration/admin_area/white_ips_test.rb +++ b/test/integration/admin_area/white_ips_test.rb @@ -3,97 +3,92 @@ require 'application_system_test_case' class AdminAreaWhiteIpsIntegrationTest < JavaScriptApplicationSystemTestCase - setup do - WebMock.allow_net_connect! - sign_in users(:admin) + setup do + WebMock.allow_net_connect! + sign_in users(:admin) - @registrar = registrars(:bestnames) - @white_ip = white_ips(:one) - end + @registrar = registrars(:bestnames) + @white_ip = white_ips(:one) + end - # Helpers ==================================== - def visit_new_whitelisted_ip_page - visit new_admin_registrar_white_ip_path(registrar_id: @registrar.id) - assert_text 'New whitelisted IP' - end + def test_visit_new_whitelisted_ip_page + visit_new_whitelisted_ip_page + end - def visit_edit_whitelisted_ip_page - visit edit_admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) - assert_text 'Edit white IP' - end + def test_create_new_whitelisted_ip + visit_new_whitelisted_ip_page + fill_in 'IPv4', with: "127.0.0.1" + fill_in 'IPv6', with: "::ffff:192.0.2.1" - def visit_info_whitelisted_ip_page - visit admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) - assert_text 'White IP' - end + find(:css, "#white_ip_interfaces_api").set(true) + find(:css, "#white_ip_interfaces_registrar").set(true) - # Tests ===================================== + click_on 'Save' - def test_visit_new_whitelisted_ip_page - visit_new_whitelisted_ip_page - end + assert_text 'Record created' + end - def test_create_new_whitelisted_ip - visit_new_whitelisted_ip_page - fill_in 'IPv4', with: "127.0.0.1" - fill_in 'IPv6', with: "::ffff:192.0.2.1" + def test_failed_to_create_new_whitelisted_ip + visit_new_whitelisted_ip_page + fill_in 'IPv4', with: "asdadadad.asd" - find(:css, "#white_ip_interfaces_api").set(true) - find(:css, "#white_ip_interfaces_registrar").set(true) + click_on 'Save' - click_on 'Save' + assert_text 'Failed to create record' + end - assert_text 'Record created' - end + def test_visit_edit_whitelisted_ip_page + visit_edit_whitelisted_ip_page + end - def test_failed_to_create_new_whitelisted_ip - visit_new_whitelisted_ip_page - fill_in 'IPv4', with: "asdadadad.asd" + def test_update_whitelisted_ip + visit_info_whitelisted_ip_page + click_on 'Edit' - click_on 'Save' + fill_in 'IPv4', with: "127.0.0.2" + find(:css, "#white_ip_interfaces_api").set(false) + click_on 'Save' - assert_text 'Failed to create record' - end + assert_text 'Record updated' + end - def test_visit_edit_whitelisted_ip_page - visit_edit_whitelisted_ip_page - end + def test_failed_to_update_whitelisted_ip + visit_info_whitelisted_ip_page + click_on 'Edit' + fill_in 'IPv4', with: "asdadad#" - def test_update_whitelisted_ip - visit_info_whitelisted_ip_page - click_on 'Edit' + click_on 'Save' - fill_in 'IPv4', with: "127.0.0.2" + assert_text 'Failed to update record' + end - find(:css, "#white_ip_interfaces_api").set(false) + def test_visit_info_whitelisted_ip_page + visit_info_whitelisted_ip_page + end - click_on 'Save' + def test_delete_whitelisted_ip + visit_info_whitelisted_ip_page + click_on 'Delete' - assert_text 'Record updated' - end + page.driver.browser.switch_to.alert.accept - def test_failed_to_update_whitelisted_ip - visit_info_whitelisted_ip_page - click_on 'Edit' + assert_text 'Record deleted' + end - fill_in 'IPv4', with: "asdadad#" + private - click_on 'Save' + def visit_new_whitelisted_ip_page + visit new_admin_registrar_white_ip_path(registrar_id: @registrar.id) + assert_text 'New whitelisted IP' + end - assert_text 'Failed to update record' - end + def visit_edit_whitelisted_ip_page + visit edit_admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) + assert_text 'Edit white IP' + end - def test_visit_info_whitelisted_ip_page - visit_info_whitelisted_ip_page - end - - def test_delete_whitelisted_ip - visit_info_whitelisted_ip_page - - click_on 'Delete' - - page.driver.browser.switch_to.alert.accept - - assert_text 'Record deleted' - end -end \ No newline at end of file + def visit_info_whitelisted_ip_page + visit admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) + assert_text 'White IP' + end +end diff --git a/test/system/admin_area/contacts_test.rb b/test/system/admin_area/contacts_test.rb index 3f40584a4..19b15c8a5 100644 --- a/test/system/admin_area/contacts_test.rb +++ b/test/system/admin_area/contacts_test.rb @@ -8,8 +8,6 @@ class AdminContactsTest < ApplicationSystemTestCase sign_in users(:admin) end - - # admin_contact def test_update_contact visit admin_contact_path(id: @contact.id) assert_text "#{@contact.name}" diff --git a/test/system/admin_area/invoices_test.rb b/test/system/admin_area/invoices_test.rb index 814f95d4a..40a50e1c7 100644 --- a/test/system/admin_area/invoices_test.rb +++ b/test/system/admin_area/invoices_test.rb @@ -40,4 +40,4 @@ class AdminAreaInvoicesTest < ApplicationSystemTestCase assert_current_path admin_invoice_path(@invoice) assert_text 'Invoice has been sent' end -end \ No newline at end of file +end diff --git a/test/system/admin_area/protected_area_test.rb b/test/system/admin_area/protected_area_test.rb index f3375776a..fa413291b 100644 --- a/test/system/admin_area/protected_area_test.rb +++ b/test/system/admin_area/protected_area_test.rb @@ -19,4 +19,4 @@ class AdminAreaProtectedAreaTest < ApplicationSystemTestCase assert_text 'You are already signed in' assert_current_path admin_domains_path end -end \ No newline at end of file +end From 8a399569fef26ec1f491de8b667c634f8aa348d2 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 27 Jan 2021 13:42:10 +0200 Subject: [PATCH 28/50] added test for domain tech contacts bulk change if domain has server update prohibited --- test/integration/api/domain_contacts_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/integration/api/domain_contacts_test.rb b/test/integration/api/domain_contacts_test.rb index 6704739d1..efd7032b4 100644 --- a/test/integration/api/domain_contacts_test.rb +++ b/test/integration/api/domain_contacts_test.rb @@ -107,6 +107,24 @@ class APIDomainContactsTest < ApplicationIntegrationTest JSON.parse(response.body, symbolize_names: true) end + def test_tech_bulk_changed_when_domain_update_prohibited + domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) + + shop_tech_contact = Contact.find_by(code: 'william-001') + assert domains(:shop).tech_contacts.include?(shop_tech_contact) + + patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001', + new_contact_id: 'john-001' }, + headers: { 'HTTP_AUTHORIZATION' => http_auth_key } + + assert_response :ok + assert_equal ({ code: 1000, + message: 'Command completed successfully', + data: { affected_domains: ["airport.test"], + skipped_domains: ["shop.test"] }}), + JSON.parse(response.body, symbolize_names: true) + end + private def http_auth_key From 486fceca9c99ae04c5475199e4288781da5d396a Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 29 Jan 2021 12:19:14 +0200 Subject: [PATCH 29/50] changed tabs --- .../admin_area/account_activities_test.rb | 64 ++++---- .../admin_area/admin_users_test.rb | 145 +++++++++--------- .../admin_area/reserved_domains_test.rb | 61 ++++---- 3 files changed, 129 insertions(+), 141 deletions(-) diff --git a/test/integration/admin_area/account_activities_test.rb b/test/integration/admin_area/account_activities_test.rb index 085c51771..306935269 100644 --- a/test/integration/admin_area/account_activities_test.rb +++ b/test/integration/admin_area/account_activities_test.rb @@ -2,38 +2,38 @@ require 'test_helper' require 'application_system_test_case' class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase - # /admin/account_activities - setup do - sign_in users(:admin) - @original_default_language = Setting.default_language - end - - def test_show_account_activities_page - account_activities(:one).update(sum: "123.00") - visit admin_account_activities_path - assert_text 'Account activities' - end + # /admin/account_activities + setup do + sign_in users(:admin) + @original_default_language = Setting.default_language + end + + def test_show_account_activities_page + account_activities(:one).update(sum: "123.00") + visit admin_account_activities_path + assert_text 'Account activities' + end - def test_default_url_params - account_activities(:one).update(sum: "123.00") - visit admin_root_path - click_link_or_button 'Settings', match: :first - find(:xpath, "//ul/li/a[text()='Account activities']").click - - assert has_current_path?(admin_account_activities_path(created_after: 'today')) - end + def test_default_url_params + account_activities(:one).update(sum: "123.00") + visit admin_root_path + click_link_or_button 'Settings', match: :first + find(:xpath, "//ul/li/a[text()='Account activities']").click + + assert has_current_path?(admin_account_activities_path(created_after: 'today')) + end - def test_download_account_activity - now = Time.zone.parse('2010-07-05 08:00') - travel_to now - account_activities(:one).update(sum: "123.00") - - get admin_account_activities_path(format: :csv) - - assert_response :ok - assert_equal "text/csv", response.headers['Content-Type'] - assert_equal %(attachment; filename="account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv), - response.headers['Content-Disposition'] - assert_not_empty response.body - end + def test_download_account_activity + now = Time.zone.parse('2010-07-05 08:00') + travel_to now + account_activities(:one).update(sum: "123.00") + + get admin_account_activities_path(format: :csv) + + assert_response :ok + assert_equal "text/csv", response.headers['Content-Type'] + assert_equal %(attachment; filename="account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv), + response.headers['Content-Disposition'] + assert_not_empty response.body + end end diff --git a/test/integration/admin_area/admin_users_test.rb b/test/integration/admin_area/admin_users_test.rb index bc9753565..5d45d3146 100644 --- a/test/integration/admin_area/admin_users_test.rb +++ b/test/integration/admin_area/admin_users_test.rb @@ -2,103 +2,100 @@ require 'test_helper' require 'application_system_test_case' class AdminAreaAdminUsersIntegrationTest < JavaScriptApplicationSystemTestCase - include Devise::Test::IntegrationHelpers - include ActionView::Helpers::NumberHelper + include Devise::Test::IntegrationHelpers + include ActionView::Helpers::NumberHelper - setup do - WebMock.allow_net_connect! - @original_default_language = Setting.default_language - sign_in users(:admin) - end + setup do + WebMock.allow_net_connect! + @original_default_language = Setting.default_language + sign_in users(:admin) + end - # Helpers funcs - def createNewAdminUser(valid) - visit admin_admin_users_path - click_on 'New admin user' + def test_create_new_admin_user + createNewAdminUser(true) + end - fill_in 'Username', with: 'test_user_name' - # If valid=true creating valid user, if else, then with invalid data - if valid - fill_in 'Password', with: 'test_password' - fill_in 'Password confirmation', with: 'test_password' - else - fill_in 'Password', with: 'test_password' - fill_in 'Password confirmation', with: 'test_password2' - end - fill_in 'Identity code', with: '38903110313' - fill_in 'Email', with: 'oleg@tester.ee' + def test_create_with_invalid_data_new_admin_user + createNewAdminUser(false) + end - select 'Estonia', from: 'admin_user_country_code', match: :first + def test_edit_successfully_exist_record + createNewAdminUser(true) - select_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[1]") - select_element.click + visit admin_admin_users_path + click_on 'test_user_name' - option_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[2]/div/div[1]") - option_element.click + assert_text 'General' + click_on 'Edit' - click_on 'Save' + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password' - if valid - assert_text 'Record created' - else - assert_text 'Failed to create record' - end - end + click_on 'Save' + assert_text 'Record updated' + end - # Tests - # "/admin/admin_users" - def test_create_new_admin_user - createNewAdminUser(true) - end + def test_edit_exist_record_with_invalid_data + createNewAdminUser(true) - def test_create_with_invalid_data_new_admin_user - createNewAdminUser(false) - end + visit admin_admin_users_path + click_on 'test_user_name' - def test_edit_successfully_exist_record - createNewAdminUser(true) + assert_text 'General' + click_on 'Edit' - visit admin_admin_users_path - click_on 'test_user_name' + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password2' - assert_text 'General' - click_on 'Edit' + click_on 'Save' + assert_text 'Failed to update record' + end + def test_delete_exist_record + createNewAdminUser(true) + + visit admin_admin_users_path + click_on 'test_user_name' + assert_text 'General' + click_on 'Delete' + + page.driver.browser.switch_to.alert.accept + + assert_text 'Record deleted' + end + + private + + def createNewAdminUser(valid) + visit admin_admin_users_path + click_on 'New admin user' + + fill_in 'Username', with: 'test_user_name' + # If valid=true creating valid user, if else, then with invalid data + if valid fill_in 'Password', with: 'test_password' fill_in 'Password confirmation', with: 'test_password' - - click_on 'Save' - assert_text 'Record updated' - end - - def test_edit_exist_record_with_invalid_data - createNewAdminUser(true) - - visit admin_admin_users_path - click_on 'test_user_name' - - assert_text 'General' - click_on 'Edit' - + else fill_in 'Password', with: 'test_password' fill_in 'Password confirmation', with: 'test_password2' - - click_on 'Save' - assert_text 'Failed to update record' end + fill_in 'Identity code', with: '38903110313' + fill_in 'Email', with: 'oleg@tester.ee' - def test_delete_exist_record - createNewAdminUser(true) + select 'Estonia', from: 'admin_user_country_code', match: :first - visit admin_admin_users_path - click_on 'test_user_name' + select_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[1]") + select_element.click - assert_text 'General' - click_on 'Delete' + option_element = find(:xpath, "/html/body/div[2]/form/div[2]/div/div[7]/div[2]/div/div[2]/div/div[1]") + option_element.click - # Accept to delete in modal window - page.driver.browser.switch_to.alert.accept + click_on 'Save' - assert_text 'Record deleted' + if valid + assert_text 'Record created' + else + assert_text 'Failed to create record' end + end end diff --git a/test/integration/admin_area/reserved_domains_test.rb b/test/integration/admin_area/reserved_domains_test.rb index 1020255b0..c09c3723b 100644 --- a/test/integration/admin_area/reserved_domains_test.rb +++ b/test/integration/admin_area/reserved_domains_test.rb @@ -3,46 +3,37 @@ require 'application_system_test_case' class AdminAreaReservedDomainsIntegrationTest < JavaScriptApplicationSystemTestCase - setup do - WebMock.allow_net_connect! - @original_default_language = Setting.default_language - sign_in users(:admin) + setup do + WebMock.allow_net_connect! + @original_default_language = Setting.default_language + sign_in users(:admin) - @reserved_domain = reserved_domains(:one) - end + @reserved_domain = reserved_domains(:one) + end - def test_remove_reserved_domain - visit admin_reserved_domains_path - - click_link_or_button 'Delete', match: :first + def test_remove_reserved_domain + visit admin_reserved_domains_path + click_link_or_button 'Delete', match: :first + page.driver.browser.switch_to.alert.accept - # Accept to delete in modal window - page.driver.browser.switch_to.alert.accept + assert_text 'Domain deleted!' + end - assert_text 'Domain deleted!' - end + def test_add_invalid_domain + visit admin_reserved_domains_path + click_on 'New reserved domain' + fill_in "Name", with: "@##@$" + click_on 'Save' - def test_add_invalid_domain - visit admin_reserved_domains_path + assert_text 'Failed to add domain!' + end - click_on 'New reserved domain' + def test_update_reserved_domain + visit admin_reserved_domains_path + click_link_or_button 'Edit Pw', match: :first + fill_in 'Password', with: '12345678' + click_on 'Save' - fill_in "Name", with: "@##@$" - - click_on 'Save' - - assert_text 'Failed to add domain!' - end - - def test_update_reserved_domain - visit admin_reserved_domains_path - - click_link_or_button 'Edit Pw', match: :first - - fill_in 'Password', with: '12345678' - - click_on 'Save' - - assert_text 'Domain updated!' - end + assert_text 'Domain updated!' + end end From 569939e84260aaab7c534267c8c2c9501d071f1b Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 29 Jan 2021 12:28:04 +0200 Subject: [PATCH 30/50] fixed tabs --- .../admin_area/admin_users_test.rb | 12 +- test/integration/admin_area/white_ips_test.rb | 128 +++++++++--------- 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/test/integration/admin_area/admin_users_test.rb b/test/integration/admin_area/admin_users_test.rb index 5d45d3146..89b9edef9 100644 --- a/test/integration/admin_area/admin_users_test.rb +++ b/test/integration/admin_area/admin_users_test.rb @@ -73,11 +73,11 @@ class AdminAreaAdminUsersIntegrationTest < JavaScriptApplicationSystemTestCase fill_in 'Username', with: 'test_user_name' # If valid=true creating valid user, if else, then with invalid data if valid - fill_in 'Password', with: 'test_password' - fill_in 'Password confirmation', with: 'test_password' + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password' else - fill_in 'Password', with: 'test_password' - fill_in 'Password confirmation', with: 'test_password2' + fill_in 'Password', with: 'test_password' + fill_in 'Password confirmation', with: 'test_password2' end fill_in 'Identity code', with: '38903110313' fill_in 'Email', with: 'oleg@tester.ee' @@ -93,9 +93,9 @@ class AdminAreaAdminUsersIntegrationTest < JavaScriptApplicationSystemTestCase click_on 'Save' if valid - assert_text 'Record created' + assert_text 'Record created' else - assert_text 'Failed to create record' + assert_text 'Failed to create record' end end end diff --git a/test/integration/admin_area/white_ips_test.rb b/test/integration/admin_area/white_ips_test.rb index b4ffda90a..499c86f57 100644 --- a/test/integration/admin_area/white_ips_test.rb +++ b/test/integration/admin_area/white_ips_test.rb @@ -3,92 +3,92 @@ require 'application_system_test_case' class AdminAreaWhiteIpsIntegrationTest < JavaScriptApplicationSystemTestCase - setup do - WebMock.allow_net_connect! - sign_in users(:admin) + setup do + WebMock.allow_net_connect! + sign_in users(:admin) - @registrar = registrars(:bestnames) - @white_ip = white_ips(:one) - end + @registrar = registrars(:bestnames) + @white_ip = white_ips(:one) + end - def test_visit_new_whitelisted_ip_page - visit_new_whitelisted_ip_page - end + def test_visit_new_whitelisted_ip_page + visit_new_whitelisted_ip_page + end - def test_create_new_whitelisted_ip - visit_new_whitelisted_ip_page - fill_in 'IPv4', with: "127.0.0.1" - fill_in 'IPv6', with: "::ffff:192.0.2.1" + def test_create_new_whitelisted_ip + visit_new_whitelisted_ip_page + fill_in 'IPv4', with: "127.0.0.1" + fill_in 'IPv6', with: "::ffff:192.0.2.1" - find(:css, "#white_ip_interfaces_api").set(true) - find(:css, "#white_ip_interfaces_registrar").set(true) + find(:css, "#white_ip_interfaces_api").set(true) + find(:css, "#white_ip_interfaces_registrar").set(true) - click_on 'Save' + click_on 'Save' - assert_text 'Record created' - end + assert_text 'Record created' + end - def test_failed_to_create_new_whitelisted_ip - visit_new_whitelisted_ip_page - fill_in 'IPv4', with: "asdadadad.asd" + def test_failed_to_create_new_whitelisted_ip + visit_new_whitelisted_ip_page + fill_in 'IPv4', with: "asdadadad.asd" - click_on 'Save' + click_on 'Save' - assert_text 'Failed to create record' - end + assert_text 'Failed to create record' + end - def test_visit_edit_whitelisted_ip_page - visit_edit_whitelisted_ip_page - end + def test_visit_edit_whitelisted_ip_page + visit_edit_whitelisted_ip_page + end - def test_update_whitelisted_ip - visit_info_whitelisted_ip_page - click_on 'Edit' + def test_update_whitelisted_ip + visit_info_whitelisted_ip_page + click_on 'Edit' - fill_in 'IPv4', with: "127.0.0.2" - find(:css, "#white_ip_interfaces_api").set(false) - click_on 'Save' + fill_in 'IPv4', with: "127.0.0.2" + find(:css, "#white_ip_interfaces_api").set(false) + click_on 'Save' - assert_text 'Record updated' - end + assert_text 'Record updated' + end - def test_failed_to_update_whitelisted_ip - visit_info_whitelisted_ip_page - click_on 'Edit' - fill_in 'IPv4', with: "asdadad#" + def test_failed_to_update_whitelisted_ip + visit_info_whitelisted_ip_page + click_on 'Edit' + fill_in 'IPv4', with: "asdadad#" - click_on 'Save' + click_on 'Save' - assert_text 'Failed to update record' - end + assert_text 'Failed to update record' + end - def test_visit_info_whitelisted_ip_page - visit_info_whitelisted_ip_page - end + def test_visit_info_whitelisted_ip_page + visit_info_whitelisted_ip_page + end - def test_delete_whitelisted_ip - visit_info_whitelisted_ip_page - click_on 'Delete' + def test_delete_whitelisted_ip + visit_info_whitelisted_ip_page + click_on 'Delete' - page.driver.browser.switch_to.alert.accept + page.driver.browser.switch_to.alert.accept - assert_text 'Record deleted' - end + assert_text 'Record deleted' + end - private + private - def visit_new_whitelisted_ip_page - visit new_admin_registrar_white_ip_path(registrar_id: @registrar.id) - assert_text 'New whitelisted IP' - end + def visit_new_whitelisted_ip_page + visit new_admin_registrar_white_ip_path(registrar_id: @registrar.id) + assert_text 'New whitelisted IP' + end - def visit_edit_whitelisted_ip_page - visit edit_admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) - assert_text 'Edit white IP' - end + def visit_edit_whitelisted_ip_page + visit edit_admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) + assert_text 'Edit white IP' + end - def visit_info_whitelisted_ip_page - visit admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) - assert_text 'White IP' - end + def visit_info_whitelisted_ip_page + visit admin_registrar_white_ip_path(registrar_id: @registrar.id, id: @white_ip.id) + assert_text 'White IP' + end end From 3c1b989723ae3981c418432a81da1f0f9cbbf096 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 29 Jan 2021 16:13:15 +0500 Subject: [PATCH 31/50] Add check if domain got *UpdateProhibited --- app/models/concerns/domain/bulk_updatable.rb | 17 +++++++++++++++++ app/models/domain.rb | 1 + app/models/tech_domain_contact.rb | 3 +-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 app/models/concerns/domain/bulk_updatable.rb diff --git a/app/models/concerns/domain/bulk_updatable.rb b/app/models/concerns/domain/bulk_updatable.rb new file mode 100644 index 000000000..a0aadb95f --- /dev/null +++ b/app/models/concerns/domain/bulk_updatable.rb @@ -0,0 +1,17 @@ +module Concerns + module Domain + module BulkUpdatable + extend ActiveSupport::Concern + + def bulk_update_prohibited? + discarded? || statuses_blocks_update? + end + + def statuses_blocks_update? + prohibited_array = [DomainStatus::SERVER_UPDATE_PROHIBITED, + DomainStatus::CLIENT_UPDATE_PROHIBITED] + prohibited_array.any? { |block_status| statuses.include?(block_status) } + end + end + end +end diff --git a/app/models/domain.rb b/app/models/domain.rb index 3acc08575..53f0fa5b6 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -10,6 +10,7 @@ class Domain < ApplicationRecord include Concerns::Domain::RegistryLockable include Concerns::Domain::Releasable include Concerns::Domain::Disputable + include Concerns::Domain::BulkUpdatable attr_accessor :roles diff --git a/app/models/tech_domain_contact.rb b/app/models/tech_domain_contact.rb index 92799061c..20f21b6ed 100644 --- a/app/models/tech_domain_contact.rb +++ b/app/models/tech_domain_contact.rb @@ -6,7 +6,7 @@ class TechDomainContact < DomainContact tech_contacts = where(contact: current_contact) tech_contacts.each do |tech_contact| - if tech_contact.domain.discarded? + if tech_contact.domain.bulk_update_prohibited? skipped_domains << tech_contact.domain.name next end @@ -18,7 +18,6 @@ class TechDomainContact < DomainContact skipped_domains << tech_contact.domain.name end end - [affected_domains.sort, skipped_domains.sort] end end From 3c068244cbc197d57da0066f5d5961d6f36dcbac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 1 Feb 2021 16:24:41 +0200 Subject: [PATCH 32/50] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5585ca6f1..4fe9d8a45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +01.02.2021 +* Improved tests for admin interface [#1805](https://github.com/internetee/registry/pull/1805) + 28.01.2021 * Fixed transfer with shared admin and tech contacts [#1808](https://github.com/internetee/registry/issues/1808) * Improved error handling with double admin/tech contacts [#1758](https://github.com/internetee/registry/issues/1758) From d07b6a9c7b08acc70f8cace60646c51585b4cb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 2 Feb 2021 13:51:46 +0200 Subject: [PATCH 33/50] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fe9d8a45..45ab590db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +02.02.2021 +* Fixed updateProhibited status not affecting bulk tech contact change operation [#1820](https://github.com/internetee/registry/pull/1820) + 01.02.2021 * Improved tests for admin interface [#1805](https://github.com/internetee/registry/pull/1805) From 1bbacbf56c16b7345ac5d74e2a01410cbf22d56f Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 11 Jan 2021 13:29:22 +0500 Subject: [PATCH 34/50] Fix class/routes namespace for ContactRequest endpoint --- .../api/v1/contact_requests_controller.rb | 23 +++++++++++ app/models/contact_request.rb | 33 ++++++++++++++++ config/routes.rb | 1 + .../api/v1/contact_requests_test.rb | 39 +++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 app/controllers/api/v1/contact_requests_controller.rb create mode 100644 app/models/contact_request.rb create mode 100644 test/integration/api/v1/contact_requests_test.rb diff --git a/app/controllers/api/v1/contact_requests_controller.rb b/app/controllers/api/v1/contact_requests_controller.rb new file mode 100644 index 000000000..0ac379396 --- /dev/null +++ b/app/controllers/api/v1/contact_requests_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class ContactRequestsController < BaseController + before_action :authenticate_shared_key + + # POST api/v1/contact_requests/ + def create + return head(:bad_request) if contact_request_params[:email].blank? + + ContactRequest.save_record(contact_request_params) + head(:created) + rescue ActionController::ParameterMissing + head(:bad_request) + end + + def update; end + + def contact_request_params + params.require(:contact_request).permit(:email, :whois_record_id, :name, :status, :id) + end + end + end +end diff --git a/app/models/contact_request.rb b/app/models/contact_request.rb new file mode 100644 index 000000000..5da1587dc --- /dev/null +++ b/app/models/contact_request.rb @@ -0,0 +1,33 @@ +class ContactRequest < ApplicationRecord + establish_connection :"whois_#{Rails.env}" + self.table_name = 'contact_requests' + + STATUS_NEW = 'new'.freeze + STATUS_CONFIRMED = 'confirmed'.freeze + STATUS_SENT = 'sent'.freeze + STATUSES = [STATUS_NEW, STATUS_CONFIRMED, STATUS_SENT].freeze + + validates :whois_record_id, presence: true + validates :email, presence: true + validates :name, presence: true + validates :status, inclusion: { in: STATUSES } + + attr_readonly :secret, + :valid_to + + def self.save_record(params) + contact_request = new(params) + contact_request.secret = create_random_secret + contact_request.valid_to = set_valid_to_24_hours_from_now + contact_request.status = STATUS_NEW + contact_request.save! + end + + def self.create_random_secret + SecureRandom.hex(64) + end + + def self.set_valid_to_24_hours_from_now + (Time.zone.now + 24.hours) + end +end diff --git a/config/routes.rb b/config/routes.rb index 3042eced4..93897b0f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -91,6 +91,7 @@ Rails.application.routes.draw do end resources :auctions, only: %i[index show update], param: :uuid + resources :contact_requests, only: %i[create update], param: :uuid resources :bounces, only: %i[create] end diff --git a/test/integration/api/v1/contact_requests_test.rb b/test/integration/api/v1/contact_requests_test.rb new file mode 100644 index 000000000..78525e0b5 --- /dev/null +++ b/test/integration/api/v1/contact_requests_test.rb @@ -0,0 +1,39 @@ +require 'test_helper' + +class ApiV1ContactRequestTest < ActionDispatch::IntegrationTest + def setup + @api_key = "Basic #{ENV['api_shared_key']}" + @headers = { "Authorization": "#{@api_key}" } + @json_body = { "contact_request": valid_contact_request_body }.as_json + end + + def test_authorizes_api_request + post api_v1_contact_requests_path, params: @json_body, headers: @headers + assert_response :created + + invalid_headers = { "Authorization": "Basic invalid_api_key" } + post api_v1_contact_requests_path, params: @json_body, headers: invalid_headers + assert_response :unauthorized + end + + def test_saves_new_contact_request + request_body = @json_body.dup + random_mail = "#{rand(10000..99999)}@registry.test" + request_body['contact_request']['email'] = random_mail + + post api_v1_contact_requests_path, params: request_body, headers: @headers + assert_response :created + + contact_request = ContactRequest.last + assert_equal contact_request.email, random_mail + assert ContactRequest::STATUS_NEW, contact_request.status + end + + def valid_contact_request_body + { + "email": "aaa@bbb.com", + "whois_record_id": "1", + "name": "test" + }.as_json + end +end From b708cebbfdd2f901e1c69886eb6c56c8892d887a Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 11 Jan 2021 14:52:03 +0500 Subject: [PATCH 35/50] Add update endpoint for ContactRequests --- .../api/v1/contact_requests_controller.rb | 16 ++++++-- app/models/contact_request.rb | 5 +++ config/routes.rb | 2 +- test/fixtures/contact_requests.yml | 8 ++++ .../api/v1/contact_requests_test.rb | 39 ++++++++++++++++--- 5 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 test/fixtures/contact_requests.yml diff --git a/app/controllers/api/v1/contact_requests_controller.rb b/app/controllers/api/v1/contact_requests_controller.rb index 0ac379396..114e3c64d 100644 --- a/app/controllers/api/v1/contact_requests_controller.rb +++ b/app/controllers/api/v1/contact_requests_controller.rb @@ -9,14 +9,24 @@ module Api ContactRequest.save_record(contact_request_params) head(:created) - rescue ActionController::ParameterMissing + rescue StandardError head(:bad_request) end - def update; end + def update + return head(:bad_request) if params[:id].blank? + + record = ContactRequest.find_by(id: params[:id]) + return head(:not_found) unless record + + record.update_status(contact_request_params[:status]) + head(:ok) + rescue StandardError + head(:bad_request) + end def contact_request_params - params.require(:contact_request).permit(:email, :whois_record_id, :name, :status, :id) + params.require(:contact_request).permit(:email, :whois_record_id, :name, :status) end end end diff --git a/app/models/contact_request.rb b/app/models/contact_request.rb index 5da1587dc..a49a92f41 100644 --- a/app/models/contact_request.rb +++ b/app/models/contact_request.rb @@ -23,6 +23,11 @@ class ContactRequest < ApplicationRecord contact_request.save! end + def update_status(status) + self.status = status + save! + end + def self.create_random_secret SecureRandom.hex(64) end diff --git a/config/routes.rb b/config/routes.rb index 93897b0f1..1635789fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -91,7 +91,7 @@ Rails.application.routes.draw do end resources :auctions, only: %i[index show update], param: :uuid - resources :contact_requests, only: %i[create update], param: :uuid + resources :contact_requests, only: %i[create update], param: :id resources :bounces, only: %i[create] end diff --git a/test/fixtures/contact_requests.yml b/test/fixtures/contact_requests.yml new file mode 100644 index 000000000..030a4d726 --- /dev/null +++ b/test/fixtures/contact_requests.yml @@ -0,0 +1,8 @@ +new: + whois_record_id: 1 + email: aaa@bbb.com + name: Testname + status: new + secret: somesecret + valid_to: 2010-07-05 + diff --git a/test/integration/api/v1/contact_requests_test.rb b/test/integration/api/v1/contact_requests_test.rb index 78525e0b5..f0621b686 100644 --- a/test/integration/api/v1/contact_requests_test.rb +++ b/test/integration/api/v1/contact_requests_test.rb @@ -4,20 +4,22 @@ class ApiV1ContactRequestTest < ActionDispatch::IntegrationTest def setup @api_key = "Basic #{ENV['api_shared_key']}" @headers = { "Authorization": "#{@api_key}" } - @json_body = { "contact_request": valid_contact_request_body }.as_json + @json_create = { "contact_request": valid_contact_request_create }.as_json + @json_update = { "contact_request": valid_contact_request_update }.as_json + @contact_request = contact_requests(:new) end def test_authorizes_api_request - post api_v1_contact_requests_path, params: @json_body, headers: @headers + post api_v1_contact_requests_path, params: @json_create, headers: @headers assert_response :created invalid_headers = { "Authorization": "Basic invalid_api_key" } - post api_v1_contact_requests_path, params: @json_body, headers: invalid_headers + post api_v1_contact_requests_path, params: @json_create, headers: invalid_headers assert_response :unauthorized end def test_saves_new_contact_request - request_body = @json_body.dup + request_body = @json_create.dup random_mail = "#{rand(10000..99999)}@registry.test" request_body['contact_request']['email'] = random_mail @@ -29,11 +31,38 @@ class ApiV1ContactRequestTest < ActionDispatch::IntegrationTest assert ContactRequest::STATUS_NEW, contact_request.status end - def valid_contact_request_body + def test_updates_existing_contact_request + request_body = @json_update.dup + + put api_v1_contact_request_path(@contact_request.id), params: request_body, headers: @headers + assert_response :ok + + @contact_request.reload + assert ContactRequest::STATUS_CONFIRMED, @contact_request.status + end + + def test_not_updates_if_status_error + request_body = @json_update.dup + request_body['contact_request']['status'] = 'some_error_status' + + put api_v1_contact_request_path(@contact_request.id), params: request_body, headers: @headers + assert_response 400 + + @contact_request.reload + assert ContactRequest::STATUS_NEW, @contact_request.status + end + + def valid_contact_request_create { "email": "aaa@bbb.com", "whois_record_id": "1", "name": "test" }.as_json end + + def valid_contact_request_update + { + "status": "#{ContactRequest::STATUS_CONFIRMED}", + }.as_json + end end From 2d510ec3a6758ce4eade3fc6d8beb968a532d8ed Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 11 Jan 2021 14:58:42 +0500 Subject: [PATCH 36/50] Fix CC --- .../api/v1/contact_requests_controller.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/contact_requests_controller.rb b/app/controllers/api/v1/contact_requests_controller.rb index 114e3c64d..a02a68606 100644 --- a/app/controllers/api/v1/contact_requests_controller.rb +++ b/app/controllers/api/v1/contact_requests_controller.rb @@ -16,13 +16,18 @@ module Api def update return head(:bad_request) if params[:id].blank? - record = ContactRequest.find_by(id: params[:id]) - return head(:not_found) unless record + result = process_id(params[:id]) + head(result) + end + + def process_id(id) + record = ContactRequest.find_by(id: id) + return :not_found unless record record.update_status(contact_request_params[:status]) - head(:ok) + :ok rescue StandardError - head(:bad_request) + :bad_request end def contact_request_params From 402005cda103017954b7720d86a47e31e2fff157 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 11 Jan 2021 15:30:05 +0500 Subject: [PATCH 37/50] Add IP address saving --- app/controllers/api/v1/contact_requests_controller.rb | 4 ++-- app/models/contact_request.rb | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/contact_requests_controller.rb b/app/controllers/api/v1/contact_requests_controller.rb index a02a68606..531b7e506 100644 --- a/app/controllers/api/v1/contact_requests_controller.rb +++ b/app/controllers/api/v1/contact_requests_controller.rb @@ -24,14 +24,14 @@ module Api record = ContactRequest.find_by(id: id) return :not_found unless record - record.update_status(contact_request_params[:status]) + record.update_status(contact_request_params) :ok rescue StandardError :bad_request end def contact_request_params - params.require(:contact_request).permit(:email, :whois_record_id, :name, :status) + params.require(:contact_request).permit(:email, :whois_record_id, :name, :status, :ip) end end end diff --git a/app/models/contact_request.rb b/app/models/contact_request.rb index a49a92f41..7b91bdd78 100644 --- a/app/models/contact_request.rb +++ b/app/models/contact_request.rb @@ -23,8 +23,9 @@ class ContactRequest < ApplicationRecord contact_request.save! end - def update_status(status) - self.status = status + def update_status(params) + self.status = params['status'] + self.ip_address = params['ip'] save! end From 83b5dc6fc783db7696c199a675acdb4aaf3523e6 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 18 Jan 2021 14:23:08 +0500 Subject: [PATCH 38/50] Return created/updated ContactRequest in body --- app/controllers/api/v1/contact_requests_controller.rb | 11 +++++------ app/models/contact_request.rb | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/contact_requests_controller.rb b/app/controllers/api/v1/contact_requests_controller.rb index 531b7e506..2b5977f59 100644 --- a/app/controllers/api/v1/contact_requests_controller.rb +++ b/app/controllers/api/v1/contact_requests_controller.rb @@ -7,8 +7,8 @@ module Api def create return head(:bad_request) if contact_request_params[:email].blank? - ContactRequest.save_record(contact_request_params) - head(:created) + contact_request = ContactRequest.save_record(contact_request_params) + render json: contact_request, status: :created rescue StandardError head(:bad_request) end @@ -16,8 +16,7 @@ module Api def update return head(:bad_request) if params[:id].blank? - result = process_id(params[:id]) - head(result) + process_id(params[:id]) end def process_id(id) @@ -25,9 +24,9 @@ module Api return :not_found unless record record.update_status(contact_request_params) - :ok + render json: record, status: :ok rescue StandardError - :bad_request + head :bad_request end def contact_request_params diff --git a/app/models/contact_request.rb b/app/models/contact_request.rb index 7b91bdd78..e6a5e9f7d 100644 --- a/app/models/contact_request.rb +++ b/app/models/contact_request.rb @@ -21,6 +21,7 @@ class ContactRequest < ApplicationRecord contact_request.valid_to = set_valid_to_24_hours_from_now contact_request.status = STATUS_NEW contact_request.save! + contact_request end def update_status(params) From bb7effc3705223f1322f8bbfe644299d0f2fe0ea Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 4 Feb 2021 12:30:13 +0500 Subject: [PATCH 39/50] Change name of API key --- app/controllers/api/v1/base_controller.rb | 2 +- config/application.yml.sample | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index b62b3e063..045e4395e 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -11,7 +11,7 @@ module Api end def authenticate_shared_key - api_key = "Basic #{ENV['api_shared_key']}" + api_key = "Basic #{ENV['internal_api_key']}" head(:unauthorized) unless api_key == request.authorization end diff --git a/config/application.yml.sample b/config/application.yml.sample index 5885c47a2..21f1df8e0 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -90,6 +90,9 @@ registrant_api_auth_allowed_ips: '127.0.0.1, 0.0.0.0' #ips, separated with comma # Bounces API api_shared_key: testkey +# Link to REST-WHOIS API +internal_api_key: testkey + # Base URL (inc. https://) of REST registrant portal # Leave blank to use internal registrant portal registrant_portal_verifications_base_url: '' From 8ed3aaf78151915871869b130e8c3eaf997c96b2 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 4 Feb 2021 12:52:42 +0200 Subject: [PATCH 40/50] test added --- test/models/white_ip_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/models/white_ip_test.rb b/test/models/white_ip_test.rb index 607887730..7a0c6078b 100644 --- a/test/models/white_ip_test.rb +++ b/test/models/white_ip_test.rb @@ -38,6 +38,20 @@ class WhiteIpTest < ActiveSupport::TestCase assert white_ip.valid? end + def test_validates_include_empty_ipv4 + white_ip = WhiteIp.new + + white_ip.ipv4 = '' + white_ip.ipv6 = '001:0db8:85a3:0000:0000:8a2e:0370:7334' + white_ip.registrar = registrars(:bestnames) + + assert_nothing_raised { white_ip.save } + assert white_ip.valid? + + assert WhiteIp.include_ip?(white_ip.ipv6) + assert_not WhiteIp.include_ip?('192.168.1.1') + end + private def valid_white_ip From dc428b3c18804d927eaa2b5de75f36d6c98fd6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 4 Feb 2021 16:24:01 +0200 Subject: [PATCH 41/50] Fix IPv4/IPv6 parsing for empty string --- app/models/white_ip.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/white_ip.rb b/app/models/white_ip.rb index 417633b12..7bb3ccb37 100644 --- a/app/models/white_ip.rb +++ b/app/models/white_ip.rb @@ -50,10 +50,10 @@ class WhiteIp < ApplicationRecord def ids_including(ip) ipv4 = ipv6 = [] if check_ip4(ip).present? - ipv4 = select { |white_ip| IPAddr.new(white_ip.ipv4, Socket::AF_INET) === check_ip4(ip) } + ipv4 = select { |white_ip| check_ip4(white_ip.ipv4) === check_ip4(ip) } end if check_ip6(ip).present? - ipv6 = select { |white_ip| IPAddr.new(white_ip.ipv6, Socket::AF_INET6) === check_ip6(ip) } + ipv6 = select { |white_ip| check_ip6(white_ip.ipv6) === check_ip6(ip) } end (ipv4 + ipv6).pluck(:id).flatten.uniq end From b34be2c0273b75a1ca3fe29b31a3954ea9a451bc Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 5 Feb 2021 10:34:32 +0200 Subject: [PATCH 42/50] modifed test --- test/models/white_ip_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/white_ip_test.rb b/test/models/white_ip_test.rb index 7a0c6078b..ba5abe42f 100644 --- a/test/models/white_ip_test.rb +++ b/test/models/white_ip_test.rb @@ -41,7 +41,7 @@ class WhiteIpTest < ActiveSupport::TestCase def test_validates_include_empty_ipv4 white_ip = WhiteIp.new - white_ip.ipv4 = '' + white_ip.ipv4 = nil white_ip.ipv6 = '001:0db8:85a3:0000:0000:8a2e:0370:7334' white_ip.registrar = registrars(:bestnames) From d99dd477c6fd667faf70a30a1faf72a4088d4837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 5 Feb 2021 11:45:58 +0200 Subject: [PATCH 43/50] WhiteIP: Replace empty string with nil --- app/models/white_ip.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/white_ip.rb b/app/models/white_ip.rb index 7bb3ccb37..38cee7b6b 100644 --- a/app/models/white_ip.rb +++ b/app/models/white_ip.rb @@ -4,8 +4,13 @@ class WhiteIp < ApplicationRecord validate :valid_ipv4? validate :valid_ipv6? - validate :validate_ipv4_and_ipv6 + before_save :normalize_blank_values + + def normalize_blank_values + %i[ipv4 ipv6].each { |c| self[c].present? || self[c] = nil } + end + def validate_ipv4_and_ipv6 return if ipv4.present? || ipv6.present? errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present)) From f4abad7a9fb8e50196d45ff088a152e089159e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 5 Feb 2021 12:46:14 +0200 Subject: [PATCH 44/50] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45ab590db..064905ba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +05.02.2021 +* Fixed IPv4 empty string issue in case of IPv6 only entries for IP whitelist [#1833](https://github.com/internetee/registry/issues/1833) + 02.02.2021 * Fixed updateProhibited status not affecting bulk tech contact change operation [#1820](https://github.com/internetee/registry/pull/1820) From 6304ebdbc63605fa152b47966dc64fcab040301a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 8 Feb 2021 16:28:04 +0200 Subject: [PATCH 45/50] Add Amazon SDK gem --- Gemfile | 2 ++ Gemfile.lock | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Gemfile b/Gemfile index dd879a11b..2d156c829 100644 --- a/Gemfile +++ b/Gemfile @@ -92,3 +92,5 @@ group :test do gem 'webdrivers' gem 'webmock' end + +gem "aws-sdk-ses", "~> 1.37" diff --git a/Gemfile.lock b/Gemfile.lock index 51c880c9e..01408ebd7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -148,6 +148,18 @@ GEM attr_required (1.0.1) autoprefixer-rails (10.0.0.2) execjs + aws-eventstream (1.1.0) + aws-partitions (1.424.0) + aws-sdk-core (3.112.0) + aws-eventstream (~> 1, >= 1.0.2) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ses (1.37.0) + aws-sdk-core (~> 3, >= 3.112.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.2.2) + aws-eventstream (~> 1, >= 1.0.2) bcrypt (3.1.16) bindata (2.4.8) bootsnap (1.4.8) @@ -226,6 +238,7 @@ GEM i18n_data (0.10.0) isikukood (0.1.2) iso8601 (0.12.1) + jmespath (1.4.0) jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -484,6 +497,7 @@ DEPENDENCIES active_interaction (~> 3.8) activerecord-import airbrake + aws-sdk-ses (~> 1.37) bootsnap (>= 1.1.0) bootstrap-sass (~> 3.4) cancancan From 2af0bfdda04f5427080385507f2faf8a31e7e783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 8 Feb 2021 16:52:31 +0200 Subject: [PATCH 46/50] BouncedMailAddress: Remove from AWS suppression list upon destroy --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/models/bounced_mail_address.rb | 17 +++++++++++++++++ config/initializers/aws_ses.rb | 4 ++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 config/initializers/aws_ses.rb diff --git a/Gemfile b/Gemfile index 2d156c829..79862bd69 100644 --- a/Gemfile +++ b/Gemfile @@ -93,4 +93,4 @@ group :test do gem 'webmock' end -gem "aws-sdk-ses", "~> 1.37" +gem "aws-sdk-sesv2", "~> 1.16" diff --git a/Gemfile.lock b/Gemfile.lock index 01408ebd7..08daf4226 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -155,7 +155,7 @@ GEM aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-ses (1.37.0) + aws-sdk-sesv2 (1.16.0) aws-sdk-core (~> 3, >= 3.112.0) aws-sigv4 (~> 1.1) aws-sigv4 (1.2.2) @@ -497,7 +497,7 @@ DEPENDENCIES active_interaction (~> 3.8) activerecord-import airbrake - aws-sdk-ses (~> 1.37) + aws-sdk-sesv2 (~> 1.16) bootsnap (>= 1.1.0) bootstrap-sass (~> 3.4) cancancan diff --git a/app/models/bounced_mail_address.rb b/app/models/bounced_mail_address.rb index 73c6a0941..d0411a6c9 100644 --- a/app/models/bounced_mail_address.rb +++ b/app/models/bounced_mail_address.rb @@ -1,5 +1,6 @@ class BouncedMailAddress < ApplicationRecord validates :email, :message_id, :bounce_type, :bounce_subtype, :action, :status, presence: true + after_destroy :destroy_aws_suppression def bounce_reason "#{action} (#{status} #{diagnostic})" @@ -25,4 +26,20 @@ class BouncedMailAddress < ApplicationRecord diagnostic: bounced_record['diagnosticCode'], } end + + def destroy_aws_suppression + return unless BouncedMailAddress.ses_configured? + + res = Aws::SESV2::Client.new.delete_suppressed_destination({ email_address: email }) + res.successful? + rescue Aws::SESV2::Errors::ServiceError => e + logger.warn("Suppression not removed. #{e}") + end + + def self.ses_configured? + ses ||= Aws::SES::Client.new + ses.config.credentials.access_key_id.present? + rescue Aws::Errors::MissingRegionError + false + end end diff --git a/config/initializers/aws_ses.rb b/config/initializers/aws_ses.rb new file mode 100644 index 000000000..baa148e65 --- /dev/null +++ b/config/initializers/aws_ses.rb @@ -0,0 +1,4 @@ +Aws.config.update( + region: ENV['aws_default_region'], + credentials: Aws::Credentials.new(ENV['aws_access_key_id'], ENV['aws_secret_access_key']) +) From f6fd10b01767bb3aa0421200ef9901ad0d387042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 8 Feb 2021 16:57:16 +0200 Subject: [PATCH 47/50] Fix CC issues --- Gemfile | 2 +- app/models/bounced_mail_address.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 79862bd69..82a0b4666 100644 --- a/Gemfile +++ b/Gemfile @@ -93,4 +93,4 @@ group :test do gem 'webmock' end -gem "aws-sdk-sesv2", "~> 1.16" +gem 'aws-sdk-sesv2', '~> 1.16' diff --git a/app/models/bounced_mail_address.rb b/app/models/bounced_mail_address.rb index d0411a6c9..db4413829 100644 --- a/app/models/bounced_mail_address.rb +++ b/app/models/bounced_mail_address.rb @@ -30,14 +30,14 @@ class BouncedMailAddress < ApplicationRecord def destroy_aws_suppression return unless BouncedMailAddress.ses_configured? - res = Aws::SESV2::Client.new.delete_suppressed_destination({ email_address: email }) + res = Aws::SESV2::Client.new.delete_suppressed_destination(email_address: email) res.successful? rescue Aws::SESV2::Errors::ServiceError => e logger.warn("Suppression not removed. #{e}") end def self.ses_configured? - ses ||= Aws::SES::Client.new + ses ||= Aws::SESV2::Client.new ses.config.credentials.access_key_id.present? rescue Aws::Errors::MissingRegionError false From b892927f11c98b961cae8d33ee3daa605a966600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 9 Feb 2021 16:12:57 +0200 Subject: [PATCH 48/50] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 064905ba7..891059845 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +09.02.2021 +* Added new endpoint for WHOIS contact requests [#1794](https://github.com/internetee/registry/pull/1794) + 05.02.2021 * Fixed IPv4 empty string issue in case of IPv6 only entries for IP whitelist [#1833](https://github.com/internetee/registry/issues/1833) From 1b6c4516564343679715fc852aecb7db4987739b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 10 Feb 2021 12:17:32 +0200 Subject: [PATCH 49/50] Create separate key for Bounces API --- app/controllers/api/v1/base_controller.rb | 2 +- app/controllers/api/v1/bounces_controller.rb | 9 ++++++++- config/application.yml.sample | 6 +++--- test/integration/api/v1/bounces/create_test.rb | 2 +- test/integration/api/v1/contact_requests_test.rb | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 045e4395e..6ee986a48 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -11,7 +11,7 @@ module Api end def authenticate_shared_key - api_key = "Basic #{ENV['internal_api_key']}" + api_key = "Basic #{ENV['rwhois_internal_api_shared_key']}" head(:unauthorized) unless api_key == request.authorization end diff --git a/app/controllers/api/v1/bounces_controller.rb b/app/controllers/api/v1/bounces_controller.rb index fd10a3398..de2814250 100644 --- a/app/controllers/api/v1/bounces_controller.rb +++ b/app/controllers/api/v1/bounces_controller.rb @@ -1,7 +1,7 @@ module Api module V1 class BouncesController < BaseController - before_action :authenticate_shared_key + before_action :validate_shared_key_integrity # POST api/v1/bounces/ def create @@ -20,6 +20,13 @@ module Api params.require(:data) end + + private + + def validate_shared_key_integrity + api_key = "Basic #{ENV['rwhois_bounces_api_shared_key']}" + head(:unauthorized) unless api_key == request.authorization + end end end end diff --git a/config/application.yml.sample b/config/application.yml.sample index 21f1df8e0..dd38e206c 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -87,11 +87,11 @@ sk_digi_doc_service_name: 'Testimine' registrant_api_base_url: registrant_api_auth_allowed_ips: '127.0.0.1, 0.0.0.0' #ips, separated with commas -# Bounces API -api_shared_key: testkey +# Shared key for REST-WHOIS Bounces API incl. CERT +rwhois_bounces_api_shared_key: testkey # Link to REST-WHOIS API -internal_api_key: testkey +rwhois_internal_api_shared_key: testkey # Base URL (inc. https://) of REST registrant portal # Leave blank to use internal registrant portal diff --git a/test/integration/api/v1/bounces/create_test.rb b/test/integration/api/v1/bounces/create_test.rb index 899b6c5c7..0d3dc65d7 100644 --- a/test/integration/api/v1/bounces/create_test.rb +++ b/test/integration/api/v1/bounces/create_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class BouncesApiV1CreateTest < ActionDispatch::IntegrationTest def setup - @api_key = "Basic #{ENV['api_shared_key']}" + @api_key = "Basic #{ENV['rwhois_bounces_api_shared_key']}" @headers = { "Authorization": "#{@api_key}" } @json_body = { "data": valid_bounce_request }.as_json end diff --git a/test/integration/api/v1/contact_requests_test.rb b/test/integration/api/v1/contact_requests_test.rb index f0621b686..c9e2ac9bd 100644 --- a/test/integration/api/v1/contact_requests_test.rb +++ b/test/integration/api/v1/contact_requests_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class ApiV1ContactRequestTest < ActionDispatch::IntegrationTest def setup - @api_key = "Basic #{ENV['api_shared_key']}" + @api_key = "Basic #{ENV['rwhois_internal_api_shared_key']}" @headers = { "Authorization": "#{@api_key}" } @json_create = { "contact_request": valid_contact_request_create }.as_json @json_update = { "contact_request": valid_contact_request_update }.as_json From 476093f3ce0a8741354160980a6189f376189146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Wed, 10 Feb 2021 14:14:23 +0200 Subject: [PATCH 50/50] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 891059845..6e53f4714 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +10.02.2021 +* Option to remove email addresses from AWS SES Supression list [#1839](https://github.com/internetee/registry/issues/1839) +* Added separate key for bounce API [#1842](https://github.com/internetee/registry/pull/1842) + 09.02.2021 * Added new endpoint for WHOIS contact requests [#1794](https://github.com/internetee/registry/pull/1794)