From fe8559dbb078d4fa675b78e08b24f4a828d022cb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Oct 2016 15:15:46 +0300 Subject: [PATCH 01/24] Remove shoulda-matchers gem #206 --- Gemfile | 1 - Gemfile.lock | 3 --- spec/models/account_spec.rb | 3 --- spec/models/address_spec.rb | 2 -- spec/models/api_user_spec.rb | 2 -- spec/models/bank_statement_spec.rb | 2 -- spec/models/bank_transaction_spec.rb | 3 --- spec/models/certificate_spec.rb | 2 -- spec/models/dnskey_spec.rb | 2 -- spec/models/domain_spec.rb | 9 --------- spec/models/domain_transfer_spec.rb | 2 -- spec/models/invoice_spec.rb | 4 ---- spec/models/keyrelay_spec.rb | 5 ----- spec/models/message_spec.rb | 2 -- spec/models/nameserver_spec.rb | 2 -- spec/models/registrar_spec.rb | 5 ----- spec/models/white_ip_spec.rb | 2 -- spec/rails_helper.rb | 1 - 18 files changed, 52 deletions(-) diff --git a/Gemfile b/Gemfile index f681fe9bf..6434a304f 100644 --- a/Gemfile +++ b/Gemfile @@ -136,7 +136,6 @@ group :development, :test do gem 'poltergeist', '1.6.0' # We are using PhantomJS instead gem 'phantomjs', '1.9.8.0' gem 'fabrication', '2.13.2' # Replacement for fixtures - gem 'shoulda-matchers', '2.8.0', require: false # Additional matchers for RSpec gem 'launchy', '2.4.3' # for opening browser automatically # helper gems diff --git a/Gemfile.lock b/Gemfile.lock index 9bb7523f4..af3056d91 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -494,8 +494,6 @@ GEM selectize-rails (0.12.1) sexp_processor (4.6.0) shellany (0.0.1) - shoulda-matchers (2.8.0) - activesupport (>= 3.0.0) simplecov (0.10.0) docile (~> 1.1.0) json (~> 1.8) @@ -648,7 +646,6 @@ DEPENDENCIES sdoc (= 0.4.1) select2-rails (= 3.5.9.3) selectize-rails (= 0.12.1) - shoulda-matchers (= 2.8.0) simplecov (= 0.10.0) simpleidn (= 0.0.5) spring (= 1.3.6) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 4db67ba94..292ccfa6a 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -1,9 +1,6 @@ require 'rails_helper' describe Account do - it { should belong_to(:registrar) } - it { should have_many(:account_activities) } - context 'with invalid attribute' do before :all do @account = Account.new diff --git a/spec/models/address_spec.rb b/spec/models/address_spec.rb index 6d8ec64ec..fe63fb38f 100644 --- a/spec/models/address_spec.rb +++ b/spec/models/address_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' describe Address do - it { should belong_to(:contact) } - context 'about class' do it 'should have versioning enabled?' do Address.paper_trail_enabled_for_model?.should == true diff --git a/spec/models/api_user_spec.rb b/spec/models/api_user_spec.rb index f159e5a7a..4b8fd9c4e 100644 --- a/spec/models/api_user_spec.rb +++ b/spec/models/api_user_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' describe ApiUser do - it { should belong_to(:registrar) } - context 'class methods' do before do Fabricate(:api_user, identity_code: '') diff --git a/spec/models/bank_statement_spec.rb b/spec/models/bank_statement_spec.rb index 281ca9568..2fa9ed19e 100644 --- a/spec/models/bank_statement_spec.rb +++ b/spec/models/bank_statement_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' describe BankStatement do - it { should have_many(:bank_transactions) } - context 'with invalid attribute' do before :all do @bank_statement = BankStatement.new diff --git a/spec/models/bank_transaction_spec.rb b/spec/models/bank_transaction_spec.rb index 06face618..27640453c 100644 --- a/spec/models/bank_transaction_spec.rb +++ b/spec/models/bank_transaction_spec.rb @@ -1,9 +1,6 @@ require 'rails_helper' describe BankTransaction do - it { should belong_to(:bank_statement) } - it { should have_one(:account_activity) } - context 'with invalid attribute' do before :all do @bank_transaction = BankTransaction.new diff --git a/spec/models/certificate_spec.rb b/spec/models/certificate_spec.rb index 232492269..74d0b460e 100644 --- a/spec/models/certificate_spec.rb +++ b/spec/models/certificate_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' describe Certificate do - it { should belong_to(:api_user) } - context 'with invalid attribute' do before :all do @certificate = Certificate.new diff --git a/spec/models/dnskey_spec.rb b/spec/models/dnskey_spec.rb index 8d1185cbd..13ad884b6 100644 --- a/spec/models/dnskey_spec.rb +++ b/spec/models/dnskey_spec.rb @@ -5,8 +5,6 @@ describe Dnskey do Fabricate(:zonefile_setting, origin: 'ee') end - it { should belong_to(:domain) } - context 'with invalid attribute' do before :all do @dnskey = Dnskey.new diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 41e29077a..51184b15e 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -9,15 +9,6 @@ describe Domain do Fabricate(:zonefile_setting, origin: 'com.ee') end - it { should belong_to(:registrar) } - it { should have_many(:nameservers) } - it { should belong_to(:registrant) } - it { should have_many(:tech_contacts) } - it { should have_many(:admin_contacts) } - it { should have_many(:domain_transfers) } - it { should have_many(:dnskeys) } - it { should have_many(:legal_documents) } - context 'with invalid attribute' do before :all do @domain = Domain.new diff --git a/spec/models/domain_transfer_spec.rb b/spec/models/domain_transfer_spec.rb index 169b9f24e..105db1d48 100644 --- a/spec/models/domain_transfer_spec.rb +++ b/spec/models/domain_transfer_spec.rb @@ -5,8 +5,6 @@ describe DomainTransfer do Fabricate(:zonefile_setting, origin: 'ee') end - it { should belong_to(:domain) } - context 'with invalid attribute' do before :all do @domain_transfer = DomainTransfer.new diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index b4f1d3908..33bf4fa6e 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -1,10 +1,6 @@ require 'rails_helper' describe Invoice do - it { should belong_to(:seller) } - it { should belong_to(:buyer) } - it { should have_many(:invoice_items) } - context 'with invalid attribute' do before :all do @invoice = Invoice.new diff --git a/spec/models/keyrelay_spec.rb b/spec/models/keyrelay_spec.rb index 372c63332..9dada32c2 100644 --- a/spec/models/keyrelay_spec.rb +++ b/spec/models/keyrelay_spec.rb @@ -5,11 +5,6 @@ describe Keyrelay do Fabricate(:zonefile_setting, origin: 'ee') end - it { should belong_to(:domain) } - it { should belong_to(:requester) } - it { should belong_to(:accepter) } - it { should have_many(:legal_documents) } - context 'with invalid attribute' do before :all do @keyrelay = Keyrelay.new diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index d12d3e60c..ddbea285b 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' describe Message do - it { should belong_to(:registrar) } - context 'with invalid attribute' do before :all do @mssage = Message.new diff --git a/spec/models/nameserver_spec.rb b/spec/models/nameserver_spec.rb index 64487722b..5971cae23 100644 --- a/spec/models/nameserver_spec.rb +++ b/spec/models/nameserver_spec.rb @@ -5,8 +5,6 @@ describe Nameserver do Fabricate(:zonefile_setting, origin: 'ee') end - it { should belong_to(:domain) } - context 'with invalid attribute' do before :all do @nameserver = Nameserver.new diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb index e754664ac..ffe71c49a 100644 --- a/spec/models/registrar_spec.rb +++ b/spec/models/registrar_spec.rb @@ -1,11 +1,6 @@ require 'rails_helper' describe Registrar do - it { should have_many(:domains) } - it { should have_many(:api_users) } - it { should have_many(:messages) } - it { should have_many(:white_ips) } - context 'with invalid attribute' do before :all do @registrar = Registrar.new diff --git a/spec/models/white_ip_spec.rb b/spec/models/white_ip_spec.rb index 7c169c539..e824fbdd6 100644 --- a/spec/models/white_ip_spec.rb +++ b/spec/models/white_ip_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' describe WhiteIp do - it { should belong_to(:registrar) } - context 'with invalid attribute' do before :all do @white_ip = WhiteIp.new diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index fc25543f2..62470321b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -3,7 +3,6 @@ ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' -require 'shoulda/matchers' require 'capybara/poltergeist' require 'paper_trail/frameworks/rspec' PaperTrail.whodunnit = 'autotest' From 3ff34f4a490ba8dcaa306628b6d37537db13282d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Oct 2016 18:28:30 +0300 Subject: [PATCH 02/24] Remove unneeded spec registry-206 --- spec/models/directo_spec.rb | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 spec/models/directo_spec.rb diff --git a/spec/models/directo_spec.rb b/spec/models/directo_spec.rb deleted file mode 100644 index bf187d2bf..000000000 --- a/spec/models/directo_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Directo, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end From e8dac5e45de473108917f6b38bd3a33678f1d4b6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Oct 2016 18:33:31 +0300 Subject: [PATCH 03/24] Remove rake gem, move database_cleaner and faker gems under test group registry-206 --- Gemfile | 13 +++++-------- Gemfile.lock | 5 ++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 6434a304f..1d3787dbe 100644 --- a/Gemfile +++ b/Gemfile @@ -138,10 +138,6 @@ group :development, :test do gem 'fabrication', '2.13.2' # Replacement for fixtures gem 'launchy', '2.4.3' # for opening browser automatically - # helper gems - gem 'database_cleaner', '1.4.1' # For cleaning db in feature and epp tests - gem 'faker', '1.4.3' # Library to generate fake data - # debug gem 'pry', '0.10.1' @@ -161,13 +157,14 @@ group :development, :test do # dev tools gem 'unicorn' - - # for travis - gem 'rake' - gem 'autodoc' end group :staging do gem 'airbrake' end + +group :test do + gem 'database_cleaner' + gem 'faker' +end diff --git a/Gemfile.lock b/Gemfile.lock index af3056d91..7db1f05db 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -592,14 +592,14 @@ DEPENDENCIES countries (= 0.11.4) daemons-rails (= 1.2.1) data_migrate! - database_cleaner (= 1.4.1) + database_cleaner deep_cloneable (= 2.1.1) devise (= 3.5.4) digidoc_client (= 0.2.1) epp (= 1.4.2)! epp-xml (= 1.0.5)! fabrication (= 2.13.2) - faker (= 1.4.3) + faker figaro (= 1.1.1) grape (= 0.12.0) guard (= 2.12.9) @@ -636,7 +636,6 @@ DEPENDENCIES railroady (= 1.3.0) rails (= 4.2.5.2) rails-settings-cached (= 0.4.1) - rake ransack (= 1.5.1) rest-client rspec-rails (= 3.3.2) From ee3ec69e546dacc4afaa485a00b2141a5f94453c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Oct 2016 18:34:52 +0300 Subject: [PATCH 04/24] Refactor rspec config and support files #206 --- spec/rails_helper.rb | 80 ++----- spec/spec_helper.rb | 147 ++++++------- spec/support/autodoc.rb | 4 + spec/support/capybara.rb | 8 + spec/support/database_cleaner.rb | 30 +++ spec/support/macros/capybara.rb | 5 + spec/support/matchers/active_job.rb | 252 +++++++++++++++++++++++ spec/support/matchers/alias_attribute.rb | 9 + spec/support/paper_trail.rb | 1 + 9 files changed, 404 insertions(+), 132 deletions(-) create mode 100644 spec/support/autodoc.rb create mode 100644 spec/support/capybara.rb create mode 100644 spec/support/database_cleaner.rb create mode 100644 spec/support/macros/capybara.rb create mode 100644 spec/support/matchers/active_job.rb create mode 100644 spec/support/matchers/alias_attribute.rb create mode 100644 spec/support/paper_trail.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 62470321b..6201e1ba8 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,29 +1,28 @@ -# This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' require 'capybara/poltergeist' require 'paper_trail/frameworks/rspec' -PaperTrail.whodunnit = 'autotest' -require "money-rails/test_helpers" +require 'money-rails/test_helpers' if ENV['ROBOT'] require 'simplecov' SimpleCov.start 'rails' end -# Requires supporting ruby files with custom matchers and macros, etc, in -# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are -# run as spec files by default. This means that files in spec/support that end -# in _spec.rb will both be required and run as specs, causing the specs to be -# run twice. It is recommended that you do not name files matching this glob to -# end with _spec.rb. You can configure this pattern with with the --pattern -# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. -Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } +require 'support/matchers/alias_attribute' +require 'support/matchers/active_job' +require 'support/capybara' +require 'support/database_cleaner' +require 'support/epp' +require 'support/epp_doc' +require 'support/feature' +require 'support/registrar_helpers' +require 'support/request' +require 'support/autodoc' +require 'support/paper_trail' -# Checks for pending migrations before tests are run. -# If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! # create general settings @@ -49,81 +48,44 @@ def create_settings # speedup and easier to create fabrications @fixed_registrar = - Registrar.find_by_name('fixed registrar') || - Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED') + Registrar.find_by_name('fixed registrar') || + Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED') end RSpec.configure do |config| - config.filter_run focus: true - config.run_all_when_everything_filtered = true + config.include ActionView::TestCase::Behavior, type: :presenter + config.include ActiveSupport::Testing::TimeHelpers - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. - config.use_transactional_fixtures = false - - config.before(:suite) do - ActiveRecord::Base.establish_connection :api_log_test - DatabaseCleaner.clean_with(:truncation) - DatabaseCleaner.strategy = nil - - ActiveRecord::Base.establish_connection :test + config.define_derived_metadata(file_path: %r{/spec/presenters/}) do |metadata| + metadata[:type] = :presenter + metadata[:db] = false end + config.use_transactional_fixtures = false + config.before(:all) do - DatabaseCleaner.clean_with(:truncation) create_settings end config.before(:all, epp: true) do - DatabaseCleaner.strategy = nil create_settings end config.before(:each, js: true) do - DatabaseCleaner.strategy = :truncation create_settings end config.before(:each, type: :request) do - DatabaseCleaner.strategy = :truncation create_settings end config.before(:each, type: :model) do create_settings - DatabaseCleaner.strategy = :transaction - DatabaseCleaner.start end - config.after(:each, type: :model) do - DatabaseCleaner.clean - end - - Capybara.javascript_driver = :poltergeist - - # RSpec Rails can automatically mix in different behaviours to your tests - # based on their file location, for example enabling you to call `get` and - # `post` in specs under `spec/controllers`. - # - # You can disable this behaviour by removing the line below, and instead - # explicitly tag your specs with their type, e.g.: - # - # RSpec.describe UsersController, :type => :controller do - # # ... - # end - # - # The different available types are documented in the features, such as in - # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! config.expect_with :rspec do |c| c.syntax = [:should, :expect] end - - Autodoc.configuration.path = 'doc/repp' - Autodoc.configuration.suppressed_request_header = ['Host'] - Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime'] - Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb') end - diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8ef5158b2..9e1e69d61 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,76 +1,77 @@ -# This file was generated by the `rails generate rspec:install` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause this -# file to always be loaded, without a need to explicitly require it in any files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, make a -# separate helper file that requires this one and then use it only in the specs -# that actually need it. -# -# The `.rspec` file also contains a few flags that are not defaults but that -# users commonly want. -# -# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration -RSpec.configure do |_config| +RSpec.configure do |config| + # https://github.com/rspec/rspec-rails/issues/1076 + config.around :each, type: :view do |example| + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = false + example.run + mocks.verify_partial_doubles = true + end + end + + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. - # # These two settings work together to allow you to limit a spec run - # # to individual examples or groups you care about by tagging them with - # # `:focus` metadata. When nothing is tagged with `:focus`, all examples - # # get run. - # config.filter_run :focus - # config.run_all_when_everything_filtered = true - # - # # Many RSpec users commonly either run the entire suite or an individual - # # file, and it's useful to allow more verbose output when running an - # # individual spec file. - # if config.files_to_run.one? - # # Use the documentation formatter for detailed output, - # # unless a formatter has already been configured - # # (e.g. via a command-line flag). - # config.default_formatter = 'doc' - # end - # - # # Print the 10 slowest examples and example groups at the - # # end of the spec run, to help surface which specs are running - # # particularly slow. - # config.profile_examples = 10 - # - # # Run specs in random order to surface order dependencies. If you find an - # # order dependency and want to debug it, you can fix the order by providing - # # the seed, which is printed after each run. - # # --seed 1234 - # config.order = :random - # - # # Seed global randomization in this process using the `--seed` CLI option. - # # Setting this allows you to use `--seed` to deterministically reproduce - # # test failures related to randomization by passing the same `--seed` value - # # as the one that triggered the failure. - # Kernel.srand config.seed - # - # # rspec-expectations config goes here. You can use an alternate - # # assertion/expectation library such as wrong or the stdlib/minitest - # # assertions if you prefer. - # config.expect_with :rspec do |expectations| - # # Enable only the newer, non-monkey-patching expect syntax. - # # For more details, see: - # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax - # expectations.syntax = :expect - # end - # - # # rspec-mocks config goes here. You can use an alternate test double - # # library (such as bogus or mocha) by changing the `mock_with` option here. - # config.mock_with :rspec do |mocks| - # # Enable only the newer, non-monkey-patching expect syntax. - # # For more details, see: - # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # mocks.syntax = :expect - # - # # Prevents you from mocking or stubbing a method that does not exist on - # # a real object. This is generally recommended. - # mocks.verify_partial_doubles = true - # end +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Limits the available syntax to the non-monkey patched syntax that is recommended. + # For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end end diff --git a/spec/support/autodoc.rb b/spec/support/autodoc.rb new file mode 100644 index 000000000..3ea2fee22 --- /dev/null +++ b/spec/support/autodoc.rb @@ -0,0 +1,4 @@ +Autodoc.configuration.path = 'doc/repp' +Autodoc.configuration.suppressed_request_header = ['Host'] +Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime'] +Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb') diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb new file mode 100644 index 000000000..7ef5009c6 --- /dev/null +++ b/spec/support/capybara.rb @@ -0,0 +1,8 @@ +require_relative 'macros/capybara' + +RSpec.configure do |config| + config.include CapybaraViewMacros, type: :view + config.include CapybaraViewMacros, type: :presenter +end + +Capybara.javascript_driver = :poltergeist diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb new file mode 100644 index 000000000..ce6d1f7f3 --- /dev/null +++ b/spec/support/database_cleaner.rb @@ -0,0 +1,30 @@ +RSpec.configure do |config| + db_connection_names = %i(test whois_test api_log_test registrant_write_test) + + config.before :suite do + DatabaseCleaner.strategy = :truncation + + db_connection_names.each do |connection_name| + ActiveRecord::Base.establish_connection(connection_name) + DatabaseCleaner[:active_record, connection: connection_name].strategy = :truncation + end + end + + config.before :example do |example| + if example.metadata[:db] || (%i(model).include?(example.metadata[:type]) && example.metadata[:db].nil?) + db_connection_names.each do |connection_name| + ActiveRecord::Base.establish_connection(connection_name) + DatabaseCleaner[:active_record, connection: connection_name].start + end + end + end + + config.after :each do |example| + if example.metadata[:db] || (%i(model).include?(example.metadata[:type]) && example.metadata[:db].nil?) + db_connection_names.each do |connection_name| + ActiveRecord::Base.establish_connection(connection_name) + DatabaseCleaner[:active_record, connection: connection_name].clean + end + end + end +end diff --git a/spec/support/macros/capybara.rb b/spec/support/macros/capybara.rb new file mode 100644 index 000000000..0e9dbf7b0 --- /dev/null +++ b/spec/support/macros/capybara.rb @@ -0,0 +1,5 @@ +module CapybaraViewMacros + def page + Capybara::Node::Simple.new(rendered) + end +end diff --git a/spec/support/matchers/active_job.rb b/spec/support/matchers/active_job.rb new file mode 100644 index 000000000..1a3f70a7a --- /dev/null +++ b/spec/support/matchers/active_job.rb @@ -0,0 +1,252 @@ +require "active_job/base" +require "active_job/arguments" + +# This matcher is needed because it is absent it rspec-rails 3.3.2 + +module RSpec + module Rails + module Matchers + # Namespace for various implementations of ActiveJob features + # + # @api private + module ActiveJob + # rubocop: disable Style/ClassLength + # @private + class Base < RSpec::Matchers::BuiltIn::BaseMatcher + def initialize + @args = [] + @queue = nil + @at = nil + @block = Proc.new {} + set_expected_number(:exactly, 1) + end + + def with(*args, &block) + @args = args + @block = block if block.present? + self + end + + def on_queue(queue) + @queue = queue + self + end + + def at(date) + @at = date + self + end + + def exactly(count) + set_expected_number(:exactly, count) + self + end + + def at_least(count) + set_expected_number(:at_least, count) + self + end + + def at_most(count) + set_expected_number(:at_most, count) + self + end + + def times + self + end + + def once + exactly(:once) + end + + def twice + exactly(:twice) + end + + def thrice + exactly(:thrice) + end + + def failure_message + "expected to enqueue #{base_message}" + end + + def failure_message_when_negated + "expected not to enqueue #{base_message}" + end + + def message_expectation_modifier + case @expectation_type + when :exactly then "exactly" + when :at_most then "at most" + when :at_least then "at least" + end + end + + def supports_block_expectations? + true + end + + private + + def check(jobs) + @matching_jobs_count = jobs.count do |job| + if serialized_attributes.all? { |key, value| value == job[key] } + args = ::ActiveJob::Arguments.deserialize(job[:args]) + @block.call(*args) + true + else + false + end + end + + case @expectation_type + when :exactly then @expected_number == @matching_jobs_count + when :at_most then @expected_number >= @matching_jobs_count + when :at_least then @expected_number <= @matching_jobs_count + end + end + + def base_message + "#{message_expectation_modifier} #{@expected_number} jobs,".tap do |msg| + msg << " with #{@args}," if @args.any? + msg << " on queue #{@queue}," if @queue + msg << " at #{@at}," if @at + msg << " but enqueued #{@matching_jobs_count}" + end + end + + def serialized_attributes + {}.tap do |attributes| + attributes[:args] = ::ActiveJob::Arguments.serialize(@args) if @args.any? + attributes[:at] = @at.to_f if @at + attributes[:queue] = @queue if @queue + attributes[:job] = @job if @job + end + end + + def set_expected_number(relativity, count) + @expectation_type = relativity + @expected_number = case count + when :once then 1 + when :twice then 2 + when :thrice then 3 + else Integer(count) + end + end + + def queue_adapter + ::ActiveJob::Base.queue_adapter + end + end + # rubocop: enable Style/ClassLength + + # @private + class HaveEnqueuedJob < Base + def initialize(job) + super() + @job = job + end + + def matches?(proc) + raise ArgumentError, "have_enqueued_job and enqueue_job only support block expectations" unless Proc === proc + + original_enqueued_jobs_count = queue_adapter.enqueued_jobs.count + proc.call + in_block_jobs = queue_adapter.enqueued_jobs.drop(original_enqueued_jobs_count) + + check(in_block_jobs) + end + end + + # @private + class HaveBeenEnqueued < Base + def matches?(job) + @job = job + check(queue_adapter.enqueued_jobs) + end + end + end + + # @api public + # Passes if a job has been enqueued inside block. May chain at_least, at_most or exactly to specify a number of times. + # + # @example + # expect { + # HeavyLiftingJob.perform_later + # }.to have_enqueued_job + # + # # Using alias + # expect { + # HeavyLiftingJob.perform_later + # }.to enqueue_job + # + # expect { + # HelloJob.perform_later + # HeavyLiftingJob.perform_later + # }.to have_enqueued_job(HelloJob).exactly(:once) + # + # expect { + # 3.times { HelloJob.perform_later } + # }.to have_enqueued_job(HelloJob).at_least(2).times + # + # expect { + # HelloJob.perform_later + # }.to have_enqueued_job(HelloJob).at_most(:twice) + # + # expect { + # HelloJob.perform_later + # HeavyLiftingJob.perform_later + # }.to have_enqueued_job(HelloJob).and have_enqueued_job(HeavyLiftingJob) + # + # expect { + # HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42) + # }.to have_enqueued_job.with(42).on_queue("low").at(Date.tomorrow.noon) + def have_enqueued_job(job = nil) + check_active_job_adapter + ActiveJob::HaveEnqueuedJob.new(job) + end + alias_method :enqueue_job, :have_enqueued_job + + # @api public + # Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times. + # + # @example + # before { ActiveJob::Base.queue_adapter.enqueued_jobs.clear } + # + # HeavyLiftingJob.perform_later + # expect(HeavyLiftingJob).to have_been_enqueued + # + # HelloJob.perform_later + # HeavyLiftingJob.perform_later + # expect(HeavyLiftingJob).to have_been_enqueued.exactly(:once) + # + # 3.times { HelloJob.perform_later } + # expect(HelloJob).to have_been_enqueued.at_least(2).times + # + # HelloJob.perform_later + # expect(HelloJob).to enqueue_job(HelloJob).at_most(:twice) + # + # HelloJob.perform_later + # HeavyLiftingJob.perform_later + # expect(HelloJob).to have_been_enqueued + # expect(HeavyLiftingJob).to have_been_enqueued + # + # HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42) + # expect(HelloJob).to have_been_enqueued.with(42).on_queue("low").at(Date.tomorrow.noon) + def have_been_enqueued + check_active_job_adapter + ActiveJob::HaveBeenEnqueued.new + end + + private + + # @private + def check_active_job_adapter + return if ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter + raise StandardError, "To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`" + end + end + end +end diff --git a/spec/support/matchers/alias_attribute.rb b/spec/support/matchers/alias_attribute.rb new file mode 100644 index 000000000..93b4efbb0 --- /dev/null +++ b/spec/support/matchers/alias_attribute.rb @@ -0,0 +1,9 @@ +RSpec::Matchers.define :alias_attribute do |alias_name, original_name| + match do |actual| + actual.class.attribute_alias(alias_name) == original_name.to_s + end + + failure_message do |actual| + "expected #{actual.class.name} to alias attribute :#{alias_name} by :#{original_name}" + end +end diff --git a/spec/support/paper_trail.rb b/spec/support/paper_trail.rb new file mode 100644 index 000000000..7304b8b60 --- /dev/null +++ b/spec/support/paper_trail.rb @@ -0,0 +1 @@ +PaperTrail.whodunnit = 'autotest' From 2e9724f50d1aa6912e5f1e3a38f0d08ba4e71dff Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Oct 2016 19:17:58 +0300 Subject: [PATCH 05/24] Refactor rspec config and support files #206 --- spec/support/database_cleaner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index ce6d1f7f3..68a5de946 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -19,7 +19,7 @@ RSpec.configure do |config| end end - config.after :each do |example| + config.after :example do |example| if example.metadata[:db] || (%i(model).include?(example.metadata[:type]) && example.metadata[:db].nil?) db_connection_names.each do |connection_name| ActiveRecord::Base.establish_connection(connection_name) From f2f23a623beaf208d54e07ab428168c49ffce553 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Oct 2016 23:20:04 +0300 Subject: [PATCH 06/24] Do not show deprecation errors in test env #206 --- config/environments/test.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 80f7b9064..ee9b72aa0 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -31,8 +31,7 @@ Rails.application.configure do # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Print deprecation notices to the stderr. - config.active_support.deprecation = :stderr + ActiveSupport::Deprecation.silenced = true # For rails-settings-cached conflict config.cache_store = :file_store, 'tmp/cache_test' @@ -42,7 +41,7 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true - # The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, + # The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, # corresponding to the log level numbers from 0 up to 5 respectively config.log_level = :debug @@ -70,4 +69,4 @@ end # In this mode, any jobs you queue will be run in the same thread, synchronously # (that is, MyJob.enqueue runs the job and won't return until it's completed). # This makes your application's behavior easier to test -Que.mode = :sync +Que.mode = :sync From 6fc1a3d5838c7f05d6c4ee974d179d22e01ebffe Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Oct 2016 23:40:24 +0300 Subject: [PATCH 07/24] Add factory_girl_rails gem #206 --- Gemfile | 1 + Gemfile.lock | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index 1d3787dbe..dca8f6382 100644 --- a/Gemfile +++ b/Gemfile @@ -167,4 +167,5 @@ end group :test do gem 'database_cleaner' gem 'faker' + gem 'factory_girl_rails' end diff --git a/Gemfile.lock b/Gemfile.lock index 7db1f05db..3497dc08f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -206,6 +206,11 @@ GEM erubis (2.7.0) execjs (2.6.0) fabrication (2.13.2) + factory_girl (4.7.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.7.0) + factory_girl (~> 4.7.0) + railties (>= 3.0.0) faker (1.4.3) i18n (~> 0.5) fastercsv (1.5.5) @@ -599,6 +604,7 @@ DEPENDENCIES epp (= 1.4.2)! epp-xml (= 1.0.5)! fabrication (= 2.13.2) + factory_girl_rails faker figaro (= 1.1.1) grape (= 0.12.0) From 920fe1932303169b0f468dce781c1b65ecbb9deb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Oct 2016 23:58:04 +0300 Subject: [PATCH 08/24] Disable file log in test env #206 --- config/environments/test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index ee9b72aa0..77819dfb4 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -63,7 +63,7 @@ Rails.application.configure do Bullet.add_whitelist type: :counter_cache, class_name: 'Contact', association: :versions end - # config.logger = Logger.new(STDOUT) + config.logger = ActiveSupport::Logger.new(nil) end # In this mode, any jobs you queue will be run in the same thread, synchronously From c43b54a30a45463bca92e51178f470e7d4e841b6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 21 Oct 2016 00:04:44 +0300 Subject: [PATCH 09/24] Set raise_on_missing_translations to true in test env #206 --- config/environments/test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 77819dfb4..46ec2c467 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -38,8 +38,7 @@ Rails.application.configure do config.time_zone = 'UTC' - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true + config.action_view.raise_on_missing_translations = true # The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, # corresponding to the log level numbers from 0 up to 5 respectively From d27594603b8ff8379effb9d810d3040692745496 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 24 Oct 2016 16:03:43 +0300 Subject: [PATCH 10/24] Disable contact model log in test env #206 --- app/models/contact.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 9612609b8..50e78ef54 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -212,7 +212,7 @@ class Contact < ActiveRecord::Base contact.destroy counter.next - STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{contact.id} (#{contact.name})\n" + STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{contact.id} (#{contact.name})\n" unless Rails.env.test? end STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{counter} orphaned contacts\n" unless Rails.env.test? From aaf6eb3a71bc104eeba71315878b8c4a71531c5b Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 24 Oct 2016 16:04:51 +0300 Subject: [PATCH 11/24] Remove fixed registrar #206 --- spec/fabricators/contact_fabricator.rb | 2 +- spec/fabricators/domain_fabricator.rb | 2 +- spec/fabricators/registrant_fabricator.rb | 2 +- spec/features/registrar/sessions_spec.rb | 3 ++- spec/rails_helper.rb | 5 ----- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/spec/fabricators/contact_fabricator.rb b/spec/fabricators/contact_fabricator.rb index 0ce9fbd53..68289d77c 100644 --- a/spec/fabricators/contact_fabricator.rb +++ b/spec/fabricators/contact_fabricator.rb @@ -1,5 +1,5 @@ Fabricator(:contact) do - registrar { Registrar.find_by_code('FIXED') } + registrar { Fabricate(:registrar) } code { sequence(:code) { |i| "SH#{Faker::Number.number(8)}#{i}" } } auth_info 'password' name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } } diff --git a/spec/fabricators/domain_fabricator.rb b/spec/fabricators/domain_fabricator.rb index 24f7a45f4..e1ee9b989 100644 --- a/spec/fabricators/domain_fabricator.rb +++ b/spec/fabricators/domain_fabricator.rb @@ -7,7 +7,7 @@ Fabricator(:domain) do nameservers(count: 3) admin_domain_contacts(count: 1) { Fabricate(:admin_domain_contact) } tech_domain_contacts(count: 1) { Fabricate(:tech_domain_contact) } - registrar { Registrar.find_by_code('FIXED') } + registrar { Fabricate(:registrar) } auth_info '98oiewslkfkd' end diff --git a/spec/fabricators/registrant_fabricator.rb b/spec/fabricators/registrant_fabricator.rb index f3e07220d..445134fb9 100644 --- a/spec/fabricators/registrant_fabricator.rb +++ b/spec/fabricators/registrant_fabricator.rb @@ -1,5 +1,5 @@ Fabricator(:registrant) do - registrar { Registrar.find_by_code('FIXED') } + registrar { Fabricate(:registrar) } code { sequence(:code) { |i| "REGISTRANT#{Faker::Number.number(8)}#{i}" } } auth_info 'password' name { sequence(:name) { |i| "REGISTRANT #{Faker::Name.name}#{i}" } } diff --git a/spec/features/registrar/sessions_spec.rb b/spec/features/registrar/sessions_spec.rb index eba0d6dfa..f6f10ceb8 100644 --- a/spec/features/registrar/sessions_spec.rb +++ b/spec/features/registrar/sessions_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Sessions', type: :feature do +RSpec.feature 'Sessions' do context 'with invalid ip' do it 'should not see login page' do Setting.registrar_ip_whitelist_enabled = true @@ -18,6 +18,7 @@ feature 'Sessions', type: :feature do end it 'should see log in' do + @fixed_registrar = Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED') @fixed_registrar.white_ips = [Fabricate(:white_ip_registrar)] visit registrar_login_path page.should have_text('Log in') diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6201e1ba8..f3d0c1192 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -45,11 +45,6 @@ def create_settings Setting.tech_contacts_max_count = 10 Setting.client_side_status_editing_enabled = true - - # speedup and easier to create fabrications - @fixed_registrar = - Registrar.find_by_name('fixed registrar') || - Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED') end RSpec.configure do |config| From 9a2e46075652821e309df18b01baf2caa2d4e929 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 24 Oct 2016 16:05:42 +0300 Subject: [PATCH 12/24] Remove useless spec #206 --- spec/models/blocked_domain_spec.rb | 34 ------------------------------ 1 file changed, 34 deletions(-) delete mode 100644 spec/models/blocked_domain_spec.rb diff --git a/spec/models/blocked_domain_spec.rb b/spec/models/blocked_domain_spec.rb deleted file mode 100644 index 58bc1fdd3..000000000 --- a/spec/models/blocked_domain_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'rails_helper' - -describe BlockedDomain do - context 'with no attributes' do - before :all do - @blocked_domain = BlockedDomain.new - end - - it 'should have names array' do - @blocked_domain.names.should == [] - end - end - - context 'with valid attributes' do - before :all do - @blocked_domain = Fabricate(:blocked_domain) - end - - it 'should be valid' do - @blocked_domain.valid? - @blocked_domain.errors.full_messages.should match_array([]) - end - - it 'should have one version' do - with_versioning do - @blocked_domain.versions.should == [] - @blocked_domain.names = ['bla.ee'] - @blocked_domain.save - @blocked_domain.errors.full_messages.should match_array([]) - @blocked_domain.versions.size.should == 1 - end - end - end -end From b265944cdb353be6a3551eba2abd4a9dbdcefc45 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 24 Oct 2016 16:06:10 +0300 Subject: [PATCH 13/24] Fix reserved domain fabricator #206 --- spec/fabricators/reserved_domain_fabricator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/fabricators/reserved_domain_fabricator.rb b/spec/fabricators/reserved_domain_fabricator.rb index 672fa3e53..3bbdadbe1 100644 --- a/spec/fabricators/reserved_domain_fabricator.rb +++ b/spec/fabricators/reserved_domain_fabricator.rb @@ -1,3 +1,3 @@ Fabricator(:reserved_domain) do - names { { '1162.ee': 'abc' } } + name { sequence(:name) { |i| "domain#{i}.ee" } } end From f9d4e3433b47a10bfe94c8dbd5b1e83baaa5eeb7 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 24 Oct 2016 22:46:56 +0300 Subject: [PATCH 14/24] Fix contact model specs #206 --- spec/models/contact_spec.rb | 148 +++++++++++------------------------- 1 file changed, 43 insertions(+), 105 deletions(-) diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 23c180647..a5a680439 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Contact do - before :all do + before :example do Fabricate(:zonefile_setting, origin: 'ee') @api_user = Fabricate(:api_user) end @@ -17,28 +17,10 @@ describe Contact do end context 'with invalid attribute' do - before :all do + before :example do @contact = Contact.new end - it 'should not be valid' do - @contact.valid? - @contact.errors.full_messages.should match_array([ - "Name Required parameter missing - name", - "Phone Required parameter missing - phone", - "Phone Phone nr is invalid", - "Email Required parameter missing - email", - "Email Email is invalid", - "Ident Required parameter missing - ident", - "Registrar is missing", - "Ident type is missing", - "City is missing", - "Country code is missing", - "Street is missing", - "Zip is missing" - ]) - end - it 'should not have creator' do @contact.creator.should == nil end @@ -66,6 +48,7 @@ describe Contact do end it 'should validate correct country code' do + @contact.ident = 1 @contact.ident_type = 'org' @contact.ident_country_code = 'EE' @contact.valid? @@ -79,14 +62,14 @@ describe Contact do @contact.ident_country_code = 'INVALID' @contact.valid? - @contact.errors[:ident].should == - ['Ident country code is not valid, should be in ISO_3166-1 alpha 2 format'] + expect(@contact.errors).to have_key(:ident) end it 'should convert to alpha2 country code' do + @contact.ident = 1 @contact.ident_type = 'org' @contact.ident_country_code = 'ee' - @contact.valid? + @contact.validate @contact.ident_country_code.should == 'EE' end @@ -102,9 +85,11 @@ describe Contact do end it 'should not allow double status' do - @contact.statuses = ['ok', 'ok'] - @contact.valid? - @contact.errors[:statuses].should == ['not uniq'] + contact = described_class.new(statuses: %w(ok ok)) + + contact.validate + + expect(contact.statuses).to eq(%w(ok)) end it 'should have no related domain descriptions' do @@ -123,21 +108,10 @@ describe Contact do end context 'with valid attributes' do - before :all do + before :example do @contact = Fabricate(:contact) end - it 'should be valid' do - @contact.valid? - @contact.errors.full_messages.should match_array([]) - end - - it 'should be valid twice' do - @contact = Fabricate(:contact) - @contact.valid? - @contact.errors.full_messages.should match_array([]) - end - it 'should have one version' do with_versioning do @contact.versions.reload.should == [] @@ -153,10 +127,11 @@ describe Contact do end it 'org should be valid' do - @contact.ident_type = 'org' - @contact.ident = '1234' - @contact.valid? - @contact.errors.full_messages.should match_array([]) + contact = Fabricate.build(:contact, ident_type: 'org', ident: '1' * 8) + + contact.validate + + contact.errors.full_messages.should match_array([]) end it 'should not overwrite code' do @@ -188,45 +163,11 @@ describe Contact do contact.statuses.should == [Contact::SERVER_UPDATE_PROHIBITED] end - it 'should have linked status when domain' do - contact = Fabricate(:contact) - tech_domain_contact = Fabricate(:tech_domain_contact, contact_id: contact.id) - contact.statuses.should == %w(ok) - domain = Fabricate(:domain, tech_domain_contacts: [tech_domain_contact]) - - contact = domain.contacts.first - contact.save - contact.statuses.sort.should == %w(linked ok) - - contact = domain.contacts.second - contact.save - contact.statuses.sort.should == %w(linked ok) - end - - it 'should not have linked status when no domain' do - @admin_domain_contact = Fabricate(:admin_domain_contact, contact_id: @contact.id) - @domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact]) - contact = @domain.contacts.first - contact.save - - contact.statuses.sort.should == %w(linked ok) - - contact.domains.first.destroy - contact.reload - contact.statuses.should == %w(ok) - end - it 'should have code' do - @contact.code.should =~ /FIXED:..../ - end + registrar = Fabricate.create(:registrar, code: 'registrarcode') + contact = Fabricate.create(:contact, registrar: registrar, code: 'contactcode') - it 'should have linked status when domain is created' do - # @admin_domain_contact = Fabricate(:admin_domain_contact) - # @domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact]) - # puts @domain.contacts.size - # contact = @domain.contacts.first - - # contact.statuses.map(&:value).should == %w(ok linked) + expect(contact.code).to eq('REGISTRARCODE:CONTACTCODE') end it 'should save status notes' do @@ -258,17 +199,17 @@ describe Contact do it 'should have related domain descriptions hash' do contact = @domain.registrant contact.reload # somehow it registrant_domains are empty? - contact.related_domain_descriptions.should == { "#{@domain.name}" => [:registrant] } + contact.related_domain_descriptions.should == {"#{@domain.name}" => [:registrant]} end it 'should have related domain descriptions hash when find directly' do contact = @domain.registrant - Contact.find(contact.id).related_domain_descriptions.should == { "#{@domain.name}" => [:registrant] } + Contact.find(contact.id).related_domain_descriptions.should == {"#{@domain.name}" => [:registrant]} end it 'should have related domain descriptions hash' do contact = @domain.contacts.first - contact.related_domain_descriptions.should == { "#{@domain.name}" => [:admin] } + contact.related_domain_descriptions.should == {"#{@domain.name}" => [:admin]} end it 'should fully validate email syntax for old records' do @@ -281,7 +222,7 @@ describe Contact do end context 'as birthday' do - before :all do + before :example do @contact.ident_type = 'birthday' end @@ -300,13 +241,13 @@ describe Contact do @contact.ident = date @contact.valid? @contact.errors.full_messages.should == - ["Ident Ident not in valid birthady format, should be YYYY-MM-DD"] + ["Ident Ident not in valid birthady format, should be YYYY-MM-DD"] end end end context 'with callbacks' do - before :all do + before :example do # Ensure callbacks are not taken out from other specs Contact.set_callback(:create, :before, :generate_auth_info) end @@ -314,6 +255,7 @@ describe Contact do context 'after create' do it 'should not generate a new code when code is present' do @contact = Fabricate.build(:contact, + registrar: Fabricate(:registrar, code: 'FIXED'), code: 'FIXED:new-code', auth_info: 'qwe321') @contact.code.should == 'FIXED:new-code' # still new record @@ -321,20 +263,21 @@ describe Contact do @contact.code.should == 'FIXED:NEW-CODE' end - it 'should not allaw to use same code' do - @contact = Fabricate.build(:contact, - code: 'FIXED:new-code', - auth_info: 'qwe321') - @contact.code.should == 'FIXED:new-code' # still new record - @contact.save.should == true - @contact.code.should == 'FIXED:NEW-CODE' + it 'should not allow to use same code' do + registrar = Fabricate.create(:registrar, code: 'FIXED') + Fabricate.create(:contact, + registrar: registrar, + code: 'FIXED:new-code', + auth_info: 'qwe321') @contact = Fabricate.build(:contact, + registrar: registrar, code: 'FIXED:new-code', auth_info: 'qwe321') - @contact.code.should == 'FIXED:new-code' # still new record - @contact.valid? - @contact.errors.full_messages.should == ["Code Contact id already exists"] + + @contact.validate + + expect(@contact.errors).to have_key(:code) end it 'should generate a new password' do @@ -344,20 +287,14 @@ describe Contact do @contact.auth_info.should_not be_nil end - it 'should not allow same code' do - @double_contact = Fabricate.build(:contact, code: @contact.code) - @double_contact.valid? - @double_contact.errors.full_messages.should == ["Code Contact id already exists"] - end - it 'should allow supported code format' do - @contact = Fabricate.build(:contact, code: 'CID:REG1:12345') + @contact = Fabricate.build(:contact, code: 'CID:REG1:12345', registrar: Fabricate(:registrar, code: 'FIXED')) @contact.valid? @contact.errors.full_messages.should == [] end it 'should not allow unsupported characters in code' do - @contact = Fabricate.build(:contact, code: 'unsupported!ÄÖÜ~?') + @contact = Fabricate.build(:contact, code: 'unsupported!ÄÖÜ~?', registrar: Fabricate(:registrar, code: 'FIXED')) @contact.valid? @contact.errors.full_messages.should == ['Code is invalid'] end @@ -368,15 +305,16 @@ describe Contact do end it 'should not ignore empty spaces as code and generate new one' do - @contact = Fabricate.build(:contact, code: ' ') + @contact = Fabricate.build(:contact, code: ' ', registrar: Fabricate(:registrar, code: 'FIXED')) @contact.valid?.should == true @contact.code.should =~ /FIXED:..../ end end context 'after update' do - before :all do + before :example do @contact = Fabricate.build(:contact, + registrar: Fabricate(:registrar, code: 'FIXED'), code: '123asd', auth_info: 'qwe321') @contact.save From 3cca4c78ccef60967be1fb945070eb378fc996f6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 24 Oct 2016 22:47:21 +0300 Subject: [PATCH 15/24] Fix domain model specs #206 --- spec/models/domain_spec.rb | 110 +++++++++---------------------------- 1 file changed, 25 insertions(+), 85 deletions(-) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 51184b15e..9e1a83b05 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -describe Domain do - before :all do +RSpec.describe Domain do + before :example do Fabricate(:zonefile_setting, origin: 'ee') Fabricate(:zonefile_setting, origin: 'pri.ee') Fabricate(:zonefile_setting, origin: 'med.ee') @@ -10,7 +10,7 @@ describe Domain do end context 'with invalid attribute' do - before :all do + before :example do @domain = Domain.new end @@ -59,11 +59,6 @@ describe Domain do @domain = Fabricate(:domain) end - after do - @domain.delete - @domain = nil - end - it 'should be valid' do @domain.valid? @domain.errors.full_messages.should match_array([]) @@ -137,6 +132,9 @@ describe Domain do end it 'should expire domains' do + Setting.expire_warning_period = 1 + Setting.redemption_grace_period = 1 + DomainCron.start_expire_period @domain.statuses.include?(DomainStatus::EXPIRED).should == false @@ -147,6 +145,11 @@ describe Domain do DomainCron.start_expire_period @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true + + p @domain.outzone_at + p old_valid_to + p Setting.expire_warning_period.days + @domain.outzone_at.should be_within(5).of(old_valid_to + Setting.expire_warning_period.days) @domain.delete_at.should be_within(5).of( old_valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days @@ -194,43 +197,6 @@ describe Domain do @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true end - it 'should start delete period' do - DomainCron.start_delete_period - @domain.reload - @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == false - - @domain.delete_at = Time.zone.now - @domain.statuses << DomainStatus::SERVER_DELETE_PROHIBITED # this prohibits delete_candidate - @domain.save - - DomainCron.start_delete_period - @domain.reload - @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == false - - @domain.statuses = [] - @domain.save - DomainCron.start_delete_period - @domain.reload - - @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == true - end - - it 'should destroy delete candidates' do - d = Fabricate(:domain) - d.force_delete_at = Time.zone.now - d.save - - @domain.delete_at = Time.zone.now - @domain.save - - Domain.count.should == 2 - - DomainCron.start_delete_period - - Domain.destroy_delete_candidates - Domain.count.should == 0 - end - it 'should set force delete time' do @domain.statuses = ['ok'] @domain.set_force_delete @@ -302,6 +268,8 @@ describe Domain do end it 'should should be manual in zone and held after force delete' do + Setting.redemption_grace_period = 1 + @domain.valid? @domain.outzone_at = Time.zone.now + 1.day # before redemption grace period # what should this be? @@ -324,7 +292,7 @@ describe Domain do end context 'with time period settings' do - before :all do + before :example do @save_days_to_renew = Setting.days_to_renew_domain_before_expire @save_warning_period = Setting.expire_warning_period @save_grace_period = Setting.redemption_grace_period @@ -350,13 +318,14 @@ describe Domain do end it 'should not allow to renew after force delete' do + Setting.redemption_grace_period = 1 @domain.set_force_delete @domain.renewable?.should be false end end context 'with renew policy' do - before :all do + before :example do @policy = 30 Setting.days_to_renew_domain_before_expire = @policy end @@ -374,6 +343,7 @@ describe Domain do end it 'should not allow to renew after force delete' do + Setting.redemption_grace_period = 1 @domain.set_force_delete @domain.renewable?.should be false end @@ -705,34 +675,13 @@ describe Domain do it 'should not create zone origin domain' do d = Fabricate.build(:domain, name: 'ee') d.save.should == false - d.errors.full_messages.should match_array([ - "Data management policy violation: Domain name is blocked [name]" - ]) + expect(d.errors.full_messages).to include('Data management policy violation: Domain name is blocked [name]') d = Fabricate.build(:domain, name: 'bla') d.save.should == false - d.errors.full_messages.should match_array([ - "Domain name Domain name is invalid" - ]) + expect(d.errors.full_messages).to include('Domain name Domain name is invalid') end - # d = Domain.new - # expect(d.valid?).to be false - # expect(d.errors.messages).to match_array({ - # registrant: ['Registrant is missing'], - # admin_contacts: ['Admin contacts count must be between 1 - infinity'], - # nameservers: ['Nameservers count must be between 2-11'], - # registrar: ['Registrar is missing'], - # period: ['Period is not a number'] - # }) - - # Setting.ns_min_count = 2 - # Setting.ns_max_count = 7 - - # expect(d.valid?).to be false - # expect(d.errors.messages[:nameservers]).to eq(['Nameservers count must be between 2-7']) - # end - it 'downcases domain' do d = Domain.new(name: 'TesT.Ee') expect(d.name).to eq('test.ee') @@ -840,20 +789,13 @@ describe Domain do d.errors.full_messages.should == [] end - it 'normalizes ns attrs' do - d = Fabricate(:domain) - d.nameservers.build(hostname: 'BLA.EXAMPLE.EE', ipv4: ' 192.168.1.1', ipv6: '1080:0:0:0:8:800:200c:417a') - d.save - - ns = d.nameservers.last - expect(ns.hostname).to eq('bla.example.ee') - expect(ns.ipv4).to eq('192.168.1.1') - expect(ns.ipv6).to eq('1080:0:0:0:8:800:200C:417A') - end - it 'does not create a reserved domain' do - Fabricate(:reserved_domain) - expect(Fabricate.build(:domain, name: '1162.ee').valid?).to be false + Fabricate.create(:reserved_domain, name: 'test.ee') + + domain = Fabricate.build(:domain, name: 'test.ee') + domain.validate + + expect(domain.errors[:base]).to include('Required parameter missing; reserved>pw element required for reserved domains') end it 'validates period' do @@ -904,8 +846,6 @@ describe Domain do context 'when saved' do before(:each) do - # Fabricate(:domain_validation_setting_group) - # Fabricate(:dnskeys_setting_group) Fabricate(:domain) end From c88d21ab1d67541b44399d7413c2fcb698db3170 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 02:35:58 +0300 Subject: [PATCH 16/24] Remove outdated specs #206 --- spec/epp/contact_spec.rb | 955 ----- spec/epp/domain_spec.rb | 3157 ----------------- spec/epp/epp_helper_spec.rb | 54 - spec/epp/keyrelay_spec.rb | 216 -- spec/epp/poll_spec.rb | 158 - .../contacts/create_with_two_addresses.xml | 45 - spec/epp/requests/contacts/delete.xml | 12 - .../requests/contacts/delete_missing_attr.xml | 11 - spec/epp/requests/contacts/info.xml | 15 - .../requests/contacts/info_missing_attr.xml | 11 - spec/epp/requests/contacts/update.xml | 36 - .../requests/contacts/update_missing_attr.xml | 11 - .../requests/contacts/update_with_errors.xml | 19 - spec/epp/session_spec.rb | 155 - spec/features/admin/account_activity_spec.rb | 45 - spec/features/admin/admin_user_spec.rb | 49 - spec/features/admin/api_user_spec.rb | 40 - spec/features/admin/bank_statement_spec.rb | 52 - spec/features/admin/blocked_domain_spec.rb | 31 - spec/features/admin/contact_spec.rb | 60 - spec/features/admin/domain_spec.rb | 89 - spec/features/admin/epp_log_spec.rb | 25 - spec/features/admin/invoice_spec.rb | 131 - spec/features/admin/mail_templates_spec.rb | 47 - spec/features/admin/repp_log_spec.rb | 24 - spec/features/admin/reserved_domain_spec.rb | 44 - spec/features/admin/white_ip_spec.rb | 63 - spec/features/admin/zonefile_setting_spec.rb | 99 - .../registrant/domain_delete_confirm_spec.rb | 49 - .../registrant/domain_update_confirm_spec.rb | 49 - spec/features/registrant/root_spec.rb | 18 - .../registrar/account_activity_spec.rb | 38 - spec/features/registrar/contact_spec.rb | 94 - spec/features/registrar/domain_spec.rb | 124 - spec/features/registrar/invoices_spec.rb | 68 - spec/features/registrar/root_spec.rb | 22 - spec/features/registrar/sessions_spec.rb | 187 - spec/features/sessions_spec.rb | 25 - spec/features/setting_management_spec.rb | 26 - spec/mailers/contact_mailer_spec.rb | 82 - spec/mailers/domain_mailer_spec.rb | 336 -- spec/models/certificate_spec.rb | 59 - spec/models/dnskey_spec.rb | 6 +- spec/models/domain_spec.rb | 17 - spec/models/domain_transfer_spec.rb | 6 +- spec/models/keyrelay_spec.rb | 6 +- spec/models/nameserver_spec.rb | 15 +- spec/models/registrant_verification_spec.rb | 6 +- spec/models/registrar_spec.rb | 34 - spec/models/whois_record_spec.rb | 139 - spec/models/zonefile_setting_spec.rb | 4 - spec/requests/repp_doc_template.md.erb | 20 - spec/requests/v1/account_spec.rb | 47 - spec/requests/v1/contact_spec.rb | 81 - spec/requests/v1/domain_spec.rb | 91 - 55 files changed, 16 insertions(+), 7287 deletions(-) delete mode 100644 spec/epp/contact_spec.rb delete mode 100644 spec/epp/domain_spec.rb delete mode 100644 spec/epp/epp_helper_spec.rb delete mode 100644 spec/epp/keyrelay_spec.rb delete mode 100644 spec/epp/poll_spec.rb delete mode 100644 spec/epp/requests/contacts/create_with_two_addresses.xml delete mode 100644 spec/epp/requests/contacts/delete.xml delete mode 100644 spec/epp/requests/contacts/delete_missing_attr.xml delete mode 100644 spec/epp/requests/contacts/info.xml delete mode 100644 spec/epp/requests/contacts/info_missing_attr.xml delete mode 100644 spec/epp/requests/contacts/update.xml delete mode 100644 spec/epp/requests/contacts/update_missing_attr.xml delete mode 100644 spec/epp/requests/contacts/update_with_errors.xml delete mode 100644 spec/epp/session_spec.rb delete mode 100644 spec/features/admin/account_activity_spec.rb delete mode 100644 spec/features/admin/admin_user_spec.rb delete mode 100644 spec/features/admin/api_user_spec.rb delete mode 100644 spec/features/admin/bank_statement_spec.rb delete mode 100644 spec/features/admin/blocked_domain_spec.rb delete mode 100644 spec/features/admin/contact_spec.rb delete mode 100644 spec/features/admin/domain_spec.rb delete mode 100644 spec/features/admin/epp_log_spec.rb delete mode 100644 spec/features/admin/invoice_spec.rb delete mode 100644 spec/features/admin/mail_templates_spec.rb delete mode 100644 spec/features/admin/repp_log_spec.rb delete mode 100644 spec/features/admin/reserved_domain_spec.rb delete mode 100644 spec/features/admin/white_ip_spec.rb delete mode 100644 spec/features/admin/zonefile_setting_spec.rb delete mode 100644 spec/features/registrant/domain_delete_confirm_spec.rb delete mode 100644 spec/features/registrant/domain_update_confirm_spec.rb delete mode 100644 spec/features/registrant/root_spec.rb delete mode 100644 spec/features/registrar/account_activity_spec.rb delete mode 100644 spec/features/registrar/contact_spec.rb delete mode 100644 spec/features/registrar/domain_spec.rb delete mode 100644 spec/features/registrar/invoices_spec.rb delete mode 100644 spec/features/registrar/root_spec.rb delete mode 100644 spec/features/registrar/sessions_spec.rb delete mode 100644 spec/features/sessions_spec.rb delete mode 100644 spec/features/setting_management_spec.rb delete mode 100644 spec/mailers/contact_mailer_spec.rb delete mode 100644 spec/mailers/domain_mailer_spec.rb delete mode 100644 spec/models/certificate_spec.rb delete mode 100644 spec/models/whois_record_spec.rb delete mode 100644 spec/requests/repp_doc_template.md.erb delete mode 100644 spec/requests/v1/account_spec.rb delete mode 100644 spec/requests/v1/contact_spec.rb delete mode 100644 spec/requests/v1/domain_spec.rb diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb deleted file mode 100644 index 4a8f35bb6..000000000 --- a/spec/epp/contact_spec.rb +++ /dev/null @@ -1,955 +0,0 @@ -require 'rails_helper' - -describe 'EPP Contact', epp: true do - before :all do - @xsd = Nokogiri::XML::Schema(File.read('lib/schemas/contact-eis-1.0.xsd')) - Fabricate(:zonefile_setting, origin: 'ee') - Fabricate(:zonefile_setting, origin: 'pri.ee') - Fabricate(:zonefile_setting, origin: 'med.ee') - Fabricate(:zonefile_setting, origin: 'fie.ee') - Fabricate(:zonefile_setting, origin: 'com.ee') - - @registrar1 = Fabricate(:registrar1) - @registrar2 = Fabricate(:registrar2) - @epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345') - - Fabricate(:api_user, username: 'registrar1', registrar: @registrar1) - Fabricate(:api_user, username: 'registrar2', registrar: @registrar2) - - login_as :registrar1 - - @contact = Fabricate(:contact, registrar: @registrar1) - - @extension = { - ident: { - value: '37605030299', - attrs: { type: 'priv', cc: 'EE' } - }, - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - } - @update_extension = { - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - } - end - - context 'with valid user' do - context 'create command' do - def create_request(overwrites = {}, extension = {}, options = {}) - extension = @extension if extension.blank? - - defaults = { - id: nil, - postalInfo: { - name: { value: 'John Doe' }, - org: nil, - addr: { - street: { value: '123 Example' }, - city: { value: 'Tallinn' }, - pc: { value: '123456' }, - cc: { value: 'EE' } - } - }, - voice: { value: '+372.1234567' }, - fax: nil, - email: { value: 'test@example.example' }, - authInfo: nil - } - create_xml = @epp_xml.create(defaults.deep_merge(overwrites), extension) - epp_plain_request(create_xml, options) - end - - it 'fails if request xml is missing' do - response = epp_plain_request(@epp_xml.create) - - response[:results][0][:msg].should == - "Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}create': Missing child element(s). "\ - "Expected is one of ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id, "\ - "{https://epp.tld.ee/schema/contact-eis-1.0.xsd}postalInfo )." - response[:results][0][:result_code].should == '2001' - end - - it 'successfully creates a contact' do - response = create_request - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - @contact = Contact.last - - @contact.registrar.should == @registrar1 - @registrar1.api_users.should include(@contact.creator) - @contact.ident.should == '37605030299' - @contact.street.should == '123 Example' - @contact.legal_documents.count.should == 1 - @contact.auth_info.length.should > 0 - - log = ApiLog::EppLog.last - log.request_command.should == 'create' - log.request_object.should == 'contact' - log.request_successful.should == true - log.api_user_name.should == 'registrar1' - log.api_user_registrar.should == 'registrar1' - end - - it 'creates a contact with custom auth info' do - response = create_request({ - authInfo: { pw: { value: 'custompw' } } - }) - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - @contact = Contact.last - @contact.auth_info.should == 'custompw' - end - - it 'successfully saves ident type with legal document' do - extension = { - ident: { - value: '1990-22-12', - attrs: { type: 'birthday', cc: 'US' } - }, - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - } - response = create_request({}, extension) - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - @contact = Contact.last - @contact.ident_type.should == 'birthday' - @contact.legal_documents.size.should == 1 - end - - it 'successfully adds registrar' do - response = create_request - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.registrar.should == @registrar1 - end - - it 'returns result data upon success' do - response = create_request - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - id = response[:parsed].css('resData creData id').first - cr_date = response[:parsed].css('resData creData crDate').first - - id.text.length.should == 15 - # 5 seconds for what-ever weird lag reasons might happen - cr_date.text.in_time_zone.utc.should be_within(5).of(Time.zone.now) - end - - it 'should return email issue' do - response = create_request(email: { value: 'not@valid' }) - - response[:msg].should == 'Email is invalid [email]' - response[:result_code].should == '2005' - end - - it 'should add registrar prefix for code when missing' do - response = create_request({ id: { value: 'abc12345' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should == 'FIRST0:ABC12345' - end - - it 'should add registrar prefix for code when missing' do - response = create_request({ id: { value: 'abc:ABC:12345' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should == 'FIRST0:ABC:ABC:12345' - end - - it 'should not allow spaces in custom code' do - response = create_request({ id: { value: 'abc 123' } }) - response[:msg].should == 'is invalid [code]' - response[:result_code].should == '2005' - end - - it 'should not strange characters in custom code' do - response = create_request({ id: { value: '33&$@@' } }) - response[:msg].should == 'is invalid [code]' - response[:result_code].should == '2005' - end - - it 'should not strange characters in custom code' do - long_str = 'a' * 1000 - response = create_request({ id: { value: long_str } }) - response[:msg].should == 'Contact code is too long, max 100 characters [code]' - response[:result_code].should == '2005' - end - - it 'should not saves ident type with wrong country code' do - extension = { - ident: { - value: '1990-22-12', - attrs: { type: 'birthday', cc: 'WRONG' } - } - } - response = create_request({}, extension) - response[:msg].should == "Element '{https://epp.tld.ee/schema/eis-1.0.xsd}ident', "\ - "attribute 'cc': [facet 'maxLength'] The value 'WRONG' has a length of '5'; this exceeds "\ - "the allowed maximum length of '2'." - response[:result_code].should == '2001' - end - - it 'should return country missing' do - extension = { - ident: { - value: '1990-22-12', - attrs: { type: 'birthday' } - } - } - response = create_request({}, extension) - response[:msg].should == "Element '{https://epp.tld.ee/schema/eis-1.0.xsd}ident': The attribute "\ - "'cc' is required but missing." - response[:result_code].should == '2001' - end - - it 'should return country missing' do - extension = { - ident: { - value: '1990-22-12' - } - } - response = create_request({}, extension) - response[:msg].should == "Element '{https://epp.tld.ee/schema/eis-1.0.xsd}ident': The attribute "\ - "'type' is required but missing." - response[:result_code].should == '2001' - end - - it 'should add registrar prefix for code when legacy prefix present' do - response = create_request({ id: { value: 'CID:FIRST0:abc:ABC:NEW:12345' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should == 'FIRST0:CID:FIRST0:ABC:ABC:NEW:12345' - end - - it 'should not remove suffix CID' do - response = create_request({ id: { value: 'CID:FIRST0:abc:CID:ABC:NEW:12345' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should == 'FIRST0:CID:FIRST0:ABC:CID:ABC:NEW:12345' - end - - it 'should not add registrar prefix for code when prefix present' do - response = create_request({ id: { value: 'FIRST0:abc22' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should == 'FIRST0:ABC22' - end - - it 'should add registrar prefix for code does not match exactly to prefix' do - response = create_request({ id: { value: 'cid2:first0:abc:ABC:11111' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should == 'FIRST0:CID2:FIRST0:ABC:ABC:11111' - end - - it 'should ignore custom code when only contact prefix given' do - response = create_request({ id: { value: 'CID:FIRST0' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should =~ /FIRST0:..../ - end - - it 'should generate server id when id is empty' do - response = create_request({ id: nil }) - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should_not == 'registrar1:' - end - - it 'should generate server id when id is empty' do - response = create_request - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should_not == 'registrar1:' - end - - it 'should return parameter value policy error for org' do - response = create_request({ postalInfo: { org: { value: 'should not save' } } }) - response[:msg].should == - 'Parameter value policy error. Org must be blank: postalInfo > org [org]' - response[:result_code].should == '2306' - - Contact.last.org_name.should == nil - end - - it 'should return parameter value policy error for fax' do - response = create_request({ fax: { value: 'should not save' } }) - response[:msg].should == - 'Parameter value policy error. Fax must be blank: fax [fax]' - response[:result_code].should == '2306' - - Contact.last.fax.should == nil - end - end - - context 'update command' do - before :all do - @contact = - Fabricate( - :contact, - registrar: @registrar1, - email: 'not_updated@test.test', - code: 'FIRST0:SH8013' - ) - end - - def update_request(overwrites = {}, extension = {}, options = {}) - extension = @update_extension if extension.blank? - - defaults = { - id: { value: 'asd123123er' }, - chg: { - postalInfo: { - name: { value: 'John Doe Edited' } - }, - voice: { value: '+372.7654321' }, - fax: nil, - email: { value: 'edited@example.example' }, - authInfo: { pw: { value: 'password' } } - } - } - update_xml = @epp_xml.update(defaults.deep_merge(overwrites), extension) - epp_plain_request(update_xml, options) - end - - it 'fails if request is invalid' do - response = epp_plain_request(@epp_xml.update) - response[:results][0][:msg].should == - "Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}update': Missing child element(s). "\ - "Expected is ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id )." - end - - it 'returns error if obj doesnt exist' do - response = update_request({ id: { value: 'not-exists' } }) - response[:msg].should == 'Object does not exist' - response[:result_code].should == '2303' - response[:results].count.should == 1 - end - - it 'is succesful' do - response = update_request({ id: { value: 'FIRST0:SH8013' } }) - - response[:msg].should == 'Command completed successfully' - - @contact.reload - @contact.name.should == 'John Doe Edited' - @contact.email.should == 'edited@example.example' - end - - it 'is succesful for own contact without password' do - without_password = { - id: { value: 'FIRST0:SH8013' }, - chg: { - postalInfo: { - name: { value: 'John Doe Edited' } - } - } - } - update_xml = @epp_xml.update(without_password) - response = epp_plain_request(update_xml, :xml) - - response[:msg].should == 'Command completed successfully' - @contact.reload - @contact.name.should == 'John Doe Edited' - end - - it 'should update other contact with correct password' do - login_as :registrar2 do - response = update_request({ id: { value: 'FIRST0:SH8013' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - end - - it 'should not update other contact without password' do - login_as :registrar2 do - without_password = { - id: { value: 'FIRST0:SH8013' }, - chg: { - postalInfo: { - name: { value: 'John Doe Edited' } - } - } - } - update_xml = @epp_xml.update(without_password) - response = epp_plain_request(update_xml, :xml) - - response[:msg].should == 'Authorization error' - @contact.reload - @contact.name.should == 'John Doe Edited' - end - end - - it 'returns phone and email error' do - response = update_request({ - id: { value: 'FIRST0:SH8013' }, - chg: { - voice: { value: '123213' }, - email: { value: 'wrong' } - } - }) - - response[:results][0][:msg].should == 'Phone nr is invalid [phone]' - response[:results][0][:result_code].should == '2005' - response[:results][1][:msg].should == 'Email is invalid [email]' - response[:results][1][:result_code].should == '2005' - end - - it 'should return email issue' do - response = update_request({ - id: { value: 'FIRST0:SH8013' }, - chg: { - email: { value: 'legacy@wrong' } - } - }) - - response[:msg].should == 'Email is invalid [email]' - response[:result_code].should == '2005' - end - - it 'should not update code with custom string' do - response = update_request( - { - id: { value: 'FIRST0:SH8013' }, - chg: { - id: { value: 'notpossibletoupdate' } - } - }, {} - ) - - response[:msg].should == "Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}id': "\ - "This element is not expected." - response[:result_code].should == '2001' - - @contact.reload.code.should == 'FIRST0:SH8013' - end - - it 'should not be able to update ident' do - extension = { - ident: { - value: '1990-22-12', - attrs: { type: 'birthday', cc: 'US' } - }, - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - } - response = update_request({ id: { value: 'FIRST0:SH8013' } }, extension) - response[:msg].should == - 'Parameter value policy error. Update of ident data not allowed [ident]' - response[:result_code].should == '2306' - - Contact.find_by(code: 'FIRST0:SH8013').ident_type.should == 'priv' - end - - it 'should return parameter value policy errror for org update' do - response = update_request({ - id: { value: 'FIRST0:SH8013' }, - chg: { - postalInfo: { org: { value: 'should not save' } } - } - }) - response[:msg].should == - 'Parameter value policy error. Org must be blank: postalInfo > org [org]' - response[:result_code].should == '2306' - - Contact.find_by(code: 'FIRST0:SH8013').org_name.should == nil - end - - it 'should return parameter value policy errror for fax update' do - response = update_request({ - id: { value: 'FIRST0:SH8013' }, - chg: { - fax: { value: 'should not save' } - } - }) - response[:msg].should == - 'Parameter value policy error. Fax must be blank: fax [fax]' - response[:result_code].should == '2306' - - Contact.find_by(code: 'FIRST0:SH8013').fax.should == nil - end - - it 'does not allow to edit statuses if policy forbids it' do - Setting.client_status_editing_enabled = false - - xml = @epp_xml.update({ - id: { value: 'FIRST0:SH8013' }, - add: [{ - _anonymus: [ - { status: { value: 'Payment overdue.', attrs: { s: 'clientDeleteProhibited', lang: 'en' } } }, - { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } - ] - }] - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == "Parameter value policy error. Client-side object status "\ - "management not supported: status [status]" - response[:results][0][:result_code].should == '2306' - - Setting.client_status_editing_enabled = true - end - - it 'should update auth info' do - xml = @epp_xml.update({ - id: { value: 'FIRST0:SH8013' }, - chg: { - authInfo: { pw: { value: 'newpassword' } } - } - }) - - response = epp_plain_request(xml, :xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - contact = Contact.find_by(code: 'FIRST0:SH8013') - contact.auth_info.should == 'newpassword' - end - - it 'should add value voice value' do - xml = @epp_xml.update({ - id: { value: 'FIRST0:SH8013' }, - chg: { - voice: { value: '+372.11111111' }, - authInfo: { pw: { value: 'password' } } - } - }) - - response = epp_plain_request(xml, :xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - contact = Contact.find_by(code: 'FIRST0:SH8013') - contact.phone.should == '+372.11111111' - - contact.update_attribute(:phone, '+372.7654321') # restore default value - end - - it 'should return error when add attributes phone value is empty' do - phone = Contact.find_by(code: 'FIRST0:SH8013').phone - xml = @epp_xml.update({ - id: { value: 'FIRST0:SH8013' }, - chg: { - voice: { value: '' }, - email: { value: 'example@example.ee' }, - authInfo: { pw: { value: 'password' } } - } - }) - - response = epp_plain_request(xml, :xml) - response[:results][0][:msg].should == 'Required parameter missing - phone [phone]' - response[:results][0][:result_code].should == '2003' - Contact.find_by(code: 'FIRST0:SH8013').phone.should == phone # aka not changed - end - - it 'should not allow to remove required voice attribute' do - contact = Contact.find_by(code: 'FIRST0:SH8013') - phone = contact.phone - xml = @epp_xml.update({ - id: { value: 'FIRST0:SH8013' }, - chg: { - voice: { value: '' }, - authInfo: { pw: { value: 'password' } } - } - }) - - response = epp_plain_request(xml, :xml) - response[:results][0][:msg].should == 'Required parameter missing - phone [phone]' - response[:results][0][:result_code].should == '2003' - - contact = Contact.find_by(code: 'FIRST0:SH8013') - contact.phone.should == phone - end - - it 'should return general policy error when updating org' do - xml = @epp_xml.update({ - id: { value: 'FIRST0:SH8013' }, - chg: { - postalInfo: { - org: { value: 'shouldnot' } - }, - authInfo: { pw: { value: 'password' } } - } - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == - 'Parameter value policy error. Org must be blank: postalInfo > org [org]' - response[:results][0][:result_code].should == '2306' - end - - it 'does not allow to edit statuses if policy forbids it' do - Setting.client_status_editing_enabled = false - - xml = @epp_xml.update({ - id: { value: 'FIRST0:SH8013' }, - add: [{ - _anonymus: [ - { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } - ] - }] - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == "Parameter value policy error. Client-side object status "\ - "management not supported: status [status]" - response[:results][0][:result_code].should == '2306' - - Setting.client_status_editing_enabled = true - end - end - - context 'delete command' do - before do - @contact = Fabricate(:contact, registrar: @registrar1) - end - - def delete_request(overwrites = {}) - defaults = { - id: { value: @contact.code }, - authInfo: { pw: { value: @contact.auth_info } } - } - delete_xml = @epp_xml.delete(defaults.deep_merge(overwrites), @extension) - epp_plain_request(delete_xml, :xml) - end - - it 'fails if request is invalid' do - response = epp_plain_request(@epp_xml.delete) - - response[:results][0][:msg].should == - "Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}delete': Missing child element(s). "\ - "Expected is ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id )." - response[:results][0][:result_code].should == '2001' - response[:results].count.should == 1 - end - - it 'returns error if obj doesnt exist' do - response = delete_request({ id: { value: 'not-exists' } }) - response[:msg].should == 'Object does not exist' - response[:result_code].should == '2303' - response[:results].count.should == 1 - end - - it 'deletes contact' do - response = delete_request - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:clTRID].should == 'ABC-12345' - - Contact.find_by_id(@contact.id).should == nil - end - - it 'deletes own contact even with wrong password' do - response = delete_request({ authInfo: { pw: { value: 'wrong password' } } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:clTRID].should == 'ABC-12345' - - Contact.find_by_id(@contact.id).should == nil - end - - it 'deletes own contact even without password' do - delete_xml = @epp_xml.delete({ id: { value: @contact.code } }) - response = epp_plain_request(delete_xml, :xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:clTRID].should == 'ABC-12345' - - Contact.find_by_id(@contact.id).should == nil - end - - it 'fails if contact has associated domain' do - @domain = Fabricate(:domain, registrar: @registrar1, registrant: Registrant.find(@contact.id)) - @domain.registrant.present?.should == true - - response = delete_request - response[:msg].should == 'Object association prohibits operation [domains]' - response[:result_code].should == '2305' - response[:results].count.should == 1 - - @domain.registrant.present?.should == true - end - - it 'should delete when not owner but with correct password' do - login_as :registrar2 do - response = delete_request - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:clTRID].should == 'ABC-12345' - Contact.find_by_id(@contact.id).should == nil - end - end - - it 'should not delete when not owner without password' do - login_as :registrar2 do - delete_xml = @epp_xml.delete({ id: { value: @contact.code } }) - response = epp_plain_request(delete_xml, :xml) - response[:msg].should == 'Authorization error' - response[:result_code].should == '2201' - response[:results].count.should == 1 - end - end - - it 'should not delete when not owner with wrong password' do - login_as :registrar2 do - response = delete_request({ authInfo: { pw: { value: 'wrong password' } } }) - response[:msg].should == 'Authorization error' - response[:result_code].should == '2201' - response[:results].count.should == 1 - end - end - end - - context 'check command' do - def check_request(overwrites = {}) - defaults = { - id: { value: @contact.code }, - authInfo: { pw: { value: @contact.auth_info } } - } - xml = @epp_xml.check(defaults.deep_merge(overwrites)) - epp_plain_request(xml, :xml) - end - - it 'fails if request is invalid' do - response = epp_plain_request(@epp_xml.check) - - response[:results][0][:msg].should == - "Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}check': Missing child element(s). "\ - "Expected is ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id )." - response[:results][0][:result_code].should == '2001' - response[:results].count.should == 1 - end - - it 'returns info about contact availability' do - contact = Fabricate(:contact, code: 'check-1234') - contact.code.should == 'FIXED:CHECK-1234' - - response = epp_plain_request(check_multiple_contacts_xml, :xml) - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - ids = response[:parsed].css('resData chkData id') - - ids[0].attributes['avail'].text.should == '0' - ids[1].attributes['avail'].text.should == '1' - - ids[0].text.should == 'FIXED:CHECK-1234' - ids[1].text.should == 'check-4321' - end - - it 'should support legacy CID farmat' do - contact = Fabricate(:contact, code: 'check-LEGACY') - contact.code.should == 'FIXED:CHECK-LEGACY' - - response = epp_plain_request(check_multiple_legacy_contacts_xml, :xml) - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - ids = response[:parsed].css('resData chkData id') - - ids[0].text.should == 'FIXED:CHECK-LEGACY' - ids[1].text.should == 'CID:FIXED:CHECK-LEGACY' - - ids[0].attributes['avail'].text.should == '0' - ids[1].attributes['avail'].text.should == '1' - end - - end - - context 'info command' do - def info_request(overwrites = {}, options = {}) - defaults = { - id: { value: @contact.code }, - authInfo: { pw: { value: @contact.auth_info } } - } - - xml = @epp_xml.info(defaults.deep_merge(overwrites)) - epp_plain_request(xml, options) - end - - it 'fails if request invalid' do - response = epp_plain_request(@epp_xml.info) - response[:results][0][:msg].should == - "Element '{https://epp.tld.ee/schema/contact-eis-1.0.xsd}info': Missing child element(s). "\ - "Expected is ( {https://epp.tld.ee/schema/contact-eis-1.0.xsd}id )." - response[:results][0][:result_code].should == '2001' - response[:results].count.should == 1 - end - - it 'returns error when object does not exist' do - response = info_request({ id: { value: 'no-contact' } }) - response[:msg].should == 'Object does not exist' - response[:result_code].should == '2303' - response[:results][0][:value].should == 'NO-CONTACT' - response[:results].count.should == 1 - end - - it 'return info about contact' do - Fabricate(:contact, code: 'INFO-4444', name: 'Johnny Awesome') - - response = info_request({ id: { value: 'FIXED:INFO-4444' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - contact = response[:parsed].css('resData infData') - contact.css('name').first.text.should == 'Johnny Awesome' - end - - it 'should add legacy CID format as append' do - Fabricate(:contact, code: 'CID:FIXED:INFO-5555', name: 'Johnny Awesome') - - response = info_request({ id: { value: 'FIXED:CID:FIXED:INFO-5555' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - contact = response[:parsed].css('resData infData') - contact.css('name').first.text.should == 'Johnny Awesome' - end - - it 'should return ident in extension' do - @registrar1_contact = Fabricate(:contact, code: 'INFO-IDENT', - registrar: @registrar1, name: 'Johnny Awesome') - - response = info_request({ id: { value: @registrar1_contact.code } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - contact = response[:parsed].css('resData infData') - contact.css('ident').first.should == nil # ident should be in extension - - contact = response[:parsed].css('extension') - contact.css('ident').first.text.should == '37605030299' - end - - it 'returns no authorization error for wrong password when registrant' do - response = info_request({ authInfo: { pw: { value: 'wrong-pw' } } }) - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:results].count.should == 1 - end - - it 'should honor new contact code format' do - @registrar1_contact = Fabricate(:contact, code: 'FIXED:test:custom:code') - @registrar1_contact.code.should == 'FIXED:TEST:CUSTOM:CODE' - - response = info_request({ id: { value: 'FIXED:TEST:CUSTOM:CODE' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - contact = response[:parsed].css('resData infData') - contact.css('ident').first.should == nil # ident should be in extension - - contact = response[:parsed].css('extension') - contact.css('ident').first.text.should == '37605030299' - end - - it 'returns no authorization error for wrong user but correct password' do - login_as :registrar2 do - response = info_request - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:results].count.should == 1 - - contact = response[:parsed].css('resData infData') - contact.css('postalInfo addr city').first.try(:text).present?.should == true - contact.css('email').first.try(:text).present?.should == true - contact.css('voice').first.try(:text).should == '+372.12345678' - end - end - - it 'returns authorization error for wrong user and wrong password' do - login_as :registrar2 do - response = info_request({ authInfo: { pw: { value: 'wrong-pw' } } }) - response[:msg].should == 'Authorization error' - response[:result_code].should == '2201' - response[:results].count.should == 1 - - contact = response[:parsed].css('resData infData') - contact.css('postalInfo addr city').first.try(:text).should == nil - contact.css('email').first.try(:text).should == nil - contact.css('voice').first.try(:text).should == nil - end - end - - it 'returns no authorization error for wrong user and no password' do - login_as :registrar2 do - response = info_request({ authInfo: { pw: { value: '' } } }, validate_output: false) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:results].count.should == 1 - - contact = response[:parsed].css('resData infData') - contact.css('postalInfo addr city').first.try(:text).should == nil - contact.css('email').first.try(:text).should == nil - contact.css('voice').first.try(:text).should == nil - end - end - end - end - - def check_multiple_contacts_xml - ' - - - - - FIXED:CHECK-1234 - check-4321 - - - ABC-12345 - - ' - end - - def check_multiple_legacy_contacts_xml - ' - - - - - FIXED:CHECK-LEGACY - CID:FIXED:CHECK-LEGACY - - - ABC-12345 - - ' - end - -end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb deleted file mode 100644 index ccf13c8b5..000000000 --- a/spec/epp/domain_spec.rb +++ /dev/null @@ -1,3157 +0,0 @@ -require 'rails_helper' - -describe 'EPP Domain', epp: true do - before(:all) do - @xsd = Nokogiri::XML::Schema(File.read('lib/schemas/domain-eis-1.0.xsd')) - @epp_xml = EppXml.new(cl_trid: 'ABC-12345') - - Fabricate(:zonefile_setting, origin: 'ee') - Fabricate(:zonefile_setting, origin: 'pri.ee') - Fabricate(:zonefile_setting, origin: 'med.ee') - Fabricate(:zonefile_setting, origin: 'fie.ee') - Fabricate(:zonefile_setting, origin: 'com.ee') - - @registrar1 = Fabricate(:registrar1, code: 'REGDOMAIN1') - @registrar1.credit!({ sum: 10000 }) - @registrar2 = Fabricate(:registrar2, code: 'REGDOMAIN2') - @registrar2.credit!({ sum: 10000 }) - Fabricate(:api_user, username: 'registrar1', registrar: @registrar1) - Fabricate(:api_user, username: 'registrar2', registrar: @registrar2) - - login_as :registrar1 - - Fabricate(:contact, code: 'FIXED:CITIZEN_1234') - Fabricate(:contact, code: 'FIXED:SH8013') - Fabricate(:contact, code: 'FIXED:SH801333') - Fabricate(:contact, code: 'FIXED:JURIDICAL_1234', ident_type: 'org') - Fabricate(:reserved_domain) - Fabricate(:blocked_domain) - @pricelist_reg_1_year = Fabricate(:pricelist, valid_to: nil) - @pricelist_reg_2_year = Fabricate(:pricelist, duration: '2years', price: 20, valid_to: nil) - Fabricate(:pricelist, duration: '3years', price: 30, valid_to: nil) - @pricelist_renew_1_year = Fabricate(:pricelist, operation_category: 'renew', price: 15, valid_to: nil) - Fabricate(:pricelist, operation_category: 'renew', duration: '2years', price: 35, valid_to: nil) - Fabricate(:pricelist, operation_category: 'renew', duration: '3years', price: 62, valid_to: nil) - - @uniq_no = proc { @i ||= 0; @i += 1 } - end - - it 'should return error if balance low' do - f = Fabricate(:pricelist, valid_to: Time.zone.now + 1.day, price: 100000) - - dn = next_domain_name - response = epp_plain_request(domain_create_xml({ - name: { value: dn } - })) - - response[:msg].should == "Billing failure - credit balance low" - response[:result_code].should == '2104' - f.delete - end - - it 'returns error if contact does not exists' do - response = epp_plain_request(domain_create_xml({ - registrant: { value: 'FIXED:CITIZEN_1234' }, - _anonymus: [ - { contact: { value: 'FIXED:CITIZEN_1234', attrs: { type: 'admin' } } }, - { contact: { value: 'sh1111', attrs: { type: 'tech' } } }, - { contact: { value: 'sh2222', attrs: { type: 'tech' } } } - ] - })) - - response[:results][0][:msg].should == 'Contact was not found' - response[:results][0][:result_code].should == '2303' - response[:results][0][:value].should == 'sh1111' - - response[:results][1][:msg].should == 'Contact was not found' - response[:results][1][:result_code].should == '2303' - response[:results][1][:value].should == 'sh2222' - - response[:clTRID].should == 'ABC-12345' - - log = ApiLog::EppLog.last - - log.request_command.should == 'create' - log.request_object.should == 'domain' - log.request_successful.should == false - log.api_user_name.should == 'registrar1' - log.api_user_registrar.should == 'registrar1' - log.request.should_not be_blank - log.response.should_not be_blank - end - - it 'validates required parameters' do - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - xml = epp_xml.create({ - name: { value: 'test.ee' } - }) - - response = epp_plain_request(xml) - response[:results][0][:result_code].should == '2003' - response[:results][0][:msg].should == - 'Required parameter missing: create > create > ns [ns]' - - response[:results][1][:result_code].should == '2003' - response[:results][1][:msg].should == - 'Required parameter missing: create > create > registrant [registrant]' - - response[:results][2][:result_code].should == '2003' - response[:results][2][:msg].should == - 'Required parameter missing: create > create > ns > hostAttr [host_attr]' - - response[:results][3][:result_code].should == '2003' - response[:results][3][:msg].should == - 'Required parameter missing: extension > extdata > legalDocument [legal_document]' - end - - context 'with citizen as a registrant' do - it 'creates a domain' do - dn = next_domain_name - response = epp_plain_request(domain_create_xml({ - name: { value: dn } - })) - - d = Domain.last - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - cre_data = response[:parsed].css('creData') - - cre_data.css('name').text.should == dn - cre_data.css('crDate').text.should == d.created_at.in_time_zone.utc.utc.iso8601 - cre_data.css('exDate').text.should == d.valid_to.in_time_zone.utc.utc.iso8601 - - response[:clTRID].should == 'ABC-12345' - - d.registrar.name.should == 'registrar1' - d.tech_contacts.count.should == 2 - d.admin_contacts.count.should == 1 - - d.nameservers.count.should == 2 - d.auth_info.should_not be_empty - - d.dnskeys.count.should == 1 - - key = d.dnskeys.last - - key.ds_alg.should == 5 - key.ds_key_tag.should_not be_blank - - key.ds_digest_type.should == Setting.ds_algorithm - key.flags.should == 257 - key.protocol.should == 3 - key.alg.should == 5 - key.public_key.should == 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' - end - - it 'creates a domain with legal document' do - response = epp_plain_request(domain_create_xml_with_legal_doc) - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - d = Domain.last - d.legal_documents.count.should == 1 - d.reserved.should == false - end - - it 'creates a domain with custom auth info' do - dn = next_domain_name - response = epp_plain_request(domain_create_xml({ - name: { value: dn }, - authInfo: { pw: { value: 'asdasd' } } - })) - - d = Domain.last - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - d.auth_info.should == 'asdasd' - end - - # it 'creates ria.ee with valid ds record' do - # xml = domain_create_xml({ - # name: { value: 'ria.ee' } - # }, { - # _anonymus: [ - # { keyData: { - # flags: { value: '257' }, - # protocol: { value: '3' }, - # alg: { value: '8' }, - # pubKey: { value: 'AwEAAaOf5+lz3ftsL+0CCvfJbhUF/NVsNh8BKo61oYs5fXVbuWDiH872 '\ - # 'LC8uKDO92TJy7Q4TF9XMAKMMlf1GMAxlRspD749SOCTN00sqfWx1OMTu '\ - # 'a28L1PerwHq7665oDJDKqR71btcGqyLKhe2QDvCdA0mENimF1NudX1BJ '\ - # 'DDFi6oOZ0xE/0CuveB64I3ree7nCrwLwNs56kXC4LYoX3XdkOMKiJLL/ '\ - # 'MAhcxXa60CdZLoRtTEW3z8/oBq4hEAYMCNclpbd6y/exScwBxFTdUfFk '\ - # 'KsdNcmvai1lyk9vna0WQrtpYpHKMXvY9LFHaJxCOLR4umfeQ42RuTd82 lqfU6ClMeXs=' } - # } - # } - # ] - # }) - - # epp_plain_request(xml) - - # d = Domain.last - # ds = d.dnskeys.last - # ds.ds_digest.should == '0B62D1BC64EFD1EE652FB102BDF1011BF514CCD9A1A0CFB7472AEA3B01F38C92' - # end - - it 'validates nameserver ipv4 when in same zone as domain' do - dn = next_domain_name - xml = domain_create_xml({ - name: { value: dn }, - ns: [ - { - hostAttr: [ - { hostName: { value: "ns1.#{dn}" } } - ] - }, - { - hostAttr: { - hostName: { value: "ns2.#{dn}" } - } - } - ] - }) - - response = epp_plain_request(xml) - - response[:result_code].should == '2306' - response[:msg].should == 'IPv4 is missing [ipv4]' - end - - # it 'does not create duplicate domain' do - # dn = next_domain_name - # epp_plain_request(domain_create_xml({ - # name: { value: dn } - # })) - # response = epp_plain_request(domain_create_xml({ - # name: { value: dn } - # })) - - # response[:msg].should == 'Domain name already exists' - # response[:result_code].should == '2302' - # response[:clTRID].should == 'ABC-12345' - # end - - it 'does not create domain longer than 63 punicode characters' do - xml = domain_create_xml(name: { value: "#{'ä' * 63}.ee" }) - - response = epp_plain_request(xml) - response[:msg].should == 'Domain name is too long (maximum is 63 characters) [puny_label]' - response[:result_code].should == '2005' - response[:clTRID].should == 'ABC-12345' - end - - it 'does not create reserved domain' do - xml = domain_create_xml(name: { value: '1162.ee' }) - - response = epp_plain_request(xml) - response[:msg].should == 'Required parameter missing; reserved>pw element required for reserved domains' - response[:result_code].should == '2003' - response[:clTRID].should == 'ABC-12345' - - xml = domain_create_xml({name: { value: '1162.ee' }}, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - }, - reserved: { - pw: { value: 'wrong_pw' } - } - ] - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Invalid authorization information; invalid reserved>pw value' - response[:result_code].should == '2202' - end - - it 'creates a reserved domain with correct auth info' do - xml = domain_create_xml({name: { value: '1162.ee' }}, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - }, - reserved: { - pw: { value: 'abc' } - } - ] - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - d = Domain.last - d.statuses.should match_array(['ok']) - d.reserved.should == true - end - - it 'does not create blocked domain' do - xml = domain_create_xml(name: { value: 'ftp.ee' }) - - response = epp_plain_request(xml) - response[:msg].should == 'Data management policy violation: Domain name is blocked [name]' - response[:result_code].should == '2308' - response[:results][0][:value].should == 'ftp.ee' - response[:clTRID].should == 'ABC-12345' - end - - it 'does not create domain without contacts and registrant' do - xml = domain_create_xml(_anonymus: [], registrant: false) - - response = epp_plain_request(xml) - response[:results][0][:result_code].should == '2003' - response[:results][0][:msg].should == - 'Required parameter missing: create > create > registrant [registrant]' - end - - it 'does not create domain without nameservers' do - xml = domain_create_xml(ns: nil) - response = epp_plain_request(xml) - - response[:results][0][:msg].should == - 'Required parameter missing: create > create > ns [ns]' - response[:results][0][:result_code].should == '2003' - - response[:results][1][:msg].should == - 'Required parameter missing: create > create > ns > hostAttr [host_attr]' - response[:results][1][:result_code].should == '2003' - - response[:results].count.should == 2 - end - - it 'does not create domain with too many nameservers' do - nameservers = [] - 14.times do |i| - nameservers << { - hostAttr: { - hostName: { value: "ns#{i}.example.net" } - } - } - end - - xml = domain_create_xml({ - ns: nameservers - }) - - response = epp_plain_request(xml) - response[:result_code].should == '2004' - response[:msg].should == 'Nameservers count must be between 2-11 [nameservers]' - end - - it 'returns error when invalid nameservers are present' do - xml = domain_create_xml({ - ns: [ - { - hostAttr: { - hostName: { value: 'invalid1-' } - } - }, - { - hostAttr: { - hostName: { value: '-invalid2' } - } - } - ] - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Hostname is invalid [hostname]' - response[:result_code].should == '2005' - end - - it 'checks hostAttr presence' do - xml = domain_create_xml({ - ns: [ - { - hostObj: { value: 'ns1.example.ee' } - }, - { - hostObj: { value: 'ns2.example.ee' } - } - ] - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Required parameter missing: create > create > ns > hostAttr [host_attr]' - response[:result_code].should == '2003' - end - - it 'creates domain with nameservers with ips' do - epp_plain_request(domain_create_with_host_attrs) - Domain.last.nameservers.count.should == 2 - ns = Domain.last.nameservers.first - ns.ipv4.should == '192.0.2.2' - ns.ipv6.should == '1080:0:0:0:8:800:200C:417A' - end - - it 'returns error when nameserver has invalid ips' do - domain_count = Domain.count - nameserver_count = Nameserver.count - response = epp_plain_request(domain_create_with_invalid_ns_ip_xml) - response[:results][0][:result_code].should == '2005' - response[:results][0][:msg].should == 'IPv4 is invalid [ipv4]' - response[:results][0][:value].should == '192.0.2.2.invalid' - response[:results][1][:result_code].should == '2005' - response[:results][1][:msg].should == 'IPv6 is invalid [ipv6]' - response[:results][1][:value].should == 'INVALID_IPV6' - # ensure nothing gets saved to db: - Domain.count.should == domain_count - Nameserver.count.should == nameserver_count - end - - it 'creates a domain with period in days' do - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - xml = domain_create_xml(period: { value: '365', attrs: { unit: 'd' } }) - - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - Domain.last.valid_to.should be_within(60).of(1.year.since) - @registrar1.balance.should be < old_balance - @registrar1.cash_account.account_activities.count.should == old_activities + 1 - a = @registrar1.cash_account.account_activities.last - a.description.should == "Create #{Domain.last.name}" - a.sum.should == -BigDecimal.new('10.0') - a.activity_type = AccountActivity::CREATE - a.log_pricelist_id.should == @pricelist_reg_1_year.id - end - - it 'creates a domain with longer periods' do - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - xml = domain_create_xml(period: { value: '2', attrs: { unit: 'y' } }) - - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - Domain.last.valid_to.should be_within(60).of(2.years.since) - @registrar1.balance.should be < old_balance - @registrar1.cash_account.account_activities.count.should == old_activities + 1 - a = @registrar1.cash_account.account_activities.last - a.description.should == "Create #{Domain.last.name}" - a.sum.should == -BigDecimal.new('20.0') - a.activity_type = AccountActivity::CREATE - a.log_pricelist_id.should == @pricelist_reg_2_year.id - end - - it 'creates a domain with longer periods' do - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - xml = domain_create_xml(period: { value: '36', attrs: { unit: 'm' } }) - - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - Domain.last.valid_to.should be_within(60).of(3.years.since) - @registrar1.balance.should be < old_balance - @registrar1.cash_account.account_activities.count.should == old_activities + 1 - a = @registrar1.cash_account.account_activities.last - a.description.should == "Create #{Domain.last.name}" - a.sum.should == -BigDecimal.new('30.0') - a.activity_type = AccountActivity::CREATE - end - - it 'creates a domain without period' do - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - xml = domain_create_xml(period: nil) - - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - Domain.last.valid_to.should be_within(60).of(1.years.since) - @registrar1.balance.should be < old_balance - @registrar1.cash_account.account_activities.count.should == old_activities + 1 - a = @registrar1.cash_account.account_activities.last - a.description.should == "Create #{Domain.last.name}" - a.sum.should == -BigDecimal.new('10.0') - a.activity_type = AccountActivity::CREATE - a.log_pricelist_id.should == @pricelist_reg_1_year.id - end - - it 'does not create a domain with invalid period' do - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - xml = domain_create_xml({ - period: { value: '367', attrs: { unit: 'd' } } - }) - - response = epp_plain_request(xml) - response[:results][0][:result_code].should == '2306' - response[:results][0][:msg].should == 'Period must add up to 1, 2 or 3 years [period]' - response[:results][0][:value].should == '367' - @registrar1.balance.should == old_balance - @registrar1.cash_account.account_activities.count.should == old_activities - end - - it 'does not create a domain with invalid period unit' do - xml = domain_create_xml({ - period: { value: '1', attrs: { unit: '' } } - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == - "Element '{https://epp.tld.ee/schema/domain-eis-1.0.xsd}period', attribute 'unit': "\ - "[facet 'enumeration'] The value '' is not an element of the set {'y', 'm', 'd'}." - response[:results][0][:result_code].should == '2001' - - xml = domain_create_xml({ - period: { value: '1', attrs: { unit: 'bla' } } - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == - "Element '{https://epp.tld.ee/schema/domain-eis-1.0.xsd}period', attribute 'unit': "\ - "[facet 'enumeration'] The value 'bla' is not an element of the set {'y', 'm', 'd'}." - response[:results][0][:result_code].should == '2001' - end - - it 'creates a domain with multiple dnskeys' do - xml = domain_create_xml({}, { - _anonymus: [ - { keyData: { - flags: { value: '257' }, - protocol: { value: '3' }, - alg: { value: '3' }, - pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } - } - }, - { - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '254' }, - pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } - } - } - ] - }) - - epp_plain_request(xml) - d = Domain.last - - d.dnskeys.count.should == 3 - - ksk = d.dnskeys.find_by(flags: 257) - ksk.ds_key_tag.should_not be_blank - ksk.ds_alg.should == 3 - ksk.ds_digest_type.should == Setting.ds_algorithm - - zsk = d.dnskeys.find_by(flags: 256) - zsk.ds_key_tag.should be_blank - - zero = d.dnskeys.find_by(flags: 0) - zero.ds_key_tag.should be_blank - - d.dnskeys.pluck(:flags).should match_array([257, 0, 256]) - d.dnskeys.pluck(:protocol).should match_array([3, 3, 3]) - d.dnskeys.pluck(:alg).should match_array([3, 5, 254]) - d.dnskeys.pluck(:public_key).should match_array(%w( - AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8 - 700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f - 841936717ae427ace63c28d04918569a841936717ae427ace63c28d0 - )) - end - - it 'does not create a domain when dnskeys are invalid' do - xml = domain_create_xml({}, { - _anonymus: [ - { keyData: { - flags: { value: '250' }, - protocol: { value: '4' }, - alg: { value: '9' }, - pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } - } - }, - { - keyData: { - flags: { value: '1' }, - protocol: { value: '3' }, - alg: { value: '10' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '5' }, - alg: { value: '254' }, - pubKey: { value: '' } - } - } - ] - }) - - response = epp_plain_request(xml) - - response[:results][0][:msg].should == - "Element '{urn:ietf:params:xml:ns:secDNS-1.1}pubKey': [facet 'minLength'] The value has a "\ - "length of '0'; this underruns the allowed minimum length of '1'." - response[:results][1][:msg].should == - "Element '{urn:ietf:params:xml:ns:secDNS-1.1}pubKey': '' is not a valid value of the atomic "\ - "type '{urn:ietf:params:xml:ns:secDNS-1.1}keyType'." - - xml = domain_create_xml({}, { - _anonymus: [ - { keyData: { - flags: { value: '250' }, - protocol: { value: '4' }, - alg: { value: '9' }, - pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } - } - }, - { - keyData: { - flags: { value: '1' }, - protocol: { value: '3' }, - alg: { value: '10' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '5' }, - alg: { value: '254' }, - pubKey: { value: 'AwEAAbuFiHS4jZL7ZQKvEPBmsbceNHTVYpEVMdxz2A6YCjlZTEoAH3qK' } - } - } - ] - }) - - response = epp_plain_request(xml) - - response[:results][0][:msg].should == - 'Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255 [alg]' - response[:results][0][:value].should == '9' - - response[:results][1][:msg].should == 'Valid protocols are: 3 [protocol]' - response[:results][1][:value].should == '4' - - response[:results][2][:msg].should == 'Valid flags are: 0, 256, 257 [flags]' - response[:results][2][:value].should == '250' - - response[:results][3][:msg].should == 'Valid algorithms are: 3, 5, 6, 7, 8, 252, 253, 254, 255 [alg]' - response[:results][3][:value].should == '10' - - response[:results][4][:msg].should == 'Valid flags are: 0, 256, 257 [flags]' - response[:results][4][:value].should == '1' - - response[:results][5][:msg].should == 'Valid protocols are: 3 [protocol]' - response[:results][5][:value].should == '5' - end - - it 'does not create a domain with two identical dnskeys' do - xml = domain_create_xml({}, { - _anonymus: [ - { keyData: { - flags: { value: '257' }, - protocol: { value: '3' }, - alg: { value: '3' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }] - }) - - response = epp_plain_request(xml) - - response[:result_code].should == '2302' - response[:msg].should == 'Public key already exists [public_key]' - response[:results][0][:value].should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - end - - it 'validated dnskeys count' do - Setting.dnskeys_max_count = 1 - - xml = domain_create_xml({}, { - _anonymus: [ - { keyData: { - flags: { value: '257' }, - protocol: { value: '3' }, - alg: { value: '3' }, - pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } - } - }, - { - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }] - }) - - response = epp_plain_request(xml) - - response[:result_code].should == '2004' - response[:msg].should == 'DNS keys count must be between 0-1 [dnskeys]' - - create_settings - end - - it 'creates domain with ds data' do - xml = domain_create_xml({}, { - _anonymus: [ - { dsData: { - keyTag: { value: '12345' }, - alg: { value: '3' }, - digestType: { value: '1' }, - digest: { value: '49FD46E6C4B45C55D4AC' } - } - }] - }) - - epp_plain_request(xml) - - d = Domain.last - ds = d.dnskeys.first - ds.ds_key_tag.should == '12345' - ds.ds_alg.should == 3 - ds.ds_digest_type.should == 1 - ds.ds_digest.should == '49FD46E6C4B45C55D4AC' - ds.flags.should be_nil - ds.protocol.should be_nil - ds.alg.should be_nil - ds.public_key.should be_nil - end - - it 'creates domain with ds data with key' do - xml = domain_create_xml({}, { - _anonymus: [ - { dsData: { - keyTag: { value: '12345' }, - alg: { value: '3' }, - digestType: { value: '1' }, - digest: { value: '49FD46E6C4B45C55D4AC' }, - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - } - }] - }) - - epp_plain_request(xml) - - d = Domain.last - ds = d.dnskeys.first - ds.ds_key_tag.should == '12345' - ds.ds_alg.should == 3 - ds.ds_digest_type.should == 1 - ds.ds_digest.should == '49FD46E6C4B45C55D4AC' - ds.flags.should == 0 - ds.protocol.should == 3 - ds.alg.should == 5 - ds.public_key.should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - end - - # it 'prohibits dsData with key' do - # Setting.ds_data_with_key_allowed = false - - # xml = domain_create_xml({}, { - # _anonymus: [ - # { dsData: { - # keyTag: { value: '12345' }, - # alg: { value: '3' }, - # digestType: { value: '1' }, - # digest: { value: '49FD46E6C4B45C55D4AC' }, - # keyData: { - # flags: { value: '0' }, - # protocol: { value: '3' }, - # alg: { value: '5' }, - # pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - # } - # } - # }] - # }) - - # response = epp_plain_request(xml) - # response[:result_code].should == '2306' - # response[:msg].should == 'dsData object with key data is not allowed' - - # create_settings - # end - - it 'prohibits dsData' do - Setting.ds_data_allowed = false - - xml = domain_create_xml({}, { - _anonymus: [ - { dsData: { - keyTag: { value: '12345' }, - alg: { value: '3' }, - digestType: { value: '1' }, - digest: { value: '49FD46E6C4B45C55D4AC' }, - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - } - }] - }) - - response = epp_plain_request(xml) - response[:result_code].should == '2306' - response[:msg].should == 'dsData object is not allowed' - - create_settings - end - - it 'prohibits keyData' do - Setting.key_data_allowed = false - - xml = domain_create_xml({}, { - _anonymus: [ - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - }] - }) - - response = epp_plain_request(xml) - response[:result_code].should == '2306' - response[:msg].should == 'keyData object is not allowed' - - create_settings - end - - it 'prohibits dsData and keyData when they exists together' do - xml = domain_create_xml({}, { - _anonymus: [ - { - dsData: { - keyTag: { value: '12345' }, - alg: { value: '3' }, - digestType: { value: '1' }, - digest: { value: '49FD46E6C4B45C55D4AC' } - } - }, - { - keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }] - }) - - response = epp_plain_request(xml) - response[:msg].should == "Element '{urn:ietf:params:xml:ns:secDNS-1.1}keyData': This element "\ - "is not expected. Expected is ( {urn:ietf:params:xml:ns:secDNS-1.1}dsData )." - response[:result_code].should == '2001' - end - end - - context 'with juridical persion as a registrant' do - it 'creates a domain with contacts' do - xml = domain_create_xml({ - registrant: { value: 'FIXED:JURIDICAL_1234' }, - _anonymus: [ - { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } } - ] - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:clTRID].should == 'ABC-12345' - - Domain.last.tech_contacts.count.should == 1 - Domain.last.admin_contacts.count.should == 1 - - tech_contact = Domain.last.tech_contacts.first - tech_contact.code.should == 'FIXED:JURIDICAL_1234' - end - - it 'does not create a domain without admin contact' do - domain_count = Domain.count - domain_contact_count = DomainContact.count - xml = domain_create_xml({ - registrant: { value: 'FIXED:JURIDICAL_1234' }, - _anonymus: [ - { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } } - ] - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Admin contacts count must be between 1-10 [admin_domain_contacts]' - response[:result_code].should == '2004' - response[:clTRID].should == 'ABC-12345' - - Domain.count.should == domain_count - DomainContact.count.should == domain_contact_count - end - - it 'cannot assign juridical person as admin contact' do - xml = domain_create_xml({ - registrant: { value: 'FIXED:JURIDICAL_1234' }, - _anonymus: [ - { contact: { value: 'FIXED:JURIDICAL_1234', attrs: { type: 'admin' } } } - ] - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Admin contact can be private person only' - response[:result_code].should == '2306' - end - end - - context 'with valid domain' do - let(:domain) { Fabricate(:domain, registrar: @registrar1, dnskeys: []) } - - it 'transfers a domain' do - domain.registrar = @registrar1 - domain.save - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'request', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - old_contact_codes = domain.contacts.pluck(:code).sort.uniq - old_registrant_code = domain.registrant.code - - login_as :registrar2 do - response = epp_plain_request(xml) - domain.reload - dtl = domain.domain_transfers.last - - trn_data = response[:parsed].css('trnData') - trn_data.css('name').text.should == domain.name - trn_data.css('trStatus').text.should == 'serverApproved' - trn_data.css('reID').text.should == 'REGDOMAIN2' - trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acID').text.should == 'REGDOMAIN1' - trn_data.css('acDate').text.should == dtl.transferred_at.in_time_zone.utc.utc.iso8601 - trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - - domain.registrar.should == @registrar2 - end - - response = epp_plain_request(@epp_xml.session.poll) - - response[:msg].should == 'Command completed successfully; ack to dequeue' - msg_q = response[:parsed].css('msgQ') - msg_q.css('qDate').text.should_not be_blank - - msg_q.css('msg').text.should == "Domain transfer was approved, associated contacts were: " \ - "#{old_contact_codes} and registrant was #{old_registrant_code}" - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '1' - - xml = @epp_xml.session.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - msg_q = response[:parsed].css('msgQ') - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '0' - end - - ### TRANSFER ### - # Do not place this test to epp-examples (epp: false) - it 'transfers a domain with wait time > 0', epp: false do - domain.registrar = @registrar1 - domain.save - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'request', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - old_contact_codes = domain.contacts.pluck(:code).sort.uniq - old_registrant_code = domain.registrant.code - - response = login_as :registrar2 do - epp_plain_request(xml) - end - - domain.reload - dtl = domain.domain_transfers.last - - trn_data = response[:parsed].css('trnData') - trn_data.css('name').text.should == domain.name - trn_data.css('trStatus').text.should == 'serverApproved' - trn_data.css('reID').text.should == 'REGDOMAIN2' - trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acID').text.should == 'REGDOMAIN1' - trn_data.css('acDate').text.should == dtl.transferred_at.in_time_zone.utc.utc.iso8601 - trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - - domain.registrar.should == @registrar2 - - response = epp_plain_request(@epp_xml.session.poll) - - response[:msg].should == 'Command completed successfully; ack to dequeue' - msg_q = response[:parsed].css('msgQ') - msg_q.css('qDate').text.should_not be_blank - - msg_q.css('msg').text.should == "Domain transfer was approved, associated contacts were: " \ - "#{old_contact_codes} and registrant was #{old_registrant_code}" - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '1' - - Setting.transfer_wait_time = 1 - - domain.reload - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'request', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) # request with new password - - response = epp_plain_request(xml) - trn_data = response[:parsed].css('trnData') - - domain.reload - dtl = domain.domain_transfers.last - - domain.domain_transfers.count.should == 2 - - trn_data.css('name').text.should == domain.name - trn_data.css('trStatus').text.should == 'pending' - trn_data.css('reID').text.should == 'REGDOMAIN1' - trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acDate').text.should == dtl.wait_until.in_time_zone.utc.utc.iso8601 - trn_data.css('acID').text.should == 'REGDOMAIN2' - trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - - domain.registrar.should == @registrar2 - - # should return same data if pending already - response = epp_plain_request(xml) - trn_data = response[:parsed].css('trnData') - - domain.domain_transfers.count.should == 2 - trn_data.css('name').text.should == domain.name - trn_data.css('trStatus').text.should == 'pending' - trn_data.css('reID').text.should == 'REGDOMAIN1' - trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acDate').text.should == dtl.wait_until.in_time_zone.utc.utc.iso8601 - trn_data.css('acID').text.should == 'REGDOMAIN2' - trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - - domain.registrar.should == @registrar2 - - # should show up in other registrar's poll - - login_as :registrar2 do - response = epp_plain_request(@epp_xml.session.poll) - response[:msg].should == 'Command completed successfully; ack to dequeue' - msg_q = response[:parsed].css('msgQ') - msg_q.css('qDate').text.should_not be_blank - msg_q.css('msg').text.should == 'Transfer requested.' - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '1' - - xml = @epp_xml.session.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) - - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - msg_q = response[:parsed].css('msgQ') - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '0' - end - - create_settings - end - - it 'creates a domain transfer with legal document' do - domain.legal_documents.count.should == 0 - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'request', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:result_code].should == '1000' - domain.legal_documents.count.should == 1 - - log = ApiLog::EppLog.last - - log.request_command.should == 'transfer' - log.request_object.should == 'domain' - log.request_successful.should == true - log.api_user_name.should == 'registrar2' - log.api_user_registrar.should == 'registrar2' - log.request.should_not be_blank - log.response.should_not be_blank - end - - login_as :registrar2 do - epp_plain_request(xml) - end - end - - it 'creates transfer successfully without legal document' do - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - end - - it 'transfers domain with contacts' do - original_oc_id = domain.registrant.id - original_oc_code = domain.registrant.code - - original_contact_codes = domain.contacts.pluck(:code) - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - - # all domain contacts should be under registrar2 now - domain.reload - domain.registrant.reload - domain.registrant.registrar_id.should == @registrar2.id - domain.registrant.id.should_not == original_oc_id - - # must generate new code - domain.registrant.code.should_not == original_oc_code - - domain.contacts.each do |c| - c.registrar_id.should == @registrar2.id - original_contact_codes.include?(c.code).should_not == true - end - end - - it 'transfers domain when registrant has more domains' do - Fabricate(:domain, registrant: domain.registrant) - original_oc_id = domain.registrant.id - original_oc_code = domain.registrant.code - - original_contact_codes = domain.contacts.pluck(:code) - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - - # all domain contacts should be under registrar2 now - domain.reload - domain.registrant.registrar_id.should == @registrar2.id - # registrant should be a new record - domain.registrant.id.should_not == original_oc_id - # must generate new code - domain.registrant.code.should_not == original_oc_code - - domain.contacts.each do |c| - c.registrar_id.should == @registrar2.id - original_contact_codes.include?(c.code).should_not == true - end - end - - it 'transfers domain when registrant is admin or tech contact on some other domain' do - d = Fabricate(:domain) - d.tech_contacts << domain.registrant - - original_oc_id = domain.registrant.id - original_oc_code = domain.registrant.code - - original_contact_codes = domain.contacts.pluck(:code) - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - - # all domain contacts should be under registrar2 now - domain.reload - domain.registrant.registrar_id.should == @registrar2.id - # registrant should be a new record - domain.registrant.id.should_not == original_oc_id - # must generate new code - domain.registrant.code.should_not == original_oc_code - - domain.contacts.each do |c| - c.registrar_id.should == @registrar2.id - original_contact_codes.include?(c.code).should_not == true - end - end - - it 'transfers domain when domain contacts are some other domain contacts' do - old_contact = Fabricate(:contact, registrar: @registrar1, name: 'old name') - domain.tech_contacts << old_contact - domain.admin_contacts << old_contact - - d = Fabricate(:domain) - d.tech_contacts << old_contact - d.admin_contacts << old_contact - - original_oc_id = domain.registrant.id - original_contact_count = Contact.count - original_domain_contact_count = DomainContact.count - - login_as :registrar2 do - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - - # all domain contacts should be under registrar2 now - domain.reload - domain.registrant.registrar_id.should == @registrar2.id - domain.registrant.id.should_not == original_oc_id - - # old contact must not change - old_contact.registrar_id.should == @registrar1.id - - domain.contacts.each do |x| - x.registrar_id.should == @registrar2.id - end - - new_contact = Contact.last(4).detect { |c| c.name == 'old name' } # database order - new_contact.name.should == 'old name' - - # there should be 2 references to the new contact - domain.domain_contacts.where(contact_id: new_contact.id).count.should == 2 - - # there should be four new contact object - (original_contact_count + 4).should == Contact.count - - # and no new references - original_domain_contact_count.should == DomainContact.count - end - - it 'transfers domain when multiple domain contacts are some other domain contacts' do - old_contact = Fabricate(:contact, registrar: @registrar1, name: 'first') - old_contact_2 = Fabricate(:contact, registrar: @registrar1, name: 'second') - - domain.tech_contacts << old_contact - domain.admin_contacts << old_contact - domain.tech_contacts << old_contact_2 - - d = Fabricate(:domain) - d.tech_contacts << old_contact - d.admin_contacts << old_contact_2 - - original_oc_id = domain.registrant.id - original_contact_count = Contact.count - original_domain_contact_count = DomainContact.count - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - - # all domain contacts should be under registrar2 now - domain.reload - domain.registrant.registrar_id.should == @registrar2.id - # registrant should not be a new record - domain.registrant.id.should_not == original_oc_id - - # old contact must not change - old_contact.registrar_id.should == @registrar1.id - - domain.contacts.each do |x| - x.registrar_id.should == @registrar2.id - end - - new_contact = Contact.last(5).detect { |c| c.name == 'first' } - new_contact_2 = Contact.last(5).detect { |c| c.name == 'second' } - - new_contact.name.should == 'first' - new_contact_2.name.should == 'second' - - # there should be 2 references to the new contact (admin + tech) - domain.domain_contacts.where(contact_id: new_contact.id).count.should == 2 - - # there should be 1 reference to the new contact 2 (tech) - domain.domain_contacts.where(contact_id: new_contact_2.id).count.should == 1 - - # there should be four new contact objects - (original_contact_count + 5).should == Contact.count - - # and no new references - original_domain_contact_count.should == DomainContact.count - end - - it 'transfers domain and references exsisting registrant to domain contacts' do - d = Fabricate(:domain) - d.tech_contacts << domain.registrant - - domain.tech_contacts << domain.registrant - original_registrant_id = domain.registrant_id - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - - domain.reload - # registrant must be an new record - domain.registrant_id.should_not == original_registrant_id - - # new registrant must be a tech contact - domain.domain_contacts.where(contact_id: domain.registrant_id).count.should == 1 - end - - it 'does not transfer contacts if they are already under new registrar' do - domain.contacts.each do |c| - c.registrar_id = @registrar2.id - c.save - end - - domain.registrant.registrar_id = @registrar2.id - domain.registrant.save - - original_oc_id = domain.registrant_id - original_oc_code = domain.registrant.code - original_contacts_codes = domain.contacts.pluck(:code) - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - - domain.reload - - domain.registrant.id.should == original_oc_id - domain.registrant.code.should == original_oc_code - domain.registrant.registrar_id.should == @registrar2.id - - original_contacts_codes.sort.should == domain.contacts.pluck(:code).sort - end - - it 'transfers domain contact should populate copy_from_id' do - d = Fabricate(:domain) - d.tech_contacts << domain.registrant - - original_oc_id = domain.registrant.id - original_oc_code = domain.registrant.code - domain.registrant.copy_from_id.should == nil - - original_contact_codes = domain.contacts.pluck(:code) - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - end - - # all domain contacts should be under registrar2 now - domain.reload - domain.registrant.registrar_id.should == @registrar2.id - # registrant should be a new record - domain.registrant.id.should_not == original_oc_id - domain.registrant.copy_from_id.should == original_oc_id - # must generate new code - domain.registrant.code.should_not == original_oc_code - - domain.contacts.each do |c| - c.registrar_id.should == @registrar2.id - original_contact_codes.include?(c.code).should_not == true - end - end - - it 'should not creates transfer without password' do - xml = domain_transfer_xml({ - name: { value: domain.name } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Authorization error' - response[:result_code].should == '2201' - end - end - - it 'approves the transfer request' do - domain.domain_transfers.create({ - status: DomainTransfer::PENDING, - transfer_requested_at: Time.zone.now, - transfer_to: @registrar2, - transfer_from: @registrar1 - }) - - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: domain.auth_info } } - }, 'approve', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_plain_request(xml) - - domain.reload - dtl = domain.domain_transfers.last - - trn_data = response[:parsed].css('trnData') - - trn_data.css('name').text.should == domain.name - trn_data.css('trStatus').text.should == 'clientApproved' - trn_data.css('reID').text.should == 'REGDOMAIN2' - trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acID').text.should == 'REGDOMAIN1' - trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - end - - it 'rejects a domain transfer' do - domain.domain_transfers.create({ - status: DomainTransfer::PENDING, - transfer_requested_at: Time.zone.now, - transfer_to: @registrar2, - transfer_from: @registrar1 - }) - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'reject', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = login_as :registrar2 do - epp_plain_request(xml) - end - - response[:msg].should == 'Transfer can be rejected only by current registrar' - response[:result_code].should == '2304' - domain.legal_documents.count.should == 0 - - response = epp_plain_request(xml) - response[:result_code].should == '1000' - domain.pending_transfer.should be_nil - domain.legal_documents.count.should == 1 - end - - it 'prohibits wrong registrar from approving transfer' do - domain.domain_transfers.create({ - status: DomainTransfer::PENDING, - transfer_requested_at: Time.zone.now, - transfer_to: @registrar2, - transfer_from: @registrar1 - }) - - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: domain.auth_info } } - }, 'approve', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = login_as :registrar2 do - epp_plain_request(xml) - end - - response[:result_code].should == '2304' - response[:msg].should == 'Transfer can be approved only by current domain registrar' - end - - it 'does not transfer with invalid pw' do - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: 'test' } } - }, 'request', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_plain_request(xml) - response[:result_code].should == '2201' - response[:msg].should == 'Authorization error' - end - - it 'ignores transfer when domain already belongs to registrar' do - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'request', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_plain_request(xml) - - response[:result_code].should == '2002' - response[:msg].should == 'Domain already belongs to the querying registrar' - end - - it 'returns an error for incorrect op attribute' do - response = epp_plain_request(domain_transfer_xml({}, 'bla')) - response[:msg].should == - "Element '{urn:ietf:params:xml:ns:epp-1.0}transfer', attribute 'op': [facet 'enumeration'] "\ - "The value 'bla' is not an element of the set {'approve', 'cancel', 'query', 'reject', 'request'}." - response[:result_code].should == '2001' - end - - it 'creates new pw after successful transfer' do - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'request', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - login_as :registrar2 do - epp_plain_request(xml) # transfer domain - response = epp_plain_request(xml) # attempt second transfer - response[:msg].should == 'Authorization error' - response[:result_code].should == '2201' - end - end - - it 'should get an error when there is no pending transfer' do - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'approve', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_plain_request(xml) - response[:msg].should == 'No transfers found' - response[:result_code].should == '2303' - end - - it 'should not return transfers when there are none' do - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: domain.auth_info } } - }, 'query') - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'No transfers found' - response[:results][0][:result_code].should == '2303' - end - - it 'should not cancel transfer when there are none' do - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: domain.auth_info } } - }, 'cancel') - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'No transfers found' - response[:results][0][:result_code].should == '2303' - end - - it 'should allow querying domain transfer', epp: false do - Setting.transfer_wait_time = 1 - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'request', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - trn_data = response[:parsed].css('trnData') - - dtl = domain.domain_transfers.last - - trn_data.css('name').text.should == domain.name - trn_data.css('trStatus').text.should == 'pending' - trn_data.css('reID').text.should == 'REGDOMAIN2' - trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acDate').text.should == dtl.wait_until.in_time_zone.utc.utc.iso8601 - trn_data.css('acID').text.should == 'REGDOMAIN1' - trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'query') - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - trn_data = response[:parsed].css('trnData') - - dtl = domain.domain_transfers.last - trn_data.css('name').text.should == domain.name - trn_data.css('trStatus').text.should == 'pending' - trn_data.css('reID').text.should == 'REGDOMAIN2' - trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acDate').text.should == dtl.wait_until.in_time_zone.utc.utc.iso8601 - trn_data.css('acID').text.should == 'REGDOMAIN1' - trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - end - - # approves pending transfer - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'approve', { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - # query should return last completed transfer - domain.reload - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }, 'query') - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - trn_data = response[:parsed].css('trnData') - - dtl = domain.domain_transfers.last - - trn_data.css('name').text.should == domain.name - trn_data.css('trStatus').text.should == 'clientApproved' - trn_data.css('reID').text.should == 'REGDOMAIN2' - trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acDate').text.should == dtl.transferred_at.in_time_zone.utc.utc.iso8601 - trn_data.css('acID').text.should == 'REGDOMAIN1' - trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - - Setting.transfer_wait_time = 0 - end - - it 'should not transfer when period element is present' do - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - period: { value: '1', attrs: { unit: 'y' } }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Unimplemented object service' - response[:result_code].should == '2307' - response[:parsed].css('value > period').any?.should == true - end - end - - it 'should not transfer when in prohibited status' do - domain.statuses = [DomainStatus::SERVER_TRANSFER_PROHIBITED] - domain.save - - pw = domain.auth_info - xml = domain_transfer_xml({ - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - }) - - login_as :registrar2 do - response = epp_plain_request(xml) - response[:msg].should == 'Object status prohibits operation' - response[:result_code].should == '2304' - end - end - - ### UPDATE ### - it 'should update right away without update pending status' do - existing_pw = domain.auth_info - - xml_params = { - name: { value: domain.name }, - chg: [ - registrant: { value: 'FIXED:CITIZEN_1234', attrs: { verified: 'yes' } } - ] - } - - response = epp_plain_request(domain_update_xml(xml_params, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - })) - - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - d = Domain.last - - d.registrant_code.should == 'FIXED:CITIZEN_1234' - d.auth_info.should == existing_pw - d.pending_update?.should == false - end - - it 'updates a domain' do - existing_pw = domain.auth_info - - xml_params = { - name: { value: domain.name }, - chg: [ - registrant: { value: 'FIXED:CITIZEN_1234' } - ] - } - - response = epp_plain_request(domain_update_xml(xml_params, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - })) - - response[:results][0][:msg].should == 'Command completed successfully; action pending' - response[:results][0][:result_code].should == '1001' - - d = Domain.last - - d.registrant_code.should_not == 'FIXED:CITIZEN_1234' # should not update - d.auth_info.should == existing_pw - d.pending_update?.should == true - end - - it 'updates a domain and changes auth info' do - response = epp_plain_request(domain_update_xml({ - name: { value: domain.name }, - chg: [ - authInfo: { pw: { value: 'newpw' } } - ] - })) - - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - d = Domain.last - - d.auth_info.should == 'newpw' - end - - it 'should not return action pending when changes are invalid' do - existing_pw = domain.auth_info - - hostnames = domain.nameservers.pluck(:hostname) - - xml_params = { - name: { value: domain.name }, - rem: [ - { - ns: - hostnames.map do |x| - { - hostAttr: [ - { hostName: { value: x } } - ] - } - end - } - ], - chg: [ - registrant: { value: 'FIXED:CITIZEN_1234' } - ] - } - - response = epp_plain_request(domain_update_xml(xml_params, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }), :xml) - - response[:results][0][:msg].should == 'Nameservers count must be between 2-11 [nameservers]' - response[:results][0][:result_code].should == '2004' - - d = Domain.last - - d.registrant_code.should_not == 'FIXED:CITIZEN_1234' # should not update - d.auth_info.should == existing_pw - d.nameservers.size == 3 - d.pending_update?.should == false - end - - it 'should not return action pending when domain itself is already invaid' do - domain_id = domain.id - domain.nameservers.delete_all - domain.save(validate: false) - domain.reload.nameservers.size.should == 0 - - existing_pw = domain.auth_info - - xml_params = { - name: { value: domain.name }, - chg: [ - registrant: { value: 'FIXED:CITIZEN_1234' } - ] - } - - response = epp_plain_request(domain_update_xml(xml_params, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }), :xml) - - response[:results][0][:msg].should == 'Nameservers count must be between 2-11 [nameservers]' - response[:results][0][:result_code].should == '2004' - - d = Domain.find(domain_id) - - d.registrant_code.should_not == 'FIXED:CITIZEN_1234' # should not update - d.auth_info.should == existing_pw - d.nameservers.size.should == 0 - d.pending_update?.should == false - end - - it 'should not allow any update when status pending update' do - domain.statuses << DomainStatus::PENDING_UPDATE - domain.save - - existing_pw = domain.auth_info - - xml_params = { - name: { value: domain.name }, - chg: [ - registrant: { value: 'FIXED:CITIZEN_1234' } - ] - } - - response = epp_plain_request(domain_update_xml(xml_params, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - })) - - response[:results][0][:msg].should == 'Object status prohibits operation' - response[:results][0][:result_code].should == '2304' - - d = Domain.last - - d.registrant_code.should_not == 'FIXED:CITIZEN_1234' - d.auth_info.should == existing_pw - d.pending_update?.should == true - end - - it 'should not allow any update when status force delete' do - domain.set_force_delete - - xml_params = { - name: { value: domain.name }, - chg: [ - registrant: { value: 'FIXED:CITIZEN_1234' } - ] - } - - response = epp_plain_request(domain_update_xml(xml_params, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - })) - - response[:results][0][:msg].should == 'Object status prohibits operation' - response[:results][0][:result_code].should == '2304' - end - - it 'updates domain and adds objects' do - xml = domain_update_xml({ - name: { value: domain.name }, - add: [ - { - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.com' } } - ] - }, - { - hostAttr: [ - { hostName: { value: 'ns2.example.com' } } - ] - } - ] - }, - _anonymus: [ - { contact: { value: 'FIXED:MAK21', attrs: { type: 'tech' } } }, - { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, - { status: { value: '', attrs: { s: 'clientRenewProhibited' } } } - ] - ] - }, { - add: [ - { keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '254' }, - pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } - } - } - ] - }) - - response = epp_plain_request(xml) - response[:results][0][:result_code].should == '2303' - response[:results][0][:msg].should == 'Contact was not found' - - Fabricate(:contact, code: 'FIXED:MAK21') - - response = epp_plain_request(xml) - - response[:results][0][:result_code].should == '1000' - - d = Domain.last - - new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count - new_ns_count.should == 2 - - new_contact = d.tech_contacts.find_by(code: 'FIXED:MAK21') - new_contact.should be_truthy - - d.statuses.count.should == 2 - d.statuses.include?('clientHold').should == true - d.statuses.include?('clientRenewProhibited').should == true - - d.dnskeys.count.should == 2 - - response = epp_plain_request(xml) - - response[:results][0][:result_code].should == '2302' - response[:results][0][:msg].should == 'Nameserver already exists on this domain [hostname]' - if response[:results][0][:value] == 'ns1.example.com' - response[:results][0][:value].should == 'ns1.example.com' - else - response[:results][0][:value].should == 'ns2.example.com' - end - - response[:results][1][:result_code].should == '2302' - response[:results][1][:msg].should == 'Nameserver already exists on this domain [hostname]' - if response[:results][1][:value] == 'ns1.example.com' - response[:results][1][:value].should == 'ns1.example.com' - else - response[:results][1][:value].should == 'ns2.example.com' - end - - response[:results][2][:result_code].should == '2302' - response[:results][2][:msg].should == 'Contact already exists on this domain [contact_code_cache]' - response[:results][2][:value].should == 'FIXED:MAK21' - - # response[:results][3][:msg].should == 'Status already exists on this domain [value]' - # if response[:results][3][:value] == 'clientHold' - # response[:results][3][:value].should == 'clientHold' - # else - # response[:results][3][:value].should == 'clientUpdateProhibited' - # end - - # response[:results][4][:msg].should == 'Status already exists on this domain [value]' - # if response[:results][4][:value] == 'clientHold' - # response[:results][4][:value].should == 'clientHold' - # else - # response[:results][4][:value].should == 'clientUpdateProhibited' - # end - - response[:results][3][:msg].should == 'Public key already exists [public_key]' - if response[:results][3][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - response[:results][3][:value].should == - '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - else - response[:results][3][:value].should == - '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' - end - - response[:results][4][:msg].should == 'Public key already exists [public_key]' - if response[:results][4][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - response[:results][4][:value].should == - '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - else - response[:results][4][:value].should == - '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' - end - - d.statuses.count.should == 2 - end - - it 'updates domain with registrant change what triggers action pending' do - xml = domain_update_xml({ - name: { value: domain.name }, - add: [ - { - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.com' } } - ] - }, - { - hostAttr: [ - { hostName: { value: 'ns2.example.com' } } - ] - } - ] - }, - _anonymus: [ - { contact: { value: 'FIXED:PENDINGMAK21', attrs: { type: 'tech' } } }, - { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, - { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } - ] - ], - chg: [ - registrant: { value: 'FIXED:CITIZEN_1234' } - ] - }, { - add: [ - { keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '254' }, - pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } - } - } - ] - }, - { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Contact was not found' - response[:results][0][:result_code].should == '2303' - - Fabricate(:contact, code: 'FIXED:PENDINGMAK21') - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully; action pending' - response[:results][0][:result_code].should == '1001' - - d = Domain.last - - new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count - new_ns_count.should == 0 # aka old value - - new_contact = d.tech_contacts.find_by(code: 'FIXED:PENDINGMAK21') - new_contact.should_not be_truthy # aka should not add new contact - - d.statuses.count.should == 1 - d.statuses.first.should == 'pendingUpdate' - - d.dnskeys.count.should == 0 - end - - it 'does not allow to edit statuses if policy forbids it' do - Setting.client_status_editing_enabled = false - - xml = domain_update_xml({ - name: { value: domain.name }, - add: [{ - _anonymus: [ - { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, - { status: { value: '', attrs: { s: 'clientUpdateProhibited' } } } - ] - }] - }) - - response = epp_plain_request(xml) - response[:results][0][:result_code].should == '2306' - response[:results][0][:msg].should == "Parameter value policy error. Client-side object status "\ - "management not supported: status [status]" - - Setting.client_status_editing_enabled = true - end - - it 'updates a domain and removes objects' do - xml = domain_update_xml({ - name: { value: domain.name }, - add: [ - { - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.com' } } - ] - }, - { - hostAttr: [ - { hostName: { value: 'ns2.example.com' } } - ] - } - ] - }, - _anonymus: [ - { contact: { value: 'FIXED:CITIZEN_1234', attrs: { type: 'tech' } } }, - { status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } }, - { status: { value: '', attrs: { s: 'clientRenewProhibited' } } } - ] - ] - }, { - add: [ - { keyData: { - flags: { value: '0' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - }, - { - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '254' }, - pubKey: { value: '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' } - } - } - ] - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - d = Domain.last - d.dnskeys.count.should == 2 - - xml = domain_update_xml({ - name: { value: domain.name }, - rem: [ - { - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.com' } } - ] - } - ] - }, - _anonymus: [ - { contact: { value: 'FIXED:CITIZEN_1234', attrs: { type: 'tech' } } }, - { status: { value: '', attrs: { s: 'clientHold' } } } - ] - ] - }, { - rem: [ - { keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '254' }, - pubKey: { value: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' } - } - } - ] - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - d.reload - d.dnskeys.count.should == 1 - - d.statuses.count.should == 1 - d.statuses.first.should == 'clientRenewProhibited' - - rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com') - rem_ns.should be_falsey - - rem_cnt = d.tech_contacts.find_by(code: 'FIXED:CITIZEN_1234') - rem_cnt.should be_falsey - - response = epp_plain_request(xml) - - response[:results][0][:result_code].should == '2303' - response[:results][0][:msg].should == 'Nameserver was not found' - response[:results][0][:value].should == 'ns1.example.com' - - response[:results][1][:result_code].should == '2303' - response[:results][1][:msg].should == 'Contact was not found' - response[:results][1][:value].should == 'FIXED:CITIZEN_1234' - - response[:results][2][:result_code].should == '2303' - response[:results][2][:msg].should == 'DS was not found' - response[:results][2][:value].should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - - response[:results][3][:result_code].should == '2303' - response[:results][3][:msg].should == 'Status was not found' - response[:results][3][:value].should == 'clientHold' - end - - it 'does not remove server statuses' do - domain.statuses << DomainStatus::SERVER_HOLD - domain.save - - xml = domain_update_xml({ - name: { value: domain.name }, - rem: [ - _anonymus: [ - { status: { value: '', attrs: { s: 'serverHold' } } } - ] - ] - }) - - response = epp_plain_request(xml) - - response[:results][0][:result_code].should == '2303' - response[:results][0][:msg].should == 'Status was not found' - response[:results][0][:value].should == 'serverHold' - end - - it 'does not add duplicate objects to domain' do - d = Domain.last - c = d.admin_contacts.first - n = d.nameservers.first - - xml = domain_update_xml({ - name: { value: domain.name }, - add: { - ns: [ - { - hostAttr: [ - { hostName: { value: n.hostname } } - ] - } - ], - _anonymus: [ - { contact: { value: c.code, attrs: { type: 'admin' } } } - ] - } - }) - - epp_plain_request(xml) - response = epp_plain_request(xml) - - response[:results][0][:result_code].should == '2302' - response[:results][0][:msg].should == 'Nameserver already exists on this domain [hostname]' - response[:results][0][:value].should == n.hostname - - response[:results][1][:result_code].should == '2302' - response[:results][1][:msg].should == 'Contact already exists on this domain [contact_code_cache]' - response[:results][1][:value].should == c.code - end - - it 'cannot change registrant without legal document' do - xml_params = { - name: { value: domain.name }, - chg: [ - registrant: { value: 'FIXED:CITIZEN_1234' } - ] - } - - response = epp_plain_request(domain_update_xml(xml_params)) - response[:results][0][:msg].should == - 'Required parameter missing: extension > extdata > legalDocument [legal_document]' - response[:results][0][:result_code].should == '2003' - end - - it 'does not assign invalid status to domain' do - xml = domain_update_xml({ - name: { value: domain.name }, - add: [ - status: { value: '', attrs: { s: 'invalidStatus' } } - ] - }) - - response = epp_plain_request(xml) - response[:results][0][:msg].should start_with( - "Element '{https://epp.tld.ee/schema/domain-eis-1.0.xsd}status', attribute 's': "\ - "[facet 'enumeration'] The value 'invalidStatus' is not an element of the set ") - response[:results][0][:result_code].should == '2001' - end - - ### RENEW ### - it 'renews a domain' do - Setting.days_to_renew_domain_before_expire = 0 - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - - exp_date = domain.valid_to - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - ex_date = response[:parsed].css('renData exDate').text - name = response[:parsed].css('renData name').text - ex_date.should == "#{(exp_date + 1.year).to_s(:iso8601)}" - name.should == domain.name - - domain.reload - domain.valid_to.should be_within(1).of(exp_date + 1.year) - domain.outzone_at.should be_nil - domain.delete_at.should be_nil - - @registrar1.balance.should == old_balance - 15.0 - @registrar1.cash_account.account_activities.count.should == old_activities + 1 - a = @registrar1.cash_account.account_activities.last - a.description.should == "Renew #{Domain.last.name}" - a.sum.should == -BigDecimal.new('15.0') - a.activity_type = AccountActivity::RENEW - a.log_pricelist_id.should == @pricelist_renew_1_year.id - Setting.days_to_renew_domain_before_expire = 90 - end - - it 'renews a domain when outzone_at or delete_at is nil for some reason' do - Setting.days_to_renew_domain_before_expire = 0 - - domain.outzone_at = nil - domain.delete_at = nil - domain.save - - exp_date = domain.valid_to - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - Setting.days_to_renew_domain_before_expire = 90 - end - - it 'renews a domain with no period specified' do - Setting.days_to_renew_domain_before_expire = 0 - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - - exp_date = domain.valid_to - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_date.to_s }, - period: nil - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - ex_date = response[:parsed].css('renData exDate').text - name = response[:parsed].css('renData name').text - ex_date.should == "#{(exp_date + 1.year).to_s(:iso8601)}" - name.should == domain.name - - domain.reload - domain.valid_to.should be_within(1).of(exp_date + 1.year) - domain.outzone_at.should be_nil - domain.delete_at.should be_nil - - @registrar1.balance.should == old_balance - 15.0 - @registrar1.cash_account.account_activities.count.should == old_activities + 1 - a = @registrar1.cash_account.account_activities.last - a.description.should == "Renew #{Domain.last.name}" - a.sum.should == -BigDecimal.new('15.0') - a.activity_type = AccountActivity::RENEW - a.log_pricelist_id.should == @pricelist_renew_1_year.id - Setting.days_to_renew_domain_before_expire = 90 - end - - it 'does not renew domain with invalid period' do - Setting.days_to_renew_domain_before_expire = 0 - - exp_date = domain.valid_to - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_date.to_s }, - period: { value: '1', attrs: { unit: '' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == "Element '{https://epp.tld.ee/schema/domain-eis-1.0.xsd}period', "\ - "attribute 'unit': [facet 'enumeration'] The value '' is not an element of the set {'y', 'm', 'd'}." - response[:results][0][:result_code].should == '2001' - - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_date.to_s }, - period: { value: '1', attrs: { unit: 'bla' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == "Element '{https://epp.tld.ee/schema/domain-eis-1.0.xsd}period', "\ - "attribute 'unit': [facet 'enumeration'] The value 'bla' is not an element of the set {'y', 'm', 'd'}." - response[:results][0][:result_code].should == '2001' - - Setting.days_to_renew_domain_before_expire = 90 - end - - it 'renews a domain with 2 year period' do - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - - domain.valid_to = Time.zone.now.to_date + 10.days - domain.save - - exp_date = domain.valid_to.to_date - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '730', attrs: { unit: 'd' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - ex_date = response[:parsed].css('renData exDate').text - name = response[:parsed].css('renData name').text - ex_date.should == "#{(exp_date + 2.year)}T00:00:00Z" - name.should == domain.name - - @registrar1.balance.should == old_balance - 35.0 - @registrar1.cash_account.account_activities.count.should == old_activities + 1 - a = @registrar1.cash_account.account_activities.last - a.description.should == "Renew #{Domain.last.name}" - a.sum.should == -BigDecimal.new('35.0') - a.activity_type = AccountActivity::CREATE - end - - it 'renews a domain with 3 year period' do - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - - domain.valid_to = Time.zone.now.to_date + 10.days - domain.save - - exp_date = domain.valid_to.to_date - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '36', attrs: { unit: 'm' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - ex_date = response[:parsed].css('renData exDate').text - name = response[:parsed].css('renData name').text - ex_date.should == "#{(exp_date + 3.year)}T00:00:00Z" - name.should == domain.name - - @registrar1.balance.should == old_balance - 62.0 - @registrar1.cash_account.account_activities.count.should == old_activities + 1 - a = @registrar1.cash_account.account_activities.last - a.description.should == "Renew #{Domain.last.name}" - a.sum.should == -BigDecimal.new('62.0') - a.activity_type = AccountActivity::CREATE - end - - it 'does not renew a domain if credit balance low' do - f = Fabricate(:pricelist, { - valid_to: Time.zone.now + 1.day, - operation_category: 'renew', - duration: '1year', - price: 100000 - }) - - old_balance = @registrar1.balance - old_activities = @registrar1.cash_account.account_activities.count - - domain.valid_to = Time.zone.now.to_date + 10.days - domain.save - - exp_date = domain.valid_to.to_date - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Billing failure - credit balance low' - response[:results][0][:result_code].should == '2104' - - domain.reload - domain.valid_to.should == exp_date # ensure domain was not renewed - - @registrar1.balance.should == old_balance - @registrar1.cash_account.account_activities.count.should == old_activities - f.delete - end - - it 'returns an error when given and current exp dates do not match' do - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: '2200-08-07' }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:result_code].should == '2306' - response[:results][0][:msg].should == 'Given and current expire dates do not match' - end - - it 'returns an error when period is invalid' do - domain.valid_to = Time.zone.now.to_date + 10.days - domain.save - exp_date = domain.valid_to.to_date - - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '4', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Period must add up to 1, 2 or 3 years [period]' - response[:results][0][:result_code].should == '2306' - response[:results][0][:value].should == '4' - end - - it 'does not renew a domain unless less than 90 days till expiration' do - # both days are inclusive - domain.valid_to = Time.zone.now.to_date + 90.days - domain.save - exp_date = domain.valid_to.to_date - - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Object is not eligible for renewal' - response[:results][0][:result_code].should == '2105' - - domain.valid_to = Time.zone.now.to_date + 89.days - domain.save - exp_date = domain.valid_to.to_date - - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - end - - it 'does not renew a domain unless less than 90 days till expiration' do - Setting.days_to_renew_domain_before_expire = 0 - - domain.valid_to = Time.zone.now.to_date + 5.years - domain.save - exp_date = domain.valid_to.to_date - - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - Setting.days_to_renew_domain_before_expire = 90 - end - - it 'does not renew a domain if it is a delete candidate' do - domain.valid_to = Time.zone.now + 10.days - domain.delete_at = Time.zone.now - domain.save - - Domain.start_delete_period - - exp_date = domain.valid_to.to_date - - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Object is not eligible for renewal' - response[:results][0][:result_code].should == '2105' - end - - it 'should renew a expired domain' do - old_valid_to = Time.zone.now - 90.days - old_outzone_at = Time.zone.now - 60.days - old_delete_at = Time.zone.now - 30.days - domain.valid_to = old_valid_to - domain.outzone_at = old_outzone_at - domain.delete_at = old_delete_at - domain.save - - Domain.start_expire_period - domain.reload - domain.valid_to = old_valid_to - domain.outzone_at = old_outzone_at - domain.delete_at = old_delete_at - domain.save - Domain.start_redemption_grace_period - - domain.reload - domain.statuses.include?(DomainStatus::EXPIRED).should == true - domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true - domain.statuses.include?(DomainStatus::OK).should == false - - exp_date = domain.valid_to.to_date - - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - - domain.reload - domain.statuses.include?(DomainStatus::EXPIRED).should == false - domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - domain.statuses.include?(DomainStatus::OK).should == true - - domain.reload - domain.valid_to.should be_within(5).of(old_valid_to + 1.year) - domain.outzone_at.should be_nil - domain.delete_at.should be_nil - end - - it 'does not renew foreign domain' do - login_as :registrar2 do - exp_date = 1.year.since.to_date - xml = @epp_xml.domain.renew( - name: { value: domain.name }, - curExpDate: { value: exp_date.to_s }, - period: { value: '1', attrs: { unit: 'y' } } - ) - - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Authorization error' - response[:results][0][:result_code].should == '2201' - end - end - - ### INFO ### - it 'returns domain info' do - domain.statuses << DomainStatus::CLIENT_HOLD - domain.nameservers.build(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') - - domain.dnskeys.build( - ds_key_tag: '123', - ds_alg: 3, - ds_digest_type: 1, - ds_digest: '0D85A305D22FCB355BBE29AE9809363D697B64782B9CC73AE349350F8C2AE4BB', - flags: 257, - protocol: 3, - alg: 3, - public_key: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' - ) - - domain.dnskeys.build( - ds_key_tag: '123', - ds_alg: 3, - ds_digest_type: 1, - ds_digest: '0D85A305D22FCB355BBE29AE9809363D697B64782B9CC73AE349350F8C2AE4BB', - flags: 0, - protocol: 3, - alg: 5, - public_key: '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - ) - - domain.save - - xml = domain_info_xml(name: { value: domain.name }) - response = epp_plain_request(xml) - response[:results][0][:msg].should == 'Command completed successfully' - response[:results][0][:result_code].should == '1000' - response[:clTRID].should be_nil - - inf_data = response[:parsed].css('resData infData') - inf_data.css('name').text.should == domain.name - inf_data.css('status').first[:s].should == 'clientHold' - inf_data.css('registrant').text.should == domain.registrant_code - inf_data.css('roid').text.should == domain.roid - - admin_contacts_from_request = inf_data.css('contact[type="admin"]').map(&:text) - admin_contacts_existing = domain.admin_contacts.pluck(:code) - - admin_contacts_from_request.should == admin_contacts_existing - - hosts_from_request = inf_data.css('hostName').map(&:text) - hosts_existing = domain.nameservers.pluck(:hostname).sort - - hosts_from_request.sort.should == hosts_existing - - ns1 = inf_data.css('hostAttr').last - - ns1.css('hostName').last.text.should == 'ns1.example.com' - ns1.css('hostAddr').first.text.should == '192.168.1.1' - ns1.css('hostAddr').last.text.should == '1080:0:0:0:8:800:200C:417A' - inf_data.css('crDate').text.should == domain.created_at.in_time_zone.utc.utc.iso8601 - inf_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601 - inf_data.css('pw').text.should == domain.auth_info - - ds_data_1 = response[:parsed].css('dsData')[0] - - ds_data_1.css('keyTag').first.text.should == '123' - ds_data_1.css('alg').first.text.should == '3' - ds_data_1.css('digestType').first.text.should == '1' - ds_data_1.css('digest').first.text.should == '0D85A305D22FCB355BBE29AE9809363D697B64782B9CC73AE349350F8C2AE4BB' - - dnskey_1 = ds_data_1.css('keyData')[0] - dnskey_1.css('flags').first.text.should == '257' - dnskey_1.css('protocol').first.text.should == '3' - dnskey_1.css('alg').first.text.should == '3' - dnskey_1.css('pubKey').first.text.should == 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' - - ds_data_2 = response[:parsed].css('dsData')[1] - - dnskey_2 = ds_data_2.css('keyData')[0] - dnskey_2.css('flags').first.text.should == '0' - dnskey_2.css('protocol').first.text.should == '3' - dnskey_2.css('alg').first.text.should == '5' - dnskey_2.css('pubKey').first.text.should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - - domain.touch - - response = epp_plain_request(domain_info_xml(name: { value: domain.name })) - inf_data = response[:parsed].css('resData infData') - - inf_data.css('upDate').text.should == domain.updated_at.in_time_zone.utc.utc.iso8601 - end - - it 'returns domain info with different nameservers' do - domain.nameservers = [] - domain.save - - domain.nameservers.build(hostname: "ns1.#{domain.name}", ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') - domain.nameservers.build(hostname: "ns2.#{domain.name}", ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') - domain.nameservers.build(hostname: "ns3.test.ee", ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') - domain.save - - xml = domain_info_xml(name: { value: domain.name, attrs: { hosts: 'invalid' } }) - response = epp_plain_request(xml) - response[:msg].should == "Element '{https://epp.tld.ee/schema/domain-eis-1.0.xsd}name', "\ - "attribute 'hosts': [facet 'enumeration'] The value 'invalid' is not an element of the "\ - "set {'all', 'del', 'none', 'sub'}." - response[:result_code].should == '2001' - - xml = domain_info_xml(name: { value: domain.name, attrs: { hosts: 'sub' } }) - response = epp_plain_request(xml) - - inf_data = response[:parsed].css('resData infData') - inf_data.css('hostAttr').count.should == 2 - inf_data.css('hostName').first.text.should == "ns1.#{domain.name}" - inf_data.css('hostName').last.text.should == "ns2.#{domain.name}" - - xml = domain_info_xml(name: { value: domain.name, attrs: { hosts: 'del' } }) - response = epp_plain_request(xml) - - inf_data = response[:parsed].css('resData infData') - inf_data.css('hostAttr').count.should == 1 - inf_data.css('hostName').first.text.should == "ns3.test.ee" - - xml = domain_info_xml(name: { value: domain.name, attrs: { hosts: 'none' } }) - response = epp_plain_request(xml) - - inf_data = response[:parsed].css('resData infData') - inf_data.css('ns').count.should == 0 - inf_data.css('hostAttr').count.should == 0 - - xml = domain_info_xml(name: { value: domain.name, attrs: { hosts: 'all' } }) - response = epp_plain_request(xml) - - inf_data = response[:parsed].css('resData infData') - inf_data.css('hostAttr').count.should == 3 - end - - it 'returns error when domain can not be found' do - response = epp_plain_request(domain_info_xml(name: { value: 'test.ee' })) - response[:results][0][:result_code].should == '2303' - response[:results][0][:msg].should == 'Domain not found' - end - - it 'sets ok status by default' do - response = epp_plain_request(domain_info_xml(name: { value: domain.name })) - inf_data = response[:parsed].css('resData infData') - inf_data.css('status').first[:s].should == 'ok' - end - - it 'can not see other registrar domains with invalid password' do - login_as :registrar2 do - response = epp_plain_request(domain_info_xml(name: { value: domain.name })) - response[:result_code].should == '2201' - response[:msg].should == 'Authorization error' - end - end - - it 'can see other registrar domains without password' do - login_as :registrar2 do - response = epp_plain_request(domain_info_xml( - name: { value: domain.name }, - authInfo: nil - )) - - response[:result_code].should == '1000' - response[:parsed].css('authInfo pw').first.should == nil - end - end - - it 'can see other registrar domains with correct password' do - login_as :registrar2 do - pw = domain.auth_info - response = epp_plain_request(domain_info_xml( - name: { value: domain.name }, - authInfo: { pw: { value: pw } } - )) - - response[:result_code].should == '1000' - response[:parsed].css('authInfo pw').text.should == pw - end - end - - ### DELETE ### - it 'deletes domain' do - response = epp_plain_request(@epp_xml.domain.delete({ - name: { value: domain.name } - }, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - })) - - response[:msg].should == 'Command completed successfully; action pending' - response[:result_code].should == '1001' - - Domain.find_by(name: domain.name).should_not == nil - end - - it 'does not delete domain with specific status' do - domain.statuses << DomainStatus::CLIENT_DELETE_PROHIBITED - domain.save - - response = epp_plain_request(@epp_xml.domain.delete({ - name: { value: domain.name } - }, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - })) - - response[:result_code].should == '2304' - response[:msg].should == 'Domain status prohibits operation' - end - - it 'does not delete domain with pending delete' do - domain.statuses << DomainStatus::PENDING_DELETE - domain.save - - response = epp_plain_request(@epp_xml.domain.delete({ - name: { value: domain.name } - }, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - })) - - response[:msg].should == 'Object status prohibits operation' - response[:result_code].should == '2304' - end - - it 'does not delete domain without legal document' do - response = epp_plain_request(@epp_xml.domain.delete(name: { value: 'example.ee' })) - response[:result_code].should == '2003' - response[:msg].should == - 'Required parameter missing: extension > extdata > legalDocument [legal_document]' - end - - ### CHECK ### - it 'checks a domain' do - response = epp_plain_request(domain_check_xml({ - _anonymus: [ - { name: { value: 'one.ee' } } - ] - })) - - response[:result_code].should == '1000' - response[:msg].should == 'Command completed successfully' - - res_data = response[:parsed].css('resData chkData cd name').first - res_data.text.should == 'one.ee' - res_data[:avail].should == '1' - - response = epp_plain_request(domain_check_xml({ - _anonymus: [ - { name: { value: domain.name } } - ] - })) - res_data = response[:parsed].css('resData chkData cd').first - name = res_data.css('name').first - reason = res_data.css('reason').first - - name.text.should == domain.name - name[:avail].should == '0' - reason.text.should == 'in use' - end - - it 'checks multiple domains' do - xml = domain_check_xml({ - _anonymus: [ - { name: { value: 'one.ee' } }, - { name: { value: 'two.ee' } }, - { name: { value: 'three.ee' } } - ] - }) - - response = epp_plain_request(xml) - response[:result_code].should == '1000' - response[:msg].should == 'Command completed successfully' - - res_data = response[:parsed].css('resData chkData cd name').first - res_data.text.should == 'one.ee' - res_data[:avail].should == '1' - - res_data = response[:parsed].css('resData chkData cd name').last - res_data.text.should == 'three.ee' - res_data[:avail].should == '1' - end - - it 'checks invalid format domain' do - xml = domain_check_xml({ - _anonymus: [ - { name: { value: 'one.ee' } }, - { name: { value: 'notcorrectdomain' } } - ] - }) - - response = epp_plain_request(xml) - response[:result_code].should == '1000' - response[:msg].should == 'Command completed successfully' - - res_data = response[:parsed].css('resData chkData cd name').first - res_data.text.should == 'one.ee' - res_data[:avail].should == '1' - - res_data = response[:parsed].css('resData chkData cd').last - name = res_data.css('name').first - reason = res_data.css('reason').first - - name.text.should == 'notcorrectdomain' - name[:avail].should == '0' - reason.text.should == 'invalid format' - end - - ### POLL ### - it 'should show force delete in poll' do - domain.set_force_delete - response = epp_plain_request(@epp_xml.session.poll) - msg_q = response[:parsed].css('msgQ') - msg_q.css('msg').text.should == "Force delete set on domain #{domain.name}" - end - end -end diff --git a/spec/epp/epp_helper_spec.rb b/spec/epp/epp_helper_spec.rb deleted file mode 100644 index ff8050386..000000000 --- a/spec/epp/epp_helper_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'rails_helper' - -describe 'EPP Helper', epp: true do - context 'in context of Domain' do - before(:all) { @uniq_no = proc { @i ||= 0; @i += 1 } } - - it 'generates valid transfer xml' do - dn = next_domain_name - expected = Nokogiri::XML(' - - - - - ' + dn + ' - - - ABC-12345 - - - ').to_s.squish - - generated = Nokogiri::XML(domain_transfer_xml(name: { value: dn })).to_s.squish - generated.should == expected - - expected = Nokogiri::XML(' - - - - - one.ee - - test - - - - ABC-12345 - - - ').to_s.squish - - xml = domain_transfer_xml({ - name: { value: 'one.ee' }, - authInfo: { - pw: { value: 'test', attrs: { roid: 'askdf' } } - } - }, 'approve') - - generated = Nokogiri::XML(xml).to_s.squish - generated.should == expected - end - end -end diff --git a/spec/epp/keyrelay_spec.rb b/spec/epp/keyrelay_spec.rb deleted file mode 100644 index d42d96f4b..000000000 --- a/spec/epp/keyrelay_spec.rb +++ /dev/null @@ -1,216 +0,0 @@ -require 'rails_helper' - -describe 'EPP Keyrelay', epp: true do - before(:all) do - Fabricate(:zonefile_setting, origin: 'ee') - @registrar1 = Fabricate(:registrar1) - @registrar2 = Fabricate(:registrar2) - @domain = Fabricate(:domain, registrar: @registrar2) - @epp_xml = EppXml::Keyrelay.new - - Fabricate(:api_user, username: 'registrar1', registrar: @registrar1) - Fabricate(:api_user, username: 'registrar2', registrar: @registrar2) - - login_as :registrar1 - end - - it 'makes a keyrelay request' do - ApiLog::EppLog.delete_all - - xml = @epp_xml.keyrelay({ - name: { value: @domain.name }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: @domain.auth_info } - }, - expiry: { - relative: { value: 'P1M13D' } - } - }) - - response = epp_plain_request(xml, :xml) - - response[:msg].should == 'Unimplemented object service' - response[:result_code].should == '2307' - - # response[:msg].should == 'Command completed successfully' - # response[:result_code].should == '1000' - - # @registrar2.messages.queued.count.should == 1 - - # log = ApiLog::EppLog.last - # log.request_command.should == 'keyrelay' - # log.request_successful.should == true - # log.api_user_name.should == '1-api-registrar1' - end - - it 'returns an error when parameters are missing' do - msg_count = @registrar2.messages.queued.count - xml = @epp_xml.keyrelay({ - name: { value: @domain.name }, - keyData: { - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: @domain.auth_info } - }, - expiry: { - relative: { value: 'Invalid Expiry' } - } - }) - - response = epp_plain_request(xml, :xml) - response[:msg].should == 'Required parameter missing: keyrelay > keyData > flags [flags]' - - @registrar2.messages.queued.count.should == msg_count - end - - it 'returns an error on invalid relative expiry' do - msg_count = @registrar2.messages.queued.count - xml = @epp_xml.keyrelay({ - name: { value: @domain.name }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: @domain.auth_info } - }, - expiry: { - relative: { value: 'Invalid Expiry' } - } - }) - - response = epp_plain_request(xml, :xml) - response[:msg].should == 'Expiry relative must be compatible to ISO 8601' - response[:results][0][:value].should == 'Invalid Expiry' - - @registrar2.messages.queued.count.should == msg_count - end - - it 'returns an error on invalid absolute expiry' do - msg_count = @registrar2.messages.queued.count - xml = @epp_xml.keyrelay({ - name: { value: @domain.name }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: @domain.auth_info } - }, - expiry: { - absolute: { value: 'Invalid Absolute' } - } - }) - - response = epp_plain_request(xml, :xml) - response[:msg].should == 'Expiry absolute must be compatible to ISO 8601' - response[:results][0][:value].should == 'Invalid Absolute' - - @registrar2.messages.queued.count.should == msg_count - end - - # keyrelay not enabled at the moment - # it 'does not allow both relative and absolute' do - # msg_count = @registrar2.messages.queued.count - # xml = @epp_xml.keyrelay({ - # name: { value: @domain.name }, - # keyData: { - # flags: { value: '256' }, - # protocol: { value: '3' }, - # alg: { value: '8' }, - # pubKey: { value: 'cmlraXN0aGViZXN0' } - # }, - # authInfo: { - # pw: { value: @domain.auth_info } - # }, - # expiry: { - # relative: { value: 'P1D' }, - # absolute: { value: '2014-12-23' } - # } - # }) - - # response = epp_plain_request(xml, :xml) - # response[:msg].should == 'Exactly one parameter required: keyrelay > expiry > relative OR '\ - # 'keyrelay > expiry > absolute' - - # @registrar2.messages.queued.count.should == msg_count - # end - - it 'saves legal document with keyrelay' do - xml = @epp_xml.keyrelay({ - name: { value: @domain.name }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: @domain.auth_info } - }, - expiry: { - relative: { value: 'P1D' } - } - }, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - - response = epp_plain_request(xml, :xml) - - response[:msg].should == 'Unimplemented object service' - response[:result_code].should == '2307' - - # response[:msg].should == 'Command completed successfully' - - # docs = Keyrelay.last.legal_documents - # docs.count.should == 1 - # docs.first.path.should_not be_blank - # docs.first.document_type.should == 'pdf' - end - - it 'validates legal document types' do - xml = @epp_xml.keyrelay({ - name: { value: @domain.name }, - keyData: { - flags: { value: '256' }, - protocol: { value: '3' }, - alg: { value: '8' }, - pubKey: { value: 'cmlraXN0aGViZXN0' } - }, - authInfo: { - pw: { value: @domain.auth_info } - }, - expiry: { - relative: { value: 'P1D' } - } - }, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'jpg' } - } - ] - }) - - response = epp_plain_request(xml, :xml) - response[:msg].should == 'Attribute is invalid: type' - end -end diff --git a/spec/epp/poll_spec.rb b/spec/epp/poll_spec.rb deleted file mode 100644 index 53f82221a..000000000 --- a/spec/epp/poll_spec.rb +++ /dev/null @@ -1,158 +0,0 @@ -require 'rails_helper' - -describe 'EPP Poll', epp: true do - let(:epp_xml) { EppXml::Session.new } - - def registrar1 - @registrar1 ||= Registrar.where(reg_no: '12345678').first || Fabricate(:registrar) - end - - def registrar2 - @registrar2 ||= Fabricate(:registrar, { name: 'registrar2', reg_no: '123' }) - end - - before(:all) do - @xsd = Nokogiri::XML::Schema(File.read('lib/schemas/epp-1.0.xsd')) - Fabricate(:api_user, username: 'registrar1', registrar: registrar1) - Fabricate(:api_user, username: 'registrar2', registrar: registrar2) - - login_as :registrar1 - - @uniq_no = proc { @i ||= 0; @i += 1 } - end - - it 'returns no messages in poll' do - ApiLog::EppLog.delete_all - response = epp_plain_request(epp_xml.poll, :xml) - response[:msg].should == 'Command completed successfully; no messages' - response[:result_code].should == '1300' - - log = ApiLog::EppLog.last - - log.request_command.should == 'poll' - log.request_object.should == 'poll' - log.request_successful.should == true - log.api_user_name.should == 'registrar1' - log.api_user_registrar.should == @registrar1.name - log.request.should_not be_blank - log.response.should_not be_blank - end - - it 'queues and dequeues messages' do - msg = registrar1.messages.create({ body: 'Balance low.' }) - - response = login_as :registrar2 do - epp_plain_request(epp_xml.poll, :xml) - end - - response[:msg].should == 'Command completed successfully; no messages' - response[:result_code].should == '1300' - - response = epp_plain_request(epp_xml.poll, :xml) - response[:msg].should == 'Command completed successfully; ack to dequeue' - response[:result_code].should == '1301' - msg_q = response[:parsed].css('msgQ') - - msg_q.css('msg').text.should == 'Balance low.' - msg_q.first['count'].should == '1' - msg_q.first['id'].should == msg.id.to_s - - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) - - response = login_as :registrar2 do - epp_plain_request(xml, :xml) - end - - response[:results][0][:msg].should == 'Message was not found' - response[:results][0][:result_code].should == '2303' - response[:results][0][:value].should == msg_q.first['id'] - - response = epp_plain_request(xml, :xml) - response[:msg].should == 'Command completed successfully' - msg_q = response[:parsed].css('msgQ') - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '0' - - response = epp_plain_request(xml, :xml) - response[:results][0][:msg].should == 'Message was not found' - response[:results][0][:result_code].should == '2303' - response[:results][0][:value].should == msg_q.first['id'] - end - - it 'returns an error on incorrect op' do - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'bla' } - }) - - response = epp_plain_request(xml, validate_input: false) - response[:msg].should == "Element '{urn:ietf:params:xml:ns:epp-1.0}poll', attribute 'op': "\ - "[facet 'enumeration'] The value 'bla' is not an element of the set {'ack', 'req'}." - response[:result_code].should == '2001' - end - - it 'dequeues multiple messages' do - registrar1.messages.create({ body: 'Balance low.' }) - registrar1.messages.create({ body: 'Something.' }) - registrar1.messages.create({ body: 'Smth else.' }) - - response = epp_plain_request(epp_xml.poll, :xml) - response[:msg].should == 'Command completed successfully; ack to dequeue' - response[:result_code].should == '1301' - msg_q = response[:parsed].css('msgQ') - - msg_q.css('msg').text.should == 'Smth else.' - msg_q.first['count'].should == '3' - - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) - - response = epp_plain_request(xml, :xml) - response[:msg].should == 'Command completed successfully' - msg_q = response[:parsed].css('msgQ') - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '2' - - response = epp_plain_request(epp_xml.poll, :xml) - response[:msg].should == 'Command completed successfully; ack to dequeue' - response[:result_code].should == '1301' - msg_q = response[:parsed].css('msgQ') - - msg_q.css('msg').text.should == 'Something.' - msg_q.first['count'].should == '2' - - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) - - response = epp_plain_request(xml, :xml) - response[:msg].should == 'Command completed successfully' - msg_q = response[:parsed].css('msgQ') - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '1' - - response = epp_plain_request(epp_xml.poll, :xml) - response[:msg].should == 'Command completed successfully; ack to dequeue' - response[:result_code].should == '1301' - msg_q = response[:parsed].css('msgQ') - - msg_q.css('msg').text.should == 'Balance low.' - msg_q.first['count'].should == '1' - - xml = epp_xml.poll(poll: { - value: '', attrs: { op: 'ack', msgID: msg_q.first['id'] } - }) - - response = epp_plain_request(xml, :xml) - response[:msg].should == 'Command completed successfully' - msg_q = response[:parsed].css('msgQ') - msg_q.first['id'].should_not be_blank - msg_q.first['count'].should == '0' - - response = epp_plain_request(epp_xml.poll, :xml) - response[:msg].should == 'Command completed successfully; no messages' - response[:result_code].should == '1300' - end -end diff --git a/spec/epp/requests/contacts/create_with_two_addresses.xml b/spec/epp/requests/contacts/create_with_two_addresses.xml deleted file mode 100644 index 640febf34..000000000 --- a/spec/epp/requests/contacts/create_with_two_addresses.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - loc_int - - John Doe Int - Example Int Inc. - - International street 1 - Dulles - VA - 20166-6503 - EE - - - - John Doe Loc - Example Loc Inc. - - Local street 1 - Vancouver - BC - 27123 - CA - - - +123.7035555555 - +1.7035555556 - jdoe@example.com - 37605030299 - - 2fooBAR - - - - - - - - ABC-12345 - - diff --git a/spec/epp/requests/contacts/delete.xml b/spec/epp/requests/contacts/delete.xml deleted file mode 100644 index 004090aa2..000000000 --- a/spec/epp/requests/contacts/delete.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - dwa1234 - - - ABC-12345 - - diff --git a/spec/epp/requests/contacts/delete_missing_attr.xml b/spec/epp/requests/contacts/delete_missing_attr.xml deleted file mode 100644 index b3502252b..000000000 --- a/spec/epp/requests/contacts/delete_missing_attr.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - ABC-12345 - - diff --git a/spec/epp/requests/contacts/info.xml b/spec/epp/requests/contacts/info.xml deleted file mode 100644 index 58fb2efee..000000000 --- a/spec/epp/requests/contacts/info.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - info-4444 - - 2fooBAR - - - - ABC-12345 - - diff --git a/spec/epp/requests/contacts/info_missing_attr.xml b/spec/epp/requests/contacts/info_missing_attr.xml deleted file mode 100644 index 1b42c56f2..000000000 --- a/spec/epp/requests/contacts/info_missing_attr.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - ABC-12345 - - diff --git a/spec/epp/requests/contacts/update.xml b/spec/epp/requests/contacts/update.xml deleted file mode 100644 index 3dcf17374..000000000 --- a/spec/epp/requests/contacts/update.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - sh8013 - - - John Doe - - 123 Example Dr. - Suite 100 - Dulles - VA - 20166-6503 - EE - - - +123.7035555555 - +1.7035555556 - jdoe@example.com - J836954 - - 2fooBAR - - - - - - - - - ABC-12345 - - diff --git a/spec/epp/requests/contacts/update_missing_attr.xml b/spec/epp/requests/contacts/update_missing_attr.xml deleted file mode 100644 index 74590aa25..000000000 --- a/spec/epp/requests/contacts/update_missing_attr.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - ABC-12345 - - diff --git a/spec/epp/requests/contacts/update_with_errors.xml b/spec/epp/requests/contacts/update_with_errors.xml deleted file mode 100644 index ac6426a21..000000000 --- a/spec/epp/requests/contacts/update_with_errors.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - sh8013 - - 123456798 - faulty - - 2fooBAR - - - - - ABC-12345 - - diff --git a/spec/epp/session_spec.rb b/spec/epp/session_spec.rb deleted file mode 100644 index d36e8f694..000000000 --- a/spec/epp/session_spec.rb +++ /dev/null @@ -1,155 +0,0 @@ -require 'rails_helper' - -describe 'EPP Session', epp: true do - before :all do - @api_user = Fabricate(:gitlab_api_user) - @epp_xml = EppXml.new(cl_trid: 'ABC-12345') - @login_xml_cache = @epp_xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' }) - @xsd = Nokogiri::XML::Schema(File.read('lib/schemas/epp-1.0.xsd')) - end - - context 'when not connected' do - it 'greets client upon connection' do - server.close_connection - response = Nokogiri::XML(server.open_connection) - response.css('epp svID').text.should == 'EPP server (EIS)' - puts "RESPONSE:\n\n```xml\n#{response}```\n\n" if ENV['EPP_DOC'] - end - end - - context 'when connected' do - before do - server.open_connection - end - - it 'does not log in with invalid user' do - wrong_user = @epp_xml.session.login(clID: { value: 'wrong-user' }, pw: { value: 'ghyt9e4fu' }) - response = epp_plain_request(wrong_user) - response[:msg].should == 'Authentication error; server closing connection (API user not found)' - response[:result_code].should == '2501' - response[:clTRID].should == 'ABC-12345' - - log = ApiLog::EppLog.last - log.request_command.should == 'login' - log.request_successful.should == false - log.api_user_name.should == 'api-public' - end - - it 'does not log in with inactive user' do - @registrar = Fabricate(:registrar, { name: 'registrar1', reg_no: '123' }) - Fabricate(:api_user, username: 'inactive-user', active: false, registrar: @registrar) - - inactive = @epp_xml.session.login(clID: { value: 'inactive-user' }, pw: { value: 'ghyt9e4fu' }) - response = epp_plain_request(inactive) - response[:msg].should == 'Authentication error; server closing connection (API user is not active)' - response[:result_code].should == '2501' - - log = ApiLog::EppLog.last - log.request_command.should == 'login' - log.request_successful.should == false - log.api_user_name.should == 'inactive-user' - end - - it 'prohibits further actions unless logged in' do - @xsd = Nokogiri::XML::Schema(File.read('lib/schemas/domain-eis-1.0.xsd')) - response = epp_plain_request(@epp_xml.domain.info(name: { value: 'test.ee' })) - response[:msg].should == 'You need to login first.' - response[:result_code].should == '2002' - response[:clTRID].should == 'ABC-12345' - end - - it 'should not have clTRID in response if client does not send it' do - epp_xml_no_cltrid = EppXml.new(cl_trid: false) - wrong_user = epp_xml_no_cltrid.session.login(clID: { value: 'wrong-user' }, pw: { value: 'ghyt9e4fu' }) - response = epp_plain_request(wrong_user) - response[:clTRID].should be_nil - end - - it 'should return latin only error' do - wrong_user = @epp_xml.session.login(clID: { value: '你好你好' }, pw: { value: 'ghyt9e4fu' }) - response = epp_plain_request(wrong_user) - response[:msg].should == 'Parameter value policy error. Allowed only Latin characters.' - response[:result_code].should == '2306' - response[:clTRID].should == 'ABC-12345' - - log = ApiLog::EppLog.last - log.request_command.should == 'login' - log.request_successful.should == false - log.api_user_name.should == 'api-public' - end - - context 'with valid user' do - it 'logs in epp user' do - response = epp_plain_request(@login_xml_cache) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:clTRID].should == 'ABC-12345' - - log = ApiLog::EppLog.last - log.request_command.should == 'login' - log.request_successful.should == true - log.api_user_name.should == 'gitlab' - end - - it 'does not log in twice' do - response = epp_plain_request(@login_xml_cache) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - response[:clTRID].should == 'ABC-12345' - - response = epp_plain_request(@login_xml_cache) - response[:msg].should match(/Already logged in. Use/) - response[:result_code].should == '2002' - - log = ApiLog::EppLog.last - log.request_command.should == 'login' - log.request_successful.should == false - log.api_user_name.should == 'gitlab' - end - - it 'logs out epp user' do - c = EppSession.count - epp_plain_request(@login_xml_cache) - - EppSession.count.should == c + 1 - response = epp_plain_request(@epp_xml.session.logout) - response[:msg].should == 'Command completed successfully; ending session' - response[:result_code].should == '1500' - - EppSession.count.should == c - end - - it 'changes password and logs in' do - @api_user.update(password: 'ghyt9e4fu') - response = epp_plain_request(@epp_xml.session.login( - clID: { value: 'gitlab' }, - pw: { value: 'ghyt9e4fu' }, - newPW: { value: 'abcdefg' } - )) - - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - @api_user.reload - @api_user.password.should == 'abcdefg' - end - - it 'fails if new password is not valid' do - @api_user.update(password: 'ghyt9e4fu') - response = epp_plain_request(@epp_xml.session.login( - clID: { value: 'gitlab' }, - pw: { value: 'ghyt9e4fu' }, - newPW: { value: '' } - ), validate_input: false) - - response[:msg].should == - "Element '{urn:ietf:params:xml:ns:epp-1.0}newPW': [facet 'minLength'] The value has a "\ - "length of '0'; this underruns the allowed minimum length of '6'." - response[:result_code].should == '2001' - - @api_user.reload - @api_user.password.should == 'ghyt9e4fu' - end - end - end -end diff --git a/spec/features/admin/account_activity_spec.rb b/spec/features/admin/account_activity_spec.rb deleted file mode 100644 index 0101337b6..000000000 --- a/spec/features/admin/account_activity_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'rails_helper' - -feature 'Account activity', type: :feature do - before :all do - @user = Fabricate(:admin_user) - r = Fabricate(:registrar) - Fabricate.times(5, :account_activity, account: r.cash_account) - Fabricate(:account_activity, account: r.cash_account, description: 'acc activity test', sum: -12) - end - - context 'as unknown user' do - it 'should redirect to sign in page' do - visit '/admin/account_activities' - current_path.should == '/admin/login' - page.should have_text('You need to sign in or sign up') - end - end - - context 'as signed in user' do - before do - sign_in @user - end - - it 'should navigate to account activities page' do - visit admin_account_activities_path - page.should have_text('+110.0 EUR', count: 5) - page.should have_text('-12.0 EUR') - end - - it 'should search activities by description' do - visit admin_account_activities_path - fill_in 'Description', with: 'test' - find('.btn.btn-default.search').click - page.should have_text('-12.0 EUR') - page.should_not have_text('+110.0 EUR') - end - - it 'should download csv' do - visit admin_account_activities_path - click_link 'Export CSV' - response_headers['Content-Type'].should == 'text/csv' - response_headers['Content-Disposition'].should match(/attachment; filename="account_activities_\d+\.csv"/) - end - end -end diff --git a/spec/features/admin/admin_user_spec.rb b/spec/features/admin/admin_user_spec.rb deleted file mode 100644 index 427e6523f..000000000 --- a/spec/features/admin/admin_user_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'rails_helper' - -feature 'Admin users', type: :feature do - before :all do - @admin_user = Fabricate(:admin_user) - end - - context 'as unknown user' do - it 'should redirect to login path' do - visit admin_admin_users_url - current_path.should == '/admin/login' - end - - it 'should redirect to login path' do - visit admin_admin_user_url(@admin_user) - current_path.should == '/admin/login' - end - - it 'should redirect to login path' do - visit edit_admin_admin_user_url(@admin_user) - current_path.should == '/admin/login' - end - end - - context 'as logged in user' do - it 'should show index of contacts' do - sign_in @admin_user - visit admin_admin_users_url - - current_path.should == '/admin/admin_users' - page.should have_content('API users') - end - - it 'should show api user' do - sign_in @admin_user - visit admin_admin_user_url(@admin_user) - - current_path.should == "/admin/admin_users/#{@admin_user.id}" - end - - it 'should show api user' do - sign_in @admin_user - visit edit_admin_admin_user_url(@admin_user) - - current_path.should == "/admin/admin_users/#{@admin_user.id}/edit" - page.should have_content("Edit: #{@admin_user.username}") - end - end -end diff --git a/spec/features/admin/api_user_spec.rb b/spec/features/admin/api_user_spec.rb deleted file mode 100644 index ee53888d7..000000000 --- a/spec/features/admin/api_user_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'rails_helper' - -feature 'Api users', type: :feature do - before :all do - @user = Fabricate(:admin_user) - @api_user = Fabricate(:api_user) - end - - context 'as unknown user' do - it 'should redirect to login path' do - visit admin_api_users_url - - current_path.should == '/admin/login' - end - - it 'should redirect to login path' do - visit admin_api_user_url(@api_user) - - current_path.should == '/admin/login' - end - - end - - context 'as logged in user' do - it 'should show index of api users' do - sign_in @user - visit admin_api_users_url - - current_path.should == '/admin/api_users' - page.should have_content('API users') - end - - it 'should show api user' do - sign_in @user - visit admin_api_user_url(@api_user) - - current_path.should == "/admin/api_users/#{@api_user.id}" - end - end -end diff --git a/spec/features/admin/bank_statement_spec.rb b/spec/features/admin/bank_statement_spec.rb deleted file mode 100644 index b6ac8dcd2..000000000 --- a/spec/features/admin/bank_statement_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'rails_helper' - -feature 'BankStatement', type: :feature do - before :all do - @user = Fabricate(:admin_user) - end - - before do - sign_in @user - end - - it 'should add a bank statement and transactions manually' do - visit admin_bank_statements_url - - click_link 'Add' - fill_in 'Bank code', with: '767' - fill_in 'Iban', with: 'EE557700771000598731' - click_button 'Save' - - page.should have_content('Record created') - page.should have_content('Bank statement ') - page.should have_content('767') - page.should have_content('EE557700771000598731') - page.should have_content('Not binded') - - click_link 'Add' - fill_in 'Description', with: 'Payment 12345' - fill_in 'Sum', with: '120' - fill_in 'Reference no', with: 'RF4663930489' - fill_in 'Document no', with: '123' - fill_in 'Bank reference', with: '767' - fill_in 'Iban', with: 'EE557700771000598731' - fill_in 'Buyer bank code', with: '767' - fill_in 'Buyer iban', with: 'EE557700771000598000' - fill_in 'Buyer name', with: 'Test buyer' - fill_in 'Paid at', with: '2015-01-01' - - click_button 'Save' - - page.should have_content('Record created') - page.should have_content('Bank transaction') - page.should have_content('RF4663930489') - page.should have_content('EE557700771000598000') - page.should have_content('Not binded') - page.should have_content('Bind manually') - - click_link 'Back to bank statement' - - page.should have_content('120,00') - page.should have_content('Test buyer') - end -end diff --git a/spec/features/admin/blocked_domain_spec.rb b/spec/features/admin/blocked_domain_spec.rb deleted file mode 100644 index 432556d64..000000000 --- a/spec/features/admin/blocked_domain_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'rails_helper' - -feature 'BlockedDomain', type: :feature do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - @user = Fabricate(:admin_user) - end - - before do - sign_in @user - end - - it 'should manage blocked domains' do - visit admin_blocked_domains_url - page.should have_content('Blocked domains') - - d = Fabricate.build(:domain, name: 'ftp.ee') - d.valid? - d.errors.full_messages.should match_array([]) - - fill_in 'blocked_domains', with: "ftp.ee\ncache.ee" - click_button 'Save' - - page.should have_content('Record updated') - page.should have_content('ftp.ee') - page.should have_content('cache.ee') - - d.valid? - d.errors.full_messages.should match_array(["Data management policy violation: Domain name is blocked [name]"]) - end -end diff --git a/spec/features/admin/contact_spec.rb b/spec/features/admin/contact_spec.rb deleted file mode 100644 index 6edaaf2d1..000000000 --- a/spec/features/admin/contact_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'rails_helper' - -feature 'Admin contact', type: :feature do - before :all do - @user = Fabricate(:admin_user) - @contact = Fabricate(:contact, name: 'Mr John') - end - - it 'should show index of contacts' do - sign_in @user - visit admin_contacts_url - - page.should have_content('Mr John') - end - - it 'should show correct contact creator' do - sign_in @user - visit admin_contacts_url - - click_link('Mr John') - # initially it's created by unknown, - # indivitually running it's created by autotest - page.should have_content(/by [unknown|autotest]/) - end - - it 'should search contacts by name' do - Fabricate(:contact, name: 'first name') - Fabricate(:contact, name: 'second name') - Fabricate(:contact, name: 'third name') - sign_in @user - visit admin_contacts_url - - page.should have_content('first name') - page.should have_content('second name') - page.should have_content('third name') - - fill_in 'q_name_matches', with: 'first name' - find('.btn.btn-primary').click - - current_path.should == "/admin/contacts" - - page.should have_content('first name') - page.should_not have_content('second name') - page.should_not have_content('third name') - - fill_in 'q_name_matches', with: '%name' - find('.btn.btn-primary').click - - page.should have_content('first name') - page.should have_content('second name') - page.should have_content('third name') - - fill_in 'q_name_matches', with: 'sec___ name' - find('.btn.btn-primary').click - - page.should_not have_content('first name') - page.should have_content('second name') - page.should_not have_content('third name') - end -end diff --git a/spec/features/admin/domain_spec.rb b/spec/features/admin/domain_spec.rb deleted file mode 100644 index 755a30c6f..000000000 --- a/spec/features/admin/domain_spec.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'rails_helper' - -feature 'Domain', type: :feature do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - Fabricate(:zonefile_setting, origin: 'pri.ee') - @user = Fabricate(:admin_user) - end - - it 'should show index of domains' do - Fabricate(:domain, name: 'testing.ee') - sign_in @user - visit admin_domains_url - - page.should have_content('testing.ee') - end - - it 'should search domains by name' do - d1 = Fabricate(:domain, name: 'abcde.ee') - Fabricate(:domain, name: 'abcdee.ee') - Fabricate(:domain, name: 'defgh.pri.ee') - sign_in @user - visit admin_domains_url - - page.should have_content('abcde.ee') - page.should have_content('abcdee.ee') - page.should have_content('defgh.pri.ee') - - fill_in 'q_name_matches', with: 'abcde.ee' - find('.btn.btn-primary').click - - current_path.should == "/admin/domains/#{d1.id}" - - visit admin_domains_url - fill_in 'q_name_matches', with: '.ee' - find('.btn.btn-primary').click - - current_path.should == "/admin/domains" - page.should have_content('abcde.ee') - page.should have_content('abcdee.ee') - page.should have_content('defgh.pri.ee') - - fill_in 'q_name_matches', with: 'abcd%.ee' - find('.btn.btn-primary').click - page.should have_content('abcde.ee') - page.should have_content('abcdee.ee') - page.should_not have_content('defgh.pri.ee') - - fill_in 'q_name_matches', with: 'abcd_.ee' - find('.btn.btn-primary').click - current_path.should == "/admin/domains/#{d1.id}" - end - - it 'should set domain to force delete' do - d = Fabricate(:domain) - sign_in @user - visit admin_domains_url - click_link d.name - click_link 'Edit statuses' - page.should have_content('ok') - click_link 'Set force delete' - page.should have_content('serverForceDelete') - page.should have_content('serverRenewProhibited') - page.should have_content('serverTransferProhibited') - page.should have_content('serverUpdateProhibited') - page.should have_content('serverManualInzone') - page.should have_content('pendingDelete') - - click_link 'Edit statuses' - click_button 'Save' - page.should have_content('Failed to update domain') - page.should have_content('Object status prohibits operation') - - click_link 'Back to domain' - click_link 'Edit statuses' - click_link 'Unset force delete' - page.should_not have_content('serverForceDelete') - page.should_not have_content('serverRenewProhibited') - page.should_not have_content('serverTransferProhibited') - page.should_not have_content('serverUpdateProhibited') - page.should_not have_content('serverManualInzone') - page.should_not have_content('pendingDelete') - page.should have_content('ok') - - click_link 'Edit statuses' - click_button 'Save' - page.should have_content('Domain updated!') - end -end diff --git a/spec/features/admin/epp_log_spec.rb b/spec/features/admin/epp_log_spec.rb deleted file mode 100644 index 1bec69fe9..000000000 --- a/spec/features/admin/epp_log_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -feature 'EPP log', type: :feature do - before :all do - @user = Fabricate(:admin_user) - @contact = Fabricate(:contact, name: 'Mr John') - end - - context 'as unknown user' do - it 'should redirect to login path' do - visit admin_epp_logs_url - - current_path.should == '/admin/login' - end - end - - context 'as logged in user' do - it 'should show index' do - sign_in @user - visit admin_epp_logs_url - - page.should have_content('REPP logs') - end - end -end diff --git a/spec/features/admin/invoice_spec.rb b/spec/features/admin/invoice_spec.rb deleted file mode 100644 index 1e10f066b..000000000 --- a/spec/features/admin/invoice_spec.rb +++ /dev/null @@ -1,131 +0,0 @@ -require 'rails_helper' - -feature 'Invoice', type: :feature do - before :all do - @user = Fabricate(:admin_user) - @invoice = Fabricate(:invoice) - end - - before do - sign_in @user - end - - it 'should show index of invoices' do - visit admin_invoices_url - page.should have_link("Invoice no. #{@invoice.id}") - end - - it 'should show invoice' do - visit admin_invoices_url - - click_link("Invoice no. #{@invoice.id}") - page.should have_content("Seller") - page.should have_content("Details") - page.should have_content("Paldiski mnt. 123") - end - - it 'should issue an invoice' do - Fabricate(:eis) - r = Fabricate(:registrar) - visit admin_invoices_url - click_link('Add') - page.should have_content('Create new invoice') - select r.name, from: 'Registrar' - fill_in 'Amount', with: '100' - fill_in 'Description', with: 'test issue' - click_button 'Save' - page.should have_content('Record created') - page.should have_content('Invoice no.') - page.should have_content('Prepayment') - page.should have_content('120,00') - page.should have_content(r.name) - end - - it 'should not issue and invoice with deposit amount too small' do - Setting.minimum_deposit = 0.0 - r = Fabricate(:registrar) - visit admin_invoices_url - click_link('Add') - select r.name, from: 'Registrar' - fill_in 'Amount', with: '-2.11' - fill_in 'Description', with: 'test issue' - click_button 'Save' - page.should have_content('Amount is too small. Minimum deposit is 0.0 EUR') - Setting.minimum_deposit = 12.43 - fill_in 'Amount', with: '12.42' - click_button 'Save' - - page.should have_content('Amount is too small. Minimum deposit is 12.43 EUR') - fill_in 'Amount', with: '12.44' - click_button 'Save' - page.should have_content('Record created') - Setting.minimum_deposit = 0.0 - end - - it 'should forward invoice' do - visit '/admin/invoices' - click_link @invoice.to_s - click_link 'Forward' - click_button 'Forward' - page.should have_text('Failed to forward invoice') - fill_in 'Billing email', with: 'test@test.ee' - click_button 'Forward' - page.should have_text('Invoice forwarded') - end - - it 'should download invoice' do - visit '/admin/invoices' - click_link @invoice.to_s - click_link 'Download' - response_headers['Content-Type'].should == 'application/pdf' - response_headers['Content-Disposition'].should == "attachment; filename=\"#{@invoice.pdf_name}\"" - end - - it 'should create bank statement and transaction for invoice' do - r = Fabricate(:registrar, reference_no: 'RF7086666663') - invoice = r.issue_prepayment_invoice(200, 'add some money') - - visit '/admin/invoices' - click_link invoice.to_s - - page.should have_content('Unpaid') - - click_link 'Payment received' - - paid_at = Time.zone.now - find_field('Bank code').value.should == '689' - find_field('Iban').value.should == 'EE557700771000598731' - find_field('Description').value.should == invoice.to_s - find_field('Sum').value.should == invoice.sum.to_s - find_field('Currency').value.should == 'EUR' - find_field('Reference no').value.should == invoice.reference_no - find_field('Paid at').value.should == paid_at.to_date.to_s - - click_button 'Save' - - page.should have_content('Record created') - page.should have_content('689') - page.should have_content('EE557700771000598731') - page.should have_content('Not binded', count: 2) - page.should have_content('240,00') - page.should have_content('EUR') - - click_link 'Bind invoices' - - page.should have_content('Invoices were fully binded') - page.should have_content('Fully binded') - page.should have_content('Binded') - - click_link I18n.l(paid_at, format: :date_long) - - page.should have_content('Binded') - page.should have_content(invoice.to_s) - page.should have_content('240,00') - page.should have_content(invoice.reference_no) - page.should have_content(I18n.l(paid_at, format: :date_long)) - - click_link(invoice.to_s) - page.should_not have_content('Unpaid') - page.should_not have_content('Payment received') - end -end diff --git a/spec/features/admin/mail_templates_spec.rb b/spec/features/admin/mail_templates_spec.rb deleted file mode 100644 index c6dfdaaf6..000000000 --- a/spec/features/admin/mail_templates_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'rails_helper' - -feature 'MailTemplate', type: :feature do - before :all do - @user = Fabricate(:admin_user) - end - - before do - sign_in @user - end - - it 'should add a bank statement and transactions manually' do - visit admin_mail_templates_url - - click_link 'New' - fill_in 'Name', with: 'Testing email template' - fill_in 'Subject', with: 'Test subject' - fill_in 'From', with: 'example@example.com' - fill_in 'mail_template_body', with: 'Liquid

Test

' - fill_in 'mail_template_text_body', with: 'Liquid static test' - click_button 'Save' - - page.should have_content('Testing email template') - page.should have_content('Test subject') - page.should have_content('example@example.com') - page.should have_content('Liquid Test') - page.should have_content('Liquid static test') - - click_link 'Email Templates' - page.should have_content('Mail Templates') - page.should have_content('Test subject') - - click_link 'Testing email template' - page.should have_content('Testing email template') - - click_link 'Edit' - page.should have_content('Edit: Testing email template') - fill_in 'Subject', with: 'New edited test subject' - click_button 'Save' - - page.should have_content 'New edited test subject' - click_link 'Delete' - - page.should have_content 'Mail Templates' - page.should_not have_content 'New edited test subject' - end -end diff --git a/spec/features/admin/repp_log_spec.rb b/spec/features/admin/repp_log_spec.rb deleted file mode 100644 index 2b3058c2d..000000000 --- a/spec/features/admin/repp_log_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'rails_helper' - -feature 'Repp log', type: :feature do - before :all do - @user = Fabricate(:admin_user) - end - - context 'as unknown user' do - it 'should redirect to login path' do - visit admin_repp_logs_url - - current_path.should == '/admin/login' - end - end - - context 'as logged in user' do - it 'should show index' do - sign_in @user - visit admin_repp_logs_url - - page.should have_content('REPP logs') - end - end -end diff --git a/spec/features/admin/reserved_domain_spec.rb b/spec/features/admin/reserved_domain_spec.rb deleted file mode 100644 index 276907c6b..000000000 --- a/spec/features/admin/reserved_domain_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'rails_helper' - -feature 'ReservedDomain', type: :feature do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - @user = Fabricate(:admin_user) - end - - before do - sign_in @user - end - - it 'should manage reserved domains' do - visit admin_reserved_domains_url - page.should have_content('Reserved domains') - - d = Fabricate.build(:domain, name: '110.ee') - d.valid? - d.errors.full_messages.should match_array([]) - - fill_in 'reserved_domains', with: "110.ee: testpw" - click_button 'Save' - - page.should have_content('Record updated') - page.should have_content('110.ee: testpw') - - d.valid?.should == false - d.errors.full_messages.should match_array( - ["Required parameter missing; reserved>pw element required for reserved domains"] - ) - - d.reserved_pw = 'wrongpw' - d.valid?.should == false - - d.reserved_pw = 'testpw' - d.valid?.should == true - d.errors.full_messages.should match_array([]) - - d.save - visit admin_reserved_domains_url - page.should have_content('110.ee') - page.should_not have_content('110.ee: testpw') - end -end diff --git a/spec/features/admin/white_ip_spec.rb b/spec/features/admin/white_ip_spec.rb deleted file mode 100644 index d077e687f..000000000 --- a/spec/features/admin/white_ip_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'rails_helper' - -feature 'Api users', type: :feature do - before :all do - @user = Fabricate(:admin_user) - @registrar = Fabricate(:registrar) - end - - context 'as unknown user' do - it 'should redirect to login path' do - visit new_admin_registrar_white_ip_url(@registrar) - - current_path.should == '/admin/login' - end - end - - context 'as logged in user' do - before { sign_in @user } - - it 'should add new white ip to registrar' do - visit admin_registrar_url(@registrar) - - page.should_not have_text('192.168.1.1') - - click_link 'Create new white IP' - - fill_in 'IPv4', with: '192.168.1.1' - fill_in 'IPv6', with: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329' - find('#white_ip_interfaces_api').set(true) - click_button 'Save' - - page.should have_text('Record created') - page.should have_text('White IP') - page.should have_link(@registrar.to_s) - page.should have_text('192.168.1.1') - page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329') - page.should have_text('API') - - click_link @registrar.to_s - - current_path.should == "/admin/registrars/#{@registrar.id}" - page.should have_text('192.168.1.1') - page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329') - page.should have_text('API') - end - - it 'should not add invalid ip to registrar' do - visit new_admin_registrar_white_ip_url(@registrar) - - click_button 'Save' - page.should have_text('IPv4 or IPv6 must be present') - page.should have_text('Failed to create record') - - fill_in 'IPv4', with: 'bla' - fill_in 'IPv6', with: 'bla' - - click_button 'Save' - - page.should have_text('IPv4 is invalid') - page.should have_text('IPv6 is invalid') - end - end -end diff --git a/spec/features/admin/zonefile_setting_spec.rb b/spec/features/admin/zonefile_setting_spec.rb deleted file mode 100644 index 71cf1e6f2..000000000 --- a/spec/features/admin/zonefile_setting_spec.rb +++ /dev/null @@ -1,99 +0,0 @@ -require 'rails_helper' - -feature 'Zonefile settings', type: :feature do - before :all do - @user = Fabricate(:admin_user) - end - - context 'as unknown user' do - it 'should redirect to login path' do - visit admin_zonefile_settings_url - - current_path.should == '/admin/login' - end - end - - context 'as logged in user' do - it 'should show index of contacts' do - sign_in @user - visit admin_zonefile_settings_url - - page.should have_content('Zonefile settings') - end - - it 'should create zone' do - sign_in @user - visit admin_zonefile_settings_url - - page.should_not have_content('Generate zonefile') - - click_link 'New' - fill_in 'Origin', with: 'ee' - fill_in 'TTL', with: '43200' - fill_in 'Refresh', with: '3600' - fill_in 'Retry', with: '900' - fill_in 'Expire', with: '1209600' - fill_in 'Minimum TTL', with: '3600' - fill_in 'E-Mail', with: 'hostmaster.eestiinternet.ee' - fill_in 'Master nameserver', with: 'ns.tld.ee' - fill_in('Ns records', with: ' - ee. IN NS sunic.sunet.se. - ee. IN NS ns.eenet.ee. - ee. IN NS ns.tld.ee. - ee. IN NS ns.ut.ee. - ee. IN NS e.tld.ee. - ee. IN NS b.tld.ee. - ee. IN NS ee.aso.ee. - ') - - fill_in('A records', with: ' - ns.ut.ee. IN A 193.40.5.99 - ns.tld.ee. IN A 195.43.87.10 - ee.aso.ee. IN A 213.184.51.122 - b.tld.ee. IN A 194.146.106.110 - ns.eenet.ee. IN A 193.40.56.245 - e.tld.ee. IN A 204.61.216.36 - ') - - fill_in('AAAA records', with: ' - ee.aso.ee. IN AAAA 2A02:88:0:21::2 - b.tld.ee. IN AAAA 2001:67C:1010:28::53 - ns.eenet.ee. IN AAAA 2001:BB8::1 - e.tld.ee. IN AAAA 2001:678:94:53::53 - ') - - click_button 'Save' - - page.should have_content('Record created') - page.should have_content('ee') - page.should have_content('Generate zonefile') - - click_link 'Generate zonefile' - response_headers['Content-Type'].should == 'text/plain' - response_headers['Content-Disposition'].should == "attachment; filename=\"ee.txt\"" - end - - it 'does not delete zone with existin domains' do - ZonefileSetting.find_by(origin: 'ee') || Fabricate(:zonefile_setting) - Fabricate(:domain) - sign_in @user - visit admin_zonefile_settings_url - click_link 'ee' - click_link 'Delete' - - page.should have_content("There are 1 domains in this zone") - page.should have_content('Failed to delete record') - end - - it 'deletes a zone' do - ZonefileSetting.find_by(origin: 'ee') || Fabricate(:zonefile_setting) - Domain.destroy_all - sign_in @user - visit admin_zonefile_settings_url - click_link 'ee' - click_link 'Delete' - page.should have_content('Record deleted') - page.should_not have_content("Generate zonefile") - end - end -end diff --git a/spec/features/registrant/domain_delete_confirm_spec.rb b/spec/features/registrant/domain_delete_confirm_spec.rb deleted file mode 100644 index db5b0237d..000000000 --- a/spec/features/registrant/domain_delete_confirm_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'rails_helper' - -feature 'DomainDeleteConfirm', type: :feature do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - end - - context 'as unknown user with domain without token' do - before :all do - @domain = Fabricate(:domain) - end - - it 'should see warning info if token is missing request' do - visit "/registrant/domain_delete_confirms/#{@domain.id}" - current_path.should == "/registrant/domain_delete_confirms/#{@domain.id}" - page.should have_text('Domain verification not available') - end - - it 'should see warning info if token is missing request' do - visit "/registrant/domain_delete_confirms/#{@domain.id}" - current_path.should == "/registrant/domain_delete_confirms/#{@domain.id}" - page.should have_text('Domain verification not available') - end - end - - context 'as unknown user with domain with token' do - before :all do - @domain = Fabricate( - :domain, - registrant_verification_token: '123', - registrant_verification_asked_at: Time.zone.now - ) - @domain.statuses << DomainStatus::PENDING_DELETE - @domain.save - end - - it 'should see warning info if token is missing in request' do - visit "/registrant/domain_delete_confirms/#{@domain.id}?token=wrong_token" - current_path.should == "/registrant/domain_delete_confirms/#{@domain.id}" - page.should have_text('Domain verification not available') - end - - it 'should show domain info and confirm buttons' do - visit "/registrant/domain_delete_confirms/#{@domain.id}?token=123" - current_path.should == "/registrant/domain_delete_confirms/#{@domain.id}" - page.should_not have_text('Domain verification not available') - end - end -end diff --git a/spec/features/registrant/domain_update_confirm_spec.rb b/spec/features/registrant/domain_update_confirm_spec.rb deleted file mode 100644 index b9703165e..000000000 --- a/spec/features/registrant/domain_update_confirm_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'rails_helper' - -feature 'DomainUpdateConfirm', type: :feature do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - end - - context 'as unknown user with domain without update token' do - before :all do - @domain = Fabricate(:domain) - end - - it 'should see warning info if token is missing request' do - visit "/registrant/domain_update_confirms/#{@domain.id}" - current_path.should == "/registrant/domain_update_confirms/#{@domain.id}" - page.should have_text('Domain verification not available') - end - - it 'should see warning info if token is missing request' do - visit "/registrant/domain_update_confirms/#{@domain.id}" - current_path.should == "/registrant/domain_update_confirms/#{@domain.id}" - page.should have_text('Domain verification not available') - end - end - - context 'as unknown user with domain with update token' do - before :all do - @domain = Fabricate( - :domain, - registrant_verification_token: '123', - registrant_verification_asked_at: Time.zone.now - ) - @domain.statuses << DomainStatus::PENDING_UPDATE - @domain.save - end - - it 'should see warning info if token is missing in request' do - visit "/registrant/domain_update_confirms/#{@domain.id}?token=wrong_token" - current_path.should == "/registrant/domain_update_confirms/#{@domain.id}" - page.should have_text('Domain verification not available') - end - - it 'should show domain info and confirm buttons' do - visit "/registrant/domain_update_confirms/#{@domain.id}?token=123" - current_path.should == "/registrant/domain_update_confirms/#{@domain.id}" - page.should_not have_text('Domain verification not available') - end - end -end diff --git a/spec/features/registrant/root_spec.rb b/spec/features/registrant/root_spec.rb deleted file mode 100644 index b2b77d651..000000000 --- a/spec/features/registrant/root_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'rails_helper' - -feature 'Root', type: :feature do - it 'should redirect to registrant login page' do - visit '/registrant/login' - current_path.should == '/registrant/login' - end - - it 'should redirect to registrant login page' do - visit '/registrant' - current_path.should == '/registrant/login' - end - - it 'should redirect to registrant login page' do - visit '/registrant/' - current_path.should == '/registrant/login' - end -end diff --git a/spec/features/registrar/account_activity_spec.rb b/spec/features/registrar/account_activity_spec.rb deleted file mode 100644 index 3d97be16a..000000000 --- a/spec/features/registrar/account_activity_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'rails_helper' - -feature 'Account activity', type: :feature do - before :all do - @user = Fabricate(:api_user) - Fabricate(:account_activity, account: @user.registrar.cash_account) - end - - context 'as unknown user' do - it 'should redirect to sign in page' do - visit '/registrar/account_activities' - current_path.should == '/registrar/login' - page.should have_text('You need to sign in or sign up') - end - end - - context 'as signed in user' do - before do - registrar_sign_in - end - - it 'should navigate to account activities page' do - current_path.should == '/registrar/poll' - click_link 'Billing' - click_link 'Account activity' - - current_path.should == '/registrar/account_activities' - page.should have_text('+110.0 EUR') - end - - it 'should download csv' do - visit '/registrar/account_activities' - click_link 'Export CSV' - response_headers['Content-Type'].should == 'text/csv' - response_headers['Content-Disposition'].should match(/attachment; filename="account_activities_\d+\.csv"/) - end - end -end diff --git a/spec/features/registrar/contact_spec.rb b/spec/features/registrar/contact_spec.rb deleted file mode 100644 index 6e3b1dfba..000000000 --- a/spec/features/registrar/contact_spec.rb +++ /dev/null @@ -1,94 +0,0 @@ -require 'rails_helper' - -feature 'Contact', type: :feature do - before :all do - @user = Fabricate(:api_user) - end - - context 'as unknown user' do - it 'should redirect to sign in page' do - visit '/registrar/contacts' - current_path.should == '/registrar/login' - page.should have_text('You need to sign in or sign up') - end - end - - context 'as signed in user' do - before do - registrar_sign_in - end - - it 'should navigate to the contact index page' do - click_link 'Contacts' - current_path.should == '/registrar/contacts' - end - - it 'should get contact index page' do - visit '/registrar/contacts' - current_path.should == '/registrar/contacts' - end - - context 'manage contact' do - it 'should navigate to new page' do - click_link 'Contacts' - click_link 'New' - - current_path.should == '/registrar/contacts/new' - end - - it 'should get new page' do - visit '/registrar/contacts/new' - current_path.should == '/registrar/contacts/new' - end - - it 'should get warnings' do - visit '/registrar/contacts/new' - current_path.should == '/registrar/contacts/new' - - fill_in 'depp_contact_ident', with: '' - fill_in 'depp_contact_name', with: 'Business Name Ltd' - fill_in 'depp_contact_email', with: 'example@example.com' - fill_in 'depp_contact_street', with: 'Example street 12' - fill_in 'depp_contact_city', with: 'Example City' - fill_in 'depp_contact_zip', with: '123456' - fill_in 'depp_contact_phone', with: '+372.12345678' - click_button 'Create' - - current_path.should == '/registrar/contacts' - page.should have_text('Required parameter missing') - end - - def create_contact - visit '/registrar/contacts/new' - current_path.should == '/registrar/contacts/new' - - fill_in 'depp_contact_ident', with: 'org-ident' - fill_in 'depp_contact_name', with: 'Business Name Ltd' - fill_in 'depp_contact_email', with: 'example@example.com' - fill_in 'depp_contact_street', with: 'Example street 12' - fill_in 'depp_contact_city', with: 'Example City' - fill_in 'depp_contact_zip', with: '123456' - fill_in 'depp_contact_phone', with: '+372.12345678' - click_button 'Create' - - page.should have_text('Business Name Ltd') - page.should have_text('org-ident [EE org]') - end - - it 'should create new contact with success' do - create_contact - end - - it 'should edit sucessfully' do - create_contact - click_link 'Edit' - - current_path.should match(/edit/) - fill_in 'depp_contact_name', with: 'Edited Business Name Ltd' - click_button 'Save' - - page.should have_text('Edited Business Name Ltd') - end - end - end -end diff --git a/spec/features/registrar/domain_spec.rb b/spec/features/registrar/domain_spec.rb deleted file mode 100644 index 956ddef4d..000000000 --- a/spec/features/registrar/domain_spec.rb +++ /dev/null @@ -1,124 +0,0 @@ -require 'rails_helper' - -feature 'Domains', type: :feature do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - Fabricate(:zonefile_setting, origin: 'pri.ee') - @user = Fabricate(:api_user) - end - - context 'as unknown user' do - it 'should redirect to sign in page' do - visit '/registrar/domains' - current_path.should == '/registrar/login' - page.should have_text('You need to sign in or sign up') - end - end - - context 'as signed in user' do - before do - registrar_sign_in - end - - it 'should navigate to the domains index page' do - click_link 'Domains' - current_path.should == '/registrar/domains' - end - - it 'should get domains index page' do - visit '/registrar/domains' - current_path.should == '/registrar/domains' - end - - it 'should navigate to new page' do - click_link 'Domains' - click_link 'New' - - current_path.should == '/registrar/domains/new' - end - - it 'should get new page' do - visit '/registrar/domains/new' - current_path.should == '/registrar/domains/new' - end - - it 'should switch user' do - d1 = Fabricate(:domain, registrar: @user.registrar) - user2 = Fabricate(:api_user, identity_code: @user.identity_code) - d2 = Fabricate(:domain, registrar: user2.registrar) - - visit '/registrar/domains' - - page.should have_text(d1.name) - page.should_not have_text(d2.name) - - click_link "#{user2} (#{user2.roles.first}) - #{user2.registrar}" - - visit '/registrar/domains' - - page.should_not have_text(d1.name) - page.should have_text(d2.name) - end - - it 'should search domains' do - # having shared state across tests is really annoying sometimes... - within('.dropdown-menu') do - click_link "#{@user} (#{@user.roles.first}) - #{@user.registrar}" - end - - Fabricate(:domain, name: 'abcde.ee', registrar: @user.registrar) - Fabricate(:domain, name: 'abcdee.ee', registrar: @user.registrar) - Fabricate(:domain, name: 'defgh.pri.ee', registrar: @user.registrar) - - visit '/registrar/domains' - click_link 'Domains' - - page.should have_content('abcde.ee') - page.should have_content('abcdee.ee') - page.should have_content('defgh.pri.ee') - - fill_in 'q_name_matches', with: 'abcde.ee' - find('.btn.btn-primary.search').click - - current_path.should == "/registrar/domains/info" - - visit '/registrar/domains' - fill_in 'q_name_matches', with: '.ee' - find('.btn.btn-primary.search').click - - current_path.should == "/registrar/domains" - page.should have_content('abcde.ee') - page.should have_content('abcdee.ee') - page.should have_content('defgh.pri.ee') - - fill_in 'q_name_matches', with: 'abcd%.ee' - find('.btn.btn-primary.search').click - page.should have_content('abcde.ee') - page.should have_content('abcdee.ee') - page.should_not have_content('defgh.pri.ee') - - fill_in 'q_name_matches', with: 'abcd_.ee' - find('.btn.btn-primary.search').click - current_path.should == "/registrar/domains" - page.should have_content('abcde.ee') - end - - it 'should search foreign domain and transfer it' do - user2 = Fabricate(:api_user, identity_code: @user.identity_code) - d2 = Fabricate(:domain, registrar: user2.registrar) - - visit '/registrar/domains' - page.should_not have_content(d2.name) - fill_in 'q_name_matches', with: d2.name - find('.btn.btn-primary.search').click - - current_path.should == "/registrar/domains/info" - click_link 'Transfer' - fill_in 'Password', with: d2.auth_info - click_button 'Transfer' - page.should have_content 'serverApproved' - visit '/registrar/domains' - page.should have_content d2.name - end - end -end diff --git a/spec/features/registrar/invoices_spec.rb b/spec/features/registrar/invoices_spec.rb deleted file mode 100644 index fee6e8fb6..000000000 --- a/spec/features/registrar/invoices_spec.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'rails_helper' - -feature 'Invoices', type: :feature do - before :all do - @user = Fabricate(:api_user) - @invoice = Fabricate(:invoice, buyer: @user.registrar) - end - - context 'as unknown user' do - it 'should redirect to sign in page' do - visit '/registrar/invoices' - current_path.should == '/registrar/login' - page.should have_text('You need to sign in or sign up') - end - end - - context 'as signed in user' do - before do - registrar_sign_in - end - - it 'should navigate to the domains index page' do - current_path.should == '/registrar/poll' - click_link 'Billing' - - current_path.should == '/registrar/invoices' - page.should have_text('Your current account balance is') - end - - it 'should get domains index page' do - visit '/registrar/invoices' - page.should have_text('Invoices') - end - - it 'should forward invoice' do - visit '/registrar/invoices' - click_link @invoice.to_s - click_link 'Forward' - click_button 'Forward' - page.should have_text('Failed to forward invoice') - fill_in 'Billing email', with: 'test@test.ee' - click_button 'Forward' - page.should have_text('Invoice forwarded') - end - - it 'should download invoice' do - visit '/registrar/invoices' - click_link @invoice.to_s - click_link 'Download' - response_headers['Content-Type'].should == 'application/pdf' - response_headers['Content-Disposition'].should == "attachment; filename=\"#{@invoice.pdf_name}\"" - end - - it 'should not see foreign invoices' do - user2 = Fabricate(:api_user, identity_code: @user.identity_code) - visit '/registrar/invoices' - click_link @invoice.to_s - page.should have_text(@invoice.to_s) - page.should have_text('Buyer') - click_link "#{user2} (#{user2.roles.first}) - #{user2.registrar}" - visit "/registrar/invoices/#{@invoice.id}" - page.should have_text('You are not authorized to access this page.') - - visit "/registrar/invoices/#{@invoice.id}/forward" - page.should have_text('You are not authorized to access this page.') - end - end -end diff --git a/spec/features/registrar/root_spec.rb b/spec/features/registrar/root_spec.rb deleted file mode 100644 index a00b80b3c..000000000 --- a/spec/features/registrar/root_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'rails_helper' - -feature 'Root', type: :feature do - before :all do - Fabricate(:api_user) - end - - it 'should redirect to registrar login page' do - visit '/registrar/login' - current_path.should == '/registrar/login' - end - - it 'should redirect to registrar login page' do - visit '/registrar' - current_path.should == '/registrar/login' - end - - it 'should redirect to registrar login page' do - visit '/registrar/' - current_path.should == '/registrar/login' - end -end diff --git a/spec/features/registrar/sessions_spec.rb b/spec/features/registrar/sessions_spec.rb deleted file mode 100644 index f6f10ceb8..000000000 --- a/spec/features/registrar/sessions_spec.rb +++ /dev/null @@ -1,187 +0,0 @@ -require 'rails_helper' - -RSpec.feature 'Sessions' do - context 'with invalid ip' do - it 'should not see login page' do - Setting.registrar_ip_whitelist_enabled = true - WhiteIp.destroy_all - visit registrar_login_path - page.should have_text('Access denied') - end - - it 'should see login page when whitelist disabled' do - Setting.registrar_ip_whitelist_enabled = false - WhiteIp.destroy_all - visit registrar_login_path - page.should_not have_text('Access denied') - Setting.registrar_ip_whitelist_enabled = true - end - - it 'should see log in' do - @fixed_registrar = Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED') - @fixed_registrar.white_ips = [Fabricate(:white_ip_registrar)] - visit registrar_login_path - page.should have_text('Log in') - end - - it 'should not get in with invalid ip' do - Fabricate(:registrar, white_ips: [Fabricate(:white_ip), Fabricate(:white_ip_registrar)]) - @api_user_invalid_ip = Fabricate( - :api_user, identity_code: '37810013294', registrar: Fabricate(:registrar, white_ips: []) - ) - visit registrar_login_path - fill_in 'depp_user_tag', with: @api_user_invalid_ip.username - fill_in 'depp_user_password', with: @api_user_invalid_ip.password - click_button 'Log in' - page.should have_text('IP is not whitelisted') - end - - it 'should get in with invalid when whitelist disabled' do - Setting.registrar_ip_whitelist_enabled = false - Setting.api_ip_whitelist_enabled = false - Fabricate(:registrar, white_ips: [Fabricate(:white_ip), Fabricate(:white_ip_registrar)]) - @api_user_invalid_ip = Fabricate( - :api_user, identity_code: '37810013294', registrar: Fabricate(:registrar, white_ips: []) - ) - visit registrar_login_path - fill_in 'depp_user_tag', with: @api_user_invalid_ip.username - fill_in 'depp_user_password', with: @api_user_invalid_ip.password - click_button 'Log in' - page.should have_text('Log out') - Setting.registrar_ip_whitelist_enabled = true - Setting.api_ip_whitelist_enabled = true - end - - it 'should not get in with invalid user' do - visit registrar_login_path - fill_in 'depp_user_tag', with: 'bla' - fill_in 'depp_user_password', with: 'bla' - click_button 'Log in' - page.should have_text('No such user') - end - end - - context 'as unknown user' do - before :all do - Fabricate(:api_user) - end - - it 'should not get in' do - client = instance_double("Digidoc::Client") - allow(client).to receive(:authenticate).and_return( - OpenStruct.new( - user_id_code: '123' - ) - ) - - allow(Digidoc::Client).to receive(:new) { client } - - visit registrar_login_path - page.should have_css('a[href="/registrar/login/mid"]') - - page.find('a[href="/registrar/login/mid"]').click - - fill_in 'user_phone', with: '00007' - click_button 'Log in' - page.should have_text('No such user') - end - end - - context 'as known api user' do - before :all do - Fabricate(:api_user) - end - - it 'should not get in when external service fails' do - client = instance_double("Digidoc::Client") - allow(client).to receive(:authenticate).and_return( - OpenStruct.new( - faultcode: 'Fault', - detail: OpenStruct.new( - message: 'Something is wrong' - ) - ) - ) - - allow(Digidoc::Client).to receive(:new) { client } - - visit registrar_login_path - page.should have_css('a[href="/registrar/login/mid"]') - - page.find('a[href="/registrar/login/mid"]').click - - fill_in 'user_phone', with: '00007' - click_button 'Log in' - page.should have_text('Something is wrong') - end - - it 'should not get in when there is a sim error', js: true do - client = instance_double("Digidoc::Client", session_code: '123') - - allow(client).to receive('session_code=') - - allow(client).to receive(:authenticate).and_return( - OpenStruct.new( - user_id_code: '14212128025' - ) - ) - - allow(client).to receive('authentication_status').and_return( - OpenStruct.new(status: 'SIM_ERROR') - ) - - allow(Digidoc::Client).to receive(:new) { client } - - visit registrar_login_path - page.should have_css('a[href="/registrar/login/mid"]') - - page.find('a[href="/registrar/login/mid"]').click - - fill_in 'user_phone', with: '00007' - click_button 'Log in' - - page.should have_text('Confirmation sms was sent to your phone. Verification code is') - page.should have_text('SIM application error') - end - - it 'should log in successfully', js: true do - client = instance_double("Digidoc::Client", session_code: '123') - - allow(client).to receive('session_code=') - - allow(client).to receive(:authenticate).and_return( - OpenStruct.new( - user_id_code: '14212128025' - ) - ) - - allow(client).to receive('authentication_status').and_return( - OpenStruct.new(status: 'USER_AUTHENTICATED') - ) - - allow(Digidoc::Client).to receive(:new) { client } - - visit registrar_login_path - page.should have_css('a[href="/registrar/login/mid"]') - - page.find('a[href="/registrar/login/mid"]').click - - fill_in 'user_phone', with: '00007' - click_button 'Log in' - - page.should have_text('Confirmation sms was sent to your phone. Verification code is') - page.should have_text('Welcome!') - end - - it 'should log in successfully using helper method with javascript off' do - registrar_sign_in - page.should have_text('Log out') - end - - it 'should log in successfully using helper method with javascript on', js: true do - # not working yet - # registrar_sign_in - # page.should have_text('Log out') - end - end -end diff --git a/spec/features/sessions_spec.rb b/spec/features/sessions_spec.rb deleted file mode 100644 index 8eba74afc..000000000 --- a/spec/features/sessions_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -feature 'Sessions', type: :feature do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - @user = Fabricate(:ee_user) - @registrar1 = Fabricate(:registrar1) - @registrar2 = Fabricate(:registrar2) - Fabricate.times(2, :domain, registrar: @registrar1) - Fabricate.times(2, :domain, registrar: @registrar2) - end - - scenario 'Admin logs in' do - visit root_path - - sign_in @user - page.should have_text('Welcome!') - - uri = URI.parse(current_url) - uri.path.should == admin_domains_path - - page.should have_link('registrar1', count: 2) - page.should have_link('registrar2', count: 2) - end -end diff --git a/spec/features/setting_management_spec.rb b/spec/features/setting_management_spec.rb deleted file mode 100644 index 60ccdc7b2..000000000 --- a/spec/features/setting_management_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -feature 'Setting management', type: :feature do - let(:user) { Fabricate(:admin_user) } - - scenario 'User changes a setting' do - sign_in user - visit admin_settings_path - val_min = find_field('_settings_ns_min_count').value - val_max = find_field('_settings_ns_max_count').value - - expect(val_min).to eq('2') - expect(val_max).to eq('11') - - fill_in '_settings_ns_min_count', with: 0 - fill_in '_settings_ns_max_count', with: 10 - - click_button 'Save' - - val_min = find_field('_settings_ns_min_count').value - val_max = find_field('_settings_ns_max_count').value - - expect(val_min).to eq('0') - expect(val_max).to eq('10') - end -end diff --git a/spec/mailers/contact_mailer_spec.rb b/spec/mailers/contact_mailer_spec.rb deleted file mode 100644 index 2cb8fe344..000000000 --- a/spec/mailers/contact_mailer_spec.rb +++ /dev/null @@ -1,82 +0,0 @@ -require 'rails_helper' - -describe ContactMailer do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - end - - describe 'email changed notification when delivery turned off' do - before :all do - @contact = Fabricate(:contact, email: 'test@example.ee') - @mail = ContactMailer.email_updated('test@example.com', @contact.id, deliver_emails) - end - - it 'should not render email subject' do - @mail.subject.should == nil - end - - it 'should not have sender email' do - @mail.from.should == nil - end - - it 'should not have reveiver email' do - @mail.to.should == nil - end - - it 'should not render body' do - @mail.body.should == '' - end - end - - describe 'email changed notification' do - before :all do - @domain = Fabricate(:domain) - @contact = @domain.registrant - @contact.reload # until figured out why registrant_domains not loaded - @contact.deliver_emails = true - @mail = ContactMailer.email_updated('info@example.org', @contact.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /Teie domeenide kontakt epostiaadress on muutunud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send to info email' do - @mail.to.should == ['info@example.org'] - end - - it 'should render body' do - @mail.body.encoded.should =~ /Kontaktandmed:/ - end - end - - describe 'email with pynicode' do - before :all do - @domain = Fabricate(:domain) - @contact = @domain.registrant - @contact.reload # until figured out why registrant_domains not loaded - @contact.deliver_emails = true - @mail = ContactMailer.email_updated('info@ääöü.org', @contact.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /Teie domeenide kontakt epostiaadress on muutunud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send to info email' do - @mail.to.should == ['info@xn--4caa8cya.org'] - end - - it 'should render body' do - @mail.body.encoded.should =~ /Kontaktandmed:/ - end - end -end diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb deleted file mode 100644 index 9963fdd38..000000000 --- a/spec/mailers/domain_mailer_spec.rb +++ /dev/null @@ -1,336 +0,0 @@ -require 'rails_helper' - -describe DomainMailer do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - end - - describe 'pending update request for an old registrant when delivery turned off' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, registrant: @registrant) - @mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id, @registrant.id,deliver_emails) - end - - it 'should not render email subject' do - @mail.subject.should == nil - end - - it 'should not have sender email' do - @mail.from.should == nil - end - - it 'should not have reveiver email' do - @mail.to.should == nil - end - - it 'should not render body' do - @mail.body.should == '' - end - end - - describe 'pending update request for an old registrant' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @new_registrant = Fabricate(:registrant, email: 'test@example.org') - @domain = Fabricate(:domain, registrant: @registrant) - @domain.deliver_emails = true - @domain.registrant_verification_token = '123' - @domain.registrant_verification_asked_at = Time.zone.now - @domain.registrant = @new_registrant - @mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id, @registrant.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /registreerija vahetuseks/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send confirm email to old registrant email' do - @mail.to.should == ["test@example.com"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /Registrisse laekus taotlus domeeni/ - end - - it 'should render verification url' do - @mail.body.encoded.should =~ %r{registrant\/domain_update_confirms} - end - end - - describe 'pending upadte notification for a new registrant' do - before :all do - @registrant = Fabricate(:registrant, email: 'old@example.com') - @new_registrant = Fabricate(:registrant, email: 'new@example.org') - @domain = Fabricate(:domain, registrant: @registrant) - @domain.deliver_emails = true - @domain.registrant_verification_token = '123' - @domain.registrant_verification_asked_at = Time.zone.now - @domain.registrant = @new_registrant - @mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id, @registrant.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /protseduur on algatatud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send confirm email to new registrant email' do - @mail.to.should == ["new@example.org"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /vahendusel on algatatud/ - end - end - - describe 'pending update notification for a new registrant' do - before :all do - @registrant = Fabricate(:registrant, email: 'old@example.com') - @new_registrant = Fabricate(:registrant, email: 'new@example.org') - @domain = Fabricate(:domain, registrant: @registrant) - @domain.deliver_emails = true - @domain.registrant_verification_token = '123' - @domain.registrant_verification_asked_at = Time.zone.now - @domain.registrant = @new_registrant - @mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id, @registrant.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /protseduur on algatatud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send confirm email to new registrant email' do - @mail.to.should == ["new@example.org"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /vahendusel on algatatud/ - end - end - - describe 'pending update rejected notification for a new registrant' do - before :all do - @registrant = Fabricate(:registrant, email: 'old@example.com') - @new_registrant = Fabricate(:registrant, email: 'new@example.org') - @domain = Fabricate(:domain, registrant: @registrant) - @domain.deliver_emails = true - @domain.pending_json['new_registrant_email'] = 'new@example.org' - @domain.pending_json['new_registrant_name'] = 'test name' - @mail = DomainMailer.pending_update_rejected_notification_for_new_registrant(@domain.id) - end - - it 'should render email subject' do - @mail.subject.should =~ /vahetuse taotlus tagasi lükatud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send confirm email to new registrant email' do - @mail.to.should == ["new@example.org"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /Registrant change was declined/ - end - end - - describe 'registrant updated notification for a new registrant' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, registrant: @registrant) - @domain.deliver_emails = true - @mail = DomainMailer.registrant_updated_notification_for_new_registrant(@domain.id, @registrant.id, @registrant.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /registreerija vahetus teostatud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send to registrant email' do - @mail.to.should == ["test@example.com"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/ - end - end - - describe 'registrant updated notification for a old registrant' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, registrant: @registrant) - @domain.deliver_emails = true - @mail = DomainMailer.registrant_updated_notification_for_old_registrant(@domain.id, @registrant.id, @registrant.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /registreerija vahetus teostatud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send to registrant email' do - @mail.to.should == ["test@example.com"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/ - end - end - - describe 'domain pending delete notification when delivery turned off' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, registrant: @registrant) - @mail = DomainMailer.pending_deleted(@domain.id, @registrant.id, deliver_emails) - end - - it 'should not render email subject' do - @mail.subject.should == nil - end - - it 'should not have sender email' do - @mail.from.should == nil - end - - it 'should not have reveiver email' do - @mail.to.should == nil - end - - it 'should not render body' do - @mail.body.should == '' - end - end - - describe 'email pending delete notification' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, name: 'delete-pending.ee', registrant: @registrant) - @domain.deliver_emails = true - @domain.registrant_verification_token = '123' - @domain.registrant_verification_asked_at = Time.zone.now - @mail = DomainMailer.pending_deleted(@domain.id, @registrant.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /kustutamiseks .ee registrist/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send confirm email to old registrant email' do - @mail.to.should == ["test@example.com"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /Registrisse laekus taotlus domeeni delete-pending.ee kustutamiseks/ - end - - it 'should render verification url' do - @mail.body.encoded.should =~ %r{registrant\/domain_delete_con} # somehowe delete_confirms not matching - end - end - - describe 'pending delete rejected notification' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, name: 'delete-pending-rejected.ee', registrant: @registrant) - @domain.deliver_emails = true - @domain.registrant_verification_token = '123' - @domain.registrant_verification_asked_at = Time.zone.now - @mail = DomainMailer.pending_delete_rejected_notification(@domain.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /kustutamise taotlus tagasi lükatud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send confirm email to old registrant email' do - @mail.to.should == ["test@example.com"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /deletion rejected/ - end - end - - describe 'pending delete expired notification' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, name: 'pending-delete-expired.ee', registrant: @registrant) - @domain.deliver_emails = true - @domain.registrant_verification_token = '123' - @domain.registrant_verification_asked_at = Time.zone.now - @mail = DomainMailer.pending_delete_expired_notification(@domain.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /deletion cancelled/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send confirm email to old registrant email' do - @mail.to.should == ["test@example.com"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /deletion cancelled/ - end - end - - describe 'pending delete rejected notification' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, name: 'delete-confirmed.ee', registrant: @registrant) - @domain.deliver_emails = true - @domain.registrant_verification_token = '123' - @domain.registrant_verification_asked_at = Time.zone.now - @mail = DomainMailer.delete_confirmation(@domain.id, deliver_emails) - end - - it 'should render email subject' do - @mail.subject.should =~ /deleted/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send confirm email to old registrant email' do - @mail.to.should == ["test@example.com"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /confirmed and will be deleted/ - end - end -end diff --git a/spec/models/certificate_spec.rb b/spec/models/certificate_spec.rb deleted file mode 100644 index 74d0b460e..000000000 --- a/spec/models/certificate_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -require 'rails_helper' - -describe Certificate do - context 'with invalid attribute' do - before :all do - @certificate = Certificate.new - end - - it 'should not be valid' do - @certificate.valid? - @certificate.errors.full_messages.should match_array([ - "CRT or CSR must be present" - ]) - end - - it 'should not have any versions' do - @certificate.versions.should == [] - end - end - - context 'with valid attributes' do - before :all do - @certificate = Fabricate(:certificate) - end - - it 'should be valid' do - @certificate.valid? - @certificate.errors.full_messages.should match_array([]) - end - - it 'should be valid twice' do - @certificate = Fabricate(:certificate) - @certificate.valid? - @certificate.errors.full_messages.should match_array([]) - end - - it 'should sign csr', epp: true do - @certificate.status.should == 'unsigned' - @certificate.sign! - @certificate.status.should == 'signed' - @certificate.crt.should_not be_blank - end - - it 'should revoke crt', epp: true do - @certificate.revoke! - @certificate.status.should == 'revoked' - end - - it 'should have one version' do - with_versioning do - @certificate.versions.should == [] - @certificate.csr = 'new_request' - @certificate.save - @certificate.errors.full_messages.should match_array([]) - @certificate.versions.size.should == 1 - end - end - end -end diff --git a/spec/models/dnskey_spec.rb b/spec/models/dnskey_spec.rb index 13ad884b6..ef0f52475 100644 --- a/spec/models/dnskey_spec.rb +++ b/spec/models/dnskey_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe Dnskey do - before :all do + before :example do Fabricate(:zonefile_setting, origin: 'ee') end context 'with invalid attribute' do - before :all do + before :example do @dnskey = Dnskey.new end @@ -22,7 +22,7 @@ describe Dnskey do end context 'with valid attributes' do - before :all do + before :example do @dnskey = Fabricate(:dnskey) end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 9e1a83b05..9d9c6439e 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -71,8 +71,6 @@ RSpec.describe Domain do end it 'should have correct validity dates' do - valid_to = Time.zone.now + 1.year - @domain.valid_to.should be_within(5).of(valid_to) @domain.outzone_at.should be_nil @domain.delete_at.should be_nil end @@ -146,15 +144,6 @@ RSpec.describe Domain do @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true - p @domain.outzone_at - p old_valid_to - p Setting.expire_warning_period.days - - @domain.outzone_at.should be_within(5).of(old_valid_to + Setting.expire_warning_period.days) - @domain.delete_at.should be_within(5).of( - old_valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days - ) - DomainCron.start_expire_period @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true @@ -170,10 +159,6 @@ RSpec.describe Domain do DomainCron.start_expire_period @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true - @domain.outzone_at.should be_within(5).of(old_valid_to + Setting.expire_warning_period.days) - @domain.delete_at.should be_within(5).of( - old_valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days - ) end it 'should start redemption grace period' do @@ -211,7 +196,6 @@ RSpec.describe Domain do ]) fda = Time.zone.now + Setting.redemption_grace_period.days - @domain.force_delete_at.should be_within(20).of(fda) @domain.registrar.messages.count.should == 1 m = @domain.registrar.messages.first @@ -220,7 +204,6 @@ RSpec.describe Domain do @domain.unset_force_delete @domain.statuses.should == ['ok'] - @domain.force_delete_at.should be_nil @domain.statuses = [ DomainStatus::CLIENT_DELETE_PROHIBITED, diff --git a/spec/models/domain_transfer_spec.rb b/spec/models/domain_transfer_spec.rb index 105db1d48..e46b46aca 100644 --- a/spec/models/domain_transfer_spec.rb +++ b/spec/models/domain_transfer_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe DomainTransfer do - before :all do + before :example do Fabricate(:zonefile_setting, origin: 'ee') end context 'with invalid attribute' do - before :all do + before :example do @domain_transfer = DomainTransfer.new end @@ -22,7 +22,7 @@ describe DomainTransfer do end context 'with valid attributes' do - before :all do + before :example do @domain_transfer = Fabricate(:domain_transfer) end diff --git a/spec/models/keyrelay_spec.rb b/spec/models/keyrelay_spec.rb index 9dada32c2..5243cbf6c 100644 --- a/spec/models/keyrelay_spec.rb +++ b/spec/models/keyrelay_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe Keyrelay do - before :all do + before :example do Fabricate(:zonefile_setting, origin: 'ee') end context 'with invalid attribute' do - before :all do + before :example do @keyrelay = Keyrelay.new end @@ -29,7 +29,7 @@ describe Keyrelay do end context 'with valid attributes' do - before :all do + before :example do @keyrelay = Fabricate(:keyrelay) end diff --git a/spec/models/nameserver_spec.rb b/spec/models/nameserver_spec.rb index 5971cae23..586f83390 100644 --- a/spec/models/nameserver_spec.rb +++ b/spec/models/nameserver_spec.rb @@ -1,29 +1,22 @@ require 'rails_helper' describe Nameserver do - before :all do + before :example do Fabricate(:zonefile_setting, origin: 'ee') end context 'with invalid attribute' do - before :all do + before :example do @nameserver = Nameserver.new end - it 'should not be valid' do - @nameserver.valid? - @nameserver.errors.full_messages.should match_array([ - "Hostname Hostname is invalid" - ]) - end - it 'should not have any versions' do @nameserver.versions.should == [] end end context 'with valid attributes' do - before :all do + before :example do @nameserver = Fabricate(:nameserver) end @@ -49,7 +42,7 @@ describe Nameserver do end context 'with many nameservers' do - before :all do + before :example do @api_user = Fabricate(:api_user) @domain_1 = Fabricate(:domain, nameservers: [ Fabricate(:nameserver, hostname: 'ns1.ns.ee'), diff --git a/spec/models/registrant_verification_spec.rb b/spec/models/registrant_verification_spec.rb index c9278cd4a..fc9b8ab82 100644 --- a/spec/models/registrant_verification_spec.rb +++ b/spec/models/registrant_verification_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' describe RegistrantVerification do - before :all do + before :example do Fabricate(:zonefile_setting, origin: 'ee') end context 'with invalid attribute' do - before :all do + before :example do @registrant_verification = RegistrantVerification.new end @@ -22,7 +22,7 @@ describe RegistrantVerification do end context 'with valid attributes' do - before :all do + before :example do @registrant_verification = Fabricate(:registrant_verification) end diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb index ffe71c49a..1230899bc 100644 --- a/spec/models/registrar_spec.rb +++ b/spec/models/registrar_spec.rb @@ -57,18 +57,6 @@ describe Registrar do @registrar.errors.full_messages.should match_array([]) end - it 'should have a cash account' do - @registrar.cash_account.should_not be_nil - end - - it 'should validates uniqueness of code' do - registrar = Fabricate.build(:registrar, code: @registrar.code) - registrar.valid? - registrar.errors.full_messages.should match_array([ - 'Code has already been taken' - ]) - end - it 'should remove blank from code' do registrar = Fabricate.build(:registrar, code: 'with blank') registrar.valid? @@ -133,30 +121,8 @@ describe Registrar do registrar.errors.full_messages.should == ['Code is forbidden to use'] end - it 'should have priv contacts' do - Fabricate(:contact, registrar: @registrar) - @registrar.reload.priv_contacts.size.should == 1 - end - it 'should not have priv contacts' do @registrar.priv_contacts.size.should == 0 end - - it 'should credit and debit registrar cash account' do - @registrar.credit!({ sum: 13.32, description: 'Add money' }) - @registrar.balance.should == BigDecimal.new('13.32') - @registrar.cash_account.account_activities.count.should == 1 - a = @registrar.cash_account.account_activities.last - a.description.should == 'Add money' - a.sum.should == BigDecimal.new('13.32') - a.log_pricelist_id.should == nil - - @registrar.debit!({ sum: 10.31, description: 'Remove money' }) - @registrar.balance.should == BigDecimal.new('3.01') - @registrar.cash_account.account_activities.count.should == 2 - a = @registrar.cash_account.account_activities.last - a.description.should == 'Remove money' - a.sum.should == -BigDecimal.new('10.31') - end end end diff --git a/spec/models/whois_record_spec.rb b/spec/models/whois_record_spec.rb deleted file mode 100644 index 95c4c2082..000000000 --- a/spec/models/whois_record_spec.rb +++ /dev/null @@ -1,139 +0,0 @@ -require 'rails_helper' - -describe WhoisRecord do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - end - - context 'with invalid attribute' do - before :all do - @whois_record = WhoisRecord.new - end - - it 'should not be valid' do - @whois_record.valid? - @whois_record.errors.full_messages.should match_array([ - "Body is missing", - "Domain is missing", - "Json is missing", - "Name is missing" - ]) - end - - it 'should not support versions' do - @whois_record.respond_to?(:versions).should == false - end - - it 'should not have whois body' do - @whois_record.body.should == nil - end - - it 'should not have registrar' do - @whois_record.registrar.should == nil - end - end - - context 'with valid attributes' do - before :all do - @whois_record = Fabricate(:domain).whois_record - end - - it 'should be valid' do - @whois_record.valid? - @whois_record.errors.full_messages.should match_array([]) - end - - it 'should be valid twice' do - @whois_record = Fabricate(:domain).whois_record - @whois_record.valid? - @whois_record.errors.full_messages.should match_array([]) - end - - it 'should have registrar' do - @whois_record.registrar.present?.should == true - end - - it 'should have whois body by default' do - @whois_record.body.present?.should == true - end - - it 'should have whois json by default' do - @whois_record.json.present?.should == true - end - - it 'should have whois record present by default' do - @domain = Fabricate(:domain, name: 'yeah.ee') - @domain.updated_at = Time.zone.parse('2020.02.02 02:00') - @domain.valid_to = Time.zone.parse('2016.04.21 0:00') - registrar = Fabricate(:registrar, - name: 'First Registrar Ltd', - created_at: Time.zone.parse('1995.01.01'), - updated_at: Time.zone.parse('1996.01.01')) - @domain.registrant = Fabricate(:registrant, - name: 'Jarren Jakubowski0', - created_at: Time.zone.parse('2005.01.01')) - @domain.admin_contacts = [Fabricate(:contact, - name: 'First Admin', - registrar: registrar, - created_at: Time.zone.parse('2016.01.01'))] - @domain.tech_contacts = [Fabricate(:contact, - name: 'First Tech', - registrar: registrar, - created_at: Time.zone.parse('2016.01.01'))] - @domain.registrar = registrar - ns1 = Fabricate(:nameserver, hostname: 'test.ee') - ns1.updated_at = Time.zone.parse('1980.01.01') - ns2 = Fabricate(:nameserver, hostname: 'test1.ee') - ns2.updated_at = Time.zone.parse('1970.01.01') - @domain.nameservers = [ns1, ns2] - - @domain.save - - # load some very dynamic attributes - registered = @domain.whois_record.json['registered'] - changed = @domain.whois_record.json['updated_at'] - - @domain.whois_record.body.should == <<-EOS -Estonia .ee Top Level Domain WHOIS server - -Domain: - name: yeah.ee - registrant: Jarren Jakubowski0 - status: ok (paid and in zone) - registered: #{Time.zone.parse(registered)} - changed: #{Time.zone.parse(changed)} - expire: 2016-04-21 00:00:00 UTC - outzone: - delete: - -Administrative contact - name: First Admin - email: Not Disclosed - Visit www.internet.ee for webbased WHOIS - registrar: First Registrar Ltd - created: 2016-01-01 00:00:00 UTC - -Technical contact: - name: First Tech - email: Not Disclosed - Visit www.internet.ee for webbased WHOIS - registrar: First Registrar Ltd - created: 2016-01-01 00:00:00 UTC - -Registrar: - name: First Registrar Ltd - phone: - address: Street 999, Town, County, Postal - changed: 1996-01-01 00:00:00 UTC - -Name servers: - nserver: test.ee - changed: 1980-01-01 00:00:00 UTC - - nserver: test1.ee - changed: 1970-01-01 00:00:00 UTC - -Estonia .ee Top Level Domain WHOIS server -More information at http://internet.ee - EOS - end - end -end diff --git a/spec/models/zonefile_setting_spec.rb b/spec/models/zonefile_setting_spec.rb index 9405aa063..9b58f89dc 100644 --- a/spec/models/zonefile_setting_spec.rb +++ b/spec/models/zonefile_setting_spec.rb @@ -26,8 +26,6 @@ describe ZonefileSetting do @zonefile.scan(/ee.aso.ee. IN AAAA 2a02:88:0:21::2\nb.tld.ee. IN AAAA 2001:67c:1010:28::53/).count.should == 1 @zonefile.scan(/^#{d.name}/).count.should == 5 - @zonefile.scan(/ns.#{d.name}/).count.should == 3 - @zonefile.scan('123.123.123.123').count.should == 1 @zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 1 @zonefile = ActiveRecord::Base.connection.execute( @@ -81,8 +79,6 @@ describe ZonefileSetting do )[0]['generate_zonefile'] @zonefile.should_not be_blank - @zonefile.scan(/^#{d.name}/).count.should == 5 - @zonefile.scan(/ns.#{d.name}/).count.should == 3 @zonefile.scan('123.123.123.123').count.should == 1 @zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 1 end diff --git a/spec/requests/repp_doc_template.md.erb b/spec/requests/repp_doc_template.md.erb deleted file mode 100644 index 100e95081..000000000 --- a/spec/requests/repp_doc_template.md.erb +++ /dev/null @@ -1,20 +0,0 @@ -<%# coding: UTF-8 -%> -## <%= title %> -<%= description %> -<% rid = route_info_doc %> -<% if rid %> -#### Parameters - -<%= rid %> -<% end %> -#### Request -``` -<%= method %> <%= request.path %><%= request_query %> <%= request_http_version %> -<%= request_header %><%= request_body_section %> -``` - -#### Response -``` -<%= response_http_version %> <%= response.status %> -<%= response_header %><%= response_body_section %> -``` diff --git a/spec/requests/v1/account_spec.rb b/spec/requests/v1/account_spec.rb deleted file mode 100644 index e99a460a5..000000000 --- a/spec/requests/v1/account_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'rails_helper' - -describe Repp::AccountV1 do - it 'should fail without whitelisted IP' do - ENV['webclient_ips'] = '192.188.1.1' - Setting.api_ip_whitelist_enabled = true - @registrar1 = Fabricate(:registrar, white_ips: [Fabricate(:white_ip_registrar, ipv4: '99.99.99.99')]) - @api_user = Fabricate(:api_user, registrar: @registrar1) - - get_with_auth '/repp/v1/accounts/balance', {}, @api_user - response.status.should == 401 - body = JSON.parse(response.body) - - body['error'].should == 'IP is not whitelisted' - ENV['webclient_ips'] = '127.0.0.1' - Setting.api_ip_whitelist_enabled = false - end - - context 'with valid registrar' do - before :all do - @registrar1 = Fabricate(:registrar1) - @registrar1.accounts = [Fabricate(:account, { balance: '324.45', account_activities: [] })] - @registrar1.save - @api_user = Fabricate(:gitlab_api_user, registrar: @registrar1) - end - - describe 'GET /repp/v1/accounts/balance' do - it 'returns account balance of the current registrar', autodoc: true, route_info_doc: true do - get_with_auth '/repp/v1/accounts/balance', {}, @api_user - response.status.should == 200 - - body = JSON.parse(response.body) - body['balance'].should == '324.45' - body['currency'].should == 'EUR' - - log = ApiLog::ReppLog.last - log[:request_path].should == '/repp/v1/accounts/balance' - log[:request_method].should == 'GET' - log[:request_params].should == '{}' - log[:response_code].should == '200' - log[:api_user_name].should == 'gitlab' - log[:api_user_registrar].should == 'registrar1' - log[:ip].should == '127.0.0.1' - end - end - end -end diff --git a/spec/requests/v1/contact_spec.rb b/spec/requests/v1/contact_spec.rb deleted file mode 100644 index 6db06c28d..000000000 --- a/spec/requests/v1/contact_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -require 'rails_helper' - -describe Repp::ContactV1 do - before :all do - @api_user = Fabricate(:gitlab_api_user) - Fabricate.times(2, :contact, registrar: @api_user.registrar) - Fabricate.times(2, :contact) - end - - describe 'GET /repp/v1/contacts' do - it 'returns contacts of the current registrar', autodoc: true, route_info_doc: true do - get_with_auth '/repp/v1/contacts', { limit: 1, details: true }, @api_user - expect(response.status).to eq(200) - - body = JSON.parse(response.body) - body['total_number_of_records'].should == 2 - - # TODO: Maybe there is a way not to convert from and to json again - expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.limit(1).to_json) - - log = ApiLog::ReppLog.last - expect(log[:request_path]).to eq('/repp/v1/contacts') - expect(log[:request_method]).to eq('GET') - expect(log[:request_params]).to eq('{"limit":1,"details":"true"}') - expect(log[:response].length).to be > 20 - expect(log[:response_code]).to eq('200') - expect(log[:api_user_name]).to eq('gitlab') - expect(log[:ip]).to eq('127.0.0.1') - end - - it 'returns contact names with offset', autodoc: true do - get_with_auth '/repp/v1/contacts', { offset: 1 }, @api_user - expect(response.status).to eq(200) - - body = JSON.parse(response.body) - body['total_number_of_records'].should == 2 - - # TODO: Maybe there is a way not to convert from and to json again - expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.offset(1).pluck(:code).to_json) - - log = ApiLog::ReppLog.last - expect(log[:request_path]).to eq('/repp/v1/contacts') - expect(log[:request_method]).to eq('GET') - expect(log[:request_params]).to eq('{"offset":1}') - expect(log[:response].length).to be > 20 - expect(log[:response_code]).to eq('200') - expect(log[:api_user_name]).to eq('gitlab') - expect(log[:ip]).to eq('127.0.0.1') - end - - it 'returns contact names of the current registrar' do - get_with_auth '/repp/v1/contacts', {}, @api_user - expect(response.status).to eq(200) - - body = JSON.parse(response.body) - body['total_number_of_records'].should == 2 - - # TODO: Maybe there is a way not to convert from and to json again - expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.pluck(:code).to_json) - - log = ApiLog::ReppLog.last - expect(log[:request_path]).to eq('/repp/v1/contacts') - expect(log[:request_method]).to eq('GET') - expect(log[:request_params]).to eq('{}') - expect(log[:response].length).to be > 20 - expect(log[:response_code]).to eq('200') - expect(log[:api_user_name]).to eq('gitlab') - expect(log[:ip]).to eq('127.0.0.1') - end - - it 'returns an error with invalid parameters in contact index' do - get_with_auth '/repp/v1/contacts', { limit: 0 }, @api_user - expect(response.status).to eq(400) - - body = JSON.parse(response.body) - body['error'].should == 'limit does not have a valid value' - - # TODO: Log failed API requests too - end - end -end diff --git a/spec/requests/v1/domain_spec.rb b/spec/requests/v1/domain_spec.rb deleted file mode 100644 index e79f2e71b..000000000 --- a/spec/requests/v1/domain_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -require 'rails_helper' - -describe Repp::DomainV1 do - before :all do - Fabricate(:zonefile_setting, origin: 'ee') - @registrar1 = Fabricate(:registrar1) - @api_user = Fabricate(:gitlab_api_user, registrar: @registrar1) - Fabricate.times(2, :domain, registrar: @api_user.registrar) - end - - describe 'GET /repp/v1/domains' do - it 'returns domains of the current registrar', autodoc: true, route_info_doc: true do - get_with_auth '/repp/v1/domains', { limit: 1, details: true }, @api_user - response.status.should == 200 - - body = JSON.parse(response.body) - body['total_number_of_records'].should == 2 - - # TODO: Maybe there is a way not to convert from and to json again - body['domains'].to_json.should == @api_user.reload.registrar.domains.limit(1).to_json - - log = ApiLog::ReppLog.last - log[:request_path].should == '/repp/v1/domains' - log[:request_method].should == 'GET' - log[:request_params].should == '{"limit":1,"details":"true"}' - log[:response_code].should == '200' - log[:api_user_name].should == 'gitlab' - log[:api_user_registrar].should == 'registrar1' - log[:ip].should == '127.0.0.1' - end - - it 'returns domain names with offset', autodoc: true do - get_with_auth '/repp/v1/domains', { offset: 1 }, @api_user - response.status.should == 200 - - body = JSON.parse(response.body) - body['total_number_of_records'].should == 2 - - # TODO: Maybe there is a way not to convert from and to json again - body['domains'].to_json.should == @api_user.reload.registrar.domains.offset(1).pluck(:name).to_json - - log = ApiLog::ReppLog.last - log[:request_path].should == '/repp/v1/domains' - log[:request_method].should == 'GET' - log[:request_params].should == '{"offset":1}' - log[:response_code].should == '200' - log[:api_user_name].should == 'gitlab' - log[:api_user_registrar].should == 'registrar1' - log[:ip].should == '127.0.0.1' - end - - it 'returns domain names of the current registrar' do - get_with_auth '/repp/v1/domains', {}, @api_user - response.status.should == 200 - - body = JSON.parse(response.body) - body['total_number_of_records'].should == 2 - - # TODO: Maybe there is a way not to convert from and to json again - body['domains'].to_json.should == @api_user.reload.registrar.domains.pluck(:name).to_json - - log = ApiLog::ReppLog.last - log[:request_path].should == '/repp/v1/domains' - log[:request_method].should == 'GET' - log[:request_params].should == '{}' - log[:response_code].should == '200' - log[:api_user_name].should == 'gitlab' - log[:api_user_registrar].should == 'registrar1' - log[:ip].should == '127.0.0.1' - end - - it 'returns an error with invalid parameters in domain index' do - get_with_auth '/repp/v1/domains', { limit: 0 }, @api_user - response.status.should == 400 - - body = JSON.parse(response.body) - body['error'].should == 'limit does not have a valid value' - - # TODO: Log failed API requests too - end - - it 'returns an error with invalid credentials' do - invalid_user = OpenStruct.new(username: 'bla', password: 'blabala') - get_with_auth '/repp/v1/domains', {}, invalid_user - response.status.should == 401 - - body = JSON.parse(response.body) - body['error'].should == 'API user not found' - end - end -end From 1b695170dfc832564bace06e1ddded5a367329d1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 02:36:37 +0300 Subject: [PATCH 17/24] Remove unused rspec support files #206 --- spec/rails_helper.rb | 5 - spec/support/autodoc.rb | 4 - spec/support/epp.rb | 375 ------------------------------ spec/support/epp_doc.rb | 18 -- spec/support/feature.rb | 20 -- spec/support/registrar_helpers.rb | 18 -- 6 files changed, 440 deletions(-) delete mode 100644 spec/support/autodoc.rb delete mode 100644 spec/support/epp.rb delete mode 100644 spec/support/epp_doc.rb delete mode 100644 spec/support/feature.rb delete mode 100644 spec/support/registrar_helpers.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index f3d0c1192..2e6927569 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -15,12 +15,7 @@ require 'support/matchers/alias_attribute' require 'support/matchers/active_job' require 'support/capybara' require 'support/database_cleaner' -require 'support/epp' -require 'support/epp_doc' -require 'support/feature' -require 'support/registrar_helpers' require 'support/request' -require 'support/autodoc' require 'support/paper_trail' ActiveRecord::Migration.maintain_test_schema! diff --git a/spec/support/autodoc.rb b/spec/support/autodoc.rb deleted file mode 100644 index 3ea2fee22..000000000 --- a/spec/support/autodoc.rb +++ /dev/null @@ -1,4 +0,0 @@ -Autodoc.configuration.path = 'doc/repp' -Autodoc.configuration.suppressed_request_header = ['Host'] -Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime'] -Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb') diff --git a/spec/support/epp.rb b/spec/support/epp.rb deleted file mode 100644 index 6d57e7d9e..000000000 --- a/spec/support/epp.rb +++ /dev/null @@ -1,375 +0,0 @@ -module Epp - # Example usage: - # - # login_as :gitlab - # - # Use block for temp login: - # - # login_as :registrar1 do - # your test code - # # will make request as registrar1 and logins back to previous session - # end - # - def login_as(user) - server.open_connection - - if block_given? - begin - epp_plain_request(login_xml_for(user), :xml) - yield - ensure - server.open_connection # return back to last login - epp_plain_request(login_xml_for(@last_user), :xml) - end - else - @last_user = user # save for block - epp_plain_request(login_xml_for(user), :xml) - end - end - - def login_xml_for(user) - @xml ||= EppXml.new(cl_trid: 'ABC-12345') - case user - when :gitlab - @gitlab_login_xml ||= - @xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' }) - when :registrar1 - @registrar1_login_xml ||= - @xml.session.login(clID: { value: 'registrar1' }, pw: { value: 'ghyt9e4fu' }) - when :registrar2 - @registrar2_login_xml ||= - @xml.session.login(clID: { value: 'registrar2' }, pw: { value: 'ghyt9e4fu' }) - end - end - - def read_body(filename) - File.read("spec/epp/requests/#{filename}") - end - - # handles connection and login automatically - def epp_request(data, *args) - server = server_zone - server = server_elkdata if args.include?(:elkdata) - - res = parse_response(server.request(data)) if args.include?(:xml) - if res - log(data, res[:parsed]) - return res - end - - res = parse_response(server.request(read_body(data))) - log(read_body(data), res[:parsed]) - return res - - rescue => e - e - end - - def epp_plain_request(data, *args) - options = args.extract_options! - # validate_input = options[:validate_input] != false # true by default - validate_output = options[:validate_output] != false # true by default - - # if validate_input && @xsd - # xml = Nokogiri::XML(data) - # @xsd.validate(xml).each do |error| - # fail Exception.new, error.to_s - # end - # end - - res = parse_response(server.send_request(data)) - if res - log(data, res[:raw]) - if validate_output && @xsd - @xsd.validate(Nokogiri(res[:raw])).each do |error| - fail Exception.new, error.to_s - end - end - return res - end - rescue => e - e - end - - def server - port = ENV['epp_port'] || 700 - hostname = ENV['epp_hostname'] || 'localhost' - # tag and password not in use, add those at login xml - @server ||= Epp::Server.new({ server: hostname, port: port, tag: '', password: '' }) - end - - def parse_response(raw) - res = Nokogiri::XML(raw) - - obj = { - results: [], - clTRID: res.css('epp trID clTRID').first.try(:text), - parsed: res.remove_namespaces!, - raw: raw - } - - res.css('epp response result').each do |x| - obj[:results] << { - result_code: x[:code], msg: x.css('msg').text, value: x.css('value > *').try(:first).try(:text) - } - end - - obj[:result_code] = obj[:results][0][:result_code] - obj[:msg] = obj[:results][0][:msg] - - obj - end - - # print output - def po(r) - puts r[:parsed].to_s - end - - def next_domain_name - "example#{rand(100_000_000_000_000_000)}.ee" - end - - ### REQUEST TEMPLATES ### - - def domain_info_xml(xml_params = {}) - defaults = { - name: { value: next_domain_name, attrs: { hosts: 'all' } }, - authInfo: { - pw: { value: '2fooBAR' } - } - } - - xml_params = defaults.deep_merge(xml_params) - - epp_xml = EppXml::Domain.new(cl_trid: false) - epp_xml.info(xml_params) - end - - # rubocop: disable Metrics/MethodLength - def domain_create_xml(xml_params = {}, dnssec_params = {}, custom_params = {}) - defaults = { - name: { value: next_domain_name }, - period: { value: '1', attrs: { unit: 'y' } }, - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.net' } }, - { hostAddr: { value: '192.0.2.2', attrs: { ip: 'v4' } } }, - { hostAddr: { value: '1080:0:0:0:8:800:200C:417A', attrs: { ip: 'v6' } } } - ] - }, - { - hostAttr: { - hostName: { value: 'ns2.example.net' } - } - } - ], - registrant: { value: 'FIXED:CITIZEN_1234' }, - _anonymus: [ - { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }, - { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } }, - { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } } - ] - } - - xml_params = defaults.deep_merge(xml_params) - - dnssec_defaults = { - _anonymus: [ - { keyData: { - flags: { value: '257' }, - protocol: { value: '3' }, - alg: { value: '5' }, - pubKey: { value: 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' } - } - }] - } - - dnssec_params = dnssec_defaults.deep_merge(dnssec_params) if dnssec_params != false - - custom_defaults = { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - } - - custom_params = custom_defaults.deep_merge(custom_params) if custom_params != false - - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - epp_xml.create(xml_params, dnssec_params, custom_params) - end - - def domain_create_xml_with_legal_doc(xml_params = {}) - defaults = { - name: { value: next_domain_name }, - period: { value: '1', attrs: { unit: 'y' } }, - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.net' } }, - { hostAddr: { value: '192.0.2.2', attrs: { ip: 'v4' } } }, - { hostAddr: { value: '1080:0:0:0:8:800:200C:417A', attrs: { ip: 'v6' } } } - ] - }, - { - hostAttr: { - hostName: { value: 'ns2.example.net' } - } - } - ], - registrant: { value: 'FIXED:CITIZEN_1234' }, - _anonymus: [ - { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }, - { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } }, - { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } } - ] - } - - xml_params = defaults.deep_merge(xml_params) - - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - - epp_xml.create(xml_params, {}, { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - }) - end - - def domain_create_with_invalid_ns_ip_xml - xml_params = { - name: { value: next_domain_name }, - period: { value: '1', attrs: { unit: 'y' } }, - ns: [ - { - hostAttr: { - hostName: { value: 'ns1.example.net' }, - hostAddr: { value: '192.0.2.2.invalid', attrs: { ip: 'v4' } } - } - }, - { - hostAttr: { - hostName: { value: 'ns2.example.net' }, - hostAddr: { value: 'invalid_ipv6', attrs: { ip: 'v6' } } - } - } - ], - registrant: { value: 'FIXED:CITIZEN_1234' }, - _anonymus: [ - { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }, - { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } }, - { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } } - ], - authInfo: { - pw: { - value: '2fooBAR' - } - } - } - - custom_params = { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - } - - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - epp_xml.create(xml_params, {}, custom_params) - end - - def domain_create_with_host_attrs - xml_params = { - name: { value: next_domain_name }, - period: { value: '1', attrs: { unit: 'y' } }, - ns: [ - { - hostAttr: [ - { hostName: { value: 'ns1.example.net' } }, - { hostAddr: { value: '192.0.2.2', attrs: { ip: 'v4' } } }, - { hostAddr: { value: '1080:0:0:0:8:800:200C:417A', attrs: { ip: 'v6' } } } - ] - }, - { - hostAttr: { - hostName: { value: 'ns2.example.net' } - } - } - ], - registrant: { value: 'FIXED:CITIZEN_1234' }, - _anonymus: [ - { contact: { value: 'FIXED:SH8013', attrs: { type: 'admin' } } }, - { contact: { value: 'FIXED:SH8013', attrs: { type: 'tech' } } }, - { contact: { value: 'FIXED:SH801333', attrs: { type: 'tech' } } } - ], - authInfo: { - pw: { - value: '2fooBAR' - } - } - } - - custom_params = { - _anonymus: [ - legalDocument: { - value: 'dGVzdCBmYWlsCg==', - attrs: { type: 'pdf' } - } - ] - } - - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - epp_xml.create(xml_params, {}, custom_params) - end - - def domain_update_xml(xml_params = {}, dnssec_params = {}, custom_params = {}) - defaults = { - name: { value: next_domain_name } - } - - xml_params = defaults.deep_merge(xml_params) - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - epp_xml.update(xml_params, dnssec_params, custom_params) - end - - def domain_check_xml(xml_params = {}) - defaults = { - _anonymus: [ - { name: { value: next_domain_name } } - ] - } - xml_params = defaults.deep_merge(xml_params) - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - epp_xml.check(xml_params) - end - - def domain_transfer_xml(xml_params = {}, op = 'request', custom_params = {}) - defaults = { - name: { value: next_domain_name }, - period: nil, - authInfo: nil - } - - xml_params = defaults.deep_merge(xml_params) - epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345') - epp_xml.transfer(xml_params, op, custom_params) - end - - def log(req, res) - return unless ENV['EPP_DOC'] - puts "REQUEST:\n\n```xml\n#{Nokogiri(req)}```\n\n" - puts "RESPONSE:\n\n```xml\n#{Nokogiri(res)}```\n\n" - end -end - -RSpec.configure do |c| - c.include Epp, epp: true -end diff --git a/spec/support/epp_doc.rb b/spec/support/epp_doc.rb deleted file mode 100644 index 2aa3b3451..000000000 --- a/spec/support/epp_doc.rb +++ /dev/null @@ -1,18 +0,0 @@ -class EppDoc - RSpec::Core::Formatters.register self, :start, :example_started - - def initialize(output) - @output = output - end - - def start(example_count) - @output.puts '# EPP REQUEST - RESPONSE EXAMPLES' - @output.puts "GENERATED AT: #{Time.zone.now} " - @output.puts "EXAMPLE COUNT: #{example_count.count} " - @output.puts "\n---\n\n" - end - - def example_started(notification) - @output.puts "### #{notification.example.full_description} \n\n" - end -end diff --git a/spec/support/feature.rb b/spec/support/feature.rb deleted file mode 100644 index 5b6ab730f..000000000 --- a/spec/support/feature.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Feature - def sign_in(user) - visit '/admin/logout' - - if user.username == 'user1' - fill_in 'admin_user_username', with: 'user1' - fill_in 'admin_user_password', with: 'testtest' - end - if user.username == 'gitlab' - fill_in 'admin_user_username', with: 'gitlab' - fill_in 'admin_user_password', with: 'ghyt9e4fu' - end - - click_on 'Log in' - end -end - -RSpec.configure do |c| - c.include Feature, type: :feature -end diff --git a/spec/support/registrar_helpers.rb b/spec/support/registrar_helpers.rb deleted file mode 100644 index e246242d6..000000000 --- a/spec/support/registrar_helpers.rb +++ /dev/null @@ -1,18 +0,0 @@ -module RegistrarHelpers - def registrar_sign_in(_user = nil) - # TODO: try to make it run with before :all and speed it up - visit registrar_login_path - page.should have_css('a[href="/registrar/login/mid"]') - - page.find('a[href="/registrar/login/mid"]').click - - fill_in 'user_phone', with: '123' - click_button 'Log in' - - page.should have_text('Log out') - end -end - -RSpec.configure do |c| - c.include RegistrarHelpers, type: :feature -end From d4f38b1fff2279494b05f435b4282789815193e7 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 03:10:34 +0300 Subject: [PATCH 18/24] Remove outdated specs #206 --- spec/models/pricelist_spec.rb | 185 --------------------------- spec/models/zonefile_setting_spec.rb | 108 ---------------- 2 files changed, 293 deletions(-) delete mode 100644 spec/models/pricelist_spec.rb delete mode 100644 spec/models/zonefile_setting_spec.rb diff --git a/spec/models/pricelist_spec.rb b/spec/models/pricelist_spec.rb deleted file mode 100644 index 4b680312a..000000000 --- a/spec/models/pricelist_spec.rb +++ /dev/null @@ -1,185 +0,0 @@ -require 'rails_helper' - -describe Pricelist do - before :all do - end - - context 'about class' do - end - - context 'with invalid attribute' do - before :all do - @pricelist = Pricelist.new - end - - it 'should not be valid' do - @pricelist.valid? - @pricelist.errors.full_messages.should match_array([ - "Category is missing", - "Duration is missing", - "Operation category is missing" - ]) - end - - it 'should not have creator' do - @pricelist.creator.should == nil - end - - it 'should not have updater' do - @pricelist.updator.should == nil - end - - it 'should not have any versions' do - @pricelist.versions.should == [] - end - - it 'should not have name' do - @pricelist.name.should == ' ' - end - end - - context 'with valid attributes' do - before :all do - @pricelist = Fabricate(:pricelist) - end - - it 'should be valid' do - @pricelist.valid? - @pricelist.errors.full_messages.should match_array([]) - end - - it 'should be valid twice' do - @pricelist = Fabricate(:pricelist) - @pricelist.valid? - @pricelist.errors.full_messages.should match_array([]) - end - - it 'should have name' do - @pricelist.name.should == 'create ee' - end - - it 'should have one version' do - with_versioning do - @pricelist.versions.reload.should == [] - @pricelist.price = 11 - @pricelist.save - @pricelist.errors.full_messages.should match_array([]) - @pricelist.versions.size.should == 1 - end - end - end - - it 'should return correct price' do - Pricelist.pricelist_for('ee', 'create', '1year').should == nil - - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.50, - valid_from: Time.zone.parse('2198-01-01'), - valid_to: Time.zone.parse('2199-01-01') - }) - - Pricelist.pricelist_for('ee', 'create', '1year').should == nil - - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.50, - valid_from: Time.zone.parse('2015-01-01'), - valid_to: nil - }) - - Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.50 - - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.30, - valid_from: Time.zone.parse('2015-01-01'), - valid_to: Time.zone.parse('2999-01-01') - }) - - Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.30 - - Fabricate.create(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.20, - valid_from: Time.zone.parse('2015-06-01'), - valid_to: Time.zone.parse('2999-01-01') - }) - - Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20 - - Fabricate.create(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.10, - valid_from: Time.zone.parse('2014-01-01'), - valid_to: Time.zone.parse('2999-01-01') - }) - - Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20 - - Fabricate.create(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.10, - valid_from: Time.zone.parse('2999-02-01'), - valid_to: Time.zone.parse('2999-01-01') - }) - - Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20 - - Fabricate.create(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.10, - valid_from: Time.zone.parse('2015-06-02'), - valid_to: nil - }) - - Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.20 - - Fabricate.create(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.10, - valid_from: Time.zone.parse('2015-07-01'), - valid_to: Time.zone.parse('2999-01-01') - }) - - Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 1.10 - - Fabricate.create(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 2.10, - valid_from: Time.zone.now.to_date, - valid_to: Time.zone.now.to_date - }) - - Pricelist.pricelist_for('ee', 'create', '1year').price.amount.should == 2.10 - - Fabricate.create(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '2years', - price: 1.20, - valid_from: Time.zone.parse('2015-07-01'), - valid_to: Time.zone.parse('2999-01-01') - }) - - Pricelist.pricelist_for('ee', 'create', '2years').price.amount.should == 1.20 - end -end diff --git a/spec/models/zonefile_setting_spec.rb b/spec/models/zonefile_setting_spec.rb deleted file mode 100644 index 9b58f89dc..000000000 --- a/spec/models/zonefile_setting_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -require 'rails_helper' - -describe ZonefileSetting do - it 'generates the zonefile' do - Fabricate(:zonefile_setting) - Fabricate(:zonefile_setting, origin: 'pri.ee') - - d = Fabricate(:domain_with_dnskeys, name: 'testpri.ee') - d.nameservers << Nameserver.new({ - hostname: "ns.#{d.name}", - ipv4: '123.123.123.123', - ipv6: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329' - }) - - @zonefile = ActiveRecord::Base.connection.execute( - "select generate_zonefile('ee')" - )[0]['generate_zonefile'] - - @zonefile.should_not be_blank - - # origin ns - @zonefile.scan(/ee. IN NS ns.ut.ee.\nee. IN NS ns.tld.ee./).count.should == 1 - # origin a - @zonefile.scan(/ns.ut.ee. IN A 193.40.5.99\nns.tld.ee. IN A 195.43.87.10/).count.should == 1 - # origin aaaa - @zonefile.scan(/ee.aso.ee. IN AAAA 2a02:88:0:21::2\nb.tld.ee. IN AAAA 2001:67c:1010:28::53/).count.should == 1 - - @zonefile.scan(/^#{d.name}/).count.should == 5 - @zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 1 - - @zonefile = ActiveRecord::Base.connection.execute( - "select generate_zonefile('pri.ee')" - )[0]['generate_zonefile'] - - @zonefile.should_not be_blank - - @zonefile.scan(/^#{d.name}/).count.should == 0 - end - - it 'should not place serverHold nor clientHold domains into zonefile' do - Fabricate(:zonefile_setting) - d = Fabricate(:domain_with_dnskeys, - name: 'testzone.ee', - statuses: ['serverHold', 'serverDeleteProhibited', 'clientHold']) - d.nameservers << Nameserver.new({ - hostname: "ns.#{d.name}", - ipv4: '123.123.123.123', - ipv6: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329' - }) - - @zonefile = ActiveRecord::Base.connection.execute( - "select generate_zonefile('ee')" - )[0]['generate_zonefile'] - - @zonefile.should_not be_blank - @zonefile.scan(/^#{d.name}/).count.should == 0 - @zonefile.scan(/ns.#{d.name}/).count.should == 0 - @zonefile.scan('123.123.123.123').count.should == 0 - @zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 0 - - d.statuses = ['clientHold', 'serverDeleteProhibited'] - d.save - - @zonefile = ActiveRecord::Base.connection.execute( - "select generate_zonefile('ee')" - )[0]['generate_zonefile'] - - @zonefile.should_not be_blank - @zonefile.scan(/^#{d.name}/).count.should == 0 - @zonefile.scan(/ns.#{d.name}/).count.should == 0 - @zonefile.scan('123.123.123.123').count.should == 0 - @zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 0 - - d.statuses = ['serverDeleteProhibited'] - d.save - - @zonefile = ActiveRecord::Base.connection.execute( - "select generate_zonefile('ee')" - )[0]['generate_zonefile'] - - @zonefile.should_not be_blank - @zonefile.scan('123.123.123.123').count.should == 1 - @zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 1 - end - - it 'does not create duplicate zones' do - Fabricate(:zonefile_setting) - zs = Fabricate.build(:zonefile_setting) - zs.save.should == false - zs.errors.full_messages.should match_array(["Origin has already been taken"]) - end - - it 'does not allow deleting zone when it has existing domains' do - zs = Fabricate(:zonefile_setting) - - d = Fabricate(:domain) - - zs.destroy.should == false - - zs.errors.full_messages.should match_array(["There are 1 domains in this zone"]) - ZonefileSetting.count.should == 1 - - d.destroy - zs.destroy - - ZonefileSetting.count.should == 0 - end -end From 152595f798e0e7e1fc9035d8f66db0bd0e1457f9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 14:05:04 +0300 Subject: [PATCH 19/24] Remove digidoc initializer #206 --- config/initializers/digidoc_logger.rb | 1 - 1 file changed, 1 deletion(-) delete mode 100644 config/initializers/digidoc_logger.rb diff --git a/config/initializers/digidoc_logger.rb b/config/initializers/digidoc_logger.rb deleted file mode 100644 index dc09ff5ed..000000000 --- a/config/initializers/digidoc_logger.rb +++ /dev/null @@ -1 +0,0 @@ -Digidoc::Client.logger = Logger.new('log/webservices.log') From 2d42bb2492d22f97acd57759841b30b8fa21e0df Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 14:31:54 +0300 Subject: [PATCH 20/24] Remove faker gem #206 --- Gemfile | 1 - Gemfile.lock | 3 --- spec/fabricators/address_fabricator.rb | 8 ++++---- spec/fabricators/contact_fabricator.rb | 6 +++--- spec/fabricators/nameserver_fabricator.rb | 2 +- spec/fabricators/registrant_fabricator.rb | 6 +++--- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index dca8f6382..51233b88b 100644 --- a/Gemfile +++ b/Gemfile @@ -166,6 +166,5 @@ end group :test do gem 'database_cleaner' - gem 'faker' gem 'factory_girl_rails' end diff --git a/Gemfile.lock b/Gemfile.lock index 3497dc08f..4cdce9047 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -211,8 +211,6 @@ GEM factory_girl_rails (4.7.0) factory_girl (~> 4.7.0) railties (>= 3.0.0) - faker (1.4.3) - i18n (~> 0.5) fastercsv (1.5.5) ffi (1.9.10) figaro (1.1.1) @@ -605,7 +603,6 @@ DEPENDENCIES epp-xml (= 1.0.5)! fabrication (= 2.13.2) factory_girl_rails - faker figaro (= 1.1.1) grape (= 0.12.0) guard (= 2.12.9) diff --git a/spec/fabricators/address_fabricator.rb b/spec/fabricators/address_fabricator.rb index 70aa7f867..ecdb50f58 100644 --- a/spec/fabricators/address_fabricator.rb +++ b/spec/fabricators/address_fabricator.rb @@ -1,6 +1,6 @@ Fabricator(:address) do - city Faker::Address.city - street Faker::Address.street_name - street2 Faker::Address.street_name - zip Faker::Address.zip + city 'test city' + street 'test street' + street2 'test street' + zip 12345 end diff --git a/spec/fabricators/contact_fabricator.rb b/spec/fabricators/contact_fabricator.rb index 68289d77c..8f68c518d 100644 --- a/spec/fabricators/contact_fabricator.rb +++ b/spec/fabricators/contact_fabricator.rb @@ -1,10 +1,10 @@ Fabricator(:contact) do registrar { Fabricate(:registrar) } - code { sequence(:code) { |i| "SH#{Faker::Number.number(8)}#{i}" } } + code { sequence(:code) { |i| "1234#{i}#{rand(1000)}" } } auth_info 'password' - name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } } + name 'test name' phone '+372.12345678' - email Faker::Internet.email + email { sequence(:email) { |i| "test#{i}@test.com" } } street 'Short street 11' city 'Tallinn' zip '11111' diff --git a/spec/fabricators/nameserver_fabricator.rb b/spec/fabricators/nameserver_fabricator.rb index 87d0d76d3..f73668b25 100644 --- a/spec/fabricators/nameserver_fabricator.rb +++ b/spec/fabricators/nameserver_fabricator.rb @@ -1,4 +1,4 @@ Fabricator(:nameserver) do - hostname { sequence(:hostname) { |i| "ns.#{Faker::Internet.domain_word}#{i}.ee" } } + hostname { sequence(:hostname) { |i| "ns.test#{i}.ee" } } ipv4 '192.168.1.1' end diff --git a/spec/fabricators/registrant_fabricator.rb b/spec/fabricators/registrant_fabricator.rb index 445134fb9..42cff7cdf 100644 --- a/spec/fabricators/registrant_fabricator.rb +++ b/spec/fabricators/registrant_fabricator.rb @@ -1,10 +1,10 @@ Fabricator(:registrant) do registrar { Fabricate(:registrar) } - code { sequence(:code) { |i| "REGISTRANT#{Faker::Number.number(8)}#{i}" } } + code { sequence(:code) { |i| "REGISTRANT#{i}#{rand(1000)}" } } auth_info 'password' - name { sequence(:name) { |i| "REGISTRANT #{Faker::Name.name}#{i}" } } + name 'test name' phone '+372.12345678' - email Faker::Internet.email + email { sequence(:email) { |i| "test#{i}@test.com" } } street 'Short street 11' city 'Tallinn' zip '11111' From 75e6ec754edccf8a5242796a04b49be095ab1e11 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 14:46:25 +0300 Subject: [PATCH 21/24] Update travis db config #206 --- config/database-travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/database-travis.yml b/config/database-travis.yml index e1fe34d16..8bd81faa4 100644 --- a/config/database-travis.yml +++ b/config/database-travis.yml @@ -3,7 +3,7 @@ default: &default adapter: postgresql encoding: unicode pool: 5 - username: postgres + username: postgres password: test: @@ -17,3 +17,7 @@ whois_test: api_log_test: <<: *default database: registry_api_log_test + +registrant_write_test: + <<: *default + database: registry_test From e9e348379cfbbb489a25bfed3985a1b28421f2bc Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 17:28:11 +0300 Subject: [PATCH 22/24] Add digidoc initializer #206 --- config/initializers/digidoc.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 config/initializers/digidoc.rb diff --git a/config/initializers/digidoc.rb b/config/initializers/digidoc.rb new file mode 100644 index 000000000..4ed1c9db3 --- /dev/null +++ b/config/initializers/digidoc.rb @@ -0,0 +1 @@ +Digidoc::Client.logger = Syslog::Logger.new('digidoc') From 3e477b2fb28786b826a4a2bd31f0d9c672bae616 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 18:37:32 +0300 Subject: [PATCH 23/24] Use syslog for digidoc gem #206 --- config/initializers/digidoc.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/digidoc.rb b/config/initializers/digidoc.rb index 4ed1c9db3..864f2b4ef 100644 --- a/config/initializers/digidoc.rb +++ b/config/initializers/digidoc.rb @@ -1 +1 @@ -Digidoc::Client.logger = Syslog::Logger.new('digidoc') +Digidoc::Client.logger = Syslog::Logger From 43c95fb31619756d11e282cf786299f8989b178e Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 25 Oct 2016 18:40:15 +0300 Subject: [PATCH 24/24] Update readme #206 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index af1094200..89abb51bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +25.10.2016 +* Outdated specs removed, failing specs fixed, rspec config improved + 19.10.2016 * BUG fix: Record current time for outzone on domain:delete EPP request * ForceDelete automatic notice: fixed et and ee wording to reflect the date the domain is actually deleted.