From b15e36ea08a15c6201a0bf783bd0816b223974a8 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 May 2017 18:32:12 +0300 Subject: [PATCH 1/7] Include "factory_girl_rails" gem in development --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 0f9ba3511..fcec0254c 100644 --- a/Gemfile +++ b/Gemfile @@ -130,6 +130,7 @@ end group :development, :test do gem 'capybara' gem 'rspec-rails', '~> 3.5' + gem 'factory_girl_rails' gem 'fabrication', '2.13.2' # Replacement for fixtures gem 'phantomjs-binaries' gem 'phantomjs' @@ -158,7 +159,6 @@ end group :test do gem 'database_cleaner' - gem 'factory_girl_rails' gem 'codeclimate-test-reporter', "~> 1.0.0" gem 'simplecov' gem 'webmock' From 33a54a7bda5a20b0377f886950732cb94a2df33c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 May 2017 19:05:58 +0300 Subject: [PATCH 2/7] Improve "admin_user" factory --- spec/factories/admin_user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/admin_user.rb b/spec/factories/admin_user.rb index 8ee6b93b9..0714d9f1f 100644 --- a/spec/factories/admin_user.rb +++ b/spec/factories/admin_user.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :admin_user do username 'test' - email 'test@test.com' + sequence(:email) { |n| "test#{n}@test.com" } password 'a' * AdminUser.min_password_length password_confirmation { password } country_code 'de' From ca6105a91913a0fe7d3014c5f8d75fc8d7d9fb58 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 14 May 2017 19:29:58 +0300 Subject: [PATCH 3/7] Move initial setup from seeds.rb to bootstrap rake task #515 --- README.md | 1 + db/seeds.rb | 34 ---------------------------------- lib/tasks/bootstrap.rake | 11 +++++++++++ 3 files changed, 12 insertions(+), 34 deletions(-) create mode 100644 lib/tasks/bootstrap.rake diff --git a/README.md b/README.md index 8b7d5db78..a8a85a3d8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Manual demo install and database setup: cp config/application-example.yml config/application.yml # and edit it cp config/database-example.yml config/database.yml # and edit it bundle exec rake db:setup:all # for production, please follow deployment howto + bundle exec rake:bootstrap bundle exec rake assets:precompile ### Apache with patched mod_epp (Debian 7/Ubuntu 14.04 LTS) diff --git a/db/seeds.rb b/db/seeds.rb index 441aa9442..5dde23342 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,36 +1,2 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). - -ActiveRecord::Base.transaction do - registrar = Registrar.create!( - name: 'Test', - reg_no: '1234', - street: 'test', - city: 'test', - state: 'test', - zip: '1234', - email: 'test@domain.tld', - country_code: 'US', - code: 'US1' - ) - - registrar.accounts.create!(account_type: Account::CASH, currency: 'EUR') - - ApiUser.create!( - username: 'test', - password: 'testtest', - identity_code: '51001091072', - active: true, - registrar: registrar, - roles: ['super'] - ) - - AdminUser.create!( - username: 'test', - email: 'test@domain.tld', - password: 'testtest', - password_confirmation: 'testtest', - country_code: 'US', - roles: ['admin'] - ) -end diff --git a/lib/tasks/bootstrap.rake b/lib/tasks/bootstrap.rake new file mode 100644 index 000000000..8bfff5ffc --- /dev/null +++ b/lib/tasks/bootstrap.rake @@ -0,0 +1,11 @@ +desc 'Bootstraps production-like environment' +task :bootstrap do + AdminUser.create!( + username: 'demo', + email: 'demo@domain.tld', + password: 'demodemo', + password_confirmation: 'demodemo', + country_code: 'US', + roles: ['admin'] + ) +end From 7d7fa65947a0d523f13ef1cf44b4789e8ed10775 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 15 May 2017 00:27:39 +0300 Subject: [PATCH 4/7] Revert "Include "factory_girl_rails" gem in development" This reverts commit b15e36ea08a15c6201a0bf783bd0816b223974a8. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index fcec0254c..0f9ba3511 100644 --- a/Gemfile +++ b/Gemfile @@ -130,7 +130,6 @@ end group :development, :test do gem 'capybara' gem 'rspec-rails', '~> 3.5' - gem 'factory_girl_rails' gem 'fabrication', '2.13.2' # Replacement for fixtures gem 'phantomjs-binaries' gem 'phantomjs' @@ -159,6 +158,7 @@ end group :test do gem 'database_cleaner' + gem 'factory_girl_rails' gem 'codeclimate-test-reporter', "~> 1.0.0" gem 'simplecov' gem 'webmock' From c1a29ea7b52989b59caf0d47d91fc718337a81e8 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 15 May 2017 01:43:20 +0300 Subject: [PATCH 5/7] Add dev:prime rake task #515 --- lib/tasks/dev.rake | 129 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 lib/tasks/dev.rake diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake new file mode 100644 index 000000000..0820550bd --- /dev/null +++ b/lib/tasks/dev.rake @@ -0,0 +1,129 @@ +namespace :dev do + desc 'Generates dummy data in development environment' \ + ' (options: [random] for random data generation - slowest)' + + task :prime, [:random] => :environment do |t, args| + abort 'Production environment is not supported' if Rails.env.production? + + require 'factory_girl' + include FactoryGirl::Syntax::Methods + FactoryGirl.find_definitions + + PaperTrail.enabled = false + with_random_data = args[:random].present? + + def generate_default_data + create(:admin_user, username: 'test', password: 'testtest', password_confirmation: 'testtest') + + zone = create(:zone, origin: 'test') + registrar = create(:registrar, name: 'test') + registrant = create(:registrant, name: 'test', registrar: registrar) + + create(:account, registrar: registrar, balance: 1_000_000) + create(:api_user, username: 'test', password: 'testtest', registrar: registrar) + create(:domain, + name: 'test.test', + period: 1, + period_unit: 'y', + registered_at: Time.zone.now, + valid_from: Time.zone.now, + expire_time: Time.zone.now + 10.years, + registrar: registrar, + registrant: registrant) + + Billing::Price.durations.each do |duration| + Billing::Price.operation_categories.each do |operation_category| + create(:price, + price: Money.from_amount(1), + valid_from: Time.zone.now.beginning_of_day, + valid_to: Time.zone.now + 10.years, + duration: duration, + operation_category: operation_category, + zone: zone) + end + end + end + + def generate_random_data + zone_count = 10 + admin_user_count = 5 + registrar_count = 50 + api_user_count = 10 + registrant_count = 50 + domain_count = 50 + registrars = [] + registrants = [] + zones = [] + registrant_names = [ + 'John Doe', + 'John Roe', + 'Jane Doe', + 'Jane Roe', + 'John Smith', + ] + + zone_count.times do + origin = SecureRandom.hex[0..(rand(5) + 1)] + zones << create(:zone, origin: origin) + end + + zone_origins = zones.collect { |zone| zone.origin } + + admin_user_count.times do + uid = SecureRandom.hex[0..(rand(5) + 1)] + create(:admin_user, username: "test#{uid}", password: 'testtest', password_confirmation: 'testtest') + end + + registrar_count.times do + uid = SecureRandom.hex[0..(rand(5) + 1)] + registrars << create(:registrar, name: "Acme Ltd. #{uid}") + end + + registrars.each do |registrar| + create(:account, registrar: registrar, balance: rand(99999)) + + api_user_count.times do |i| + create(:api_user, username: "test#{registrar.id}#{i}", password: 'testtest', registrar: registrar) + end + + registrant_count.times do |i| + registrants << create(:registrant, name: registrant_names.sample, registrar: registrar) + end + + domain_count.times do |i| + name = "test#{registrar.id}#{i}#{rand(99999)}.#{zone_origins.sample}" + period = rand(3) + 1 + + create(:domain, + name: name, + period: period, + period_unit: 'y', + registered_at: Time.zone.now, + valid_from: Time.zone.now, + expire_time: Time.zone.now + period.years, + registrar: registrar, + registrant: registrants.sample) + end + end + + zones.each do |zone| + Billing::Price.durations.each do |duration| + Billing::Price.operation_categories.each do |operation_category| + create(:price, + price: Money.from_amount(rand(10) + 1), + valid_from: Time.zone.now.beginning_of_day, + valid_to: Time.zone.now + (rand(10) + 1).years, + duration: duration, + operation_category: operation_category, + zone: zone) + end + end + end + end + + ActiveRecord::Base.transaction do + generate_default_data + generate_random_data if with_random_data + end + end +end From 48ae54d507d2c068f84d453f32948a3b9b4661d2 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 15 May 2017 11:48:16 +0300 Subject: [PATCH 6/7] Improve rake:bootstrap task #515 --- lib/tasks/bootstrap.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tasks/bootstrap.rake b/lib/tasks/bootstrap.rake index 8bfff5ffc..36202a6c7 100644 --- a/lib/tasks/bootstrap.rake +++ b/lib/tasks/bootstrap.rake @@ -1,10 +1,10 @@ desc 'Bootstraps production-like environment' task :bootstrap do AdminUser.create!( - username: 'demo', - email: 'demo@domain.tld', - password: 'demodemo', - password_confirmation: 'demodemo', + username: 'admin', + email: 'admin@domain.tld', + password: 'adminadmin', + password_confirmation: 'adminadmin', country_code: 'US', roles: ['admin'] ) From 8455f69dbc4051342453a54e100f1fc19f0c07d1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 31 May 2017 19:48:16 +0300 Subject: [PATCH 7/7] Replace SERVER_DELETE_PROHIBITED with PENDING_UPDATE on EPP domain:update #512 --- app/controllers/epp_controller.rb | 10 +++++ .../requests/epp/domain/update/status_spec.rb | 37 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 spec/requests/epp/domain/update/status_spec.rb diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 4f84f7284..96c2348f2 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -135,6 +135,16 @@ class EppController < ApplicationController @errors += obj.errors[:epp_errors] end + if params[:parsed_frame].at_css('update') + @errors.each_with_index do |errors, index| + if errors[:code] == '2304' && + errors[:value][:val] == DomainStatus::SERVER_DELETE_PROHIBITED && + errors[:value][:obj] == 'status' + @errors[index][:value][:val] = DomainStatus::PENDING_UPDATE + end + end + end + # for debugging if @errors.blank? @errors << { diff --git a/spec/requests/epp/domain/update/status_spec.rb b/spec/requests/epp/domain/update/status_spec.rb new file mode 100644 index 000000000..1ef8d7900 --- /dev/null +++ b/spec/requests/epp/domain/update/status_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +RSpec.describe 'EPP domain:update' do + let(:request) { post '/epp/command/update', frame: request_xml } + let(:request_xml) { <<-XML + + + + + + test.com + + + + + XML + } + + before :example do + sign_in_to_epp_area + end + + context 'when domain has both SERVER_DELETE_PROHIBITED and PENDING_UPDATE statuses' do + let!(:domain) { create(:domain, + name: 'test.com', + statuses: [DomainStatus::SERVER_DELETE_PROHIBITED, + DomainStatus::PENDING_UPDATE]) + } + + it 'returns PENDING_UPDATE as domain status' do + request + status = Nokogiri::XML(response.body).at_xpath('//domain:status', + domain: 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').content + expect(status).to eq(DomainStatus::PENDING_UPDATE) + end + end +end