mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 02:09:39 +02:00
Add schema validations for session spec #2660
This commit is contained in:
parent
a9449bb05e
commit
2ecce2141e
6 changed files with 43 additions and 38 deletions
2
Gemfile
2
Gemfile
|
@ -68,7 +68,7 @@ gem 'digidoc_client', '~> 0.2.1'
|
||||||
|
|
||||||
# epp
|
# epp
|
||||||
gem 'epp', '~> 1.4.2', github: 'gitlabeu/epp'
|
gem 'epp', '~> 1.4.2', github: 'gitlabeu/epp'
|
||||||
gem 'epp-xml', '~> 0.10.4' # EPP XMLs
|
gem 'epp-xml', '~> 1.0.1' # EPP XMLs
|
||||||
gem 'uuidtools', '~> 2.1.4' # For unique IDs (used by the epp gem)
|
gem 'uuidtools', '~> 2.1.4' # For unique IDs (used by the epp gem)
|
||||||
|
|
||||||
# for importing legacy db
|
# for importing legacy db
|
||||||
|
|
|
@ -161,7 +161,7 @@ GEM
|
||||||
nokogiri (>= 1.4.0)
|
nokogiri (>= 1.4.0)
|
||||||
savon (>= 2.4.0)
|
savon (>= 2.4.0)
|
||||||
docile (1.1.5)
|
docile (1.1.5)
|
||||||
epp-xml (0.10.4)
|
epp-xml (1.0.1)
|
||||||
activesupport (~> 4.1)
|
activesupport (~> 4.1)
|
||||||
builder (~> 3.2)
|
builder (~> 3.2)
|
||||||
equalizer (0.0.11)
|
equalizer (0.0.11)
|
||||||
|
@ -512,7 +512,7 @@ DEPENDENCIES
|
||||||
devise (~> 3.4.1)
|
devise (~> 3.4.1)
|
||||||
digidoc_client (~> 0.2.1)
|
digidoc_client (~> 0.2.1)
|
||||||
epp (~> 1.4.2)!
|
epp (~> 1.4.2)!
|
||||||
epp-xml (~> 0.10.4)
|
epp-xml (~> 1.0.1)
|
||||||
fabrication (~> 2.12.2)
|
fabrication (~> 2.12.2)
|
||||||
faker (~> 1.3.0)
|
faker (~> 1.3.0)
|
||||||
figaro (~> 1.1.0)
|
figaro (~> 1.1.0)
|
||||||
|
|
|
@ -939,15 +939,6 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'renew command' do
|
|
||||||
it 'returns 2101-unimplemented command' do
|
|
||||||
response = epp_plain_request('contacts/renew.xml')
|
|
||||||
|
|
||||||
response[:msg].should == 'Unimplemented command'
|
|
||||||
response[:result_code].should == '2101'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_multiple_contacts_xml
|
def check_multiple_contacts_xml
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
||||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
|
||||||
<command>
|
|
||||||
<renew>
|
|
||||||
<contact:renew
|
|
||||||
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
|
|
||||||
<contact:id>info-4444</contact:id>
|
|
||||||
<contact:authInfo>
|
|
||||||
<contact:pw>2fooBAR</contact:pw>
|
|
||||||
</contact:authInfo>
|
|
||||||
</contact:renew>
|
|
||||||
</renew>
|
|
||||||
<clTRID>ABC-12345</clTRID>
|
|
||||||
</command>
|
|
||||||
</epp>
|
|
|
@ -5,6 +5,7 @@ describe 'EPP Session', epp: true do
|
||||||
@api_user = Fabricate(:gitlab_api_user)
|
@api_user = Fabricate(:gitlab_api_user)
|
||||||
@epp_xml = EppXml.new(cl_trid: 'ABC-12345')
|
@epp_xml = EppXml.new(cl_trid: 'ABC-12345')
|
||||||
@login_xml_cache = @epp_xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' })
|
@login_xml_cache = @epp_xml.session.login(clID: { value: 'gitlab' }, pw: { value: 'ghyt9e4fu' })
|
||||||
|
@xsd = Nokogiri::XML::Schema(File.read('doc/schemas/epp-1.0.xsd'))
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when not connected' do
|
context 'when not connected' do
|
||||||
|
@ -40,14 +41,15 @@ describe 'EPP Session', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prohibits further actions unless logged in' do
|
it 'prohibits further actions unless logged in' do
|
||||||
response = epp_plain_request(@epp_xml.domain.create, :xml)
|
@xsd = Nokogiri::XML::Schema(File.read('doc/schemas/domain-1.0.xsd'))
|
||||||
|
response = epp_plain_request(@epp_xml.domain.info(name: { value: 'test.ee' }), :xml)
|
||||||
response[:msg].should == 'You need to login first.'
|
response[:msg].should == 'You need to login first.'
|
||||||
response[:result_code].should == '2002'
|
response[:result_code].should == '2002'
|
||||||
response[:clTRID].should == 'ABC-12345'
|
response[:clTRID].should == 'ABC-12345'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not have clTRID in response if client does not send it' do
|
it 'should not have clTRID in response if client does not send it' do
|
||||||
epp_xml_no_cltrid = EppXml.new(cl_trid: '')
|
epp_xml_no_cltrid = EppXml.new(cl_trid: false)
|
||||||
wrong_user = epp_xml_no_cltrid.session.login(clID: { value: 'wrong-user' }, pw: { value: 'ghyt9e4fu' })
|
wrong_user = epp_xml_no_cltrid.session.login(clID: { value: 'wrong-user' }, pw: { value: 'ghyt9e4fu' })
|
||||||
response = epp_plain_request(wrong_user, :xml)
|
response = epp_plain_request(wrong_user, :xml)
|
||||||
response[:clTRID].should be_nil
|
response[:clTRID].should be_nil
|
||||||
|
@ -115,7 +117,22 @@ describe 'EPP Session', epp: true do
|
||||||
clID: { value: 'gitlab' },
|
clID: { value: 'gitlab' },
|
||||||
pw: { value: 'ghyt9e4fu' },
|
pw: { value: 'ghyt9e4fu' },
|
||||||
newPW: { value: '' }
|
newPW: { value: '' }
|
||||||
), :xml)
|
), validate_input: false)
|
||||||
|
|
||||||
|
response[:msg].should == 'Password is missing [password]'
|
||||||
|
response[:result_code].should == '2306'
|
||||||
|
|
||||||
|
@api_user.reload
|
||||||
|
@api_user.password.should == 'ghyt9e4fu'
|
||||||
|
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 == 'Password is missing [password]'
|
response[:msg].should == 'Password is missing [password]'
|
||||||
response[:result_code].should == '2306'
|
response[:result_code].should == '2306'
|
||||||
|
|
|
@ -66,15 +66,27 @@ module Epp
|
||||||
end
|
end
|
||||||
|
|
||||||
def epp_plain_request(data, *args)
|
def epp_plain_request(data, *args)
|
||||||
res = parse_response(server.send_request(data)) if args.include?(:xml)
|
options = args.extract_options!
|
||||||
if res
|
validate_input = options[:validate_input] != false # true by default
|
||||||
log(data, res[:parsed])
|
validate_output = options[:validate_output] != false # true by default
|
||||||
return res
|
|
||||||
|
if validate_input && @xsd
|
||||||
|
xml = Nokogiri::XML(data)
|
||||||
|
@xsd.validate(xml).each do |error|
|
||||||
|
fail Exception.new, error.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
res = parse_response(server.send_request(read_body(data)))
|
res = parse_response(server.send_request(data))
|
||||||
log(read_body(data), res[:parsed])
|
if res
|
||||||
|
log(data, res[:parsed])
|
||||||
|
if validate_output && @xsd
|
||||||
|
@xsd.validate(Nokogiri(res[:raw])).each do |error|
|
||||||
|
fail Exception.new, error.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
return res
|
return res
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
e
|
e
|
||||||
end
|
end
|
||||||
|
@ -127,7 +139,7 @@ module Epp
|
||||||
|
|
||||||
xml_params = defaults.deep_merge(xml_params)
|
xml_params = defaults.deep_merge(xml_params)
|
||||||
|
|
||||||
epp_xml = EppXml::Domain.new(cl_trid: '')
|
epp_xml = EppXml::Domain.new(cl_trid: false)
|
||||||
epp_xml.info(xml_params)
|
epp_xml.info(xml_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue