Merge branch 'master' into enable-trimming-dnskey

This commit is contained in:
Thiago Youssef 2022-10-06 06:57:47 -03:00
commit ae738aa11e
70 changed files with 1089 additions and 464 deletions

View file

@ -0,0 +1,41 @@
require 'test_helper'
class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
setup do
ENV['registry_demo_registrar_api_user_url'] = 'http://registry.test:3000/api/v1/accreditation_center/show_api_user'
ENV['registry_demo_registrar_port'] = '3000'
@api_user = users(:api_bestnames)
sign_in users(:admin)
end
def test_set_test_date_to_api_user
# ENV['registry_demo_registrar_api_user_url'] = 'http://testapi.test'
date = Time.zone.now - 10.minutes
api_user = @api_user.dup
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
assert_nil @api_user.accreditation_date
assert_equal api_user.accreditation_date, date
# api_v1_accreditation_center_show_api_user_url
stub_request(:get, "http://registry.test:3000/api/v1/accreditation_center/show_api_user?username=#{@api_user.username}&identity_code=#{@api_user.identity_code}")
.with(
headers: {
'Accept' => '*/*',
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent' => 'Ruby'
}
)
.to_return(status: 200, body: { code: 200, user_api: api_user }.to_json, headers: {})
post set_test_date_to_api_user_admin_registrars_path, params: { user_api_id: @api_user.id }, headers: { 'HTTP_REFERER' => root_path }
@api_user.reload
assert_equal @api_user.accreditation_date.to_date, api_user.accreditation_date.to_date
assert_equal @api_user.accreditation_expire_date.to_date, api_user.accreditation_expire_date.to_date
end
end

View file

@ -170,4 +170,15 @@ class AdminAreaAuctionIntegrationTest < ApplicationSystemTestCase
find(:id, "reserved-modal", match: :first).click
assert_text 'Reserved domains'
end
def test_delete_auction
visit admin_auctions_path
domain = Auction.first
find(:id, "delete-auction-#{domain.id}", match: :first).click
assert_raises ActiveRecord::RecordNotFound do
domain.reload
end
end
end

View file

@ -0,0 +1,18 @@
require 'test_helper'
class DomainShowTest < ApplicationIntegrationTest
setup do
@domain = domains(:shop)
sign_in users(:admin)
end
def test_downloads_domain
filename = "#{@domain.name}.pdf"
get download_admin_domain_path(@domain)
assert_response :ok
assert_equal 'application/pdf', response.headers['Content-Type']
assert_equal "attachment; filename=\"#{filename}\"; filename*=UTF-8''#{filename}", response.headers['Content-Disposition']
assert_not_empty response.body
end
end

View file

@ -4,6 +4,8 @@ class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
setup do
ENV['registry_demo_registrar_results_url'] = 'http://registry.test:3000/api/v1/accreditation_center/results'
ENV['registry_demo_registrar_port'] = '3000'
@registrar = registrars(:bestnames)
sign_in users(:admin)
end
@ -17,4 +19,29 @@ class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest
assert_equal new_iban, @registrar.iban
end
def test_set_test_date
api_user = @registrar.api_users.first.dup
api_user.accreditation_date = Time.zone.now - 10.minutes
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
assert_nil @registrar.api_users.first.accreditation_date
stub_request(:get, "http://registry.test:3000/api/v1/accreditation_center/results?registrar_name=#{@registrar.name}")
.with(
headers: {
'Accept' => '*/*',
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent' => 'Ruby'
}
)
.to_return(status: 200, body: { code: 200, registrar_users: [api_user] }.to_json, headers: {})
post set_test_date_admin_registrars_path, params: { registrar_id: @registrar.id }, headers: { 'HTTP_REFERER' => root_path }
@registrar.reload
assert_equal @registrar.api_users.first.accreditation_date.to_date, api_user.accreditation_date.to_date
assert_equal @registrar.api_users.first.accreditation_expire_date.to_date, api_user.accreditation_expire_date.to_date
end
end

View file

@ -28,7 +28,7 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
assert_equal ({ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
'domain' => 'auction.test',
'status' => Auction.statuses[:awaiting_payment],
'platform' => nil }), ActiveSupport::JSON.decode(response.body)
'platform' => "auto" }), ActiveSupport::JSON.decode(response.body)
end
def test_marks_as_awaiting_payment

View file

@ -1,35 +1,37 @@
require 'test_helper'
class ReppV1AccreditationInfoTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
if Feature.allow_accr_endspoints?
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
@auth_headers = { 'Authorization' => token }
end
def test_valid_login
get '/repp/v1/registrar/accreditation/get_info', headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
def test_valid_login
get '/repp/v1/registrar/accreditation/get_info', headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal json[:data][:username], @user.username
assert json[:data][:roles].include? 'super'
assert_equal json[:data][:registrar_name], 'Best Names'
assert_equal json[:data][:registrar_reg_no], '1234'
end
assert_response :ok
assert_equal json[:data][:username], @user.username
assert json[:data][:roles].include? 'super'
assert_equal json[:data][:registrar_name], 'Best Names'
assert_equal json[:data][:registrar_reg_no], '1234'
end
def test_invalid_login
token = Base64.encode64("#{@user.username}:0066600")
token = "Basic #{token}"
def test_invalid_login
token = Base64.encode64("#{@user.username}:0066600")
token = "Basic #{token}"
auth_headers = { 'Authorization' => token }
auth_headers = { 'Authorization' => token }
get '/repp/v1/registrar/accreditation/get_info', headers: auth_headers
json = JSON.parse(response.body, symbolize_names: true)
get '/repp/v1/registrar/accreditation/get_info', headers: auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :unauthorized
assert_equal json[:message], 'Invalid authorization information'
assert_response :unauthorized
assert_equal json[:message], 'Invalid authorization information'
end
end
end

View file

@ -1,52 +1,54 @@
require 'test_helper'
class ReppV1AccreditationResultsTest < ActionDispatch::IntegrationTest
TEMPORARY_SECRET_KEY = ENV['accreditation_secret'].freeze
if Feature.allow_accr_endspoints?
TEMPORARY_SECRET_KEY = ENV['accreditation_secret'].freeze
def setup
@user = users(:api_bestnames)
def setup
@user = users(:api_bestnames)
token = "Basic #{TEMPORARY_SECRET_KEY}"
token = "Basic #{TEMPORARY_SECRET_KEY}"
@auth_headers = { 'Authorization' => token }
end
@auth_headers = { 'Authorization' => token }
end
def test_should_return_valid_response
post '/repp/v1/registrar/accreditation/push_results',
headers: @auth_headers,
params: {accreditation_result: {username: @user.username, result: true} }
json = JSON.parse(response.body, symbolize_names: true)
def test_should_return_valid_response
post '/repp/v1/registrar/accreditation/push_results',
headers: @auth_headers,
params: {accreditation_result: {username: @user.username, result: true} }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_emails 2
assert_equal json[:data][:user][:username], @user.username
assert_equal json[:data][:result], "true"
assert_equal json[:data][:message], "Accreditation info successfully added"
end
assert_response :ok
assert_emails 2
assert_equal json[:data][:user][:username], @user.username
assert_equal json[:data][:result], "true"
assert_equal json[:data][:message], "Accreditation info successfully added"
end
def test_should_return_valid_response_invalid_authorization
post '/repp/v1/registrar/accreditation/push_results',
headers: { 'Authorization' => 'Basic temporary-secret-ke'},
params: {accreditation_result: {username: @user.username, result: true} }
json = JSON.parse(response.body, symbolize_names: true)
def test_should_return_valid_response_invalid_authorization
post '/repp/v1/registrar/accreditation/push_results',
headers: { 'Authorization' => 'Basic temporary-secret-ke'},
params: {accreditation_result: {username: @user.username, result: true} }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :unauthorized
assert_response :unauthorized
assert_emails 0
assert_equal json[:code], 2202
assert_equal json[:message], 'Invalid authorization information'
end
assert_emails 0
assert_equal json[:code], 2202
assert_equal json[:message], 'Invalid authorization information'
end
def test_should_return_valid_response_record_exception
post '/repp/v1/registrar/accreditation/push_results',
headers: @auth_headers,
params: {accreditation_result: { username: "chungachanga", result: true} }
json = JSON.parse(response.body, symbolize_names: true)
def test_should_return_valid_response_record_exception
post '/repp/v1/registrar/accreditation/push_results',
headers: @auth_headers,
params: {accreditation_result: { username: "chungachanga", result: true} }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_response :ok
assert_emails 0
assert_equal json[:code], 2303
assert_equal json[:message], "Object 'chungachanga' does not exist"
assert_emails 0
assert_equal json[:code], 2303
assert_equal json[:message], "Object 'chungachanga' does not exist"
end
end
end

View file

@ -0,0 +1,22 @@
require 'test_helper'
class RecordDateOfTestTest < ActiveSupport::TestCase
setup do
@api_bestname = users(:api_bestnames)
@api_bestname.accreditation_date = Time.zone.now - 10.minutes
@api_bestname.accreditation_expire_date = @api_bestname.accreditation_date + 1.year
@api_bestname.save
end
def test_should_record_data_to_apiuser
api_goodname = users(:api_goodnames)
assert_nil api_goodname.accreditation_date
assert_nil api_goodname.accreditation_expire_date
Actions::RecordDateOfTest.record_result_to_api_user(api_user: api_goodname, date: @api_bestname.accreditation_date)
assert_equal api_goodname.accreditation_date, @api_bestname.accreditation_date
assert_equal api_goodname.accreditation_expire_date, @api_bestname.accreditation_expire_date
end
end

View file

@ -131,6 +131,49 @@ class AuctionTest < ActiveSupport::TestCase
assert_not @auction.domain_registrable?('')
end
def test_restart_new_auction_should_with_previous_manual_platform
@auction.update(platform: 'manual')
@auction.reload
assert_equal @auction.platform, 'manual'
assert_difference 'Auction.count' do
@auction.restart
end
new_auction = Auction.last
assert_equal new_auction.platform, 'manual'
end
def test_restart_new_auction_should_with_previous_auto_platform
@auction.update(platform: 'auto')
@auction.reload
assert_equal @auction.platform, 'auto'
assert_difference 'Auction.count' do
@auction.restart
end
new_auction = Auction.last
assert_equal new_auction.platform, 'auto'
end
def test_restart_new_auction_should_with_auto_if_platform_is_nil
@auction.update(platform: nil)
@auction.reload
assert_nil @auction.platform
assert_difference 'Auction.count' do
@auction.restart
end
new_auction = Auction.last
assert_equal new_auction.platform, 'auto'
end
def test_restarts_an_auction
assert_equal 'auction.test', @auction.domain
@ -142,4 +185,30 @@ class AuctionTest < ActiveSupport::TestCase
assert_equal 'auction.test', new_auction.domain
assert new_auction.started?
end
def test_auction_restart_should_assign_the_previous_manual_platform
assert_equal 'auction.test', @auction.domain
@auction.update(platform: :manual)
@auction.reload
assert_difference 'Auction.count' do
@auction.restart
end
auctions = Auction.where(domain: @auction.domain)
assert_equal auctions.first.platform, auctions.last.platform
end
def test_auction_restart_should_assign_the_previous_auto_platform
assert_equal 'auction.test', @auction.domain
@auction.update(platform: :auto)
@auction.reload
assert_difference 'Auction.count' do
@auction.restart
end
auctions = Auction.where(domain: @auction.domain)
assert_equal auctions.first.platform, auctions.last.platform
end
end

View file

@ -37,8 +37,7 @@ class BankTransactionTest < ActiveSupport::TestCase
first_transaction = BankTransaction.new(sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678')
first_transaction.create_activity(another_invoice.buyer, another_invoice)
first_transaction.bind_invoice(another_invoice.number)
transaction = BankTransaction.new(sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678')

View file

@ -3,6 +3,7 @@ require 'application_system_test_case'
class AdminApiUsersSystemTest < ApplicationSystemTestCase
setup do
sign_in users(:admin)
@registrar = registrars(:bestnames)
end
def test_shows_api_user_list
@ -11,4 +12,71 @@ class AdminApiUsersSystemTest < ApplicationSystemTestCase
api_user = users(:api_bestnames)
assert_link api_user.username, href: admin_registrar_api_user_path(api_user.registrar, api_user)
end
def test_should_display_tests_button_in_api_user
visit admin_api_users_path
assert_button 'Set Test'
assert_no_button 'Remove Test'
end
def test_should_display_remove_test_if_there_accreditated_apiuser
date = Time.zone.now - 10.minutes
api_user = @registrar.api_users.first
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
visit admin_api_users_path
assert_button 'Remove Test'
end
def test_should_not_display_remove_test_if_api_user_accreditation_date_is_expired
date = Time.zone.now - 1.year - 10.minutes
api_user = @registrar.api_users.first
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
visit admin_api_users_path
assert_no_button 'Remove'
end
def test_should_display_tests_button_in_api_user_details
api_user = @registrar.api_users.first
visit admin_api_user_path(api_user)
assert_button 'Set Test'
assert_no_button 'Remove Test'
end
def test_should_display_remove_test_in_api_user_details_if_there_accreditated_apiuser
date = Time.zone.now - 10.minutes
api_user = @registrar.api_users.first
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
visit admin_api_user_path(api_user)
assert_button 'Remove Test'
end
def test_should_not_display_remove_test_if_api_user_accreditation_date_is_expired_in_api_details
date = Time.zone.now - 1.year - 10.minutes
api_user = @registrar.api_users.first
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
visit admin_api_user_path(api_user)
assert_no_button 'Remove'
end
end

View file

@ -93,4 +93,70 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
assert_text 'Language English'
assert_text 'billing@bestnames.test'
end
def test_should_display_btn_for_set_test_date
visit admin_registrars_path
assert_button 'Set Test'
assert_no_button 'Remove Test'
end
def test_should_display_remove_test_if_there_accreditated_registrars
date = Time.zone.now - 10.minutes
api_user = @registrar.api_users.first
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
visit admin_registrars_path
assert_button 'Remove Test'
end
def test_should_not_display_remove_test_if_accreditation_date_is_expired
date = Time.zone.now - 1.year - 10.minutes
api_user = @registrar.api_users.first
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
visit admin_registrars_path
assert_no_button 'Remove'
end
def test_should_display_tests_button_in_registrar_deftails
visit admin_registrar_path(@registrar)
assert_button 'Set Test'
assert_no_button 'Remove Test'
end
def test_should_display_remove_test_if_there_accreditated_registrars_in_registrar_details
date = Time.zone.now - 10.minutes
api_user = @registrar.api_users.first
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
visit admin_registrar_path(@registrar)
assert_button 'Remove Test'
end
def test_should_not_display_remove_test_if_accreditation_date_is_expired_in_registrar_details
date = Time.zone.now - 1.year - 10.minutes
api_user = @registrar.api_users.first
api_user.accreditation_date = date
api_user.accreditation_expire_date = api_user.accreditation_date + 1.year
api_user.save
visit admin_registrar_path(@registrar)
assert_no_button 'Remove'
end
end

View file

@ -4,7 +4,6 @@ if ENV['COVERAGE']
add_filter '/app/models/version/'
add_filter '/lib/action_controller/'
add_filter '/lib/core_monkey_patches/'
add_filter '/lib/daemons/'
add_filter '/lib/gem_monkey_patches/'
add_filter '/lib/tasks/'
end