Simplify ip_service

This commit is contained in:
simon lehericey 2019-08-01 15:34:33 +02:00
parent fc8cebd78d
commit b7f8bb2fea
2 changed files with 13 additions and 7 deletions

View file

@ -3,13 +3,7 @@ class IPService
def ip_trusted?(ip)
ip_address = parse_address(ip)
if ip_address.nil?
false
elsif trusted_networks.present?
trusted_networks.any? { |network| network.include?(ip_address) }
else
false
end
trusted_networks.any? { |network| network.include?(ip_address) }
end
private

View file

@ -28,6 +28,18 @@ describe IPService do
it { is_expected.to be(false) }
end
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
end
context 'when a trusted network is defined' do