demarches-normaliennes/spec/services/ip_service_spec.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

2019-04-03 14:24:05 +02:00
describe IPService do
describe '.ip_trusted?' do
2019-08-20 16:40:50 +02:00
after(:each) { ENV['TRUSTED_NETWORKS'] = nil }
2019-04-03 14:24:05 +02:00
subject { IPService.ip_trusted?(ip) }
context 'when the ip is nil' do
let(:ip) { nil }
it { is_expected.to be(false) }
end
context 'when the ip is defined' do
let(:ip) { '192.168.1.10' }
context 'when it belongs to a trusted network' do
before do
ENV['TRUSTED_NETWORKS'] = '10.0.0.0/8 192.168.0.0/16 bad_network'
end
it { is_expected.to be(true) }
end
context 'when it does not belong to a trusted network' do
before do
ENV['TRUSTED_NETWORKS'] = '10.0.0.0/8'
end
it { is_expected.to be(false) }
end
2019-08-01 15:34:33 +02:00
context 'when the trusted network is not defined' do
it { is_expected.to be(false) }
end
context 'when the trusted network is malformed' do
before do
ENV['TRUSTED_NETWORKS'] = 'bad network'
end
it { is_expected.to be(false) }
end
2019-04-03 14:24:05 +02:00
end
context 'when a trusted network is defined' do
before { ENV['TRUSTED_NETWORKS'] = '10.0.0.0/8' }
context 'when the ip is nil' do
let(:ip) { nil }
it { is_expected.to be(false) }
end
context 'when the ip is badly formatted' do
let(:ip) { 'yop' }
it { is_expected.to be(false) }
end
end
end
end