From d4a0f1e783209a8543b9a15a9c19d7b9b6f963dc Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 21 Jul 2015 17:02:31 +0300 Subject: [PATCH] Updated contact doc and added too long epp message #2753 --- app/controllers/epp_controller.rb | 2 +- app/models/contact.rb | 4 ++-- app/models/epp/contact.rb | 4 +++- config/locales/en.yml | 1 + doc/epp/contact.md | 3 ++- spec/epp/contact_spec.rb | 19 +++++++++---------- spec/models/contact_spec.rb | 2 +- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 5184b3ebb..1291bf3c0 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -102,7 +102,7 @@ class EppController < ApplicationController msg: 'handle_errors was executed when there were actually no errors' } # rubocop:disable Rails/Output - puts obj.errors.full_messages if Rails.env.test? + puts "FULL MESSAGE: #{obj.errors.full_messages} #{obj.errors.inspect}" if Rails.env.test? # rubocop: enable Rails/Output end diff --git a/app/models/contact.rb b/app/models/contact.rb index a5d558c98..4a33d6716 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -23,8 +23,8 @@ class Contact < ActiveRecord::Base validates :ident_country_code, presence: true, if: proc { |c| %w(bic priv).include? c.ident_type } validates :code, uniqueness: { message: :epp_id_taken }, - format: { with: /\A[\w\-\:]*\Z/i }, - length: { maximum: 100 } + format: { with: /\A[\w\-\:]*\Z/i, message: :invalid }, + length: { maximum: 100, message: :too_long_contact_code } validate :ident_valid_format? before_validation :set_ident_country_code diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index d85b16cec..e82e6b884 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -125,7 +125,9 @@ class Epp::Contact < Contact [:ident, :invalid], [:ident, :invalid_EE_identity_format], [:ident, :invalid_birthday_format], - [:ident, :invalid_country_code] + [:ident, :invalid_country_code], + [:code, :invalid], + [:code, :too_long_contact_code] ], '2302' => [ # Object exists [:code, :epp_id_taken] diff --git a/config/locales/en.yml b/config/locales/en.yml index e360bc69b..26d4e68c1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -36,6 +36,7 @@ en: attributes: code: blank: "Required parameter missing - code" + too_long_contact_code: "Contact code is too long, max 100 characters" name: blank: "Required parameter missing - name" phone: diff --git a/doc/epp/contact.md b/doc/epp/contact.md index 3ed0b1aae..8d0045506 100644 --- a/doc/epp/contact.md +++ b/doc/epp/contact.md @@ -13,7 +13,8 @@ Contact Mapping protocol short version: ----------------------- ------- ----------------- 1 1 Attribute: xmlns:contact="https://raw.githubusercontent.com/internetee/registry/alpha/doc/schemas/contact-eis-1.0.xsd" - 0-1 Contact id, optional, generated automatically if missing + 0-1 Contact id, optional, string, no spaces, max 100 characters, + generated automatically if missing 1 Postal information container 1 Full name of the contact 0 Org is not supported and must be blank or missing diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 5eb8a3832..166ce8659 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -170,26 +170,25 @@ describe 'EPP Contact', epp: true do Contact.last.code.should == 'FIRST0:ABC:ABC:12345' 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 - fit 'should not allow spaces in custom code' do - response = create_request({ id: { value: '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111' } }) + 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: { diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 86fe6fc90..4b99e9d0e 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -97,7 +97,7 @@ describe Contact do it 'should not accept long code' do @contact.code = 'verylongcode' * 100 @contact.valid? - @contact.errors[:code].should == ['is too long (maximum is 100 characters)'] + @contact.errors[:code].should == ['Contact code is too long, max 100 characters'] end it 'should have no related domain descriptions' do