Add ISO 8601 validations

This commit is contained in:
Martin Lensment 2014-12-22 13:54:20 +02:00
parent b5bf21b127
commit 2ac59e68ff
10 changed files with 104 additions and 4 deletions

View file

@ -40,5 +40,29 @@ describe 'EPP Keyrelay', epp: true do
expect(zone.messages.queued.count).to eq(1)
end
it 'returns an error on invalid relative expiry' do
xml = epp_xml.keyrelay({
name: { value: 'example.ee' },
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_request(xml, :xml, :elkdata)
expect(response[:msg]).to eq('Expiry relative must be compatible to ISO 8601')
expect(response[:results][0][:value]).to eq('Invalid Expiry')
expect(zone.messages.queued.count).to eq(0)
end
end
end

View file

@ -0,0 +1,4 @@
Fabricator(:keyrelay) do
pa_date { DateTime.now }
expiry_relative 'P1W'
end

View file

@ -0,0 +1,23 @@
require 'rails_helper'
describe Keyrelay do
it { should belong_to(:domain) }
it { should belong_to(:requester) }
it { should belong_to(:accepter) }
it 'is in pending status' do
kr = Fabricate(:keyrelay)
expect(kr.status).to eq('pending')
end
it 'is in expired status' do
kr = Fabricate(:keyrelay, pa_date: DateTime.now - 2.weeks)
expect(kr.status).to eq('expired')
end
it 'does not accept invalid relative expiry' do
kr = Fabricate.build(:keyrelay, expiry_relative: 'adf')
expect(kr.save).to eq(false)
expect(kr.errors[:expiry_relative].first).to eq('Expiry relative must be compatible to ISO 8601')
end
end