-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from internetee/registry-386
Validate contact phone for zeros
- Loading branch information
Showing
6 changed files
with
152 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class PhoneValidator < ActiveModel::EachValidator | ||
def validate_each(record, attribute, value) | ||
return if record.errors[:phone].any? | ||
|
||
splitted_phone = value.split('.') | ||
country_code = splitted_phone.first | ||
phone_number = splitted_phone.second | ||
|
||
if zeros_only?(country_code) || zeros_only?(phone_number) | ||
record.errors.add(attribute, :invalid) | ||
end | ||
end | ||
|
||
private | ||
|
||
def zeros_only?(value) | ||
value.delete('0+').empty? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'rails_helper' | ||
require_relative '../shared/phone' | ||
|
||
RSpec.describe 'EPP contact:create' do | ||
let(:request) { post '/epp/command/create', frame: request_xml } | ||
let(:request_xml) { <<-XML | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd"> | ||
<command> | ||
<create> | ||
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd"> | ||
<contact:postalInfo> | ||
<contact:name>test</contact:name> | ||
</contact:postalInfo> | ||
<contact:voice>#{phone}</contact:voice> | ||
<contact:email>[email protected]</contact:email> | ||
</contact:create> | ||
</create> | ||
<extension> | ||
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd"> | ||
<eis:ident type="org" cc="US">123456</eis:ident> | ||
</eis:extdata> | ||
</extension> | ||
</command> | ||
</epp> | ||
XML | ||
} | ||
|
||
before do | ||
sign_in_to_epp_area | ||
allow(Contact).to receive(:address_processing?).and_return(false) | ||
end | ||
|
||
include_examples 'EPP contact phone' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
RSpec.shared_examples 'EPP contact phone' do | ||
context 'when phone is valid' do | ||
let(:phone) { '+123.4' } | ||
|
||
specify do | ||
request | ||
expect(response).to have_code_of(1000) | ||
end | ||
end | ||
|
||
context 'when phone has invalid format' do | ||
let(:phone) { '1234' } | ||
|
||
specify do | ||
request | ||
expect(response).to have_code_of(2005) | ||
end | ||
end | ||
|
||
context 'when phone has only zeros' do | ||
let(:phone) { '+000.0' } | ||
|
||
specify do | ||
request | ||
expect(response).to have_code_of(2005) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'rails_helper' | ||
require_relative '../shared/phone' | ||
|
||
RSpec.describe 'EPP contact:update' do | ||
let!(:contact) { create(:contact, code: 'TEST') } | ||
let(:request) { post '/epp/command/update', frame: request_xml } | ||
let(:request_xml) { <<-XML | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd"> | ||
<command> | ||
<update> | ||
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd"> | ||
<contact:id>TEST</contact:id> | ||
<contact:chg> | ||
<contact:voice>#{phone}</contact:voice> | ||
</contact:chg> | ||
</contact:update> | ||
</update> | ||
</command> | ||
</epp> | ||
XML | ||
} | ||
|
||
before do | ||
sign_in_to_epp_area | ||
allow(Contact).to receive(:address_processing?).and_return(false) | ||
end | ||
|
||
include_examples 'EPP contact phone' | ||
end |